blob: b1d0eef3ec4822f4d0d8e99be930b233246a2919 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 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
Pierre Ossmana56bc862015-03-17 13:44:34 +010019#include <winsock2.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000020#include <windows.h>
21#include <commctrl.h>
22#include <string.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000023
24#include "resource.h"
25#include <rfb/Logger_stdio.h>
26#include <rfb/LogWriter.h>
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000027#include <rfb_win32/Dialog.h>
28#include <rfb_win32/RegConfig.h>
29#include <rfb_win32/CurrentUser.h>
30
31using namespace rfb;
32using namespace rfb::win32;
33
34static LogWriter vlog("main");
35
36
37#include <vncconfig/Authentication.h>
38#include <vncconfig/Connections.h>
39#include <vncconfig/Sharing.h>
40#include <vncconfig/Hooking.h>
41#include <vncconfig/Inputs.h>
42#include <vncconfig/Legacy.h>
43#include <vncconfig/Desktop.h>
44
45
Pierre Ossmanbc84faa2015-05-04 15:04:21 +020046TStr rfb::win32::AppName("TigerVNC Configuration");
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000047
48
49#ifdef _DEBUG
50BoolParameter captureDialogs("CaptureDialogs", "", false);
51#endif
52
53HKEY configKey = HKEY_CURRENT_USER;
54
55
56void
57processParams(int argc, char* argv[]) {
58 for (int i=1; i<argc; i++) {
59 if (strcasecmp(argv[i], "-service") == 0) {
60 configKey = HKEY_LOCAL_MACHINE;
61 } else if (strcasecmp(argv[i], "-user") == 0) {
62 configKey = HKEY_CURRENT_USER;
63 } else {
64 // Try to process <option>=<value>, or -<bool>
65 if (Configuration::setParam(argv[i], true))
66 continue;
67 // Try to process -<option> <value>
68 if ((argv[i][0] == '-') && (i+1 < argc)) {
69 if (Configuration::setParam(&argv[i][1], argv[i+1], true)) {
70 i++;
71 continue;
72 }
73 }
74 }
75 }
76}
77
78
79int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, char* cmdLine, int cmdShow) {
80
81 // Configure debugging output
82#ifdef _DEBUG
83 AllocConsole();
84 freopen("CONIN$","rb",stdin);
85 freopen("CONOUT$","wb",stdout);
86 freopen("CONOUT$","wb",stderr);
87 setbuf(stderr, 0);
88 initStdIOLoggers();
89 LogWriter vlog("main");
90 logParams.setParam("*:stderr:100");
91 vlog.info("Starting vncconfig applet");
92#endif
93
Adam Tkac33dfe5e2010-11-11 11:18:16 +000094 Configuration::enableServerParams();
95
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000096 try {
97 try {
98 // Process command-line args
99 int argc = __argc;
100 char** argv = __argv;
101 processParams(argc, argv);
102
103 /* *** Required if we wish to use IP address control
104 INITCOMMONCONTROLSEX icce;
105 icce.dwSize = sizeof(icce);
106 icce.dwICC = ICC_INTERNET_CLASSES;
107 InitCommonControlsEx(&icce);
108 */
109
110 // Create the required configuration registry key
111 RegKey rootKey;
Peter Åstrand4eacc022009-02-27 10:12:14 +0000112 rootKey.createKey(configKey, _T("Software\\TigerVNC\\WinVNC4"));
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000113
114 // Override whatever security it already had (NT only)
115 bool warnOnChangePassword = false;
116 try {
117 AccessEntries access;
118 Sid::Administrators adminSID;
119 Sid::SYSTEM systemSID;
120 access.addEntry(adminSID, KEY_ALL_ACCESS, GRANT_ACCESS);
121 access.addEntry(systemSID, KEY_ALL_ACCESS, GRANT_ACCESS);
122 UserSID userSID;
123 if (configKey == HKEY_CURRENT_USER)
124 access.addEntry(userSID, KEY_ALL_ACCESS, GRANT_ACCESS);
125 AccessControlList acl(CreateACL(access));
126
127 // Set the DACL, and don't allow the key to inherit its parent's DACL
128 rootKey.setDACL(acl, false);
129 } catch (rdr::SystemException& e) {
130 // Something weird happens on NT 4.0 SP5 but I can't reproduce it on other
131 // NT 4.0 service pack revisions.
132 if (e.err == ERROR_INVALID_PARAMETER) {
133 MsgBox(0, _T("Windows reported an error trying to secure the VNC Server settings for this user. ")
134 _T("Your settings may not be secure!"), MB_ICONWARNING | MB_OK);
135 } else if (e.err != ERROR_CALL_NOT_IMPLEMENTED &&
136 e.err != ERROR_NOT_LOGGED_ON) {
137 // If the call is not implemented, ignore the error and continue
138 // If we are on Win9x and no user is logged on, ignore error and continue
139 throw;
140 }
141 warnOnChangePassword = true;
142 }
143
144 // Start a RegConfig thread, to load in existing settings
145 RegConfigThread config;
Peter Åstrand4eacc022009-02-27 10:12:14 +0000146 config.start(configKey, _T("Software\\TigerVNC\\WinVNC4"));
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000147
148 // Build the dialog
149 std::list<PropSheetPage*> pages;
Adam Tkac670a09c2011-02-01 14:36:51 +0000150 SecPage auth(rootKey); pages.push_back(&auth);
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000151 auth.setWarnPasswdInsecure(warnOnChangePassword);
152 ConnectionsPage conn(rootKey); pages.push_back(&conn);
153 InputsPage inputs(rootKey); pages.push_back(&inputs);
154 SharingPage sharing(rootKey); pages.push_back(&sharing);
155 DesktopPage desktop(rootKey); pages.push_back(&desktop);
156 HookingPage hooks(rootKey); pages.push_back(&hooks);
157 LegacyPage legacy(rootKey, configKey == HKEY_CURRENT_USER); pages.push_back(&legacy);
158
159 // Load the default icon to use
160 HICON icon = (HICON)LoadImage(inst, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 0, 0, LR_SHARED);
161
162 // Create the PropertySheet handler
Pierre Ossmanf8d525b2014-07-09 17:02:27 +0200163 const TCHAR* propSheetTitle = _T("VNC Server Properties (Service-Mode)");
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000164 if (configKey == HKEY_CURRENT_USER)
165 propSheetTitle = _T("VNC Server Properties (User-Mode)");
166 PropSheet sheet(inst, propSheetTitle, pages, icon);
167
168#ifdef _DEBUG
169 vlog.debug("capture dialogs=%s", captureDialogs ? "true" : "false");
170 sheet.showPropSheet(0, true, false, captureDialogs);
171#else
172 sheet.showPropSheet(0, true, false);
173#endif
174 } catch (rdr::SystemException& e) {
175 switch (e.err) {
176 case ERROR_ACCESS_DENIED:
177 MsgBox(0, _T("You do not have sufficient access rights to run the VNC Configuration applet"),
178 MB_ICONSTOP | MB_OK);
179 return 1;
180 };
181 throw;
182 }
183
184 } catch (rdr::Exception& e) {
185 MsgBox(NULL, TStr(e.str()), MB_ICONEXCLAMATION | MB_OK);
186 return 1;
187 }
188
189 return 0;
190}