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