Changeset 70f2d7b in nscp
- Timestamp:
- 03/29/06 22:19:32 (7 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 76aafc4
- Parents:
- aabbd97
- Files:
-
- 8 edited
-
NSClient++.cpp (modified) (5 diffs)
-
NSClient++.h (modified) (1 diff)
-
NSClient++.sln (modified) (1 diff)
-
include/INISettings.h (modified) (1 diff)
-
include/REGSettings.h (modified) (5 diffs)
-
include/Settings.h (modified) (2 diffs)
-
include/TSettings.h (modified) (1 diff)
-
include/config.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
NSClient++.cpp
rf42280d r70f2d7b 20 20 #include <Socket.h> 21 21 #include <b64/b64.h> 22 #include <config.h> 22 23 23 24 … … 65 66 g_bConsoleLog = true; 66 67 std::string password; 67 Settings::getInstance()->setFile(mainClient.getBasePath() + "NSC.ini"); 68 try { 69 Settings::getInstance()->setFile(mainClient.getBasePath() + "NSC.ini"); 70 } catch (SettingsException e) { 71 std::cout << "Could not find settings: " << e.getMessage() << std::endl;; 72 return 1; 73 } 68 74 std::cout << "Enter password to encrypt (has to be a single word): "; 69 75 std::cin >> password; … … 97 103 #endif 98 104 g_bConsoleLog = true; 99 mainClient.InitiateService(); 105 if (!mainClient.InitiateService()) { 106 LOG_ERROR_STD("Service *NOT* started!"); 107 return -1; 108 } 109 LOG_MESSAGE_STD("Using settings from: " + Settings::getInstance()->getActiveType()); 100 110 LOG_MESSAGE("Enter command to inject or exit to terminate..."); 101 111 std::string s = ""; … … 146 156 * When the program is started as a service this will be the entry point. 147 157 */ 148 void NSClientT::InitiateService(void) { 149 Settings::getInstance()->setFile(getBasePath() + "NSC.ini"); 150 158 bool NSClientT::InitiateService(void) { 159 try { 160 Settings::getInstance()->setFile(getBasePath() + "NSC.ini"); 161 } catch (SettingsException e) { 162 LOG_ERROR_STD("Could not find settings: " + e.getMessage()); 163 return false; 164 } 151 165 try { 152 166 simpleSocket::WSAStartup(); 153 167 } catch (simpleSocket::SocketException e) { 154 168 LOG_ERROR_STD("Uncaught exception: " + e.getMessage()); 169 return false; 155 170 } 156 171 … … 161 176 } catch(const NSPluginException& e) { 162 177 LOG_ERROR_STD("Exception raised: " + e.error_ + " in module: " + e.file_); 178 return false; 163 179 } 164 180 } 165 181 loadPlugins(); 182 return true; 166 183 } 167 184 /** -
NSClient++.h
r6817602 r70f2d7b 53 53 54 54 // Service helper functions 55 voidInitiateService(void);55 bool InitiateService(void); 56 56 void TerminateService(void); 57 57 static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv); -
NSClient++.sln
r6817602 r70f2d7b 119 119 {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Distribution.Build.0 = Debug|Win32 120 120 {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Release.ActiveCfg = Release|Win32 121 {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Release.Build.0 = Release|Win32122 121 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug|Win32 123 122 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.Build.0 = Debug|Win32 -
include/INISettings.h
raabbd97 r70f2d7b 25 25 { 26 26 } 27 std::string getActiveType() { 28 return "INI-file"; 29 } 27 30 28 31 static bool hasSettings(std::string file) { 29 std::cout << GetPrivateProfileInt(MAIN_SECTION_TITLE, MAIN_USEFILE, MAIN_USEFILE_DEFAULT, file.c_str()) << ":" << file << std::endl;30 32 return GetPrivateProfileInt(MAIN_SECTION_TITLE, MAIN_USEFILE, MAIN_USEFILE_DEFAULT, file.c_str()) == 1; 31 33 } -
include/REGSettings.h
raabbd97 r70f2d7b 6 6 #define BUFF_LEN 4096 7 7 8 #include <iostream> 8 9 class REGSettings : public TSettings 9 10 { … … 19 20 20 21 static bool hasSettings() { 21 // @todo 22 return false; 22 return getInt_(NS_HKEY_ROOT, NS_REG_ROOT, "use_reg", 0) == 1; 23 } 24 25 std::string getActiveType() { 26 return "registry"; 23 27 } 24 28 25 29 sectionList getSections(unsigned int bufferLength = BUFF_LEN) { 26 sectionList ret; 27 return ret; 30 return getSubKeys_(NS_HKEY_ROOT, NS_REG_ROOT); 28 31 } 29 32 … … 34 37 */ 35 38 sectionList getSection(std::string section, unsigned int bufferLength = BUFF_LEN) { 36 sectionList ret; 37 return ret; 39 return getValues_(NS_HKEY_ROOT, std::string((std::string)NS_REG_ROOT + "\\" + section).c_str()); 38 40 } 39 41 /** … … 45 47 */ 46 48 std::string getString(std::string section, std::string key, std::string defaultValue = "") const { 47 std::string ret; 48 return ret; 49 return getString_(NS_HKEY_ROOT, std::string((std::string)NS_REG_ROOT + "\\" + section).c_str(), key.c_str(), defaultValue); 49 50 } 50 51 … … 60 61 */ 61 62 int getInt(std::string section, std::string key, int defaultValue = 0) { 62 return 0;63 return getInt_(NS_HKEY_ROOT, std::string((std::string)NS_REG_ROOT + "\\" + section).c_str(), key.c_str(), defaultValue); 63 64 } 64 65 void setInt(std::string section, std::string key, int value) { 65 66 } 67 68 69 static std::string getString_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, std::string def) { 70 std::string ret = def; 71 HKEY hTemp; 72 if (RegOpenKeyEx(hKey, lpszPath, 0, KEY_QUERY_VALUE, &hTemp) != ERROR_SUCCESS) { 73 return def; 74 } 75 DWORD type; 76 DWORD cbData = 1024; 77 BYTE *bData = new BYTE[cbData]; 78 BOOL bRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 79 if (type != REG_SZ) { 80 bRet = false; 81 } 82 RegCloseKey(hTemp); 83 if (bRet) { 84 ret = (LPCTSTR)bData; 85 } 86 delete [] bData; 87 return ret; 88 } 89 static DWORD getInt_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, DWORD def) { 90 DWORD ret = def; 91 LONG bRet; 92 HKEY hTemp; 93 if ((bRet = RegOpenKeyEx(hKey, lpszPath, 0, KEY_READ, &hTemp)) != ERROR_SUCCESS) { 94 return def; 95 } 96 DWORD type; 97 DWORD cbData = 1024; 98 BYTE *bData = new BYTE[sizeof(DWORD)]; 99 bRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 100 if (type != REG_DWORD) { 101 bRet = -1; 102 } 103 RegCloseKey(hTemp); 104 if (bRet == ERROR_SUCCESS) { 105 ret = (DWORD)*bData; 106 } 107 delete [] bData; 108 return ret; 109 } 110 static sectionList getValues_(HKEY hKey, LPCTSTR lpszPath) { 111 sectionList ret; 112 LONG bRet; 113 HKEY hTemp; 114 if ((bRet = RegOpenKeyEx(hKey, lpszPath, 0, KEY_READ, &hTemp)) != ERROR_SUCCESS) { 115 return ret; 116 } 117 DWORD cValues=0; 118 DWORD cMaxValLen; 119 // Get the class name and the value count. 120 bRet = RegQueryInfoKey(hTemp,NULL,NULL,NULL,NULL,NULL,NULL,&cValues,&cMaxValLen,NULL,NULL,NULL); 121 if ((bRet == ERROR_SUCCESS)&&(cValues>0)) { 122 TCHAR *lpValueName = new TCHAR[cMaxValLen+1]; 123 for (unsigned int i=0; i<cValues; i++) { 124 DWORD len = cMaxValLen; 125 bRet = RegEnumValue(hKey, i, lpValueName, &len, NULL, NULL, NULL, NULL); 126 if (bRet == ERROR_SUCCESS) { 127 ret.push_back(std::string(lpValueName)); 128 } 129 } 130 delete [] lpValueName; 131 } 132 return ret; 133 } 134 static sectionList getSubKeys_(HKEY hKey, LPCTSTR lpszPath) { 135 sectionList ret; 136 LONG bRet; 137 HKEY hTemp; 138 if ((bRet = RegOpenKeyEx(hKey, lpszPath, 0, KEY_READ, &hTemp)) != ERROR_SUCCESS) { 139 return ret; 140 } 141 DWORD cSubKeys=0; 142 DWORD cMaxKeyLen; 143 // Get the class name and the value count. 144 bRet = RegQueryInfoKey(hTemp,NULL,NULL,NULL,&cSubKeys,&cMaxKeyLen,NULL,NULL,NULL,NULL,NULL,NULL); 145 if ((bRet == ERROR_SUCCESS)&&(cSubKeys>0)) { 146 TCHAR *lpValueName = new TCHAR[cMaxKeyLen+1]; 147 for (unsigned int i=0; i<cSubKeys; i++) { 148 DWORD len = cMaxKeyLen; 149 bRet = RegEnumKey(hKey, i, lpValueName, len); 150 if (bRet == ERROR_SUCCESS) { 151 ret.push_back(std::string(lpValueName)); 152 } 153 } 154 delete [] lpValueName; 155 } 156 return ret; 157 } 66 158 }; -
include/Settings.h
raabbd97 r70f2d7b 10 10 11 11 class SettingsException { 12 private: 13 std::string err; 12 14 public: 13 SettingsException(std::string str) {} 15 SettingsException(std::string str) : err(str) {} 16 std::string getMessage() { 17 return err; 18 } 14 19 15 20 }; … … 41 46 delete settingsManager; 42 47 } 48 std::string getActiveType() { 49 if (!settingsManager) { 50 return ""; 51 } return settingsManager->getActiveType(); 52 } 43 53 44 54 /** -
include/TSettings.h
raabbd97 r70f2d7b 16 16 { 17 17 } 18 18 virtual std::string getActiveType() = 0; 19 19 virtual sectionList getSections(unsigned int bufferLength = BUFF_LEN) = 0; 20 20 virtual sectionList getSection(std::string section, unsigned int bufferLength = BUFF_LEN) = 0; -
include/config.h
raabbd97 r70f2d7b 105 105 #define MAIN_ALLOWED_HOSTS "allowed_hosts" 106 106 #define MAIN_ALLOWED_HOSTS_DEFAULT "127.0.0.1" 107 108 109 // Main Registry ROOT 110 #define NS_HKEY_ROOT HKEY_LOCAL_MACHINE 111 #define NS_REG_ROOT "SOFTWARE\\NSClient++"
Note: See TracChangeset
for help on using the changeset viewer.








