blob: 18045c7710d93d731c13a4eb735540e044166027 [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
Constantin Kaplinsky729598c2006-05-25 05:12:25 +0000138 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}