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.

Legacy.cxx 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 <vncconfig/Legacy.h>
  19. #include <rfb/LogWriter.h>
  20. #include <rfb_win32/CurrentUser.h>
  21. using namespace rfb;
  22. using namespace win32;
  23. static LogWriter vlog("Legacy");
  24. void LegacyPage::LoadPrefs()
  25. {
  26. // VNC 3.3.3R3 Preferences Algorithm, as described by vncProperties.cpp
  27. // - Load user-specific settings, based on logged-on user name,
  28. // from HKLM/Software/ORL/WinVNC3/<user>. If they don't exist,
  29. // try again with username "Default".
  30. // - Load system-wide settings from HKLM/Software/ORL/WinVNC3.
  31. // - If AllowProperties is non-zero then load the user's own
  32. // settings from HKCU/Software/ORL/WinVNC3.
  33. // Get the name of the current user
  34. CharArray username;
  35. try {
  36. UserName name;
  37. username.buf = name.takeBuf();
  38. } catch (rdr::SystemException& e) {
  39. if (e.err != ERROR_NOT_LOGGED_ON)
  40. throw;
  41. }
  42. // Open and read the WinVNC3 registry key
  43. allowProperties = true;
  44. RegKey winvnc3;
  45. try {
  46. winvnc3.openKey(HKEY_LOCAL_MACHINE, "Software\\ORL\\WinVNC3");
  47. int debugMode = winvnc3.getInt("DebugMode", 0);
  48. const char* debugTarget = 0;
  49. if (debugMode & 2) debugTarget = "file";
  50. if (debugMode & 4) debugTarget = "stderr";
  51. if (debugTarget) {
  52. char logSetting[32];
  53. sprintf(logSetting, "*:%s:%d", debugTarget, winvnc3.getInt("DebugLevel", 0));
  54. regKey.setString("Log", logSetting);
  55. }
  56. std::string authHosts = winvnc3.getString("AuthHosts", "");
  57. if (!authHosts.empty()) {
  58. CharArray newHosts;
  59. newHosts.buf = strDup("");
  60. // Reformat AuthHosts to Hosts. Wish I'd left the format the same. :( :( :(
  61. try {
  62. CharArray tmp(strDup(authHosts.c_str()));
  63. while (tmp.buf) {
  64. // Split the AuthHosts string into patterns to match
  65. CharArray first;
  66. rfb::strSplit(tmp.buf, ':', &first.buf, &tmp.buf);
  67. if (strlen(first.buf)) {
  68. int bits = 0;
  69. char pattern[1+4*4+4];
  70. pattern[0] = first.buf[0];
  71. pattern[1] = 0;
  72. // Split the pattern into IP address parts and process
  73. rfb::CharArray address;
  74. address.buf = rfb::strDup(&first.buf[1]);
  75. while (address.buf) {
  76. rfb::CharArray part;
  77. rfb::strSplit(address.buf, '.', &part.buf, &address.buf);
  78. if (bits)
  79. strcat(pattern, ".");
  80. if (strlen(part.buf) > 3)
  81. throw rdr::Exception("Invalid IP address part");
  82. if (strlen(part.buf) > 0) {
  83. strcat(pattern, part.buf);
  84. bits += 8;
  85. }
  86. }
  87. // Pad out the address specification if required
  88. int addrBits = bits;
  89. while (addrBits < 32) {
  90. if (addrBits) strcat(pattern, ".");
  91. strcat(pattern, "0");
  92. addrBits += 8;
  93. }
  94. // Append the number of bits to match
  95. char buf[4];
  96. sprintf(buf, "/%d", bits);
  97. strcat(pattern, buf);
  98. // Append this pattern to the Hosts value
  99. int length = strlen(newHosts.buf) + strlen(pattern) + 2;
  100. CharArray tmpHosts(length);
  101. strcpy(tmpHosts.buf, pattern);
  102. if (strlen(newHosts.buf)) {
  103. strcat(tmpHosts.buf, ",");
  104. strcat(tmpHosts.buf, newHosts.buf);
  105. }
  106. delete [] newHosts.buf;
  107. newHosts.buf = tmpHosts.takeBuf();
  108. }
  109. }
  110. // Finally, save the Hosts value
  111. regKey.setString("Hosts", newHosts.buf);
  112. } catch (rdr::Exception&) {
  113. MsgBox(0, "Unable to convert AuthHosts setting to Hosts format.",
  114. MB_ICONWARNING | MB_OK);
  115. }
  116. } else {
  117. regKey.setString("Hosts", "+");
  118. }
  119. regKey.setBool("LocalHost", winvnc3.getBool("LoopbackOnly", false));
  120. // *** check AllowLoopback?
  121. if (winvnc3.getBool("AuthRequired", true))
  122. regKey.setString("SecurityTypes", "VncAuth");
  123. else
  124. regKey.setString("SecurityTypes", "None");
  125. int connectPriority = winvnc3.getInt("ConnectPriority", 0);
  126. regKey.setBool("DisconnectClients", connectPriority == 0);
  127. regKey.setBool("AlwaysShared", connectPriority == 1);
  128. regKey.setBool("NeverShared", connectPriority == 2);
  129. } catch(rdr::Exception&) {
  130. }
  131. // Open the local, default-user settings
  132. allowProperties = true;
  133. try {
  134. RegKey userKey;
  135. userKey.openKey(winvnc3, "Default");
  136. vlog.info("loading Default prefs");
  137. LoadUserPrefs(userKey);
  138. } catch(rdr::Exception& e) {
  139. vlog.error("error reading Default settings:%s", e.str());
  140. }
  141. // Open the local, user-specific settings
  142. if (userSettings && username.buf) {
  143. try {
  144. RegKey userKey;
  145. userKey.openKey(winvnc3, username.buf);
  146. vlog.info("loading local User prefs");
  147. LoadUserPrefs(userKey);
  148. } catch(rdr::Exception& e) {
  149. vlog.error("error reading local User settings:%s", e.str());
  150. }
  151. // Open the user's own settings
  152. if (allowProperties) {
  153. try {
  154. RegKey userKey;
  155. userKey.openKey(HKEY_CURRENT_USER, "Software\\ORL\\WinVNC3");
  156. vlog.info("loading global User prefs");
  157. LoadUserPrefs(userKey);
  158. } catch(rdr::Exception& e) {
  159. vlog.error("error reading global User settings:%s", e.str());
  160. }
  161. }
  162. }
  163. // Disable the Options menu item if appropriate
  164. regKey.setBool("DisableOptions", !allowProperties);
  165. }
  166. void LegacyPage::LoadUserPrefs(const RegKey& key)
  167. {
  168. regKey.setInt("PortNumber", key.getBool("SocketConnect") ? key.getInt("PortNumber", 5900) : 0);
  169. if (key.getBool("AutoPortSelect", false)) {
  170. MsgBox(0, "The AutoPortSelect setting is not supported by this release."
  171. "The port number will default to 5900.",
  172. MB_ICONWARNING | MB_OK);
  173. regKey.setInt("PortNumber", 5900);
  174. }
  175. regKey.setInt("IdleTimeout", key.getInt("IdleTimeout", 0));
  176. regKey.setBool("RemoveWallpaper", key.getBool("RemoveWallpaper"));
  177. regKey.setBool("DisableEffects", key.getBool("DisableEffects"));
  178. if (key.getInt("QuerySetting", 2) != 2) {
  179. regKey.setBool("QueryConnect", key.getInt("QuerySetting") > 2);
  180. MsgBox(0, "The QuerySetting option has been replaced by QueryConnect."
  181. "Please see the documentation for details of the QueryConnect option.",
  182. MB_ICONWARNING | MB_OK);
  183. }
  184. regKey.setInt("QueryTimeout", key.getInt("QueryTimeout", 10));
  185. std::vector<uint8_t> passwd;
  186. passwd = key.getBinary("Password");
  187. regKey.setBinary("Password", passwd.data(), passwd.size());
  188. bool enableInputs = key.getBool("InputsEnabled", true);
  189. regKey.setBool("AcceptKeyEvents", enableInputs);
  190. regKey.setBool("AcceptPointerEvents", enableInputs);
  191. regKey.setBool("AcceptCutText", enableInputs);
  192. regKey.setBool("SendCutText", enableInputs);
  193. switch (key.getInt("LockSetting", 0)) {
  194. case 0: regKey.setString("DisconnectAction", "None"); break;
  195. case 1: regKey.setString("DisconnectAction", "Lock"); break;
  196. case 2: regKey.setString("DisconnectAction", "Logoff"); break;
  197. };
  198. regKey.setBool("DisableLocalInputs", key.getBool("LocalInputsDisabled", false));
  199. // *** ignore polling preferences
  200. // PollUnderCursor, PollForeground, OnlyPollConsole, OnlyPollOnEvent
  201. regKey.setBool("UseHooks", !key.getBool("PollFullScreen", false));
  202. if (key.isValue("AllowShutdown"))
  203. MsgBox(0, "The AllowShutdown option is not supported by this release.", MB_ICONWARNING | MB_OK);
  204. if (key.isValue("AllowEditClients"))
  205. MsgBox(0, "The AllowEditClients option is not supported by this release.", MB_ICONWARNING | MB_OK);
  206. allowProperties = key.getBool("AllowProperties", allowProperties);
  207. }