You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vncconfig.cxx 6.1KB

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