Constantin Kaplinsky | 47ed8d3 | 2004-10-08 09:43:57 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 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 | |
| 21 | #include <rfb_win32/Registry.h> |
| 22 | #include <rfb_win32/Dialog.h> |
| 23 | #include <rfb_win32/Win32Util.h> |
| 24 | #include <rfb/ServerCore.h> |
| 25 | #include <rfb/secTypes.h> |
| 26 | #include <rfb/vncAuth.h> |
| 27 | |
| 28 | |
| 29 | extern rfb::VncAuthPasswdConfigParameter vncAuthPasswd; |
| 30 | |
| 31 | namespace rfb { |
| 32 | |
| 33 | namespace win32 { |
| 34 | |
| 35 | class VncPasswdDialog : public Dialog { |
| 36 | public: |
| 37 | VncPasswdDialog(const RegKey& rk) : Dialog(GetModuleHandle(0)), regKey(rk), warnPasswdInsecure(false) {} |
| 38 | bool showDialog() { |
| 39 | return Dialog::showDialog(MAKEINTRESOURCE(IDD_AUTH_VNC_PASSWD)); |
| 40 | } |
| 41 | bool onOk() { |
| 42 | TCharArray password1 = getItemString(IDC_PASSWORD1); |
| 43 | TCharArray password2 = getItemString(IDC_PASSWORD2);; |
| 44 | if (_tcscmp(password1.buf, password2.buf) != 0) { |
| 45 | MsgBox(0, _T("The supplied passwords do not match"), |
| 46 | MB_ICONEXCLAMATION | MB_OK); |
| 47 | return false; |
| 48 | } |
| 49 | if (warnPasswdInsecure && |
| 50 | (MsgBox(0, _T("Please note that your VNC password cannot be stored securely on this system. ") |
| 51 | _T("Are you sure you wish to continue?"), |
| 52 | MB_YESNO | MB_ICONWARNING) == IDNO)) |
| 53 | return false; |
| 54 | char passwd[9]; |
| 55 | memset(passwd, 0, sizeof(passwd)); |
| 56 | strCopy(passwd, CStr(password1.buf), sizeof(passwd)); |
| 57 | vncAuthObfuscatePasswd(passwd); |
| 58 | regKey.setBinary(_T("Password"), passwd, 8); |
| 59 | return true; |
| 60 | } |
| 61 | void setWarnPasswdInsecure(bool warn) { |
| 62 | warnPasswdInsecure = warn; |
| 63 | } |
| 64 | protected: |
| 65 | const RegKey& regKey; |
| 66 | bool warnPasswdInsecure; |
| 67 | }; |
| 68 | |
| 69 | class AuthenticationPage : public PropSheetPage { |
| 70 | public: |
| 71 | AuthenticationPage(const RegKey& rk) |
| 72 | : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_AUTHENTICATION)), |
| 73 | passwd(rk), regKey(rk) {} |
| 74 | void initDialog() { |
| 75 | CharArray sec_types_str; |
| 76 | sec_types_str.buf = rfb::Server::sec_types.getData(); |
| 77 | std::list<int> sec_types = parseSecTypes(sec_types_str.buf); |
| 78 | |
| 79 | useNone = useVNC = false; |
| 80 | std::list<int>::iterator i; |
| 81 | for (i=sec_types.begin(); i!=sec_types.end(); i++) { |
| 82 | if ((*i) == secTypeNone) useNone = true; |
| 83 | else if ((*i) == secTypeVncAuth) useVNC = true; |
| 84 | } |
| 85 | |
| 86 | setItemChecked(IDC_AUTH_NONE, useNone); |
| 87 | setItemChecked(IDC_AUTH_VNC, useVNC); |
| 88 | setItemChecked(IDC_QUERY_CONNECT, rfb::Server::queryConnect); |
| 89 | } |
| 90 | bool onCommand(int id, int cmd) { |
| 91 | switch (id) { |
| 92 | case IDC_AUTH_VNC_PASSWD: |
| 93 | passwd.showDialog(); |
| 94 | return true; |
| 95 | case IDC_AUTH_NONE: |
| 96 | case IDC_AUTH_VNC: |
| 97 | case IDC_QUERY_CONNECT: |
| 98 | setChanged((rfb::Server::queryConnect != isItemChecked(IDC_QUERY_CONNECT)) || |
| 99 | (useNone != isItemChecked(IDC_AUTH_NONE)) || |
| 100 | (useVNC != isItemChecked(IDC_AUTH_VNC))); |
| 101 | return false; |
| 102 | }; |
| 103 | return false; |
| 104 | } |
| 105 | bool onOk() { |
| 106 | useVNC = isItemChecked(IDC_AUTH_VNC); |
| 107 | useNone = isItemChecked(IDC_AUTH_NONE); |
| 108 | if (useVNC) { |
| 109 | CharArray password = vncAuthPasswd.getVncAuthPasswd(); |
| 110 | if (!password.buf || strlen(password.buf) == 0) { |
| 111 | MsgBox(0, _T("The VNC authentication method is enabled, but no password is specified! ") |
| 112 | _T("The password dialog will now be shown."), MB_ICONEXCLAMATION | MB_OK); |
| 113 | passwd.showDialog(); |
| 114 | } |
| 115 | regKey.setString(_T("SecurityTypes"), _T("VncAuth")); |
| 116 | } else if (useNone) { |
| 117 | regKey.setString(_T("SecurityTypes"), _T("None")); |
| 118 | } |
| 119 | regKey.setString(_T("ReverseSecurityTypes"), _T("None")); |
| 120 | regKey.setBool(_T("QueryConnect"), isItemChecked(IDC_QUERY_CONNECT)); |
| 121 | return true; |
| 122 | } |
| 123 | void setWarnPasswdInsecure(bool warn) { |
| 124 | passwd.setWarnPasswdInsecure(warn); |
| 125 | } |
| 126 | protected: |
| 127 | RegKey regKey; |
| 128 | VncPasswdDialog passwd; |
| 129 | bool useNone; |
| 130 | bool useVNC; |
| 131 | }; |
| 132 | |
| 133 | }; |
| 134 | |
| 135 | }; |
| 136 | |
| 137 | #endif |