- Timestamp:
- 11/01/09 11:06:01 (4 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 5229435
- Parents:
- 5da0459
- Location:
- service
- Files:
-
- 11 moved
-
NSCPlugin.cpp (moved) (moved from NSCPlugin.cpp)
-
NSCPlugin.h (moved) (moved from NSCPlugin.h)
-
NSClient++-2005.vcproj (moved) (moved from NSClient++-2005.vcproj) (4 diffs)
-
NSClient++.cpp (moved) (moved from NSClient++.cpp) (16 diffs)
-
NSClient++.h (moved) (moved from NSClient++.h) (5 diffs)
-
NSClient++.manifest (moved) (moved from NSClient++.manifest)
-
NSClient++.rc (moved) (moved from NSClient++.rc)
-
StdAfx.cpp (moved) (moved from StdAfx.cpp)
-
StdAfx.h (moved) (moved from StdAfx.h)
-
resource.h (moved) (moved from resource.h)
-
tray_manager.hpp (moved) (moved from tray_manager.hpp)
Legend:
- Unmodified
- Added
- Removed
-
service/NSClient++-2005.vcproj
r5da0459 rf0eb62d 2693 2693 </File> 2694 2694 <File 2695 RelativePath=".\include\INISettings.h"2696 >2697 </File>2698 <File2699 2695 RelativePath=".\include\Mutex.h" 2700 2696 > … … 2729 2725 </File> 2730 2726 <File 2731 RelativePath=".\include\OLDSettings.hpp"2732 >2733 </File>2734 <File2735 2727 RelativePath=".\include\PDHCounter.h" 2736 2728 > 2737 2729 </File> 2738 2730 <File 2739 RelativePath=".\include\REGSettings.h"2740 >2741 </File>2742 <File2743 2731 RelativePath=".\include\remote_processes.hpp" 2744 2732 > … … 2753 2741 </File> 2754 2742 <File 2755 RelativePath=".\include\Settings.h" 2743 RelativePath=".\include\settings\Settings.h" 2744 > 2745 </File> 2746 <File 2747 RelativePath=".\include\settings\settings_ini.hpp" 2748 > 2749 </File> 2750 <File 2751 RelativePath=".\include\settings\settings_old.hpp" 2752 > 2753 </File> 2754 <File 2755 RelativePath=".\include\settings\settings_registry.hpp" 2756 2756 > 2757 2757 </File> … … 3110 3110 CommandLine="echo Copying $(InputFileName)...
cmd /c "copy "$(InputDir)\$(InputFileName)" "$(TargetDir)""
" 3111 3111 Outputs="$(TargetDir)$(InputFileName)" 3112 />3113 </FileConfiguration>3114 </File>3115 <File3116 RelativePath=".\Doxyfile"3117 >3118 <FileConfiguration3119 Name="Release|Win32"3120 ExcludedFromBuild="true"3121 >3122 <Tool3123 Name="VCCustomBuildTool"3124 CommandLine="doxygen.exe $(InputPath)
"3125 Outputs=".\Doc"3126 />3127 </FileConfiguration>3128 <FileConfiguration3129 Name="Release|x64"3130 ExcludedFromBuild="true"3131 >3132 <Tool3133 Name="VCCustomBuildTool"3134 CommandLine="doxygen.exe $(InputPath)
"3135 Outputs=".\Doc"3136 />3137 </FileConfiguration>3138 <FileConfiguration3139 Name="Debug|Win32"3140 >3141 <Tool3142 Name="VCCustomBuildTool"3143 CommandLine="doxygen.exe $(InputPath)
"3144 Outputs="html"3145 />3146 </FileConfiguration>3147 <FileConfiguration3148 Name="Debug|x64"3149 ExcludedFromBuild="true"3150 >3151 <Tool3152 Name="VCCustomBuildTool"3153 CommandLine="doxygen.exe $(InputPath)
"3154 />3155 </FileConfiguration>3156 <FileConfiguration3157 Name="Distribution|Win32"3158 ExcludedFromBuild="true"3159 >3160 <Tool3161 Name="VCCustomBuildTool"3162 CommandLine="doxygen.exe $(InputPath)
"3163 Outputs=".\Doc"3164 />3165 </FileConfiguration>3166 <FileConfiguration3167 Name="Distribution|x64"3168 ExcludedFromBuild="true"3169 >3170 <Tool3171 Name="VCCustomBuildTool"3172 CommandLine="doxygen.exe $(InputPath)
"3173 Outputs=".\Doc"3174 />3175 </FileConfiguration>3176 <FileConfiguration3177 Name="Nightly|Win32"3178 ExcludedFromBuild="true"3179 >3180 <Tool3181 Name="VCCustomBuildTool"3182 CommandLine="doxygen.exe $(InputPath)
"3183 Outputs=".\Doc"3184 />3185 </FileConfiguration>3186 <FileConfiguration3187 Name="Nightly|x64"3188 ExcludedFromBuild="true"3189 >3190 <Tool3191 Name="VCCustomBuildTool"3192 CommandLine="doxygen.exe $(InputPath)
"3193 Outputs=".\Doc"3194 />3195 </FileConfiguration>3196 <FileConfiguration3197 Name="Debug-MemCheck|Win32"3198 ExcludedFromBuild="true"3199 >3200 <Tool3201 Name="VCCustomBuildTool"3202 CommandLine="doxygen.exe $(InputPath)
"3203 />3204 </FileConfiguration>3205 <FileConfiguration3206 Name="Debug-MemCheck|x64"3207 ExcludedFromBuild="true"3208 >3209 <Tool3210 Name="VCCustomBuildTool"3211 CommandLine="doxygen.exe $(InputPath)
"3212 />3213 </FileConfiguration>3214 <FileConfiguration3215 Name="OP5|Win32"3216 ExcludedFromBuild="true"3217 >3218 <Tool3219 Name="VCCustomBuildTool"3220 CommandLine="doxygen.exe $(InputPath)
"3221 Outputs=".\Doc"3222 />3223 </FileConfiguration>3224 <FileConfiguration3225 Name="OP5|x64"3226 ExcludedFromBuild="true"3227 >3228 <Tool3229 Name="VCCustomBuildTool"3230 CommandLine="doxygen.exe $(InputPath)
"3231 Outputs=".\Doc"3232 />3233 </FileConfiguration>3234 <FileConfiguration3235 Name="Release|Itanium"3236 ExcludedFromBuild="true"3237 >3238 <Tool3239 Name="VCCustomBuildTool"3240 CommandLine="doxygen.exe $(InputPath)
"3241 Outputs=".\Doc"3242 />3243 </FileConfiguration>3244 <FileConfiguration3245 Name="Debug|Itanium"3246 ExcludedFromBuild="true"3247 >3248 <Tool3249 Name="VCCustomBuildTool"3250 CommandLine="doxygen.exe $(InputPath)
"3251 />3252 </FileConfiguration>3253 <FileConfiguration3254 Name="Distribution|Itanium"3255 ExcludedFromBuild="true"3256 >3257 <Tool3258 Name="VCCustomBuildTool"3259 CommandLine="doxygen.exe $(InputPath)
"3260 Outputs=".\Doc"3261 />3262 </FileConfiguration>3263 <FileConfiguration3264 Name="Nightly|Itanium"3265 ExcludedFromBuild="true"3266 >3267 <Tool3268 Name="VCCustomBuildTool"3269 CommandLine="doxygen.exe $(InputPath)
"3270 Outputs=".\Doc"3271 />3272 </FileConfiguration>3273 <FileConfiguration3274 Name="Debug-MemCheck|Itanium"3275 ExcludedFromBuild="true"3276 >3277 <Tool3278 Name="VCCustomBuildTool"3279 CommandLine="doxygen.exe $(InputPath)
"3280 3112 /> 3281 3113 </FileConfiguration> -
service/NSClient++.cpp
r5da0459 rf0eb62d 16 16 #include <winsvc.h> 17 17 #include "NSClient++.h" 18 #include < Settings.h>18 #include <settings/Settings.h> 19 19 #include <charEx.h> 20 20 #include <Socket.h> … … 28 28 #include <crtdbg.h> 29 29 //#endif 30 #include <settings.h> 31 #include <INISettings.h> 32 #include <REGSettings.h> 33 #include <OLDSettings.hpp> 30 #include <settings/settings_ini.hpp> 31 #include <settings/settings_registry.hpp> 32 #include <settings/settings_old.hpp> 34 33 #include <Userenv.h> 35 34 #include <remote_processes.hpp> … … 72 71 73 72 static bool start(DWORD dwSessionId) { 74 std::wstring program = mainClient.getBasePath() + _T("\\") + S ettings::getInstance()->getString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_SYSTRAY_EXE, NSCLIENT_SETTINGS_SYSTRAY_EXE_DEFAULT);73 std::wstring program = mainClient.getBasePath() + _T("\\") + SETTINGS_GET_STRING(nsclient::SYSTRAY_EXE); 75 74 std::wstring cmdln = _T("\"") + program + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 76 75 return tray_starter::startTrayHelper(dwSessionId, program, cmdln); … … 234 233 } 235 234 }; 236 237 235 238 236 #define SETTINGS_GET_BOOL(key) \ … … 303 301 throw SettingsException(_T("Undefined settings type: ") + SettingsCore::type_to_string(type)); 304 302 } 303 305 304 }; 306 305 307 306 typedef Singleton<NSCSettingsImpl> SettingsHandler; 307 308 308 // Alias to make handling "compatible" with old syntax 309 309 Settings::SettingsInterface* get_settings() { … … 316 316 SettingsHandler::destroyInstance(); 317 317 } 318 318 319 319 320 bool init_settings() { … … 322 323 get_core()->set_base(mainClient.getBasePath()); 323 324 get_core()->boot(_T("boot.ini")); 324 #define MAIN_MODULES_SECTION_OLD _T("modules")325 #define MAIN_SECTION_TITLE _T("Settings")326 #define MAIN_STRING_LENGTH _T("string_length")327 get_core()->add_mapping(MAIN_MODULES_SECTION, MAIN_MODULES_SECTION_OLD);328 get_core()->add_mapping(settings::settings_def::PAYLOAD_LEN_PATH, settings::settings_def::PAYLOAD_LEN, MAIN_SECTION_TITLE, MAIN_STRING_LENGTH);329 325 get_core()->register_key(SETTINGS_REG_KEY_I_GEN(settings_def::PAYLOAD_LEN, Settings::SettingsCore::key_integer)); 330 326 get_core()->register_key(SETTINGS_REG_KEY_S_GEN(protocol_def::ALLOWED_HOSTS, Settings::SettingsCore::key_string)); … … 995 991 } 996 992 try { 997 loadPlugins( );993 loadPlugins(boot?NSCAPI::normalStart:NSCAPI::dontStart); 998 994 } catch (...) { 999 995 LOG_ERROR_STD(_T("Unknown exception loading plugins")); … … 1143 1139 return mainClient.service_ctrl_ex(dwControl, dwEventType, lpEventData, lpContext); 1144 1140 } 1145 1146 1141 /** 1147 1142 * Forward this to the main service dispatcher helper class … … 1165 1160 tray_starter::start(dwSessionId); 1166 1161 } 1167 1168 1162 1169 1163 ////////////////////////////////////////////////////////////////////////// … … 1292 1286 } 1293 1287 1294 void NSClientT::loadPlugins( ) {1288 void NSClientT::loadPlugins(NSCAPI::moduleLoadMode mode) { 1295 1289 bool hasBroken = false; 1296 1290 { … … 1315 1309 LOG_ERROR_STD(_T("Could not load plugin: ") + (*it)->getModule()); 1316 1310 } 1311 } 1317 1312 } 1318 1313 for (pluginList::iterator it=plugins_.begin(); it != plugins_.end();) { 1319 1314 LOG_DEBUG_STD(_T("Loading plugin: ") + (*it)->getName() + _T("...")); 1320 1315 try { 1321 (*it)->load_plugin( );1316 (*it)->load_plugin(mode); 1322 1317 ++it; 1323 1318 } catch(NSPluginException e) { … … 1513 1508 void NSClientT::listPlugins() { 1514 1509 ReadLock readLock(&m_mutexRW, true, 10000); 1510 if (!readLock.IsLocked()) { 1511 LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 1512 return; 1513 } 1514 for (pluginList::iterator it=plugins_.begin(); it != plugins_.end(); ++it) { 1515 1515 try { 1516 std::wstring msg, perf; 1517 int returnCode = shared_client_->inject(command, arrayBuffer::arrayBuffer2string(argument, argLen, _T(" ")), L' ', true, msg, perf); 1518 NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, msg, returnCode); 1519 return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, perf, returnCode); 1520 } catch (nsclient_session::session_exception &e) { 1521 LOG_ERROR_STD(_T("Failed to inject remote command: ") + e.what()); 1522 int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command: ") + e.what(), NSCAPI::returnCRIT); 1523 return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 1524 } catch (...) { 1525 LOG_ERROR_STD(_T("Failed to inject remote command: Unknown exception")); 1526 int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command: + e.what()"), NSCAPI::returnCRIT); 1527 return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 1528 } 1529 } else { 1530 ReadLock readLock(&m_mutexRW, true, 5000); 1531 if (!readLock.IsLocked()) { 1532 LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 1533 return NSCAPI::returnUNKNOWN; 1534 } 1535 for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 1536 try { 1537 NSCAPI::nagiosReturn c = commandHandlers_[i]->handleCommand(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 1538 switch (c) { 1539 case NSCAPI::returnInvalidBufferLen: 1540 LOG_ERROR(_T("UNKNOWN: Return buffer to small to handle this command.")); 1541 return c; 1542 case NSCAPI::returnIgnored: 1543 break; 1544 case NSCAPI::returnOK: 1545 case NSCAPI::returnWARN: 1546 case NSCAPI::returnCRIT: 1547 case NSCAPI::returnUNKNOWN: 1548 LOG_DEBUG_STD(_T("Injected Result: ") + NSCHelper::translateReturn(c) + _T(" '") + (std::wstring)(returnMessageBuffer) + _T("'")); 1549 LOG_DEBUG_STD(_T("Injected Performance Result: '") +(std::wstring)(returnPerfBuffer) + _T("'")); 1550 return c; 1551 default: 1552 LOG_ERROR_STD(_T("Unknown error from handleCommand: ") + strEx::itos(c) + _T(" the injected command was: ") + (std::wstring)command); 1553 return c; 1554 } 1555 } catch(const NSPluginException& e) { 1556 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 1557 return NSCAPI::returnCRIT; 1558 } catch(...) { 1559 LOG_ERROR_STD(_T("Unknown exception raised in module")); 1560 return NSCAPI::returnCRIT; 1561 } 1562 } 1563 LOG_MESSAGE_STD(_T("No handler for command: '") + command + _T("'")); 1564 return NSCAPI::returnIgnored; 1565 } 1516 if ((*it)->isBroken()) { 1517 std::wcout << (*it)->getModule() << _T(": ") << _T("broken") << std::endl; 1518 } else { 1519 std::wcout << (*it)->getModule() << _T(": ") << (*it)->getName() << std::endl; 1520 } 1521 } catch (NSPluginException e) { 1522 LOG_ERROR_STD(_T("Could not load plugin: ") + e.file_ + _T(": ") + e.error_); 1523 } 1524 } 1525 1566 1526 } 1567 1527 … … 1579 1539 return (debug_ == log_debug); 1580 1540 } 1581 void NSClientT::enableDebug(bool debug) {1582 if (debug) {1583 debug_ = log_debug;1584 LOG_DEBUG(_T("Enabling debug mode..."));1585 }1586 else1587 debug_ = log_nodebug;1588 }1589 1590 1541 1591 1542 void log_broken_message(std::wstring msg) { … … 1949 1900 return NSCAPI::isSuccess; 1950 1901 } 1951 NSCAPI::errorReturn NSAPISettingsAddKeyMapping(const TCHAR* source_path, const TCHAR* source_key, const TCHAR* destination_path, const TCHAR* destination_key) {1952 try {1953 settings_manager::get_core()->add_mapping(source_path, source_key, destination_path, destination_key);1954 } catch (SettingsException e) {1955 LOG_ERROR_STD(_T("Failed to add mapping: ") + e.getMessage());1956 return NSCAPI::hasFailed;1957 } catch (...) {1958 LOG_ERROR_STD(_T("Failed to add mapping"));1959 return NSCAPI::hasFailed;1960 }1961 return NSCAPI::isSuccess;1962 }1963 NSCAPI::errorReturn NSAPISettingsAddPathMapping(const TCHAR* src, const TCHAR* dst) {1964 try {1965 settings_manager::get_core()->add_mapping(src, dst);1966 } catch (SettingsException e) {1967 LOG_ERROR_STD(_T("Failed to add mapping: ") + e.getMessage());1968 return NSCAPI::hasFailed;1969 } catch (...) {1970 LOG_ERROR_STD(_T("Failed to add mapping"));1971 return NSCAPI::hasFailed;1972 }1973 return NSCAPI::isSuccess;1974 }1975 1976 1902 NSCAPI::errorReturn NSAPISettingsRegKey(const TCHAR* path, const TCHAR* key, int type, const TCHAR* title, const TCHAR* description, const TCHAR* defVal, int advanced) { 1977 1903 try { … … 2100 2026 if (_wcsicmp(buffer, _T("NSAPIRegisterCommand")) == 0) 2101 2027 return &NSAPIRegisterCommand; 2102 if (_wcsicmp(buffer, _T("NSAPISettingsAddKeyMapping")) == 0)2103 return &NSAPISettingsAddKeyMapping;2104 if (_wcsicmp(buffer, _T("NSAPISettingsAddPathMapping")) == 0)2105 return &NSAPISettingsAddPathMapping;2106 2107 2028 if (_wcsicmp(buffer, _T("NSAPISettingsRegKey")) == 0) 2108 2029 return &NSAPISettingsRegKey; -
service/NSClient++.h
r5da0459 rf0eb62d 115 115 public: 116 116 // c-tor, d-tor 117 NSClientT(void) : debug_(log_unknown), boot_(true) {}118 117 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false) {} 119 118 virtual ~NSClientT(void) {} … … 123 122 else 124 123 debug_ = log_nodebug; 125 }126 void setBoot(bool boot = true) {127 boot_ = boot;128 124 } 129 125 … … 149 145 void addPlugins(const std::list<std::wstring> plugins); 150 146 plugin_type loadPlugin(const std::wstring plugin); 151 void loadPlugins( void);147 void loadPlugins(NSCAPI::moduleLoadMode mode); 152 148 void unloadPlugins(bool unloadLoggers); 153 149 std::wstring describeCommand(std::wstring command); … … 218 214 NSCAPI::errorReturn NSAPIReleaseAllCommandNamessBuffer(TCHAR***, unsigned int *); 219 215 NSCAPI::errorReturn NSAPIRegisterCommand(const TCHAR*,const TCHAR*); 220 NSCAPI::errorReturn NSAPISettingsAddKeyMapping(const TCHAR*, const TCHAR*, const TCHAR*, const TCHAR*);221 NSCAPI::errorReturn NSAPISettingsAddPathMapping(const TCHAR*, const TCHAR*);222 216 NSCAPI::errorReturn NSAPISettingsRegKey(const TCHAR*, const TCHAR*, int, const TCHAR*, const TCHAR*, const TCHAR*, int); 223 217 NSCAPI::errorReturn NSAPISettingsRegPath(const TCHAR*, const TCHAR*, const TCHAR*, int); … … 225 219 NSCAPI::errorReturn NSAPIReleasePluginList(int,NSCAPI::plugin_info*[]); 226 220 NSCAPI::errorReturn NSAPISettingsSave(void); 227 228 221 229 222
Note: See TracChangeset
for help on using the changeset viewer.








