blob: f4b38f8c327bf8c0fc3caa1fae1b64eaa03ad1e1 [file] [log] [blame]
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18#ifndef WINVNCCONF_AUTHENTICATION
19#define WINVNCCONF_AUTHENTICATION
20
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000021#include <vncconfig/PasswordDialog.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000022#include <rfb_win32/Registry.h>
23#include <rfb_win32/Dialog.h>
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000024#include <rfb_win32/OSVersion.h>
25#include <rfb_win32/MsgBox.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000026#include <rfb/ServerCore.h>
27#include <rfb/secTypes.h>
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000028#include <rfb/Password.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000029
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000030static rfb::BoolParameter queryOnlyIfLoggedOn("QueryOnlyIfLoggedOn",
31 "Only prompt for a local user to accept incoming connections if there is a user logged on", false);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000032
33namespace rfb {
34
35 namespace win32 {
36
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000037 class AuthenticationPage : public PropSheetPage {
38 public:
39 AuthenticationPage(const RegKey& rk)
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000040 : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_AUTHENTICATION)), regKey(rk) {}
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000041 void initDialog() {
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000042 CharArray sec_types_str(SSecurityFactoryStandard::sec_types.getData());
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000043 std::list<int> sec_types = parseSecTypes(sec_types_str.buf);
44
45 useNone = useVNC = false;
46 std::list<int>::iterator i;
47 for (i=sec_types.begin(); i!=sec_types.end(); i++) {
48 if ((*i) == secTypeNone) useNone = true;
49 else if ((*i) == secTypeVncAuth) useVNC = true;
50 }
51
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000052 HWND security = GetDlgItem(handle, IDC_ENCRYPTION);
53 SendMessage(security, CB_ADDSTRING, 0, (LPARAM)_T("Always Off"));
54 SendMessage(security, CB_SETCURSEL, 0, 0);
55 enableItem(IDC_AUTH_NT, false); enableItem(IDC_AUTH_NT_CONF, false);
56 enableItem(IDC_ENCRYPTION, false); enableItem(IDC_AUTH_RA2_CONF, false);
57
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000058 setItemChecked(IDC_AUTH_NONE, useNone);
59 setItemChecked(IDC_AUTH_VNC, useVNC);
60 setItemChecked(IDC_QUERY_CONNECT, rfb::Server::queryConnect);
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000061 setItemChecked(IDC_QUERY_LOGGED_ON, queryOnlyIfLoggedOn);
62 onCommand(IDC_AUTH_NONE, 0);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000063 }
64 bool onCommand(int id, int cmd) {
65 switch (id) {
66 case IDC_AUTH_VNC_PASSWD:
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000067 {
68 PasswordDialog passwdDlg(regKey, registryInsecure);
69 passwdDlg.showDialog(handle);
70 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000071 return true;
72 case IDC_AUTH_NONE:
73 case IDC_AUTH_VNC:
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000074 enableItem(IDC_AUTH_VNC_PASSWD, isItemChecked(IDC_AUTH_VNC));
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000075 case IDC_QUERY_CONNECT:
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000076 case IDC_QUERY_LOGGED_ON:
77 setChanged((useNone != isItemChecked(IDC_AUTH_NONE)) ||
78 (useVNC != isItemChecked(IDC_AUTH_VNC)) ||
79 (rfb::Server::queryConnect != isItemChecked(IDC_QUERY_CONNECT)) ||
80 (queryOnlyIfLoggedOn != isItemChecked(IDC_QUERY_LOGGED_ON)));
81 enableItem(IDC_QUERY_LOGGED_ON, enableQueryOnlyIfLoggedOn());
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000082 return false;
83 };
84 return false;
85 }
86 bool onOk() {
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000087 bool useVncChanged = useVNC != isItemChecked(IDC_AUTH_VNC);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000088 useVNC = isItemChecked(IDC_AUTH_VNC);
89 useNone = isItemChecked(IDC_AUTH_NONE);
90 if (useVNC) {
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000091 verifyVncPassword(regKey);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000092 regKey.setString(_T("SecurityTypes"), _T("VncAuth"));
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +000093 } else {
94 if (haveVncPassword() && useVncChanged &&
95 MsgBox(0, _T("The VNC authentication method is disabled, but a password is still stored for it.\n")
96 _T("Do you want to remove the VNC authentication password from the registry?"),
97 MB_ICONWARNING | MB_YESNO) == IDYES) {
98 regKey.setBinary(_T("Password"), 0, 0);
99 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000100 regKey.setString(_T("SecurityTypes"), _T("None"));
101 }
102 regKey.setString(_T("ReverseSecurityTypes"), _T("None"));
103 regKey.setBool(_T("QueryConnect"), isItemChecked(IDC_QUERY_CONNECT));
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +0000104 regKey.setBool(_T("QueryOnlyIfLoggedOn"), isItemChecked(IDC_QUERY_LOGGED_ON));
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000105 return true;
106 }
107 void setWarnPasswdInsecure(bool warn) {
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +0000108 registryInsecure = warn;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000109 }
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +0000110 bool enableQueryOnlyIfLoggedOn() {
111 return isItemChecked(IDC_QUERY_CONNECT) && osVersion.isPlatformNT && (osVersion.dwMajorVersion >= 5);
112 }
113
114
115 static bool haveVncPassword() {
116 PlainPasswd password(SSecurityFactoryStandard::vncAuthPasswd.getVncAuthPasswd());
117 return password.buf && strlen(password.buf) != 0;
118 }
119
120 static void verifyVncPassword(const RegKey& regKey) {
121 if (!haveVncPassword()) {
122 MsgBox(0, _T("The VNC authentication method is enabled, but no password is specified.\n")
123 _T("The password dialog will now be shown."), MB_ICONINFORMATION | MB_OK);
124 PasswordDialog passwd(regKey, registryInsecure);
125 passwd.showDialog();
126 }
127 }
128
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000129 protected:
130 RegKey regKey;
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +0000131 static bool registryInsecure;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000132 bool useNone;
133 bool useVNC;
134 };
135
136 };
137
Constantin Kaplinsky7f8d7742006-05-11 05:29:14 +0000138 bool AuthenticationPage::registryInsecure = false;
139
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000140};
141
142#endif