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