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.0KB

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