Changeset bc97cd8 in nscp
- Timestamp:
- 09/06/08 20:51:13 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- dc59b0e
- Parents:
- c0522cd
- Files:
-
- 26 edited
-
AutoBuild.h (modified) (1 diff)
-
NSClient++-2005.sln (modified) (4 diffs)
-
NSClient++.cpp (modified) (7 diffs)
-
NSClient++.h (modified) (2 diffs)
-
changelog (modified) (1 diff)
-
helpers/installer/Product.wxs (modified) (2 diffs)
-
helpers/systray_helper/TrayWidget.cpp (modified) (10 diffs)
-
helpers/systray_helper/TrayWidget.h (modified) (4 diffs)
-
helpers/systray_helper/systray_helper.cpp (modified) (1 diff)
-
helpers/systray_helper/systray_helper.vcproj (modified) (1 diff)
-
include/NSCHelper.cpp (modified) (1 diff)
-
include/NTService.h (modified) (10 diffs)
-
include/error.hpp (modified) (4 diffs)
-
include/execute_process.hpp (modified) (1 diff)
-
include/nsclient_session.hpp (modified) (3 diffs)
-
include/strEx.h (modified) (1 diff)
-
include/sysinfo.h (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.cpp (modified) (3 diffs)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (3 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (1 diff)
-
modules/FileLogger/FileLogger.cpp (modified) (4 diffs)
-
modules/LUAScript/script_wrapper.hpp (modified) (1 diff)
-
modules/NSCAAgent/NSCAAgent-2005.vcproj (modified) (1 diff)
-
modules/NSCAAgent/NSCAThread.cpp (modified) (2 diffs)
-
modules/SysTray/SysTray.cpp (modified) (1 diff)
-
scripts/test.lua (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
rc0522cd rbc97cd8 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,3,3 76 #define PRODUCTVER 0,3,3,3 77 #define STRFILEVER _T("0.3.3.3 7")8 #define STRPRODUCTVER _T("0.3.3.3 7")9 #define STRPRODUCTDATE _T("2008-0 8-24")5 #define FILEVER 0,3,3,39 6 #define PRODUCTVER 0,3,3,39 7 #define STRFILEVER _T("0.3.3.39") 8 #define STRPRODUCTVER _T("0.3.3.39") 9 #define STRPRODUCTDATE _T("2008-09-05") 10 10 #endif // AUTOBUILD_H -
NSClient++-2005.sln
rc0522cd rbc97cd8 964 964 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Release|Mixed Platforms.Build.0 = Release 965 965 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Release|Win32.ActiveCfg = Release 966 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Release|Win32.Build.0 = Release967 966 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Release|x64.ActiveCfg = Release 968 967 {A3CF4E23-1D1B-4D93-A16A-48C52D118560}.Release|x64.Build.0 = Release … … 1001 1000 {6206F046-3D36-4258-BB03-3291A7070117}.Release|Mixed Platforms.Build.0 = Release|Win32 1002 1001 {6206F046-3D36-4258-BB03-3291A7070117}.Release|Win32.ActiveCfg = Release|Win32 1003 {6206F046-3D36-4258-BB03-3291A7070117}.Release|Win32.Build.0 = Release|Win321004 1002 {6206F046-3D36-4258-BB03-3291A7070117}.Release|x64.ActiveCfg = Release|Win32 1005 1003 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Debug|Any CPU.ActiveCfg = Debug|x64 … … 1038 1036 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|Mixed Platforms.Build.0 = Release|x64 1039 1037 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|Win32.ActiveCfg = Release|Win32 1040 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|Win32.Build.0 = Release|Win321041 1038 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|x64.ActiveCfg = Release|x64 1042 1039 {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Debug|Any CPU.ActiveCfg = Debug|Win32 … … 1072 1069 {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Release|Mixed Platforms.Build.0 = Release|Win32 1073 1070 {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Release|Win32.ActiveCfg = Release|Win32 1074 {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Release|Win32.Build.0 = Release|Win321075 1071 {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Release|x64.ActiveCfg = Release|Win32 1076 1072 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Debug|Any CPU.ActiveCfg = Debug|x64 -
NSClient++.cpp
rc0522cd rbc97cd8 26 26 #include <Lmcons.h> 27 27 28 NSClient mainClient ; // Global core instance.28 NSClient mainClient(SZSERVICENAME); // Global core instance. 29 29 bool g_bConsoleLog = false; 30 30 … … 380 380 381 381 if (enable_shared_session_) { 382 LOG_MESSAGE_STD(_T("Enabling shared session...")); 382 383 if (boot) { 384 LOG_MESSAGE_STD(_T("Starting shared session...")); 383 385 try { 384 386 shared_server_.reset(new nsclient_session::shared_server_session(this)); … … 397 399 } 398 400 } else { 401 LOG_MESSAGE_STD(_T("Attaching to shared session...")); 399 402 try { 400 403 std::wstring id = _T("_attached_") + strEx::itos(GetCurrentProcessId()) + _T("_"); … … 594 597 */ 595 598 void WINAPI NSClientT::service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv) { 596 mainClient.service_main(dwArgc, lpszArgv); 599 try { 600 mainClient.service_main(dwArgc, lpszArgv); 601 } catch (service_helper::service_exception e) { 602 LOG_ERROR_STD(_T("Unknown service error: ") + e.what()); 603 } catch (...) { 604 LOG_ERROR_STD(_T("Unknown service error!")); 605 } 597 606 } 598 607 DWORD WINAPI NSClientT::service_ctrl_dispatch_ex(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) { … … 965 974 ReadLock readLock(&m_mutexRW, true, 5000); 966 975 if (!readLock.IsLocked()) { 976 OutputDebugString(_T("Message was lost as the core was locked...")); 967 977 std::wcout << _T("Message was lost as the core was locked...") << std::endl; 968 978 return; … … 970 980 MutexLock lock(messageMutex); 971 981 if (!lock.hasMutex()) { 982 OutputDebugString(_T("Message was lost as the core was locked...")); 983 OutputDebugString(message.c_str()); 972 984 std::wcout << _T("Message was lost as the core was locked...") << std::endl; 973 985 std::wcout << message << std::endl; … … 996 1008 } 997 1009 if (messageHandlers_.size() == 0 || !plugins_loaded_) { 1010 OutputDebugString(message.c_str()); 998 1011 log_cache_.push_back(cached_log_entry(msgType, file, line, message)); 999 1012 } else { -
NSClient++.h
rc0522cd rbc97cd8 152 152 reportMessage(msgType, file, line, message); 153 153 } 154 int session_inject(std::wstring command, std::wstring arguments, std::wstringsplitter, bool escape, std::wstring &msg, std::wstring & perf) {155 return inject(command, arguments, splitter [0], escape, msg, perf);154 int session_inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 155 return inject(command, arguments, splitter, escape, msg, perf); 156 156 } 157 157 … … 163 163 }; 164 164 165 typedef NTService<NSClientT> NSClient;165 typedef service_helper::NTService<NSClientT> NSClient; 166 166 167 167 -
changelog
rc0522cd rbc97cd8 4 4 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 5 5 * Improved socket performance (would be nice if we could be used as a "hub") 6 7 2008-09-06 MickeM 8 * Improved error reporting in the eventlogchecker 9 * *BREAKING CHANGE* filter=new is now the default so unless you use the new filtering you need to specify filter=old instead! 10 I Recomend everyone to stop using the "old" filtering. 11 12 2008-09-04 MickeM 13 * Fixed issues with new service stuff on NT4 and W2K (should work fine now) 14 + Added some DebugOutput to service handling features so if you experience tropubel try using sysinternals DebugView too se logging before the agent startes. 15 * Fixed a memory leak in the error formating code 16 17 2008-08-24 MickeM 18 * Changed NSCA "general problem" error message to be more descriptive. 19 * Fixed issue with CheckCPU not returning a valid performance unit (%) see issue #219 for details. 6 20 7 21 2008-08-16 MickeM -
helpers/installer/Product.wxs
rda1c7e1 rbc97cd8 35 35 <?endif?> 36 36 37 <Product Id="$(var.Product.GUID)" Name="NSClient++ ($(var.PlatForm))" Language="1033" Version="0.3. 1.0" Manufacturer="MySolutions NORDIC">37 <Product Id="$(var.Product.GUID)" Name="NSClient++ ($(var.PlatForm))" Language="1033" Version="0.3.4.0" Manufacturer="MySolutions NORDIC"> 38 38 <Package Id="$(var.Package.GUID)" Description="A simple windows monitor agent for (amongst others) nagios." 39 39 Comments="This will appear in the file summary stream." InstallerVersion="200" Compressed="yes"/> … … 60 60 LongName="Stop NSClient++ ($(var.PlatForm))" WorkingDirectory='INSTALLDIR' Icon="nsclient.exe" 61 61 IconIndex="0" Arguments="/stop" Description="Stop NSClient++ as a service"/> 62 </File> 63 <File Id="NSClientTRAY" Name="systray.exe" DiskId="1" 64 Source="$(var.Source)/systray.exe" Vital="yes"> 65 <Shortcut Id="StartmenuNSClientTray" Directory="ProgramMenuDir" Name="NSCPTray" 66 LongName="NSClient++ ($(var.PlatForm) system tray)" WorkingDirectory="INSTALLDIR" Icon="nsclient.exe" 67 IconIndex="0" Description="Run NSClient++ in test mode"/> 62 68 </File> 63 69 <File Id="NSClientINI" Name="NSC.ini" LongName="NSC.ini" DiskId="1" Source="$(var.Source)/NSC.ini" Vital="yes"/> -
helpers/systray_helper/TrayWidget.cpp
rc0522cd rbc97cd8 73 73 } 74 74 HINSTANCE ghInstance = NULL; 75 IconWidget *gTrayInstance = NULL;76 IconWidget::IconWidget(std::wstring cmdLine) {75 TrayWidget *gTrayInstance = NULL; 76 TrayWidget::TrayWidget(std::wstring cmdLine) { 77 77 strEx::splitList list = strEx::splitEx(cmdLine, _T(" ")); 78 78 channel_id_ = getArgumentValue(_T("-channel"), list); … … 90 90 } 91 91 } 92 IconWidget::~IconWidget() {92 TrayWidget::~TrayWidget() { 93 93 gTrayInstance = NULL; 94 94 try { … … 104 104 shared_client_.reset(); 105 105 } 106 void IconWidget::connectService() {106 void TrayWidget::connectService() { 107 107 LOG_MESSAGE_TRAY(_T("Reconnecting to the service...")); 108 108 try { … … 114 114 } 115 115 } 116 int IconWidget::inject(std::wstring command, std::wstring arguments, std::wstringsplitter, bool escape, std::wstring &msg, std::wstring & perf) {116 int TrayWidget::inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 117 117 if (shared_client_.get() == NULL) { 118 118 LOG_ERROR_TRAY(_T("No active shared instance!")); 119 119 return -1; 120 120 } 121 return shared_client_->inject(command, arguments, splitter [0], escape, msg, perf);122 } 123 124 125 126 void IconWidget::createDialog(HINSTANCE hInstance) {121 return shared_client_->inject(command, arguments, splitter, escape, msg, perf); 122 } 123 124 125 126 void TrayWidget::createDialog(HINSTANCE hInstance) { 127 127 ghInstance = hInstance; 128 128 hDlgWnd = ::CreateDialog(hInstance,MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); … … 160 160 } 161 161 162 void IconWidget::session_error(std::wstring file, unsigned int line, std::wstring msg) {162 void TrayWidget::session_error(std::wstring file, unsigned int line, std::wstring msg) { 163 163 log(_T("error"), file.c_str(), line, msg); 164 164 } 165 165 166 void IconWidget::session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message) {166 void TrayWidget::session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message) { 167 167 log(_T("message"), file, line, message); 168 168 } 169 void IconWidget::log(std::wstring category, const TCHAR* file, const int line, std::wstring message) {169 void TrayWidget::log(std::wstring category, const TCHAR* file, const int line, std::wstring message) { 170 170 log_entry record(category, file, line, message); 171 171 g_log_instance.log(_T("error"), record.file.c_str(), record.line, record.message.c_str()); … … 193 193 } 194 194 195 IconWidget::log_type IconWidget::getLog() {195 TrayWidget::log_type TrayWidget::getLog() { 196 196 log_type ret; 197 197 for (log_type::const_iterator cit = log_.begin(); cit != log_.end(); ++cit) … … 286 286 std::wstring perf; 287 287 try { 288 int ret = gTrayInstance->inject(cmd, args, _T(" "), true, msg, perf);288 int ret = gTrayInstance->inject(cmd, args, L' ', true, msg, perf); 289 289 //NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd, args, ' ', msg, perf); 290 290 /* … … 450 450 451 451 452 void insert_logrecord(HWND hwndLV, const IconWidget::log_entry &entry) {452 void insert_logrecord(HWND hwndLV, const TrayWidget::log_entry &entry) { 453 453 LVITEM item; 454 454 item.mask = LVIF_TEXT; … … 490 490 col.pszText = _T("Message"); 491 491 ListView_InsertColumn(hwndLV, 4, &col); 492 IconWidget::log_type log = gTrayInstance->getLog();493 for ( IconWidget::log_type::const_iterator cit = log.begin(); cit != log.end(); ++cit) {492 TrayWidget::log_type log = gTrayInstance->getLog(); 493 for (TrayWidget::log_type::const_iterator cit = log.begin(); cit != log.end(); ++cit) { 494 494 insert_logrecord(hwndLV, *cit); 495 495 } … … 505 505 { 506 506 HWND hwndLV = GetDlgItem(hwndDlg, IDC_LOG); 507 const IconWidget::log_entry* record = reinterpret_cast<const IconWidget::log_entry*>(wParam);507 const TrayWidget::log_entry* record = reinterpret_cast<const TrayWidget::log_entry*>(wParam); 508 508 insert_logrecord(hwndLV, *record); 509 509 -
helpers/systray_helper/TrayWidget.h
rc0522cd rbc97cd8 28 28 #define WM_MY_CLOSE WM_USER+2 29 29 30 class IconWidget : public nsclient_session::session_handler_interface {30 class TrayWidget : public nsclient_session::session_handler_interface { 31 31 public: 32 32 struct log_entry { … … 50 50 51 51 public: 52 IconWidget(std::wstring cmdLine);53 ~ IconWidget();52 TrayWidget(std::wstring cmdLine); 53 ~TrayWidget(); 54 54 void createDialog(HINSTANCE hInstance); 55 55 log_type getLog(); … … 61 61 void session_error(std::wstring file, unsigned int line, std::wstring msg); 62 62 void session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message); 63 int session_inject(std::wstring command, std::wstring arguments, std::wstringsplitter, bool escape, std::wstring &msg, std::wstring & perf) {63 int session_inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 64 64 return -1; 65 65 } … … 68 68 void setLogWindow(HWND hWnd) { hLogWnd = hWnd; } 69 69 HWND getLogWindow() const { return hLogWnd; } 70 int inject(std::wstring command, std::wstring arguments, std::wstringsplitter, bool escape, std::wstring &msg, std::wstring & perf);70 int inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf); 71 71 72 72 -
helpers/systray_helper/systray_helper.cpp
rc0522cd rbc97cd8 26 26 27 27 28 IconWidget widget(lpCmdLine);28 TrayWidget widget(lpCmdLine); 29 29 widget.createDialog(hInstance); 30 30 return 0; -
helpers/systray_helper/systray_helper.vcproj
rc0522cd rbc97cd8 218 218 <Tool 219 219 Name="VCLinkerTool" 220 OutputFile=" $(OutDir)\systray.exe"220 OutputFile="..\..\Release/systray.exe" 221 221 LinkIncremental="1" 222 222 GenerateDebugInformation="true" -
include/NSCHelper.cpp
rc0522cd rbc97cd8 249 249 break; 250 250 default: 251 throw NSCMHExcpetion(_T("Unknown inject error.")); 251 delete [] msgBuffer; 252 delete [] perfBuffer; 253 throw NSCMHExcpetion(_T("Unknown return code when injecting: ") + std::wstring(command)); 252 254 } 253 255 delete [] msgBuffer; -
include/NTService.h
rc0522cd rbc97cd8 24 24 #include <sysinfo.h> 25 25 26 26 namespace service_helper { 27 class service_exception { 28 std::wstring what_; 29 public: 30 service_exception(std::wstring what) : what_(what) { 31 OutputDebugString((std::wstring(_T("ERROR:")) + what).c_str()); 32 } 33 std::wstring what() { 34 return what_; 35 } 36 }; 27 37 /** 28 38 * @ingroup NSClient++ … … 51 61 class NTService : public TBase 52 62 { 63 public: 53 64 private: 54 65 HANDLE hServerStopEvent; 55 66 SERVICE_STATUS ssStatus; 56 67 SERVICE_STATUS_HANDLE sshStatusHandle; 57 DWORD dwErr;58 68 SERVICE_TABLE_ENTRY *dispatchTable; 69 DWORD dwControlsAccepted; 70 std::wstring name_; 71 wchar_t *serviceName_; 59 72 public: 60 NTService() : dispatchTable(NULL), hServerStopEvent(NULL), dwErr(0) { 61 // TODO This ought to be made dynamic somehow... 73 NTService(std::wstring name) : dispatchTable(NULL), hServerStopEvent(NULL), name_(name), dwControlsAccepted(SERVICE_ACCEPT_STOP) { 74 serviceName_ = new wchar_t[name.length()+2]; 75 wcsncpy(serviceName_, name.c_str(), name.length()); 62 76 dispatchTable = new SERVICE_TABLE_ENTRY[2]; 63 dispatchTable[0].lpServiceName = SZSERVICENAME;77 dispatchTable[0].lpServiceName = serviceName_; 64 78 dispatchTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)TBase::service_main_dispatch; 65 79 dispatchTable[1].lpServiceName = NULL; … … 68 82 virtual ~NTService() { 69 83 delete [] dispatchTable; 84 delete [] serviceName_; 70 85 } 71 86 … … 73 88 BOOL ret = ::StartServiceCtrlDispatcher(dispatchTable); 74 89 if (ret == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { 75 std::wcout << "We are running in console mode, terminating..." << std::endl;90 OutputDebugString(_T("We are running in console mode, terminating...")); 76 91 return false; 77 92 } 78 93 return ret != 0; 79 94 } 95 96 97 98 typedef DWORD (WINAPI *LPHANDLER_FUNCTION_EX) ( 99 DWORD dwControl, // requested control code 100 DWORD dwEventType, // event type 101 LPVOID lpEventData, // event data 102 LPVOID lpContext // user-defined context data 103 ); 104 typedef SERVICE_STATUS_HANDLE (WINAPI *REGISTER_SERVICE_CTRL_HANDLER_EX) ( 105 LPCTSTR lpServiceName, // name of service 106 LPHANDLER_FUNCTION_EX lpHandlerProc, // handler function 107 LPVOID lpContext // user data 108 ); 109 110 SERVICE_STATUS_HANDLE RegisterServiceCtrlHandlerEx_(LPCTSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext) { 111 HMODULE hAdvapi32 = NULL; 112 REGISTER_SERVICE_CTRL_HANDLER_EX fRegisterServiceCtrlHandlerEx = NULL; 113 114 if ((hAdvapi32 = GetModuleHandle(TEXT("Advapi32.dll"))) == NULL) 115 return 0; 116 #ifdef _UNICODE 117 fRegisterServiceCtrlHandlerEx = (REGISTER_SERVICE_CTRL_HANDLER_EX)GetProcAddress(hAdvapi32, "RegisterServiceCtrlHandlerExW"); 118 #else 119 fRegisterServiceCtrlHandlerEx = (REGISTER_SERVICE_CTRL_HANDLER_EX)GetProcAddress(hAdvapi32, "RegisterServiceCtrlHandlerExA"); 120 #endif // _UNICODE 121 if (!fRegisterServiceCtrlHandlerEx) 122 return 0; 123 return fRegisterServiceCtrlHandlerEx(lpServiceName, lpHandlerProc, lpContext); 124 } 125 126 80 127 81 128 void service_main(DWORD dwArgc, LPTSTR *lpszArgv) 82 129 { 83 if (systemInfo::isAboveW2K(systemInfo::getOSVersion())) { 84 ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SESSIONCHANGE; 85 sshStatusHandle = RegisterServiceCtrlHandlerEx( SZSERVICENAME, TBase::service_ctrl_dispatch_ex, NULL); 130 OutputDebugString(_T("service_main launcing...")); 131 sshStatusHandle = RegisterServiceCtrlHandlerEx_(name_.c_str(), TBase::service_ctrl_dispatch_ex, NULL); 132 if (sshStatusHandle == 0) { 133 OutputDebugString(_T("Failed to register RegisterServiceCtrlHandlerEx_ (attempting to use normal one)...")); 134 sshStatusHandle = RegisterServiceCtrlHandler(name_.c_str(), TBase::service_ctrl_dispatch); 86 135 } else { 87 // register our service control handler: 88 sshStatusHandle = RegisterServiceCtrlHandler( SZSERVICENAME, TBase::service_ctrl_dispatch); 89 } 90 91 // SERVICE_STATUS members that don't change in example 136 if (systemInfo::isAboveXP(systemInfo::getOSVersion())) 137 dwControlsAccepted |= SERVICE_ACCEPT_SESSIONCHANGE; 138 else 139 OutputDebugString(_T("Not >w2k so sessiong messages disabled...")); 140 } 141 ssStatus.dwControlsAccepted = dwControlsAccepted; 142 if (sshStatusHandle == 0) 143 throw service_exception(_T("Failed to register service: ") + error::lookup::last_error()); 144 145 92 146 ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; 93 147 ssStatus.dwServiceSpecificExitCode = 0; 94 148 95 149 // report the status to the service control manager. 96 if (!ReportStatusToSCMgr(SERVICE_START_PENDING,NO_ERROR,3000)) { 97 if (sshStatusHandle) 98 ReportStatusToSCMgr(SERVICE_STOPPED,dwErr,0); 99 } 100 101 ServiceStart( dwArgc, lpszArgv ); 102 103 // try to report the stopped status to the service control manager. 104 if (sshStatusHandle) 105 ReportStatusToSCMgr(SERVICE_STOPPED,dwErr,0); 150 if (!ReportStatusToSCMgr(SERVICE_START_PENDING,3000)) { 151 ReportStatusToSCMgr(SERVICE_STOPPED,0); 152 throw service_exception(_T("Failed to report service status: ") + error::lookup::last_error()); 153 } 154 try { 155 OutputDebugString(_T("Attempting to start service...")); 156 ServiceStart(dwArgc, lpszArgv); 157 } catch (...) { 158 throw service_exception(_T("Uncaught exception in service... terminating: ") + error::lookup::last_error()); 159 } 160 ReportStatusToSCMgr(SERVICE_STOPPED,0); 106 161 } 107 162 … … 119 174 { 120 175 case SERVICE_CONTROL_STOP: 121 ReportStatusToSCMgr(SERVICE_STOP_PENDING, NO_ERROR,0);176 ReportStatusToSCMgr(SERVICE_STOP_PENDING, 0); 122 177 ServiceStop(); 123 178 return 0; … … 140 195 141 196 } 142 ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR,0);197 ReportStatusToSCMgr(ssStatus.dwCurrentState, 0); 143 198 return 0; 144 199 } … … 159 214 * 160 215 */ 161 BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwW in32ExitCode, DWORD dwWaitHint) {216 BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWaitHint) { 162 217 static DWORD dwCheckPoint = 1; 163 218 BOOL fResult = TRUE; … … 166 221 ssStatus.dwControlsAccepted = 0; 167 222 else 168 ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP| SERVICE_ACCEPT_SESSIONCHANGE;223 ssStatus.dwControlsAccepted = dwControlsAccepted; 169 224 170 225 ssStatus.dwCurrentState = dwCurrentState; 171 ssStatus.dwWin32ExitCode = dwWin32ExitCode;226 ssStatus.dwWin32ExitCode = 0; 172 227 ssStatus.dwWaitHint = dwWaitHint; 173 228 … … 196 251 void ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv) { 197 252 hServerStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); 198 if (!ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR,0)) {253 if (!ReportStatusToSCMgr(SERVICE_RUNNING,0)) { 199 254 if (hServerStopEvent) 200 255 CloseHandle(hServerStopEvent); … … 228 283 } 229 284 }; 285 } -
include/error.hpp
rb7ed6ac rbc97cd8 9 9 public: 10 10 static std::wstring from_system(unsigned long dwError) { 11 LPVOID lpMsgBuf ;11 LPVOID lpMsgBuf = NULL; 12 12 unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,NULL,dwError,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,NULL); 13 13 if (dwRet == 0) { … … 17 17 wsprintf(szBuf, _T("%d: %s"), dwError, lpMsgBuf); 18 18 std::wstring str = szBuf; 19 delete [] szBuf; 19 20 LocalFree(lpMsgBuf); 20 21 return str; … … 29 30 wsprintf(szBuf, _T("%d: %s"), dwError, lpMsgBuf); 30 31 std::wstring str = szBuf; 32 delete [] szBuf; 31 33 LocalFree(lpMsgBuf); 32 34 return str; … … 47 49 wsprintf(szBuf, _T("%d: %s"), dwError, lpMsgBuf); 48 50 std::wstring str = szBuf; 51 delete [] szBuf; 49 52 LocalFree(lpMsgBuf); 50 53 FreeLibrary(hevt); -
include/execute_process.hpp
rdff5db9 rbc97cd8 146 146 DWORD error = GetLastError(); 147 147 if (error == ERROR_BAD_EXE_FORMAT) { 148 NSC_LOG_ERROR_STD(command + _T(" is not an .exe file or a valid image (if you run a script you usually need to prefix the command with the interpreter like so: \"command=c:\ perl.exe <script>\""));148 NSC_LOG_ERROR_STD(command + _T(" is not an .exe file or a valid image (if you run a script you usually need to prefix the command with the interpreter like so: \"command=c:\\perl.exe <script>\"")); 149 149 msg = _T("ExternalCommands: failed to create process (") + command + _T("): it is not an exe file (check NSC.log for more info) - ") + error::lookup::last_error(error); 150 150 } else { -
include/nsclient_session.hpp
rc0522cd rbc97cd8 25 25 virtual void session_error(std::wstring file, unsigned int line, std::wstring msg) = 0; 26 26 virtual void session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message) = 0; 27 virtual int session_inject(std::wstring command, std::wstring arguments, std::wstringsplitter, bool escape, std::wstring &msg, std::wstring & perf) = 0;27 virtual int session_inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) = 0; 28 28 }; 29 29 … … 650 650 remote_channel::local_message_type msg; 651 651 msg.command = message_inject; 652 error(__FILEW__, __LINE__, _T("splitter") + strEx::ctos(splitter)); 653 error(__FILEW__, __LINE__, _T("splitter") + splitter); 654 652 655 msg.arguments.push_back(command); 653 656 msg.arguments.push_back(arguments); 654 657 msg.arguments.push_back(strEx::ctos(splitter)); 655 658 msg.arguments.push_back(escape?_T("1"):_T("0")); 659 660 error(__FILEW__, __LINE__, _T("arg1") + msg.arguments[1]); 661 error(__FILEW__, __LINE__, _T("arg2") + msg.arguments[2]); 662 error(__FILEW__, __LINE__, _T("arg3") + msg.arguments[3]); 656 663 657 664 unsigned int msg_id = send_server(msg); … … 772 779 if (msg.arguments.size() == 4) { 773 780 try { 774 ret = handler_->session_inject(msg.arguments[0], msg.arguments[1], msg.arguments[2], msg.arguments[2]==_T("1"), message, perf); 781 error(__FILEW__, __LINE__, _T("arg1") + msg.arguments[1]); 782 error(__FILEW__, __LINE__, _T("arg2") + msg.arguments[2]); 783 error(__FILEW__, __LINE__, _T("arg3") + msg.arguments[3]); 784 ret = handler_->session_inject(msg.arguments[0], msg.arguments[1], strEx::stoc(msg.arguments[2]), msg.arguments[2]==_T("1"), message, perf); 775 785 } catch (...) { 776 786 message = _T("Unknown exception!"); -
include/strEx.h
rc0522cd rbc97cd8 214 214 } 215 215 inline std::wstring ctos(TCHAR c) { 216 return std::wstring(c,1); 216 return std::wstring(1, c); 217 } 218 inline TCHAR stoc(std::wstring str) { 219 if (str.length() == 0) 220 return L' '; 221 return str[0]; 217 222 } 218 223 inline std::wstring itos(unsigned int i) { -
include/sysinfo.h
r7e33d82 rbc97cd8 58 58 return ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)&&(osVersion.dwMajorVersion>4)); 59 59 } 60 inline bool isAboveXP(const OSVERSIONINFO &osVersion) { 61 if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion>=4)&&(osVersion.dwMinorVersion>=1)) 62 return true; 63 return false; 64 } 65 inline bool isBelowXP(const OSVERSIONINFO &osVersion) { 66 if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion<4)) 67 return true; 68 if ((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion==4)&&(osVersion.dwMinorVersion<1)) 69 return true; 70 return false; 71 } 60 72 61 73 } -
modules/CheckDisk/CheckDisk.cpp
rc165d1d rbc97cd8 530 530 CheckFileContainer query; 531 531 std::wstring syntax = _T("%filename%"); 532 std::wstring alias; 532 533 bool bPerfData = true; 533 534 … … 539 540 MAP_OPTIONS_STR(_T("syntax"), syntax) 540 541 MAP_OPTIONS_PUSH(_T("path"), paths) 542 MAP_OPTIONS_STR(_T("alias"), alias) 541 543 MAP_OPTIONS_PUSH(_T("file"), paths) 542 544 MAP_OPTIONS_BOOL_EX(_T("filter"), finder.bFilterIn, _T("in"), _T("out")) … … 569 571 if (finder.error) 570 572 return NSCAPI::returnUNKNOWN; 571 query.alias = finder.alias; 573 if (!alias.empty()) 574 query.alias = alias; 575 else 576 query.alias = finder.alias; 577 if (query.alias.empty()) 578 query.alias = _T("no files found"); 572 579 query.runCheck(finder.hit_count, returnCode, message, perf); 573 580 if ((truncate > 0) && (message.length() > (truncate-4))) -
modules/CheckEventLog/CheckEventLog.cpp
r34e7428 rbc97cd8 405 405 bool bFilterIn = true; 406 406 bool bFilterAll = false; 407 bool bFilterNew = false;407 bool bFilterNew = true; 408 408 bool bShowDescriptions = false; 409 409 bool unique = false; … … 471 471 472 472 unsigned long int hit_count = 0; 473 if (files.empty()) { 474 message = _T("No file specified try adding: file=Application"); 475 return NSCAPI::returnUNKNOWN; 476 } 473 477 474 478 for (std::list<std::wstring>::const_iterator cit2 = files.begin(); cit2 != files.end(); ++cit2) { … … 502 506 503 507 if (filter_chain.empty()) { 504 message = _T("No filters specified .");508 message = _T("No filters specified try adding: filter+generated=>2d"); 505 509 return NSCAPI::returnUNKNOWN; 506 510 } -
modules/CheckSystem/CheckSystem.cpp
r846bbe4 rbc97cd8 341 341 342 342 static std::wstring get_perf_unit(__int64 value) { 343 return _T(" ");343 return _T("%"); 344 344 } 345 345 static std::wstring print_perf(__int64 value, std::wstring unit) { -
modules/FileLogger/FileLogger.cpp
rfebff5f rbc97cd8 40 40 } 41 41 42 std::wstring FileLogger::getFileName() 43 { 42 #ifndef CSIDL_COMMON_APPDATA 43 #define CSIDL_COMMON_APPDATA 0x0023 44 #endif 45 typedef BOOL (WINAPI *fnSHGetSpecialFolderPath)(HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate); 46 47 __inline BOOL WINAPI _SHGetSpecialFolderPath(HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate) { 48 static fnSHGetSpecialFolderPath __SHGetSpecialFolderPath = NULL; 49 if (!__SHGetSpecialFolderPath) { 50 HMODULE hDLL = LoadLibrary(_T("shfolder.dll")); 51 if (hDLL != NULL) 52 __SHGetSpecialFolderPath = (fnSHGetSpecialFolderPath)GetProcAddress(hDLL,"SHGetSpecialFolderPathW"); 53 } 54 if(__SHGetSpecialFolderPath) 55 return __SHGetSpecialFolderPath(hwndOwner, lpszPath, nFolder, fCreate); 56 return FALSE; 57 } 58 59 std::wstring getFolder(std::wstring key) { 60 if (key == _T("exe")) { 61 return NSCModuleHelper::getBasePath(); 62 } else { 63 if (key == _T("local-app-data")) { 64 TCHAR buf[MAX_PATH+1]; 65 _SHGetSpecialFolderPath(NULL, buf, CSIDL_COMMON_APPDATA, FALSE); 66 return buf; 67 } 68 } 69 return NSCModuleHelper::getBasePath(); 70 } 71 std::wstring FileLogger::getFileName() { 44 72 if (file_.empty()) { 45 73 file_ = NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_FILENAME, LOG_FILENAME_DEFAULT); 46 if (file_.find(_T("\\")) == std::wstring::npos) 47 file_ = NSCModuleHelper::getBasePath() + _T("\\") + file_; 74 if (file_.find(_T("\\")) == std::wstring::npos) { 75 std::wstring root = getFolder(NSCModuleHelper::getSettingsString(LOG_SECTION_TITLE, LOG_ROOT, LOG_ROOT_DEFAULT)); 76 std::wstring::size_type pos = root.find_last_not_of(L'\\'); 77 if (pos != std::wstring::npos) { 78 //root = root.substr(0, pos); 79 } 80 file_ = root + _T("\\") + file_; 81 } 48 82 } 49 83 return file_; … … 57 91 std::wstring hello = _T("Starting to log for: ") + NSCModuleHelper::getApplicationName() + _T(" - ") + NSCModuleHelper::getApplicationVersionString(); 58 92 handleMessage(NSCAPI::log, __FILEW__, __LINE__, hello.c_str()); 93 NSC_LOG_MESSAGE_STD(_T("Log path is: ") + file_ ); 59 94 return true; 60 95 } … … 68 103 return true; 69 104 } 105 HANDLE openAppendOrNew(std::wstring file) { 106 DWORD numberOfBytesWritten = 0; 107 HANDLE hFile = ::CreateFile(file.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 108 if (hFile == INVALID_HANDLE_VALUE) { 109 hFile = ::CreateFile(file.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 110 if (hFile != INVALID_HANDLE_VALUE) { 111 WORD wBOM = 0xFEFF; 112 ::WriteFile(hFile, &wBOM, sizeof(WORD), &numberOfBytesWritten, NULL); 113 } 114 } 115 return hFile; 116 } 70 117 void FileLogger::writeEntry(std::wstring line) { 71 118 DWORD numberOfBytesWritten; 72 HANDLE hFile = ::CreateFile(file_.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);119 HANDLE hFile = openAppendOrNew(file_); 73 120 if (hFile == INVALID_HANDLE_VALUE) { 74 hFile = ::CreateFile(file_.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 75 if (hFile == INVALID_HANDLE_VALUE) { 76 std::wcout << _T("Failed to write to log file: ") << file_ << std::endl; 77 return; 78 } 79 WORD wBOM = 0xFEFF; 80 ::WriteFile(hFile, &wBOM, sizeof(WORD), &numberOfBytesWritten, NULL); 121 if (line.find(_T("can not log to file")) != std::wstring::npos) 122 NSC_LOG_MESSAGE_STD(_T("Failed to create log file and temporary log! (can not log to file): ") + file_ ); 123 return; 81 124 } 82 //::WriteFile(hFile, &wBOM, sizeof(WORD), &NumberOfBytesWritten, NULL);83 125 if (::SetFilePointer(hFile, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER) { 84 126 std::wcout << _T("Failed to move pointer to end of file...") << std::endl; … … 89 131 90 132 void FileLogger::handleMessage(int msgType, TCHAR* file, int line, const TCHAR* message) { 91 if (!init_) 133 if (!init_) { 134 std::wcout << _T("Discarding message (not initzialized yet") << std::endl; 92 135 return; 136 } 93 137 TCHAR buffer[65]; 94 138 __time64_t ltime; -
modules/LUAScript/script_wrapper.hpp
r367bf20 rbc97cd8 355 355 356 356 lua_createtable(L, 0, argLen); 357 for ( int i=0;i<argLen;i++) {357 for (unsigned int i=0;i<argLen;i++) { 358 358 lua_pushnumber(L,i+1); 359 359 lua_pushstring(L,strEx::wstring_to_string(char_args[i]).c_str()); -
modules/NSCAAgent/NSCAAgent-2005.vcproj
rc0522cd rbc97cd8 234 234 Name="VCLinkerTool" 235 235 AdditionalDependencies="ws2_32.lib Crypto++.lib" 236 OutputFile=" $(OutDir)\$(ProjectName).dll"236 OutputFile="../../Release/modules/$(ProjectName).dll" 237 237 LinkIncremental="1" 238 238 AdditionalLibraryDirectories="$(SolutionDir)lib\$(ConfigurationName)\$(PlatformName)" -
modules/NSCAAgent/NSCAThread.cpp
r5aebda1 rbc97cd8 182 182 crypt_inst.encrypt_init(password_.c_str(),encryption_method_,reinterpret_cast<unsigned char*>(packet_in->iv)); 183 183 } catch (nsca_encrypt::encryption_exception &e) { 184 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header: ") + e.getMessage());184 NSC_LOG_ERROR_STD(_T("<<< NSCA Encryption header missmatch (hint: if you dont use NSCA dot use the NSCA module): ") + e.getMessage()); 185 185 return; 186 186 } catch (...) { 187 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!"));187 NSC_LOG_ERROR_STD(_T("<<< NSCA Encryption header missmatch (hint: if you dont use NSCA dot use the NSCA module)!")); 188 188 return; 189 189 } … … 206 206 socket.close(); 207 207 } catch (...) { 208 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!"));208 NSC_LOG_ERROR_STD(_T("<<< NSCA Configuration missmatch (hint: if you dont use NSCA dot use the NSCA module)!")); 209 209 return; 210 210 } -
modules/SysTray/SysTray.cpp
rc0522cd rbc97cd8 43 43 } 44 44 bool SysTray::loadModule() { 45 if (systemInfo::isBelowXP(systemInfo::getOSVersion())) { 46 try { 47 if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 48 NSC_LOG_ERROR(_T("SysTray is not installed (or it cannot interact with the desktop) SysTray won't be loaded. Run ") SZAPPNAME _T(" SysTray install to change this.")); 49 return true; 50 } 51 } catch (serviceControll::SCException e) { 45 if (NSCModuleHelper::getSettingsInt(MAIN_SECTION_TITLE, MAIN_SHARED_SESSION, MAIN_SHARED_SESSION_DEFAULT) == 1) { 46 NSC_LOG_ERROR(_T("You have enabled shared session, systray module will not load...")); 47 return true; 48 } 49 try { 50 if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 52 51 NSC_LOG_ERROR(_T("SysTray is not installed (or it cannot interact with the desktop) SysTray won't be loaded. Run ") SZAPPNAME _T(" SysTray install to change this.")); 53 52 return true; 54 53 } 55 show();56 } else {57 NSC_LOG_ERROR(_T("SysTray module is not used on windows XP and above (so you can remove it)."));54 } catch (serviceControll::SCException e) { 55 NSC_LOG_ERROR(_T("SysTray is not installed (or it cannot interact with the desktop) SysTray won't be loaded. Run ") SZAPPNAME _T(" SysTray install to change this.")); 56 return true; 58 57 } 58 show(); 59 59 return true; 60 60 } -
scripts/test.lua
r367bf20 rbc97cd8 1 --require("luacom")2 --require("luacom")3 --require("luacom-lua5-13")4 5 1 nscp.print('Loading test script...') 6 -- win = loadlib("win32.dll","luaopen_w32")7 -- print(win) -- nil8 require( 'w32' )9 nscp.print(w32)10 nscp.print(w32.FindWindow)11 2 12 3 nscp.execute('version') … … 22 13 function something (command) 23 14 nscp.print(command) 24 --code, msg, perf = inject('CheckCPU','time=5','MaxCrit=5') 25 msg = 'hello' 26 perf = 'hello' 27 code = 'ok' 15 code, msg, perf = nscp.execute('CheckCPU','time=5','MaxCrit=5') 28 16 print(code .. ': ' .. msg .. ', ' .. perf) 29 17 collectgarbage ()
Note: See TracChangeset
for help on using the changeset viewer.








