📄 vncproperties.cpp
字号:
// for sysadmin-defined, user-specific settings. // 2. If not found, fall back to %username%=Default // 3. If AllowOverrides is set then load settings from // HKEY_CURRENT_USER/Software/ORL/WinVNC3 // GET THE CORRECT KEY TO READ FROM // Get the user name / service name if (!vncService::CurrentUser((char *)&username, sizeof(username))) return; // If there is no user logged on them default to SYSTEM if (strcmp(username, "") == 0) strcpy((char *)&username, "SYSTEM"); // Try to get the machine registry key for WinVNC if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, WINVNC_REGISTRY_KEY, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkLocal, &dw) != ERROR_SUCCESS) return; // Now try to get the per-user local key if (RegOpenKeyEx(hkLocal, username, 0, KEY_READ, &hkLocalUser) != ERROR_SUCCESS) hkLocalUser = NULL; // Get the default key if (RegCreateKeyEx(hkLocal, "Default", 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkDefault, &dw) != ERROR_SUCCESS) hkDefault = NULL; // LOAD THE MACHINE-LEVEL PREFS // Logging/debugging prefs vnclog.Print(LL_INTINFO, VNCLOG("loading local-only settings\n")); vnclog.SetMode(LoadInt(hkLocal, "DebugMode", 0)); vnclog.SetLevel(LoadInt(hkLocal, "DebugLevel", 0)); // Authentication required, loopback allowed, loopbackOnly m_server->SetLoopbackOnly(LoadInt(hkLocal, "LoopbackOnly", false)); if (m_server->LoopbackOnly()) m_server->SetLoopbackOk(true); else m_server->SetLoopbackOk(LoadInt(hkLocal, "AllowLoopback", false)); m_server->SetAuthRequired(LoadInt(hkLocal, "AuthRequired", true)); m_server->SetConnectPriority(LoadInt(hkLocal, "ConnectPriority", 0)); if (!m_server->LoopbackOnly()) { char *authhosts = LoadString(hkLocal, "AuthHosts"); if (authhosts != 0) { m_server->SetAuthHosts(authhosts); delete [] authhosts; } else { m_server->SetAuthHosts(0); } } else { m_server->SetAuthHosts(0); } // LOAD THE USER PREFERENCES // Set the default user prefs vnclog.Print(LL_INTINFO, VNCLOG("clearing user settings\n")); m_pref_HTTPConnect = TRUE; m_pref_AutoPortSelect=TRUE; m_pref_PortNumber=5900; m_pref_SockConnect=TRUE; m_pref_CORBAConn=FALSE; { vncPasswd::FromClear crypt; memcpy(m_pref_passwd, crypt, MAXPWLEN); } m_pref_QuerySetting=2; m_pref_QueryTimeout=10; m_pref_IdleTimeout=0; m_pref_EnableRemoteInputs=TRUE; m_pref_DisableLocalInputs=FALSE; m_pref_LockSettings=-1; m_pref_PollUnderCursor=FALSE; m_pref_PollForeground=TRUE; m_pref_PollFullScreen=FALSE; m_pref_PollConsoleOnly=TRUE; m_pref_PollOnEventOnly=FALSE; m_pref_RemoveWallpaper=TRUE; m_alloweditclients = TRUE; m_allowshutdown = TRUE; m_allowproperties = TRUE; // Load the local prefs for this user if (hkDefault != NULL) { vnclog.Print(LL_INTINFO, VNCLOG("loading DEFAULT local settings\n")); LoadUserPrefs(hkDefault); m_allowshutdown = LoadInt(hkDefault, "AllowShutdown", m_allowshutdown); m_allowproperties = LoadInt(hkDefault, "AllowProperties", m_allowproperties); m_alloweditclients = LoadInt(hkDefault, "AllowEditClients", m_alloweditclients); } // Are we being asked to load the user settings, or just the default local system settings? if (usersettings) { // We want the user settings, so load them! if (hkLocalUser != NULL) { vnclog.Print(LL_INTINFO, VNCLOG("loading \"%s\" local settings\n"), username); LoadUserPrefs(hkLocalUser); m_allowshutdown = LoadInt(hkLocalUser, "AllowShutdown", m_allowshutdown); m_allowproperties = LoadInt(hkLocalUser, "AllowProperties", m_allowproperties); m_alloweditclients = LoadInt(hkLocalUser, "AllowEditClients", m_alloweditclients); } // Now override the system settings with the user's settings // If the username is SYSTEM then don't try to load them, because there aren't any... if (m_allowproperties && (strcmp(username, "SYSTEM") != 0)) { HKEY hkGlobalUser; if (RegCreateKeyEx(HKEY_CURRENT_USER, WINVNC_REGISTRY_KEY, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkGlobalUser, &dw) == ERROR_SUCCESS) { vnclog.Print(LL_INTINFO, VNCLOG("loading \"%s\" global settings\n"), username); LoadUserPrefs(hkGlobalUser); RegCloseKey(hkGlobalUser); // Close the user registry hive so it can unload if required RegCloseKey(HKEY_CURRENT_USER); } } } else { vnclog.Print(LL_INTINFO, VNCLOG("bypassing user-specific settings (both local and global)\n")); } if (hkLocalUser != NULL) RegCloseKey(hkLocalUser); if (hkDefault != NULL) RegCloseKey(hkDefault); RegCloseKey(hkLocal); // Make the loaded settings active.. ApplyUserPrefs(); // Note whether we loaded the user settings or just the default system settings m_usersettings = usersettings;}voidvncProperties::LoadUserPrefs(HKEY appkey){ // LOAD USER PREFS FROM THE SELECTED KEY // Connection prefs m_pref_SockConnect=LoadInt(appkey, "SocketConnect", m_pref_SockConnect); m_pref_HTTPConnect=LoadInt(appkey, "HTTPConnect", m_pref_HTTPConnect); m_pref_AutoPortSelect=LoadInt(appkey, "AutoPortSelect", m_pref_AutoPortSelect); m_pref_PortNumber=LoadInt(appkey, "PortNumber", m_pref_PortNumber); m_pref_IdleTimeout=LoadInt(appkey, "IdleTimeout", m_pref_IdleTimeout); m_pref_RemoveWallpaper=LoadInt(appkey, "RemoveWallpaper", m_pref_RemoveWallpaper); // Connection querying settings m_pref_QuerySetting=LoadInt(appkey, "QuerySetting", m_pref_QuerySetting); m_pref_QueryTimeout=LoadInt(appkey, "QueryTimeout", m_pref_QueryTimeout); // Load the password LoadPassword(appkey, m_pref_passwd); // CORBA Settings m_pref_CORBAConn=LoadInt(appkey, "CORBAConnect", m_pref_CORBAConn); // Remote access prefs m_pref_EnableRemoteInputs=LoadInt(appkey, "InputsEnabled", m_pref_EnableRemoteInputs); m_pref_LockSettings=LoadInt(appkey, "LockSetting", m_pref_LockSettings); m_pref_DisableLocalInputs=LoadInt(appkey, "LocalInputsDisabled", m_pref_DisableLocalInputs); // Polling prefs m_pref_PollUnderCursor=LoadInt(appkey, "PollUnderCursor", m_pref_PollUnderCursor); m_pref_PollForeground=LoadInt(appkey, "PollForeground", m_pref_PollForeground); m_pref_PollFullScreen=LoadInt(appkey, "PollFullScreen", m_pref_PollFullScreen); m_pref_PollConsoleOnly=LoadInt(appkey, "OnlyPollConsole", m_pref_PollConsoleOnly); m_pref_PollOnEventOnly=LoadInt(appkey, "OnlyPollOnEvent", m_pref_PollOnEventOnly);}voidvncProperties::ApplyUserPrefs(){ // APPLY THE CACHED PREFERENCES TO THE SERVER // Update the connection querying settings m_server->SetQuerySetting(m_pref_QuerySetting); m_server->SetQueryTimeout(m_pref_QueryTimeout); m_server->SetAutoIdleDisconnectTimeout(m_pref_IdleTimeout); m_server->EnableRemoveWallpaper(m_pref_RemoveWallpaper); // Is the listening socket closing? if (!m_pref_SockConnect) m_server->SockConnect(m_pref_SockConnect); m_server->EnableHTTPConnect(m_pref_HTTPConnect); // Are inputs being disabled? if (!m_pref_EnableRemoteInputs) m_server->EnableRemoteInputs(m_pref_EnableRemoteInputs); if (m_pref_DisableLocalInputs) m_server->DisableLocalInputs(m_pref_DisableLocalInputs); // Update the password m_server->SetPassword(m_pref_passwd); // Now change the listening port settings m_server->SetAutoPortSelect(m_pref_AutoPortSelect); if (!m_pref_AutoPortSelect) m_server->SetPort(m_pref_PortNumber); m_server->SockConnect(m_pref_SockConnect); // Set the CORBA connection status m_server->CORBAConnect(m_pref_CORBAConn); // Remote access prefs m_server->EnableRemoteInputs(m_pref_EnableRemoteInputs); m_server->SetLockSettings(m_pref_LockSettings); m_server->DisableLocalInputs(m_pref_DisableLocalInputs); // Polling prefs m_server->PollUnderCursor(m_pref_PollUnderCursor); m_server->PollForeground(m_pref_PollForeground); m_server->PollFullScreen(m_pref_PollFullScreen); m_server->PollConsoleOnly(m_pref_PollConsoleOnly); m_server->PollOnEventOnly(m_pref_PollOnEventOnly);}voidvncProperties::SaveInt(HKEY key, LPCSTR valname, LONG val){ RegSetValueEx(key, valname, 0, REG_DWORD, (LPBYTE) &val, sizeof(val));}voidvncProperties::SavePassword(HKEY key, char *buffer){ RegSetValueEx(key, "Password", 0, REG_BINARY, (LPBYTE) buffer, MAXPWLEN);}voidvncProperties::Save(){ HKEY appkey; DWORD dw; if (!m_allowproperties) return; // NEW (R3) PREFERENCES ALGORITHM // The user's prefs are only saved if the user is allowed to override // the machine-local settings specified for them. Otherwise, the // properties entry on the tray icon menu will be greyed out. // GET THE CORRECT KEY TO READ FROM // Have we loaded user settings, or system settings? if (m_usersettings) { // Verify that we know who is logged on char username[UNLEN+1]; if (!vncService::CurrentUser((char *)&username, sizeof(username))) return; if (strcmp(username, "") == 0) return; // Try to get the per-user, global registry key for WinVNC if (RegCreateKeyEx(HKEY_CURRENT_USER, WINVNC_REGISTRY_KEY, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &appkey, &dw) != ERROR_SUCCESS) return; } else { // Try to get the default local registry key for WinVNC HKEY hkLocal; if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, WINVNC_REGISTRY_KEY, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkLocal, &dw) != ERROR_SUCCESS) { MessageBox(NULL, "MB1", "WVNC", MB_OK); return; } if (RegCreateKeyEx(hkLocal, "Default", 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &appkey, &dw) != ERROR_SUCCESS) { RegCloseKey(hkLocal); return; } RegCloseKey(hkLocal); } // SAVE PER-USER PREFS IF ALLOWED SaveUserPrefs(appkey); RegCloseKey(appkey); // Close the user registry hive, to allow it to unload if reqd RegCloseKey(HKEY_CURRENT_USER);}voidvncProperties::SaveUserPrefs(HKEY appkey){ // SAVE THE PER USER PREFS vnclog.Print(LL_INTINFO, VNCLOG("saving current settings to registry\n")); // Connection prefs SaveInt(appkey, "SocketConnect", m_server->SockConnected()); SaveInt(appkey, "HTTPConnect", m_server->HTTPConnectEnabled()); SaveInt(appkey, "AutoPortSelect", m_server->AutoPortSelect()); if (!m_server->AutoPortSelect()) SaveInt(appkey, "PortNumber", m_server->GetPort()); SaveInt(appkey, "InputsEnabled", m_server->RemoteInputsEnabled()); SaveInt(appkey, "LocalInputsDisabled", m_server->LocalInputsDisabled()); SaveInt(appkey, "IdleTimeout", m_server->AutoIdleDisconnectTimeout()); // Connection querying settings SaveInt(appkey, "QuerySetting", m_server->QuerySetting()); SaveInt(appkey, "QueryTimeout", m_server->QueryTimeout()); // Lock settings SaveInt(appkey, "LockSetting", m_server->LockSettings()); // Wallpaper removal SaveInt(appkey, "RemoveWallpaper", m_server->RemoveWallpaperEnabled()); // Save the password char passwd[MAXPWLEN]; m_server->GetPassword(passwd); SavePassword(appkey, passwd);#if(defined(_CORBA)) // Don't save the CORBA enabled flag if CORBA is not compiled in! SaveInt(appkey, "CORBAConnect", m_server->CORBAConnected());#endif // Polling prefs SaveInt(appkey, "PollUnderCursor", m_server->PollUnderCursor()); SaveInt(appkey, "PollForeground", m_server->PollForeground()); SaveInt(appkey, "PollFullScreen", m_server->PollFullScreen()); SaveInt(appkey, "OnlyPollConsole", m_server->PollConsoleOnly()); SaveInt(appkey, "OnlyPollOnEvent", m_server->PollOnEventOnly());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -