Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 3 | * 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 Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 21 | #include <vncconfig/PasswordDialog.h> |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 22 | #include <rfb_win32/Registry.h> |
| 23 | #include <rfb_win32/Dialog.h> |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 24 | #include <rfb_win32/OSVersion.h> |
| 25 | #include <rfb_win32/MsgBox.h> |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 26 | #include <rfb/ServerCore.h> |
| 27 | #include <rfb/secTypes.h> |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 28 | #include <rfb/Password.h> |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 29 | |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 30 | static rfb::BoolParameter queryOnlyIfLoggedOn("QueryOnlyIfLoggedOn", |
| 31 | "Only prompt for a local user to accept incoming connections if there is a user logged on", false); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 32 | |
| 33 | namespace rfb { |
| 34 | |
| 35 | namespace win32 { |
| 36 | |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 37 | class AuthenticationPage : public PropSheetPage { |
| 38 | public: |
| 39 | AuthenticationPage(const RegKey& rk) |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 40 | : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_AUTHENTICATION)), regKey(rk) {} |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 41 | void initDialog() { |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 42 | CharArray sec_types_str(SSecurityFactoryStandard::sec_types.getData()); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 43 | 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 Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 52 | 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 Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 58 | setItemChecked(IDC_AUTH_NONE, useNone); |
| 59 | setItemChecked(IDC_AUTH_VNC, useVNC); |
| 60 | setItemChecked(IDC_QUERY_CONNECT, rfb::Server::queryConnect); |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 61 | setItemChecked(IDC_QUERY_LOGGED_ON, queryOnlyIfLoggedOn); |
| 62 | onCommand(IDC_AUTH_NONE, 0); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 63 | } |
| 64 | bool onCommand(int id, int cmd) { |
| 65 | switch (id) { |
| 66 | case IDC_AUTH_VNC_PASSWD: |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 67 | { |
| 68 | PasswordDialog passwdDlg(regKey, registryInsecure); |
| 69 | passwdDlg.showDialog(handle); |
| 70 | } |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 71 | return true; |
| 72 | case IDC_AUTH_NONE: |
| 73 | case IDC_AUTH_VNC: |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 74 | enableItem(IDC_AUTH_VNC_PASSWD, isItemChecked(IDC_AUTH_VNC)); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 75 | case IDC_QUERY_CONNECT: |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 76 | 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 Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 82 | return false; |
| 83 | }; |
| 84 | return false; |
| 85 | } |
| 86 | bool onOk() { |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 87 | bool useVncChanged = useVNC != isItemChecked(IDC_AUTH_VNC); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 88 | useVNC = isItemChecked(IDC_AUTH_VNC); |
| 89 | useNone = isItemChecked(IDC_AUTH_NONE); |
| 90 | if (useVNC) { |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 91 | verifyVncPassword(regKey); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 92 | regKey.setString(_T("SecurityTypes"), _T("VncAuth")); |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 93 | } 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 Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 100 | regKey.setString(_T("SecurityTypes"), _T("None")); |
| 101 | } |
| 102 | regKey.setString(_T("ReverseSecurityTypes"), _T("None")); |
| 103 | regKey.setBool(_T("QueryConnect"), isItemChecked(IDC_QUERY_CONNECT)); |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 104 | regKey.setBool(_T("QueryOnlyIfLoggedOn"), isItemChecked(IDC_QUERY_LOGGED_ON)); |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 105 | return true; |
| 106 | } |
| 107 | void setWarnPasswdInsecure(bool warn) { |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 108 | registryInsecure = warn; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 109 | } |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 110 | 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 Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 129 | protected: |
| 130 | RegKey regKey; |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 131 | static bool registryInsecure; |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 132 | bool useNone; |
| 133 | bool useVNC; |
| 134 | }; |
| 135 | |
| 136 | }; |
| 137 | |
Constantin Kaplinsky | 7f8d774 | 2006-05-11 05:29:14 +0000 | [diff] [blame] | 138 | bool AuthenticationPage::registryInsecure = false; |
| 139 | |
Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | #endif |