Changeset c0522cd in nscp
- Timestamp:
- 08/24/08 19:23:10 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- bc97cd8
- Parents:
- 846bbe4
- Files:
-
- 16 added
- 38 edited
-
AutoBuild.h (modified) (1 diff)
-
NSC.dist (modified) (2 diffs)
-
NSCPlugin.cpp (modified) (6 diffs)
-
NSCPlugin.h (modified) (3 diffs)
-
NSClient++-2005.sln (modified) (17 diffs)
-
NSClient++-2005.vcproj (modified) (13 diffs)
-
NSClient++.cpp (modified) (36 diffs)
-
NSClient++.h (modified) (5 diffs)
-
changelog (modified) (1 diff)
-
helpers/UploadBinaries/UploadBinaries.vcproj (modified) (1 diff)
-
helpers/UploadInstaller/UploadInstaller.vcproj (modified) (1 diff)
-
helpers/systray_helper/ReadMe.txt (added)
-
helpers/systray_helper/Resource.h (added)
-
helpers/systray_helper/TrayWidget.cpp (added)
-
helpers/systray_helper/TrayWidget.h (added)
-
helpers/systray_helper/stdafx.cpp (added)
-
helpers/systray_helper/stdafx.h (added)
-
helpers/systray_helper/systray_helper.cpp (added)
-
helpers/systray_helper/systray_helper.h (added)
-
helpers/systray_helper/systray_helper.rc (added)
-
helpers/systray_helper/systray_helper.vcproj (added)
-
include/Mutex.h (modified) (8 diffs)
-
include/NSCHelper.cpp (modified) (3 diffs)
-
include/NSCHelper.h (modified) (3 diffs)
-
include/NTService.h (modified) (6 diffs)
-
include/ServiceCmd.cpp (modified) (1 diff)
-
include/config.h (modified) (3 diffs)
-
include/event_handler.hpp (added)
-
include/file_logger.hpp (added)
-
include/nsclient_session.hpp (added)
-
include/remote_processes.hpp (added)
-
include/shared_memory.hpp (added)
-
include/strEx.h (modified) (4 diffs)
-
modules/CheckDisk/CheckDisk-2005.vcproj (modified) (2 diffs)
-
modules/CheckEventLog/CheckEventLog-2005.vcproj (modified) (2 diffs)
-
modules/CheckExternalScripts/CheckExternalScripts-2005.vcproj (modified) (2 diffs)
-
modules/CheckHelpers/CheckHelpers-2005.vcproj (modified) (2 diffs)
-
modules/CheckSystem/CheckSystem-2005.vcproj (modified) (2 diffs)
-
modules/CheckTaskSched/CheckTaskSched-2005.vcproj (modified) (6 diffs)
-
modules/CheckWMI/CheckWMI-2005.vcproj (modified) (2 diffs)
-
modules/FileLogger/FileLogger-2005.vcproj (modified) (2 diffs)
-
modules/LUAScript/LUAScript-2005.vcproj (modified) (2 diffs)
-
modules/NRPEClient/NRPEClient-2005.vcproj (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener-2005.vcproj (modified) (2 diffs)
-
modules/NSCAAgent/NSCAAgent-2005.vcproj (modified) (2 diffs)
-
modules/NSClientListener/NSClientListener-2005.vcproj (modified) (2 diffs)
-
modules/RemoteConfiguration/RemoteConfiguration-2005.vcproj (modified) (2 diffs)
-
modules/SysTray/SysTray-2005.vcproj (modified) (2 diffs)
-
modules/SysTray/SysTray.cpp (modified) (5 diffs)
-
modules/SysTray/SysTray.def (modified) (1 diff)
-
modules/SysTray/SysTray.h (modified) (2 diffs)
-
modules/SysTray/SysTray.rc (modified) (2 diffs)
-
modules/SysTray/TrayIcon.cpp (modified) (3 diffs)
-
tray_manager.hpp (added)
Legend:
- Unmodified
- Added
- Removed
-
AutoBuild.h
r846bbe4 rc0522cd 3 3 // change the FALSE to TRUE for autoincrement of build number 4 4 #define INCREMENT_VERSION TRUE 5 #define FILEVER 0,3,3, 296 #define PRODUCTVER 0,3,3, 297 #define STRFILEVER _T("0.3.3. 29")8 #define STRPRODUCTVER _T("0.3.3. 29")9 #define STRPRODUCTDATE _T("2008-0 7-28")5 #define FILEVER 0,3,3,37 6 #define PRODUCTVER 0,3,3,37 7 #define STRFILEVER _T("0.3.3.37") 8 #define STRPRODUCTVER _T("0.3.3.37") 9 #define STRPRODUCTDATE _T("2008-08-24") 10 10 #endif // AUTOBUILD_H -
NSC.dist
rdff5db9 rc0522cd 54 54 ; the registry will be used instead. 55 55 use_file=1 56 ; 57 ; # USE SHARED MEMORY CHANNELS 58 ; This is the "new" way for using the system tray based on an IPC framework on top shared memmory channels and events. 59 ; It is brand new and (probably has bugs) so dont enable this unless for testing! 60 ; If set to 1 shared channels will be created and system tray icons created and such and such... 61 ;shared_session=0 62 56 63 57 64 [log] … … 62 69 ;# LOG FILE 63 70 ; The file to print log statements to 64 ;file= NSC.log71 ;file=nsclient.log 65 72 ; 66 73 ;# LOG DATE MASK 67 74 ; The format to for the date/time part of the log entry written to file. 68 75 ;date_mask=%Y-%m-%d %H:%M:%S 76 ; 77 ;# LOG ROOT FOLDER 78 ; The root folder to use for logging. 79 ; exe = the folder where the executable is located 80 ; local-app-data = local application data (probably a better choice then the old default) 81 ;root_folder=exe 69 82 70 83 -
NSCPlugin.cpp
rc1d545e rc0522cd 42 42 ,fGetVersion(NULL) 43 43 ,fCommandLineExec(NULL) 44 ,fShowTray(NULL) 45 ,fHideTray(NULL) 44 46 ,bLoaded_(false) 45 47 { … … 58 60 ,fGetVersion(NULL) 59 61 ,fCommandLineExec(NULL) 62 ,fShowTray(NULL) 63 ,fHideTray(NULL) 60 64 ,bLoaded_(false) 61 65 { … … 89 93 TCHAR *buffer = new TCHAR[1024]; 90 94 if (!getName_(buffer, 1023)) { 91 throw NSPluginException(file_, _T("Could not get name"));95 return _T("Could not get name"); 92 96 } 93 97 std::wstring ret = buffer; … … 244 248 bool NSCPlugin::getName_(TCHAR* buf, unsigned int buflen) { 245 249 if (fGetName == NULL) 246 throw NSPluginException(file_, _T("Critical error (fGetName)"));250 return false;//throw NSPluginException(file_, _T("Critical error (fGetName)")); 247 251 try { 248 252 return fGetName(buf, buflen)?true:false; 249 253 } catch (...) { 250 throw NSPluginException(file_, _T("Unhandled exception in getName."));254 return false; //throw NSPluginException(file_, _T("Unhandled exception in getName.")); 251 255 } 252 256 } … … 260 264 } 261 265 } 266 267 void NSCPlugin::showTray() { 268 if (fShowTray == NULL) 269 throw NSPluginException(file_, _T("Critical error (ShowTray)")); 270 try { 271 fShowTray(); 272 } catch (...) { 273 throw NSPluginException(file_, _T("Unhandled exception in ShowTray.")); 274 } 275 } 276 void NSCPlugin::hideTray() { 277 if (fHideTray == NULL) 278 throw NSPluginException(file_, _T("Critical error (HideTray)")); 279 try { 280 fHideTray(); 281 } catch (...) { 282 throw NSPluginException(file_, _T("Unhandled exception in HideTray.")); 283 } 284 } 285 262 286 /** 263 287 * Load all remote function pointers from the loaded module. … … 316 340 fGetConfigurationMeta = (lpGetConfigurationMeta)GetProcAddress(hModule_, "NSGetConfigurationMeta"); 317 341 fCommandLineExec = (lpCommandLineExec)GetProcAddress(hModule_, "NSCommandLineExec"); 342 343 fShowTray = (lpShowTray)GetProcAddress(hModule_, "ShowIcon"); 344 fHideTray = (lpHideTray)GetProcAddress(hModule_, "HideIcon"); 345 318 346 } 319 347 -
NSCPlugin.h
r99e4d8f rc0522cd 107 107 typedef INT (*lpUnLoadModule)(); 108 108 typedef INT (*lpGetConfigurationMeta)(int, TCHAR*); 109 typedef void (*lpShowTray)(); 110 typedef void (*lpHideTray)(); 109 111 110 112 … … 121 123 lpGetConfigurationMeta fGetConfigurationMeta; 122 124 lpCommandLineExec fCommandLineExec; 125 lpShowTray fShowTray; 126 lpHideTray fHideTray; 123 127 124 128 public: … … 139 143 std::wstring getCongifurationMeta(); 140 144 int commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR **arguments); 145 void showTray(); 146 void hideTray(); 147 141 148 std::wstring getModule() { 142 149 if (file_.empty()) -
NSClient++-2005.sln
rda1c7e1 rc0522cd 6 6 Release.AspNetCompiler.Debug = "False" 7 7 EndProjectSection 8 ProjectSection(ProjectDependencies) = postProject9 {F3401E75-60FB-4A0E-A18C-6505587D5B1A} = {F3401E75-60FB-4A0E-A18C-6505587D5B1A}10 {BA246C01-063A-4548-8957-32D5CC76171B} = {BA246C01-063A-4548-8957-32D5CC76171B}11 {BBFF8362-C626-4838-B0A2-F695D638AD24} = {BBFF8362-C626-4838-B0A2-F695D638AD24}12 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} = {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}13 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} = {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}14 {6F55C9BF-57F6-4A15-A058-C83A52F539EE} = {6F55C9BF-57F6-4A15-A058-C83A52F539EE}15 {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996} = {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996}16 {26B84883-BE52-40E6-9BEE-55AD056D5751} = {26B84883-BE52-40E6-9BEE-55AD056D5751}17 {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129} = {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129}18 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} = {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}19 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} = {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}20 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} = {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}21 {08D6246D-1B4A-47A3-965D-296DCC54A4E8} = {08D6246D-1B4A-47A3-965D-296DCC54A4E8}22 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} = {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}23 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} = {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}24 EndProjectSection25 8 EndProject 26 9 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SysTray", "modules\SysTray\SysTray-2005.vcproj", "{BBFF8362-C626-4838-B0A2-F695D638AD24}" … … 157 140 ProjectSection(ProjectDependencies) = postProject 158 141 {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 142 {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 159 143 EndProjectSection 160 144 EndProject … … 175 159 EndProjectSection 176 160 ProjectSection(ProjectDependencies) = postProject 161 {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 177 162 {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 178 163 EndProjectSection … … 191 176 EndProject 192 177 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckTaskSched", "modules\CheckTaskSched\CheckTaskSched-2005.vcproj", "{F3401E75-60FB-4A0E-A18C-6505587D5B1A}" 178 ProjectSection(WebsiteProperties) = preProject 179 Debug.AspNetCompiler.Debug = "True" 180 Release.AspNetCompiler.Debug = "False" 181 EndProjectSection 182 EndProject 183 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "systray_helper", "helpers\systray_helper\systray_helper.vcproj", "{43718644-173B-42D8-8AD1-E359BFB2BB20}" 193 184 ProjectSection(WebsiteProperties) = preProject 194 185 Debug.AspNetCompiler.Debug = "True" … … 262 253 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|Win32.ActiveCfg = Release|Win32 263 254 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|Win32.Build.0 = Release|Win32 264 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|x64.ActiveCfg = Release|Win32 255 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|x64.ActiveCfg = Release|x64 256 {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|x64.Build.0 = Release|x64 265 257 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Any CPU.ActiveCfg = Debug|x64 266 258 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Itanium.ActiveCfg = Debug|x64 … … 300 292 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|Win32.ActiveCfg = Release|Win32 301 293 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|Win32.Build.0 = Release|Win32 302 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|x64.ActiveCfg = Release|Win32 294 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|x64.ActiveCfg = Release|x64 295 {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|x64.Build.0 = Release|x64 303 296 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|Any CPU.ActiveCfg = Debug|x64 304 297 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|Itanium.ActiveCfg = Debug|x64 … … 338 331 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|Win32.ActiveCfg = Release|Win32 339 332 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|Win32.Build.0 = Release|Win32 340 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|x64.ActiveCfg = Release|Win32 333 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|x64.ActiveCfg = Release|x64 334 {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|x64.Build.0 = Release|x64 341 335 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Any CPU.ActiveCfg = Debug|x64 342 336 {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Itanium.ActiveCfg = Debug|x64 … … 376 370 {BA246C01-063A-4548-8957-32D5CC76171B}.Release|Win32.ActiveCfg = Release|Win32 377 371 {BA246C01-063A-4548-8957-32D5CC76171B}.Release|Win32.Build.0 = Release|Win32 378 {BA246C01-063A-4548-8957-32D5CC76171B}.Release|x64.ActiveCfg = Release|Win32 372 {BA246C01-063A-4548-8957-32D5CC76171B}.Release|x64.ActiveCfg = Release|x64 373 {BA246C01-063A-4548-8957-32D5CC76171B}.Release|x64.Build.0 = Release|x64 379 374 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|Any CPU.ActiveCfg = Debug|x64 380 375 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|Itanium.ActiveCfg = Debug|x64 … … 414 409 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|Win32.ActiveCfg = Release|Win32 415 410 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|Win32.Build.0 = Release|Win32 416 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|x64.ActiveCfg = Release|Win32 411 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|x64.ActiveCfg = Release|x64 412 {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|x64.Build.0 = Release|x64 417 413 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Any CPU.ActiveCfg = Debug|x64 418 414 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Itanium.ActiveCfg = Debug|x64 … … 452 448 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|Win32.ActiveCfg = Release|Win32 453 449 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|Win32.Build.0 = Release|Win32 454 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|x64.ActiveCfg = Release|Win32 450 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|x64.ActiveCfg = Release|x64 451 {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|x64.Build.0 = Release|x64 455 452 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Any CPU.ActiveCfg = Debug|x64 456 453 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Itanium.ActiveCfg = Debug|x64 … … 490 487 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|Win32.ActiveCfg = Release|Win32 491 488 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|Win32.Build.0 = Release|Win32 492 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|x64.ActiveCfg = Release|Win32 489 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|x64.ActiveCfg = Release|x64 490 {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|x64.Build.0 = Release|x64 493 491 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|Any CPU.ActiveCfg = Debug|x64 494 492 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|Itanium.ActiveCfg = Debug|x64 … … 528 526 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|Win32.ActiveCfg = Release|Win32 529 527 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|Win32.Build.0 = Release|Win32 530 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|x64.ActiveCfg = Release|Win32 528 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|x64.ActiveCfg = Release|x64 529 {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|x64.Build.0 = Release|x64 531 530 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|Any CPU.ActiveCfg = Debug|x64 532 531 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|Itanium.ActiveCfg = Debug|x64 … … 566 565 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|Win32.ActiveCfg = Release|Win32 567 566 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|Win32.Build.0 = Release|Win32 568 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|x64.ActiveCfg = Release|Win32 567 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|x64.ActiveCfg = Release|x64 568 {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|x64.Build.0 = Release|x64 569 569 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|Any CPU.ActiveCfg = Debug|x64 570 570 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|Itanium.ActiveCfg = Debug|x64 … … 604 604 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|Win32.ActiveCfg = Release|Win32 605 605 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|Win32.Build.0 = Release|Win32 606 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|x64.ActiveCfg = Release|Win32 606 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|x64.ActiveCfg = Release|x64 607 {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|x64.Build.0 = Release|x64 607 608 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Any CPU.ActiveCfg = Debug|x64 608 609 {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Itanium.ActiveCfg = Debug|x64 … … 1039 1040 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|Win32.Build.0 = Release|Win32 1040 1041 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|x64.ActiveCfg = Release|x64 1041 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|x64.Build.0 = Release|x641042 1042 {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Debug|Any CPU.ActiveCfg = Debug|Win32 1043 1043 {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Debug|Itanium.ActiveCfg = Debug|Win32 … … 1114 1114 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Release|x64.ActiveCfg = Release|x64 1115 1115 {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Release|x64.Build.0 = Release|x64 1116 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Any CPU.ActiveCfg = Debug|Win32 1117 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Itanium.ActiveCfg = Debug|Win32 1118 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 1119 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Mixed Platforms.Build.0 = Debug|Win32 1120 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.ActiveCfg = Debug|Win32 1121 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.Build.0 = Debug|Win32 1122 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.ActiveCfg = Debug|x64 1123 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.Build.0 = Debug|x64 1124 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Any CPU.ActiveCfg = Debug|Win32 1125 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Itanium.ActiveCfg = Debug|Win32 1126 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Mixed Platforms.ActiveCfg = Debug|Win32 1127 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Mixed Platforms.Build.0 = Debug|Win32 1128 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Win32.ActiveCfg = Debug|Win32 1129 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Win32.Build.0 = Debug|Win32 1130 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|x64.ActiveCfg = Debug|Win32 1131 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Any CPU.ActiveCfg = Debug|Win32 1132 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Itanium.ActiveCfg = Debug|Win32 1133 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Mixed Platforms.ActiveCfg = Debug|Win32 1134 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Mixed Platforms.Build.0 = Debug|Win32 1135 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Win32.ActiveCfg = Debug|Win32 1136 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Win32.Build.0 = Debug|Win32 1137 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|x64.ActiveCfg = Debug|Win32 1138 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Any CPU.ActiveCfg = Release|Win32 1139 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Itanium.ActiveCfg = Release|Win32 1140 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Mixed Platforms.ActiveCfg = Release|Win32 1141 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Mixed Platforms.Build.0 = Release|Win32 1142 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Win32.ActiveCfg = Nightly|Win32 1143 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Win32.Build.0 = Nightly|Win32 1144 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|x64.ActiveCfg = Nightly|x64 1145 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|x64.Build.0 = Nightly|x64 1146 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Any CPU.ActiveCfg = Release|Win32 1147 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Itanium.ActiveCfg = Release|Win32 1148 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Mixed Platforms.ActiveCfg = Release|Win32 1149 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Mixed Platforms.Build.0 = Release|Win32 1150 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Win32.ActiveCfg = Release|Win32 1151 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Win32.Build.0 = Release|Win32 1152 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|x64.ActiveCfg = Release|x64 1153 {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|x64.Build.0 = Release|x64 1116 1154 EndGlobalSection 1117 1155 GlobalSection(SolutionProperties) = preSolution … … 1135 1173 {F3401E75-60FB-4A0E-A18C-6505587D5B1A} = {9757464B-C125-4307-A84A-F4181AE6A081} 1136 1174 {0E2B21D9-F432-4127-8E92-7716B1072510} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 1137 {A3CF4E23-1D1B-4D93-A16A-48C52D118560} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2}1138 1175 {6206F046-3D36-4258-BB03-3291A7070117} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 1139 1176 {D96F7075-F6CD-4921-B5D8-8488E2D24BDB} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} -
NSClient++-2005.vcproj
r367bf20 rc0522cd 38 38 <Tool 39 39 Name="VCCustomBuildTool" 40 CommandLine=" "40 CommandLine="
" 41 41 Outputs="$(InputDir)\$(OutDir)\msvcp71.dll" 42 42 /> … … 85 85 <Tool 86 86 Name="VCLinkerTool" 87 AdditionalDependencies="kernel32.lib user32.lib advapi32.lib ws2_32.lib "87 AdditionalDependencies="kernel32.lib user32.lib advapi32.lib ws2_32.lib Userenv.lib" 88 88 OutputFile=".\Release/NSClient++.exe" 89 89 LinkIncremental="1" … … 139 139 <Tool 140 140 Name="VCCustomBuildTool" 141 CommandLine=" echo Copying dependency DLLs
cmd /c "copy $(InputDir)\dist_dll\*.* $(InputDir)\$(OutDir)\"
"141 CommandLine="
" 142 142 Outputs="$(InputDir)\$(OutDir)\msvcp71.dll" 143 143 /> … … 187 187 <Tool 188 188 Name="VCLinkerTool" 189 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Pdh.lib"189 AdditionalDependencies="kernel32.lib user32.lib advapi32.lib ws2_32.lib Userenv.lib" 190 190 OutputFile=".\Release/NSClient++.exe" 191 191 LinkIncremental="1" … … 283 283 <Tool 284 284 Name="VCLinkerTool" 285 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib "285 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 286 286 OutputFile=".\Debug/NSClient++.exe" 287 287 LinkIncremental="1" … … 378 378 <Tool 379 379 Name="VCLinkerTool" 380 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib "380 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 381 381 OutputFile=".\Debug/NSClient++.exe" 382 382 LinkIncremental="1" … … 669 669 <Tool 670 670 Name="VCLinkerTool" 671 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib "671 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 672 672 LinkIncremental="1" 673 673 SuppressStartupBanner="true" … … 757 757 <Tool 758 758 Name="VCLinkerTool" 759 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib "759 AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 760 760 LinkIncremental="1" 761 761 SuppressStartupBanner="true" … … 2377 2377 </File> 2378 2378 <File 2379 RelativePath=".\include\event_handler.hpp" 2380 > 2381 </File> 2382 <File 2379 2383 RelativePath=".\include\INISettings.h" 2380 2384 > … … 2401 2405 </File> 2402 2406 <File 2407 RelativePath=".\include\nsclient_session.hpp" 2408 > 2409 </File> 2410 <File 2403 2411 RelativePath=".\NSCPlugin.h" 2404 2412 > … … 2417 2425 </File> 2418 2426 <File 2427 RelativePath=".\include\remote_processes.hpp" 2428 > 2429 </File> 2430 <File 2419 2431 RelativePath=".\include\ServiceCmd.h" 2420 2432 > … … 2425 2437 </File> 2426 2438 <File 2439 RelativePath=".\include\shared_memory.hpp" 2440 > 2441 </File> 2442 <File 2427 2443 RelativePath=".\include\Singleton.h" 2428 2444 > … … 2442 2458 <File 2443 2459 RelativePath=".\include\thread.h" 2460 > 2461 </File> 2462 <File 2463 RelativePath=".\tray_manager.hpp" 2444 2464 > 2445 2465 </File> -
NSClient++.cpp
r846bbe4 rc0522cd 1 ////////////////////////////////////////////////////////////////////////// 1 /////////////////////////////////////////////////////////////////////////// 2 2 // NSClient++ Base Service 3 3 // … … 22 22 #include <config.h> 23 23 #include <msvc_wrappers.h> 24 24 #include <Userenv.h> 25 #include <remote_processes.hpp> 26 #include <Lmcons.h> 25 27 26 28 NSClient mainClient; // Global core instance. 27 29 bool g_bConsoleLog = false; 30 31 32 class tray_starter { 33 struct start_block { 34 std::wstring cmd; 35 std::wstring cmd_line; 36 DWORD sessionId; 37 }; 38 39 public: 40 static LPVOID init(DWORD dwSessionId, std::wstring exe, std::wstring cmdline) { 41 start_block *sb = new start_block; 42 sb->cmd = exe; 43 sb->cmd_line = cmdline; 44 sb->sessionId = dwSessionId; 45 return sb; 46 } 47 DWORD threadProc(LPVOID lpParameter) { 48 start_block* param = static_cast<start_block*>(lpParameter); 49 DWORD dwSessionId = param->sessionId; 50 std::wstring cmd = param->cmd; 51 std::wstring cmdline = param->cmd_line; 52 delete param; 53 for (int i=0;i<10;i++) { 54 Sleep(1000); 55 if (startTrayHelper(dwSessionId, cmd, cmdline, false)) 56 break; 57 } 58 return 0; 59 } 60 61 static bool start(DWORD dwSessionId) { 62 std::wstring program = mainClient.getBasePath() + _T("\\") + Settings::getInstance()->getString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_SYSTRAY_EXE, NSCLIENT_SETTINGS_SYSTRAY_EXE_DEFAULT); 63 std::wstring cmdln = _T("\"") + program + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 64 return tray_starter::startTrayHelper(dwSessionId, program, cmdln); 65 } 66 67 static bool startTrayHelper(DWORD dwSessionId, std::wstring exe, std::wstring cmdline, bool startThread = true) { 68 HANDLE hToken = NULL; 69 if (!remote_processes::GetSessionUserToken(dwSessionId, &hToken)) { 70 LOG_ERROR_STD(_T("Failed to query user token: ") + error::lookup::last_error()); 71 return false; 72 } else { 73 STARTUPINFO StartUPInfo; 74 PROCESS_INFORMATION ProcessInfo; 75 76 ZeroMemory(&StartUPInfo,sizeof(STARTUPINFO)); 77 ZeroMemory(&ProcessInfo,sizeof(PROCESS_INFORMATION)); 78 StartUPInfo.wShowWindow = SW_HIDE; 79 StartUPInfo.lpDesktop = L"Winsta0\\Default"; 80 StartUPInfo.cb = sizeof(STARTUPINFO); 81 82 wchar_t *buffer = new wchar_t[cmdline.size()+10]; 83 wcscpy(buffer, cmdline.c_str()); 84 LOG_MESSAGE_STD(_T("Running: ") + exe); 85 LOG_MESSAGE_STD(_T("Running: ") + cmdline); 86 87 LPVOID pEnv =NULL; 88 DWORD dwCreationFlags = CREATE_NO_WINDOW; //0; //DETACHED_PROCESS 89 90 if(CreateEnvironmentBlock(&pEnv,hToken,TRUE)) { 91 dwCreationFlags|=CREATE_UNICODE_ENVIRONMENT; 92 } else { 93 LOG_ERROR_STD(_T("Failed to create enviornment: ") + error::lookup::last_error()); 94 pEnv=NULL; 95 } 96 /* 97 LOG_ERROR_STD(_T("Impersonating user: ")); 98 if (!ImpersonateLoggedOnUser(hToken)) { 99 LOG_ERROR_STD(_T("Failed to impersonate the user: ") + error::lookup::last_error()); 100 } 101 102 wchar_t pszUname[UNLEN + 1]; 103 ZeroMemory(pszUname,sizeof(pszUname)); 104 DWORD dwSize = UNLEN; 105 if (!GetUserName(pszUname,&dwSize)) { 106 DWORD dwErr = GetLastError(); 107 if (!RevertToSelf()) 108 LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 109 LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 110 return false; 111 } 112 113 114 PROFILEINFO info; 115 info.dwSize = sizeof(PROFILEINFO); 116 info.lpUserName = pszUname; 117 if (!LoadUserProfile(hToken, &info)) { 118 DWORD dwErr = GetLastError(); 119 if (!RevertToSelf()) 120 LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 121 LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 122 return false; 123 } 124 */ 125 if (!CreateProcessAsUser(hToken, exe.c_str(), buffer, NULL, NULL, FALSE, dwCreationFlags, pEnv, NULL, &StartUPInfo, &ProcessInfo)) { 126 DWORD dwErr = GetLastError(); 127 delete [] buffer; 128 /* 129 if (!RevertToSelf()) { 130 LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 131 } 132 */ 133 if (startThread && dwErr == ERROR_PIPE_NOT_CONNECTED) { 134 LOG_MESSAGE(_T("Failed to start trayhelper: starting a background thread to do it instead...")); 135 Thread<tray_starter> *pThread = new Thread<tray_starter>(_T("tray-starter-thread")); 136 pThread->createThread(tray_starter::init(dwSessionId, exe, cmdline)); 137 return false; 138 } else if (dwErr == ERROR_PIPE_NOT_CONNECTED) { 139 LOG_ERROR_STD(_T("Thread failed to start trayhelper (will try again): ") + error::format::from_system(dwErr)); 140 return false; 141 } else { 142 LOG_ERROR_STD(_T("Failed to start trayhelper: ") + error::format::from_system(dwErr)); 143 return true; 144 } 145 } else { 146 delete [] buffer; 147 /* 148 if (!RevertToSelf()) { 149 LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 150 } 151 */ 152 LOG_MESSAGE_STD(_T("Started tray in other user session: ") + strEx::itos(dwSessionId)); 153 } 154 155 156 CloseHandle(hToken); 157 return true; 158 } 159 } 160 }; 161 162 163 164 28 165 29 166 /** … … 62 199 return -1; 63 200 } 201 LOG_MESSAGE(_T("Service uninstalled!")); 64 202 } else if ( _wcsicmp( _T("encrypt"), argv[1]+1 ) == 0 ) { 65 203 g_bConsoleLog = true; … … 104 242 LOG_MESSAGE(SZAPPNAME _T(" Version: ") SZVERSION _T(", Plattform: ") SZARCH); 105 243 } else if ( _wcsicmp( _T("noboot"), argv[1]+1 ) == 0 ) { 106 mainClient.setBoot(false);107 244 g_bConsoleLog = false; 108 245 mainClient.enableDebug(true); 109 mainClient. InitiateService();246 mainClient.initCore(false); 110 247 int nRetCode = -1; 111 248 if (argc>=4) … … 113 250 else if (argc>=3) 114 251 nRetCode = mainClient.commandLineExec(argv[2], argv[3], 0, NULL); 115 mainClient. TerminateService();252 mainClient.exitCore(false); 116 253 return nRetCode; 117 254 } else if ( _wcsicmp( _T("test"), argv[1]+1 ) == 0 ) { 118 std::wcout << "Launching test mode..." << std::endl; 255 bool server = false; 256 if (argc > 2 && _wcsicmp( _T("server"), argv[2] ) == 0 ) { 257 server = true; 258 } 259 std::wcout << "Launching test mode - " << (server?_T("server mode"):_T("client mode")) << std::endl; 119 260 LOG_MESSAGE_STD(_T("Booting: " SZSERVICEDISPLAYNAME )); 120 261 try { … … 123 264 } 124 265 } catch (const serviceControll::SCException& e) { 125 // Empty by design266 e;// Empty by design 126 267 } 127 268 g_bConsoleLog = true; 128 269 mainClient.enableDebug(true); 129 if (!mainClient. InitiateService()) {270 if (!mainClient.initCore(true)) { 130 271 LOG_ERROR_STD(_T("Service *NOT* started!")); 131 272 return -1; 132 273 } 274 if (server) 275 mainClient.startTrayIcon(0); 133 276 LOG_MESSAGE_STD(_T("Using settings from: ") + Settings::getInstance()->getActiveType()); 134 277 LOG_MESSAGE(_T("Enter command to inject or exit to terminate...")); … … 147 290 std::wcout << _T("Setting debug log on...") << std::endl; 148 291 mainClient.enableDebug(true); 292 } else if (s == _T("reattach")) { 293 std::wcout << _T("Reattaching to session 0") << std::endl; 294 mainClient.startTrayIcon(0); 149 295 } else if (std::cin.peek() < 15) { 150 296 buff += s; … … 166 312 } 167 313 } 168 mainClient. TerminateService();314 mainClient.exitCore(true); 169 315 return 0; 170 316 } else { … … 176 322 } else if (argc > 2) { 177 323 g_bConsoleLog = true; 178 mainClient. InitiateService();324 mainClient.initCore(true); 179 325 if (argc>=3) 180 326 nRetCode = mainClient.commandLineExec(argv[1], argv[2], argc-3, &argv[3]); 181 327 else 182 328 nRetCode = mainClient.commandLineExec(argv[1], argv[2], 0, NULL); 183 mainClient. TerminateService();329 mainClient.exitCore(true); 184 330 return nRetCode; 185 331 } else if (argc > 1) { … … 198 344 } 199 345 346 void NSClientT::session_error(std::wstring file, unsigned int line, std::wstring msg) { 347 NSAPIMessage(NSCAPI::error, file.c_str(), line, msg.c_str()); 348 } 349 350 351 352 200 353 ////////////////////////////////////////////////////////////////////////// 201 354 // Service functions 202 355 203 356 /** 204 * Service control handler startup point. 205 * When the program is started as a service this will be the entry point. 357 * Initialize the program 358 * @param boot true if we shall boot all plugins 359 * @param attachIfPossible is true we will attach to a running instance. 360 * @return success 361 * @author mickem 206 362 */ 207 bool NSClientT::InitiateService() { 363 bool NSClientT::initCore(bool boot) { 364 LOG_MESSAGE(_T("Attempting to start NSCLient++ - " SZVERSION)); 208 365 try { 209 366 Settings::getInstance()->setFile(getBasePath(), _T("NSC.ini")); … … 211 368 Settings::getInstance()->setInt(_T("log"), _T("debug"), 1); 212 369 } 370 if (enable_shared_session_) 371 Settings::getInstance()->setInt(MAIN_SECTION_TITLE, MAIN_SHARED_SESSION, 1); 372 enable_shared_session_ = Settings::getInstance()->getInt(MAIN_SECTION_TITLE, MAIN_SHARED_SESSION, MAIN_SHARED_SESSION_DEFAULT); 213 373 } catch (SettingsException e) { 214 374 LOG_ERROR_STD(_T("Could not find settings: ") + e.getMessage()); … … 217 377 LOG_ERROR_STD(_T("Unknown exception reading settings...")); 218 378 return false; 379 } 380 381 if (enable_shared_session_) { 382 if (boot) { 383 try { 384 shared_server_.reset(new nsclient_session::shared_server_session(this)); 385 if (!shared_server_->session_exists()) { 386 shared_server_->create_new_session(); 387 } else { 388 LOG_ERROR_STD(_T("Session already exists cant create a new one!")); 389 } 390 startTrayIcons(); 391 } catch (nsclient_session::session_exception e) { 392 LOG_ERROR_STD(_T("Failed to create new session: ") + e.what()); 393 shared_server_ = NULL; 394 } catch (...) { 395 LOG_ERROR_STD(_T("Failed to create new session: Unknown exception")); 396 shared_server_ = NULL; 397 } 398 } else { 399 try { 400 std::wstring id = _T("_attached_") + strEx::itos(GetCurrentProcessId()) + _T("_"); 401 shared_client_.reset(new nsclient_session::shared_client_session(id, this)); 402 if (shared_client_->session_exists()) { 403 shared_client_->attach_to_session(id); 404 } else { 405 LOG_ERROR_STD(_T("No session was found cant attach!")); 406 } 407 LOG_ERROR_STD(_T("Session is: ") + shared_client_->get_client_id()); 408 } catch (nsclient_session::session_exception e) { 409 LOG_ERROR_STD(_T("Failed to attach to session: ") + e.what()); 410 shared_client_ = NULL; 411 } catch (...) { 412 LOG_ERROR_STD(_T("Failed to attach to session: Unknown exception")); 413 shared_client_ = NULL; 414 } 415 } 219 416 } 220 417 … … 238 435 return false; 239 436 } 240 if (boot _) {437 if (boot) { 241 438 try { 242 439 SettingsT::sectionList list = Settings::getInstance()->getSection(_T("modules")); … … 256 453 } 257 454 } catch (SettingsException e) { 258 NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage());455 LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 259 456 } catch (...) { 260 457 LOG_ERROR_STD(_T("Unknown exception when loading settings")); … … 268 465 } 269 466 } 467 LOG_MESSAGE_STD(_T("NSCLient++ - " SZVERSION) + _T(" Started!")); 468 return true; 469 } 470 471 /** 472 * Service control handler startup point. 473 * When the program is started as a service this will be the entry point. 474 */ 475 bool NSClientT::InitiateService() { 476 if (!initCore(true)) 477 return false; 478 /* 479 DWORD dwSessionId = remote_processes::getActiveSessionId(); 480 if (dwSessionId != 0xFFFFFFFF) 481 tray_starter::start(dwSessionId); 482 else 483 LOG_ERROR_STD(_T("Failed to start tray helper:" ) + error::lookup::last_error()); 484 */ 485 return true; 486 } 487 488 void NSClientT::startTrayIcons() { 489 if (shared_server_.get() == NULL) { 490 LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 491 return; 492 } 493 remote_processes::PWTS_SESSION_INFO list; 494 DWORD count; 495 if (!remote_processes::_WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE , 0, 1, &list, &count)) { 496 LOG_ERROR_STD(_T("Failed to enumerate sessions:" ) + error::lookup::last_error()); 497 } else { 498 LOG_DEBUG_STD(_T("Found ") + strEx::itos(count) + _T(" sessions")); 499 for (DWORD i=0;i<count;i++) { 500 LOG_DEBUG_STD(_T("Found session") + strEx::itos(list[i].SessionId) + _T(" state: ") + strEx::itos(list[i].State)); 501 if (list[i].State == remote_processes::_WTS_CONNECTSTATE_CLASS::WTSActive) { 502 startTrayIcon(list[i].SessionId); 503 } 504 } 505 } 506 } 507 void NSClientT::startTrayIcon(DWORD dwSessionId) { 508 if (shared_server_.get() == NULL) { 509 LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 510 return; 511 } 512 if (!shared_server_->re_attach_client(dwSessionId)) { 513 if (!tray_starter::start(dwSessionId)) { 514 LOG_ERROR_STD(_T("Failed to start session (") + strEx::itos(dwSessionId) + _T("): " ) + error::lookup::last_error()); 515 } 516 } 517 } 518 519 bool NSClientT::exitCore(bool boot) { 520 LOG_MESSAGE(_T("Attempting to stop NSCLient++ - " SZVERSION)); 521 if (boot) { 522 try { 523 LOG_DEBUG_STD(_T("Stopping: NON Message Handling Plugins")); 524 mainClient.unloadPlugins(false); 525 } catch(NSPluginException e) { 526 std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 527 } catch(...) { 528 std::wcout << _T("UNknown exception raised: ") << std::endl;; 529 } 530 } 531 LOG_DEBUG_STD(_T("Stopping: COM helper")); 532 try { 533 com_helper_.unInitialize(); 534 } catch (com_helper::com_exception e) { 535 LOG_ERROR_STD(_T("COM exception: ") + e.getMessage()); 536 } catch (...) { 537 LOG_ERROR_STD(_T("Unknown exception uniniating COM...")); 538 } 539 LOG_DEBUG_STD(_T("Stopping: Socket Helpers")); 540 try { 541 simpleSocket::WSACleanup(); 542 } catch (simpleSocket::SocketException e) { 543 LOG_ERROR_STD(_T("Socket exception: ") + e.getMessage()); 544 } catch (...) { 545 LOG_ERROR_STD(_T("Unknown exception uniniating socket...")); 546 } 547 LOG_DEBUG_STD(_T("Stopping: Settings instance")); 548 Settings::destroyInstance(); 549 try { 550 if (shared_client_.get() != NULL) { 551 LOG_DEBUG_STD(_T("Stopping: shared client")); 552 shared_client_->set_handler(NULL); 553 shared_client_->close_session(); 554 } 555 } catch(nsclient_session::session_exception &e) { 556 std::wcout << _T("Exception closing shared client session: ") << e.what() << std::endl;; 557 } catch(...) { 558 std::wcout << _T("Exception closing shared client session: Unknown exception!") << std::endl;; 559 } 560 try { 561 if (shared_server_.get() != NULL) { 562 LOG_DEBUG_STD(_T("Stopping: shared server")); 563 shared_server_->set_handler(NULL); 564 shared_server_->close_session(); 565 } 566 } catch(...) { 567 std::wcout << _T("UNknown exception raised: ") << std::endl;; 568 } 569 if (boot) { 570 try { 571 LOG_DEBUG_STD(_T("Stopping: Message handling Plugins")); 572 mainClient.unloadPlugins(true); 573 } catch(NSPluginException e) { 574 std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 575 } catch(...) { 576 std::wcout << _T("UNknown exception raised: ") << std::endl;; 577 } 578 } 579 LOG_MESSAGE_STD(_T("NSCLient++ - " SZVERSION) + _T(" Stopped succcessfully")); 270 580 return true; 271 581 } … … 275 585 */ 276 586 void NSClientT::TerminateService(void) { 277 if (boot_) { 278 try { 279 mainClient.unloadPlugins(); 280 } catch(NSPluginException e) { 281 std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 282 } catch(...) { 283 std::wcout << _T("UNknown exception raised: ") << std::endl;; 284 } 285 } 286 try { 287 com_helper_.unInitialize(); 288 } catch (com_helper::com_exception e) { 289 LOG_ERROR_STD(_T("COM exception: ") + e.getMessage()); 290 } catch (...) { 291 LOG_ERROR_STD(_T("Unknown exception uniniating COM...")); 292 } 293 try { 294 simpleSocket::WSACleanup(); 295 } catch (simpleSocket::SocketException e) { 296 LOG_ERROR_STD(_T("Socket exception: ") + e.getMessage()); 297 } catch (...) { 298 LOG_ERROR_STD(_T("Unknown exception uniniating socket...")); 299 } 300 Settings::destroyInstance(); 587 exitCore(true); 301 588 } 302 589 … … 309 596 mainClient.service_main(dwArgc, lpszArgv); 310 597 } 598 DWORD WINAPI NSClientT::service_ctrl_dispatch_ex(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) { 599 LOG_ERROR_STD(_T("service_ctrl_dispatch_ex dispatching event: ") + strEx::itos(dwControl)); 600 return mainClient.service_ctrl_ex(dwControl, dwEventType, lpEventData, lpContext); 601 } 602 311 603 /** 312 604 * Forward this to the main service dispatcher helper class … … 314 606 */ 315 607 void WINAPI NSClientT::service_ctrl_dispatch(DWORD dwCtrlCode) { 316 mainClient.service_ctrl(dwCtrlCode); 317 } 608 LOG_ERROR_STD(_T("service_ctrl_dispatch dispatching event: ") + strEx::itos(dwCtrlCode)); 609 mainClient.service_ctrl_ex(dwCtrlCode, NULL, NULL, NULL); 610 } 611 612 613 void NSClientT::service_on_session_changed(DWORD dwSessionId, bool logon, DWORD dwEventType) { 614 LOG_MESSAGE_STD(_T("Got session change: ") + strEx::itos(dwSessionId)); 615 if (!logon) { 616 LOG_MESSAGE_STD(_T("Not a logon event: ") + strEx::itos(dwEventType)); 617 return; 618 } 619 tray_starter::start(dwSessionId); 620 } 621 318 622 319 623 ////////////////////////////////////////////////////////////////////////// … … 383 687 * Unload all plug-ins (in reversed order) 384 688 */ 385 void NSClientT::unloadPlugins( ) {689 void NSClientT::unloadPlugins(bool unloadLoggers) { 386 690 { 387 691 WriteLock writeLock(&m_mutexRW, true, 10000); … … 391 695 } 392 696 commandHandlers_.clear(); 393 messageHandlers_.clear(); 697 if (unloadLoggers) 698 messageHandlers_.clear(); 394 699 } 395 700 { … … 401 706 for (pluginList::size_type i=plugins_.size();i>0;i--) { 402 707 NSCPlugin *p = plugins_[i-1]; 403 LOG_DEBUG_STD(_T("Unloading plugin: ") + p->getName() + _T("...")); 708 if (!unloadLoggers && p->hasMessageHandler()) { 709 LOG_DEBUG_STD(_T("Skipping log plugin: ") + p->getModule() + _T("...")); 710 continue; 711 } 712 LOG_DEBUG_STD(_T("Unloading plugin: ") + p->getModule() + _T("...")); 404 713 p->unload(); 405 714 } … … 413 722 for (pluginList::size_type i=plugins_.size();i>0;i--) { 414 723 NSCPlugin *p = plugins_[i-1]; 415 plugins_[i-1] = NULL; 416 delete p; 417 } 418 plugins_.clear(); 724 if (unloadLoggers || !p->hasMessageHandler()) { 725 LOG_DEBUG_STD(_T("Deleating plugin instance: ") + p->getModule() + _T("...")); 726 plugins_[i-1] = NULL; 727 delete p; 728 plugins_.erase(plugins_.begin() + i-1); 729 --i; 730 } 731 } 732 //plugins_.clear(); 419 733 } 420 734 } … … 430 744 (*it)->load_plugin(); 431 745 } 746 plugins_loaded_ = true; 432 747 } 433 748 /** … … 498 813 len = Settings::getInstance()->getInt(MAIN_SECTION_TITLE, MAIN_STRING_LENGTH, MAIN_STRING_LENGTH_DEFAULT); 499 814 } catch (SettingsException &e) { 500 NSC_DEBUG_MSG(_T("Failed to get length: ") + e.getMessage());815 LOG_DEBUG_STD(_T("Failed to get length: ") + e.getMessage()); 501 816 return MAIN_STRING_LENGTH_DEFAULT; 502 817 } catch (...) { 503 NSC_LOG_ERROR(_T("Failed to get length: :("));818 LOG_ERROR(_T("Failed to get length: :(")); 504 819 return MAIN_STRING_LENGTH_DEFAULT; 505 820 } … … 509 824 510 825 NSCAPI::nagiosReturn NSClientT::inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 511 unsigned int aLen = 0; 512 TCHAR ** aBuf = arrayBuffer::split2arrayBuffer(arguments, splitter, aLen, escape); 513 unsigned int buf_len = getBufferLength(); 514 TCHAR * mBuf = new TCHAR[buf_len+1]; mBuf[0] = '\0'; 515 TCHAR * pBuf = new TCHAR[buf_len+1]; pBuf[0] = '\0'; 516 NSCAPI::nagiosReturn ret = injectRAW(command.c_str(), aLen, aBuf, mBuf, buf_len, pBuf, buf_len); 517 arrayBuffer::destroyArrayBuffer(aBuf, aLen); 518 if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) { 826 if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 827 try { 828 return shared_client_->inject(command, arguments, splitter, escape, msg, perf); 829 } catch (nsclient_session::session_exception &e) { 830 LOG_ERROR_STD(_T("Failed to inject remote command: ") + e.what()); 831 return NSCAPI::returnCRIT; 832 } catch (...) { 833 LOG_ERROR_STD(_T("Failed to inject remote command: Unknown exception")); 834 return NSCAPI::returnCRIT; 835 } 836 } else { 837 unsigned int aLen = 0; 838 TCHAR ** aBuf = arrayBuffer::split2arrayBuffer(arguments, splitter, aLen, escape); 839 unsigned int buf_len = getBufferLength(); 840 TCHAR * mBuf = new TCHAR[buf_len+1]; mBuf[0] = '\0'; 841 TCHAR * pBuf = new TCHAR[buf_len+1]; pBuf[0] = '\0'; 842 NSCAPI::nagiosReturn ret = injectRAW(command.c_str(), aLen, aBuf, mBuf, buf_len, pBuf, buf_len); 843 arrayBuffer::destroyArrayBuffer(aBuf, aLen); 844 if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) { 845 delete [] mBuf; 846 delete [] pBuf; 847 return ret; 848 } 849 msg = mBuf; 850 perf = pBuf; 519 851 delete [] mBuf; 520 852 delete [] pBuf; 521 853 return ret; 522 854 } 523 msg = mBuf;524 perf = pBuf;525 delete [] mBuf;526 delete [] pBuf;527 return ret;528 855 } 529 856 … … 544 871 LOG_DEBUG_STD(_T("Injecting: ") + (std::wstring) command + _T(": ") + arrayBuffer::arrayBuffer2string(argument, argLen, _T(", "))); 545 872 } 546 ReadLock readLock(&m_mutexRW, true, 5000); 547 if (!readLock.IsLocked()) { 548 LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 549 return NSCAPI::returnUNKNOWN; 550 } 551 for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 873 if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 552 874 try { 553 NSCAPI::nagiosReturn c = commandHandlers_[i]->handleCommand(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 554 switch (c) { 555 case NSCAPI::returnInvalidBufferLen: 556 LOG_ERROR(_T("UNKNOWN: Return buffer to small to handle this command.")); 557 return c; 558 case NSCAPI::returnIgnored: 559 break; 560 case NSCAPI::returnOK: 561 case NSCAPI::returnWARN: 562 case NSCAPI::returnCRIT: 563 case NSCAPI::returnUNKNOWN: 564 LOG_DEBUG_STD(_T("Injected Result: ") + NSCHelper::translateReturn(c) + _T(" '") + (std::wstring)(returnMessageBuffer) + _T("'")); 565 LOG_DEBUG_STD(_T("Injected Performance Result: '") +(std::wstring)(returnPerfBuffer) + _T("'")); 566 return c; 567 default: 568 LOG_ERROR_STD(_T("Unknown error from handleCommand: ") + strEx::itos(c) + _T(" the injected command was: ") + (std::wstring)command); 569 return c; 570 } 571 } catch(const NSPluginException& e) { 572 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 573 return NSCAPI::returnCRIT; 574 } catch(...) { 575 LOG_ERROR_STD(_T("Unknown exception raised in module")); 576 return NSCAPI::returnCRIT; 577 } 578 } 579 LOG_MESSAGE_STD(_T("No handler for command: '") + command + _T("'")); 580 return NSCAPI::returnIgnored; 875 std::wstring msg, perf; 876 int returnCode = shared_client_->inject(command, arrayBuffer::arrayBuffer2string(argument, argLen, _T(" ")), L' ', true, msg, perf); 877 NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, msg, returnCode); 878 return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, perf, returnCode); 879 } catch (nsclient_session::session_exception &e) { 880 LOG_ERROR_STD(_T("Failed to inject remote command: ") + e.what()); 881 int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command: ") + e.what(), NSCAPI::returnCRIT); 882 return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 883 } catch (...) { 884 LOG_ERROR_STD(_T("Failed to inject remote command: Unknown exception")); 885 int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command: + e.what()"), NSCAPI::returnCRIT); 886 return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 887 } 888 } else { 889 ReadLock readLock(&m_mutexRW, true, 5000); 890 if (!readLock.IsLocked()) { 891 LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 892 return NSCAPI::returnUNKNOWN; 893 } 894 for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 895 try { 896 NSCAPI::nagiosReturn c = commandHandlers_[i]->handleCommand(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 897 switch (c) { 898 case NSCAPI::returnInvalidBufferLen: 899 LOG_ERROR(_T("UNKNOWN: Return buffer to small to handle this command.")); 900 return c; 901 case NSCAPI::returnIgnored: 902 break; 903 case NSCAPI::returnOK: 904 case NSCAPI::returnWARN: 905 case NSCAPI::returnCRIT: 906 case NSCAPI::returnUNKNOWN: 907 LOG_DEBUG_STD(_T("Injected Result: ") + NSCHelper::translateReturn(c) + _T(" '") + (std::wstring)(returnMessageBuffer) + _T("'")); 908 LOG_DEBUG_STD(_T("Injected Performance Result: '") +(std::wstring)(returnPerfBuffer) + _T("'")); 909 return c; 910 default: 911 LOG_ERROR_STD(_T("Unknown error from handleCommand: ") + strEx::itos(c) + _T(" the injected command was: ") + (std::wstring)command); 912 return c; 913 } 914 } catch(const NSPluginException& e) { 915 LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 916 return NSCAPI::returnCRIT; 917 } catch(...) { 918 LOG_ERROR_STD(_T("Unknown exception raised in module")); 919 return NSCAPI::returnCRIT; 920 } 921 } 922 LOG_MESSAGE_STD(_T("No handler for command: '") + command + _T("'")); 923 return NSCAPI::returnIgnored; 924 } 581 925 } 582 926 … … 606 950 if ((msgType == NSCAPI::debug)&&(!logDebug())) { 607 951 return; 952 } 953 if (shared_server_.get() != NULL && shared_server_->hasClients()) { 954 try { 955 shared_server_->sendLogMessageToClients(msgType, file, line, message); 956 } catch (nsclient_session::session_exception e) { 957 std::wcout << _T("Failed to send message to clients: ") << e.what() << std::endl; 958 } 608 959 } 609 960 std::wstring file_stl = file; … … 644 995 std::cout << k << " " << strEx::wstring_to_string(file_stl) << "(" << line << ") " << strEx::wstring_to_string(message) << std::endl; 645 996 } 646 for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 647 try { 648 messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 649 } catch(const NSPluginException& e) { 650 // Here we are pretty much fucked! (as logging this might cause a loop :) 651 std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 652 std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 997 if (messageHandlers_.size() == 0 || !plugins_loaded_) { 998 log_cache_.push_back(cached_log_entry(msgType, file, line, message)); 999 } else { 1000 if (log_cache_.size() > 0) { 1001 std::wcout << _T("*** SENDING CACHE***") << std::endl; 1002 for (log_cache_type::const_iterator cit=log_cache_.begin();cit!=log_cache_.end();++cit) { 1003 for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 1004 try { 1005 messageHandlers_[i]->handleMessage((*cit).msgType, (_T("CACHE") + (*cit).file).c_str(), (*cit).line, (*cit).message.c_str()); 1006 } catch(const NSPluginException& e) { 1007 // Here we are pretty much fucked! (as logging this might cause a loop :) 1008 std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 1009 std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 1010 } 1011 } 1012 } 1013 log_cache_.clear(); 1014 } 1015 for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 1016 try { 1017 messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 1018 } catch(const NSPluginException& e) { 1019 // Here we are pretty much fucked! (as logging this might cause a loop :) 1020 std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 1021 std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 1022 } 653 1023 } 654 1024 } … … 673 1043 Settings::getInstance()->setFile(basePath, _T("NSC.ini")); 674 1044 } catch (SettingsException e) { 675 NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage());1045 LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 676 1046 } 677 1047 return basePath; … … 683 1053 return NSCHelper::wrapReturnString(buffer, bufLen, Settings::getInstance()->getString(section, key, defaultValue), NSCAPI::isSuccess); 684 1054 } catch (...) { 685 NSC_LOG_ERROR_STD(_T("Failed to getString: ") + key);1055 LOG_ERROR_STD(_T("Failed to getString: ") + key); 686 1056 return NSCAPI::hasFailed; 687 1057 } … … 691 1061 return Settings::getInstance()->getInt(section, key, defaultValue); 692 1062 } catch (SettingsException e) { 693 NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage());1063 LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 694 1064 return defaultValue; 695 1065 } … … 720 1090 return NSCAPI::isSuccess; 721 1091 } catch (...) { 722 NSC_LOG_ERROR_STD(_T("Failed to getSection: ") + section);1092 LOG_ERROR_STD(_T("Failed to getSection: ") + section); 723 1093 return NSCAPI::hasFailed; 724 1094 } … … 848 1218 Settings::getInstance()->setString(section, key, value); 849 1219 } catch (...) { 850 NSC_LOG_ERROR_STD(_T("Failed to setString: ") + key);1220 LOG_ERROR_STD(_T("Failed to setString: ") + key); 851 1221 return NSCAPI::hasFailed; 852 1222 } … … 857 1227 Settings::getInstance()->setInt(section, key, value); 858 1228 } catch (...) { 859 NSC_LOG_ERROR_STD(_T("Failed to setInt: ") + key);1229 LOG_ERROR_STD(_T("Failed to setInt: ") + key); 860 1230 return NSCAPI::hasFailed; 861 1231 } … … 874 1244 return NSCAPI::hasFailed; 875 1245 } catch (...) { 876 NSC_LOG_ERROR_STD(_T("Failed to write settings"));1246 LOG_ERROR_STD(_T("Failed to write settings")); 877 1247 return NSCAPI::hasFailed; 878 1248 } … … 891 1261 return NSCAPI::hasFailed; 892 1262 } catch (...) { 893 NSC_LOG_ERROR_STD(_T("Failed to read settings"));1263 LOG_ERROR_STD(_T("Failed to read settings")); 894 1264 return NSCAPI::hasFailed; 895 1265 } -
NSClient++.h
r367bf20 rc0522cd 30 30 #include <map> 31 31 #include <com_helpers.hpp> 32 32 #include <nsclient_session.hpp> 33 33 34 34 /** … … 57 57 * 58 58 */ 59 class NSClientT { 59 class NSClientT : public nsclient_session::session_handler_interface { 60 60 61 private: 62 63 class NSException { 64 std::wstring what_; 65 public: 66 NSException(std::wstring what) : what_(what){} 67 std::wstring what() { 68 return what_; 69 } 70 }; 71 struct cached_log_entry { 72 cached_log_entry(int msgType_, std::wstring file_, int line_, std::wstring message_) 73 : msgType(msgType_), 74 file(file_), 75 line(line_), 76 message(message_) 77 {} 78 int msgType; 79 std::wstring file; 80 int line; 81 std::wstring message; 82 }; 83 61 84 typedef NSCPlugin* plugin_type; 62 85 typedef std::vector<plugin_type> pluginList; 63 86 typedef std::map<std::wstring,std::wstring> cmdMap; 87 typedef std::list<cached_log_entry> log_cache_type; 64 88 pluginList plugins_; 65 89 pluginList commandHandlers_; … … 73 97 typedef enum log_status {log_unknown, log_debug, log_nodebug }; 74 98 log_status debug_; 75 bool boot_;76 99 com_helper::initialize_com com_helper_; 100 std::auto_ptr<nsclient_session::shared_client_session> shared_client_; 101 std::auto_ptr<nsclient_session::shared_server_session> shared_server_; 102 log_cache_type log_cache_; 103 bool plugins_loaded_; 104 bool enable_shared_session_; 77 105 78 106 public: 79 107 // c-tor, d-tor 80 NSClientT(void) : debug_(log_unknown), boot_(true) {}108 NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false) {} 81 109 virtual ~NSClientT(void) {} 82 110 void enableDebug(bool debug = true) { … … 86 114 debug_ = log_nodebug; 87 115 } 88 void setBoot(bool boot = true) {89 boot_ = boot;90 }91 116 92 117 // Service helper functions 93 118 bool InitiateService(); 94 119 void TerminateService(void); 120 bool initCore(bool boot); 121 bool exitCore(bool boot); 95 122 static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv); 96 123 static void WINAPI service_ctrl_dispatch(DWORD dwCtrlCode); 124 static DWORD WINAPI service_ctrl_dispatch_ex(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext); 125 void service_on_session_changed(DWORD dwSessionId, bool logon, DWORD dwEventType); 97 126 98 127 // Member functions … … 108 137 plugin_type loadPlugin(const std::wstring plugin); 109 138 void loadPlugins(void); 110 void unloadPlugins( void);139 void unloadPlugins(bool unloadLoggers); 111 140 std::wstring describeCommand(std::wstring command); 112 141 std::list<std::wstring> getAllCommandNames(); 113 142 void registerCommand(std::wstring cmd, std::wstring desc); 114 143 unsigned int getBufferLength(); 144 void startTrayIcons(); 145 void startTrayIcon(DWORD dwSessionId); 115 146 116 147 bool logDebug(); 148 149 // Shared session interface: 150 void session_error(std::wstring file, unsigned int line, std::wstring msg); 151 void session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message) { 152 reportMessage(msgType, file, line, message); 153 } 154 int session_inject(std::wstring command, std::wstring arguments, std::wstring splitter, bool escape, std::wstring &msg, std::wstring & perf) { 155 return inject(command, arguments, splitter[0], escape, msg, perf); 156 } 157 158 117 159 118 160 private: -
changelog
r846bbe4 rc0522cd 5 5 * Improved socket performance (would be nice if we could be used as a "hub") 6 6 7 2008-08-16 MickeM 8 * *WARNING* THIS IS VERY VERY UNSTABEL (possibly) 9 * *WARNING* A lot of new untested code here so dont run in production enviornments :) 10 + Added shared session so system tray can communicate with master 11 + Added new system tray handlig (via TS so FUS should work with it) 12 + Added new option [System] / shared_session=0 (or 1) to enable / disable the new shared memory framework (it is for now disabled by default) 13 If you want to try this remember to change that option but also beware! it is dagerous and not finnished and and also there is as of now no security at all. 14 7 15 2008-08-09 MickeM 8 + Added ChangeWindowMessageFilter so systray should notwork on vista and beyond!16 + Added ChangeWindowMessageFilter so systray should maybe work on vista and beyond! 9 17 10 18 2008-07-28 MickeM -
helpers/UploadBinaries/UploadBinaries.vcproj
r846bbe4 rc0522cd 381 381 <Tool 382 382 Name="VCCustomBuildTool" 383 CommandLine="echo Making archive
7z.exe a -r -tzip -bd "$(TargetDir)\NSClient++-$(PlatformName).zip" "$(TargetDir)\*"
echo Renaming archive
postbuild.pl "$(TargetDir)\NSClient++-$(PlatformName).zip" zip
echo Sending to server
pscp.exe "$(TargetDir)\*.zip" mickem@ssl.nakednuns.org:/var/www/files/nightly/
"383 CommandLine="echo Making archive
7z.exe a -r -tzip -bd "$(TargetDir)\NSClient++-$(PlatformName).zip" "$(TargetDir)\*"
echo Renaming archive
postbuild.pl "$(TargetDir)\NSClient++-$(PlatformName).zip" zip
echo Sending to server
pscp.exe "$(TargetDir)\*.zip" nscp@druss.medin.name:/var/www/files/nightly/
" 384 384 Outputs="foo" 385 385 /> -
helpers/UploadInstaller/UploadInstaller.vcproj
r846bbe4 rc0522cd 247 247 <Tool 248 248 Name="VCCustomBuildTool" 249 CommandLine="echo Renaming archive
echo mkdir "$(OutDir)"
mkdir "$(OutDir)"
cmd /c del "$(OutDir)\*.msi""
cmd /c copy "..\installer\bin\$(ConfigurationName)\NSClient++.msi" "$(OutDir)\NSClient++-$(PlatformName).msi""
postbuild.pl "$(TargetDir)\NSClient++-$(PlatformName).msi" msi
echo Sending to server
pscp.exe "$(TargetDir)\*.msi" mickem@ssl.nakednuns.org:/var/www/files/nightly/
"249 CommandLine="echo Renaming archive
echo mkdir "$(OutDir)"
mkdir "$(OutDir)"
cmd /c del "$(OutDir)\*.msi""
cmd /c copy "..\installer\bin\$(ConfigurationName)\NSClient++.msi" "$(OutDir)\NSClient++-$(PlatformName).msi""
postbuild.pl "$(TargetDir)\NSClient++-$(PlatformName).msi" msi
echo Sending to server
pscp.exe "$(TargetDir)\*.msi" nscp@druss.medin.name:/var/www/files/nightly/
" 250 250 Outputs="foo" 251 251 /> -
include/Mutex.h
r394f7a1 rc0522cd 25 25 #include <windows.h> 26 26 #include <iostream> 27 #include <error.hpp> 28 29 class mutex_exception { 30 std::wstring what_; 31 public: 32 mutex_exception(std::wstring what) : what_(what) {} 33 std::wstring what() { return what_; } 34 }; 27 35 28 36 /** … … 50 58 */ 51 59 class MutexHandler { 60 public: 52 61 private: 53 62 HANDLE hMutex; 63 DWORD dwWaitResult; 64 bool bCreated; 54 65 public: 55 66 /** … … 57 68 * Creates an unnamed mutex. 58 69 */ 59 MutexHandler() : hMutex(NULL) { 60 hMutex = CreateMutex(NULL, FALSE, NULL); 70 MutexHandler(std::wstring name = _T("")) : hMutex(NULL), dwWaitResult(0), bCreated(false) { 71 //std::wcout << _T("Creating mutex: ") << name << std::endl; 72 hMutex = CreateMutex(NULL, FALSE, name.empty()?NULL:name.c_str()); 61 73 if (hMutex == NULL && GetLastError() == ERROR_ALREADY_EXISTS ) 62 hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NULL); 63 if (hMutex == NULL) { 64 std::wcout << _T("Error in mutex creation: ") << GetLastError() << std::endl; 65 } 74 hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name.empty()?NULL:name.c_str()); 75 else 76 bCreated = true; 77 if (hMutex == NULL) 78 throw mutex_exception(_T("Failed to create mutex: ") + error::lookup::last_error()); 66 79 } 67 80 /** … … 74 87 hMutex = NULL; 75 88 } 89 void close() { 90 if (hMutex) 91 CloseHandle(hMutex); 92 hMutex = NULL; 93 } 94 bool mutexWasCreated() { 95 return bCreated; 96 } 76 97 /** 77 98 * HANDLe cast operator to retrieve the handle from the enclosed mutex object. … … 80 101 operator HANDLE () const { 81 102 return hMutex; 103 } 104 /** 105 * Release the mutex 106 */ 107 void releaseLock() { 108 if (hMutex == NULL) 109 throw mutex_exception(_T("Failed to release mutex lock (mutex handle is null)")); 110 if (!ReleaseMutex(hMutex)) 111 throw mutex_exception(_T("Failed to relase the mutex: ") + error::lookup::last_error()); 112 } 113 /** 114 * Waits for the mutex object. 115 * @timeout The timeout before abandoning wait 116 */ 117 bool accuireLock(DWORD timeout = 5000L) { 118 if (hMutex == NULL) 119 throw mutex_exception(_T("Failed to get mutex lock (mutex handle is null)")); 120 dwWaitResult = WaitForSingleObject(hMutex, timeout); 121 switch (dwWaitResult) { 122 // The thread got mutex ownership. 123 case WAIT_OBJECT_0: 124 return true; 125 case WAIT_TIMEOUT: 126 return false; 127 case WAIT_ABANDONED: 128 return true; 129 default: 130 throw mutex_exception(_T("Unknown returncode from the mutex: ") + strEx::itos(dwWaitResult)); 131 132 } 133 } 134 /** 135 * Get the result of the wait operation. 136 * @return Result of the wait operation 137 */ 138 DWORD getWaitResult() const { 139 return dwWaitResult; 82 140 } 83 141 }; … … 125 183 MutexLock(HANDLE hMutex, DWORD timeout = 5000L) : bHasMutex(false), hMutex_(hMutex) { 126 184 if (hMutex_ == NULL) { 127 std::wcout << _T("Error in mutex lock: ") << std::endl; 185 throw mutex_exception(_T("Failed to get mutex lock (mutex handle is null)")); 186 /* 128 187 bHasMutex = false; 129 188 return; 189 */ 130 190 } 131 191 dwWaitResult = WaitForSingleObject(hMutex_, timeout); … … 135 195 bHasMutex = true; 136 196 break; 137 case WAIT_TIMEOUT: 138 bHasMutex = false; 139 break; 140 case WAIT_ABANDONED: 197 case WAIT_TIMEOUT: 198 bHasMutex = false; 199 break; 200 case WAIT_ABANDONED: 141 201 bHasMutex = false; 142 202 break; … … 195 255 void lock(DWORD timeout = 5000L) { 196 256 if (hMutex_ == NULL) { 257 throw mutex_exception(_T("Failed to get mutex lock (mutex handle is null)")); 258 /* 197 259 std::wcout << _T("Error in mutex lock: ") << std::endl; 198 260 bHasMutex = false; 199 261 return; 262 */ 200 263 } 201 264 dwWaitResult = WaitForSingleObject(hMutex_, timeout); -
include/NSCHelper.cpp
r846bbe4 rc0522cd 146 146 lpNSAPIMessage fNSAPIMessage = NULL; 147 147 lpNSAPIStopServer fNSAPIStopServer = NULL; 148 lpNSAPIExit fNSAPIExit = NULL; 148 149 lpNSAPIInject fNSAPIInject = NULL; 149 150 lpNSAPICheckLogMessages fNSAPICheckLogMessages = NULL; … … 310 311 } 311 312 /** 313 * Close the program (usefull for tray/testmode) without stopping the service (unless this is the service). 314 * @author mickem 315 */ 316 void NSCModuleHelper::Exit(void) { 317 if (fNSAPIExit) 318 fNSAPIExit(); 319 } 320 /** 312 321 * Retrieve a string from the settings subsystem (INI-file) 313 322 * Might possibly be located in the registry in the future. … … 609 618 NSCModuleHelper::fNSAPIMessage = (NSCModuleHelper::lpNSAPIMessage)f(_T("NSAPIMessage")); 610 619 NSCModuleHelper::fNSAPIStopServer = (NSCModuleHelper::lpNSAPIStopServer)f(_T("NSAPIStopServer")); 620 NSCModuleHelper::fNSAPIExit = (NSCModuleHelper::lpNSAPIExit)f(_T("NSAPIExit")); 611 621 NSCModuleHelper::fNSAPIInject = (NSCModuleHelper::lpNSAPIInject)f(_T("NSAPIInject")); 612 622 NSCModuleHelper::fNSAPIGetBasePath = (NSCModuleHelper::lpNSAPIGetBasePath)f(_T("NSAPIGetBasePath")); -
include/NSCHelper.h
r796d8ff rc0522cd 110 110 typedef void (*lpNSAPIMessage)(int, const TCHAR*, const int, const TCHAR*); 111 111 typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 112 typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); 112 113 typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const TCHAR*, const unsigned int, TCHAR **, TCHAR *, unsigned int, TCHAR *, unsigned int); 113 114 typedef void* (*lpNSAPILoader)(TCHAR*); … … 137 138 NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, TCHAR splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 138 139 void StopService(void); 140 void Exit(void); 139 141 std::wstring getBasePath(); 140 142 bool logDebug(); … … 333 335 } catch (...) { \ 334 336 NSC_LOG_CRITICAL(_T("Unknown exception in: commandLineExec(...)")); \ 337 std::wcerr << _T("Unknown exception in: commandLineExec(...)") << std::endl; \ 335 338 return NSCAPI::hasFailed; \ 336 339 } \ -
include/NTService.h
r978bd31 rc0522cd 22 22 23 23 #include <string> 24 #include <sysinfo.h> 24 25 25 26 … … 80 81 void service_main(DWORD dwArgc, LPTSTR *lpszArgv) 81 82 { 82 // register our service control handler: 83 sshStatusHandle = RegisterServiceCtrlHandler( SZSERVICENAME, TBase::service_ctrl_dispatch); 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); 86 } else { 87 // register our service control handler: 88 sshStatusHandle = RegisterServiceCtrlHandler( SZSERVICENAME, TBase::service_ctrl_dispatch); 89 } 84 90 85 91 // SERVICE_STATUS members that don't change in example … … 100 106 } 101 107 102 103 void service_ctrl(DWORD dwCtrlCode) { 108 typedef struct tagWTSSESSION_NOTIFICATION 109 { 110 DWORD cbSize; 111 DWORD dwSessionId; 112 113 } WTSSESSION_NOTIFICATION, *PWTSSESSION_NOTIFICATION; 114 #define WTS_SESSION_LOGON 0x5 115 #define WTS_SESSION_LOGOFF 0x6 116 117 DWORD service_ctrl_ex(DWORD dwCtrlCode, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) { 104 118 switch(dwCtrlCode) 105 119 { … … 107 121 ReportStatusToSCMgr(SERVICE_STOP_PENDING, NO_ERROR, 0); 108 122 ServiceStop(); 109 return ;123 return 0; 110 124 111 125 case SERVICE_CONTROL_INTERROGATE: 112 126 break; 113 127 128 case SERVICE_CONTROL_SESSIONCHANGE: 129 if (lpEventData != NULL && dwEventType == WTS_SESSION_LOGON) 130 service_on_session_changed(reinterpret_cast<WTSSESSION_NOTIFICATION*>(lpEventData)->dwSessionId, true, dwEventType); 131 else if (lpEventData != NULL && dwEventType == WTS_SESSION_LOGOFF) 132 service_on_session_changed(reinterpret_cast<WTSSESSION_NOTIFICATION*>(lpEventData)->dwSessionId, false, dwEventType); 133 else { 134 service_on_session_changed(reinterpret_cast<WTSSESSION_NOTIFICATION*>(lpEventData)->dwSessionId, false, dwEventType); 135 } 136 break; 137 114 138 default: 115 139 break; … … 117 141 } 118 142 ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR, 0); 143 return 0; 119 144 } 120 145 … … 141 166 ssStatus.dwControlsAccepted = 0; 142 167 else 143 ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP ;168 ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP| SERVICE_ACCEPT_SESSIONCHANGE; 144 169 145 170 ssStatus.dwCurrentState = dwCurrentState; -
include/ServiceCmd.cpp
rb5ef837 rc0522cd 95 95 CloseServiceHandle(schSCManager); 96 96 if (result != TRUE) 97 throw SCException(_T("Could not queryservice information"));97 throw SCException(_T("Could not change service information")); 98 98 } 99 99 -
include/config.h
rda1c7e1 rc0522cd 80 80 #define NSCLIENT_SETTINGS_READ_TIMEOUT _T("socket_timeout") 81 81 #define NSCLIENT_SETTINGS_READ_TIMEOUT_DEFAULT 30 82 #define NSCLIENT_SETTINGS_SYSTRAY_EXE _T("systray_exe") 83 #define NSCLIENT_SETTINGS_SYSTRAY_EXE_DEFAULT _T("systray.exe") 82 84 83 85 // NRPE Settings headlines … … 198 200 #define LOG_DATEMASK _T("date_mask") 199 201 #define LOG_DATEMASK_DEFAULT _T("%Y-%m-%d %H:%M:%S") 202 #define LOG_ROOT _T("root_folder") 203 #define LOG_ROOT_DEFAULT _T("exe") 200 204 201 205 // Main Settings … … 216 220 #define MAIN_STRING_LENGTH _T("string_length") 217 221 #define MAIN_STRING_LENGTH_DEFAULT 4096 218 219 220 // LOA Config itemns 222 #define MAIN_SHARED_SESSION _T("shared_session") 223 #define MAIN_SHARED_SESSION_DEFAULT 0 224 225 226 // LOA Config items 221 227 #define LUA_SCRIPT_SECTION_TITLE _T("LUA Scripts") 222 228 -
include/strEx.h
r846bbe4 rc0522cd 37 37 class string_exception : public std::exception { 38 38 std::wstring _what; 39 public: 39 40 string_exception(std::wstring what) : _what(what) {} 40 41 std::wstring what() { … … 68 69 inline std::string wstring_to_string( const wchar_t* pStr, int len) { 69 70 if (pStr == NULL) 70 throw string_exception( "Invalid pointer in wstring_to_string");71 throw string_exception(_T("Invalid pointer in wstring_to_string")); 71 72 if (len < 0 && len != -1) 72 throw string_exception( "Invalid string length in wstring_to_string");73 throw string_exception(_T("Invalid string length in wstring_to_string")); 73 74 74 75 // figure out how many narrow characters we are going to get … … 94 95 inline std::wstring string_to_wstring( const char* pStr , int len ) { 95 96 if (pStr == NULL) 96 throw string_exception( "Invalid pointer in wstring_to_string");97 throw string_exception(_T("Invalid pointer in wstring_to_string")); 97 98 if (len < 0 && len != -1) 98 throw string_exception( "Invalid string length in wstring_to_string");99 throw string_exception(_T("Invalid string length in wstring_to_string")); 99 100 100 101 // figure out how many wide characters we are going to get … … 212 213 } 213 214 } 215 inline std::wstring ctos(TCHAR c) { 216 return std::wstring(c,1); 217 } 214 218 inline std::wstring itos(unsigned int i) { 215 219 std::wstringstream ss; -
modules/CheckDisk/CheckDisk-2005.vcproj
r3f569d3 rc0522cd 188 188 Name="Release|Win32" 189 189 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 190 IntermediateDirectory=" $(ConfigurationName)"190 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 191 191 ConfigurationType="2" 192 192 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 267 267 Name="Release|x64" 268 268 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 269 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"269 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 270 270 ConfigurationType="2" 271 271 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/CheckEventLog/CheckEventLog-2005.vcproj
r367bf20 rc0522cd 25 25 Name="Release|Win32" 26 26 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 27 IntermediateDirectory=" $(ConfigurationName)"27 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 28 28 ConfigurationType="2" 29 29 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 105 105 Name="Release|x64" 106 106 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 107 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"107 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 108 108 ConfigurationType="2" 109 109 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/CheckExternalScripts/CheckExternalScripts-2005.vcproj
rdff5db9 rc0522cd 193 193 Name="Release|Win32" 194 194 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 195 IntermediateDirectory=" $(ConfigurationName)"195 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 196 196 ConfigurationType="2" 197 197 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 274 274 Name="Release|x64" 275 275 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 276 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"276 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 277 277 ConfigurationType="2" 278 278 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/CheckHelpers/CheckHelpers-2005.vcproj
r3f569d3 rc0522cd 188 188 Name="Release|Win32" 189 189 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 190 IntermediateDirectory=" $(ConfigurationName)"190 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 191 191 ConfigurationType="2" 192 192 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 267 267 Name="Release|x64" 268 268 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 269 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"269 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 270 270 ConfigurationType="2" 271 271 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/CheckSystem/CheckSystem-2005.vcproj
r3f569d3 rc0522cd 190 190 Name="Release|Win32" 191 191 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 192 IntermediateDirectory=" $(ConfigurationName)"192 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 193 193 ConfigurationType="2" 194 194 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 270 270 Name="Release|x64" 271 271 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 272 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"272 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 273 273 ConfigurationType="2" 274 274 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/CheckTaskSched/CheckTaskSched-2005.vcproj
rda1c7e1 rc0522cd 153 153 <Tool 154 154 Name="VCLinkerTool" 155 AdditionalDependencies=" Wbemuuid.lib"155 AdditionalDependencies="Mstask.lib" 156 156 OutputFile="../../Debug/modules/$(ProjectName).dll" 157 157 LinkIncremental="2" … … 192 192 Name="Release|Win32" 193 193 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 194 IntermediateDirectory=" $(ConfigurationName)"194 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 195 195 ConfigurationType="2" 196 196 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 273 273 Name="Release|x64" 274 274 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 275 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"275 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 276 276 ConfigurationType="2" 277 277 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 315 315 <Tool 316 316 Name="VCLinkerTool" 317 AdditionalDependencies=" Wbemuuid.lib"317 AdditionalDependencies="Mstask.lib" 318 318 OutputFile="../../Release/modules/$(ProjectName).dll" 319 319 LinkIncremental="1" … … 478 478 <Tool 479 479 Name="VCLinkerTool" 480 AdditionalDependencies=" Wbemuuid.lib"480 AdditionalDependencies="Mstask.lib" 481 481 OutputFile="../../Dist/modules/$(ProjectName).dll" 482 482 LinkIncremental="1" … … 801 801 <Tool 802 802 Name="VCLinkerTool" 803 AdditionalDependencies=" Wbemuuid.lib"803 AdditionalDependencies="Mstask.lib" 804 804 OutputFile="../../Debug/modules/$(ProjectName).dll" 805 805 LinkIncremental="2" -
modules/CheckWMI/CheckWMI-2005.vcproj
r3f569d3 rc0522cd 192 192 Name="Release|Win32" 193 193 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 194 IntermediateDirectory=" $(ConfigurationName)"194 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 195 195 ConfigurationType="2" 196 196 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 273 273 Name="Release|x64" 274 274 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 275 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"275 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 276 276 ConfigurationType="2" 277 277 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/FileLogger/FileLogger-2005.vcproj
r3f569d3 rc0522cd 25 25 Name="Release|Win32" 26 26 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 27 IntermediateDirectory=" $(ConfigurationName)"27 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 28 28 ConfigurationType="2" 29 29 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 104 104 Name="Release|x64" 105 105 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 106 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"106 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 107 107 ConfigurationType="2" 108 108 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/LUAScript/LUAScript-2005.vcproj
r99b84bf rc0522cd 192 192 Name="Release|Win32" 193 193 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 194 IntermediateDirectory=" $(ConfigurationName)"194 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 195 195 ConfigurationType="2" 196 196 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 273 273 Name="Release|x64" 274 274 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 275 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"275 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 276 276 ConfigurationType="2" 277 277 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/NRPEClient/NRPEClient-2005.vcproj
r394f7a1 rc0522cd 193 193 Name="Release|Win32" 194 194 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 195 IntermediateDirectory=" $(ConfigurationName)"195 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 196 196 ConfigurationType="2" 197 197 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 274 274 Name="Release|x64" 275 275 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 276 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"276 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 277 277 ConfigurationType="2" 278 278 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/NRPEListener/NRPEListener-2005.vcproj
r394f7a1 rc0522cd 193 193 Name="Release|Win32" 194 194 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 195 IntermediateDirectory=" $(ConfigurationName)"195 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 196 196 ConfigurationType="2" 197 197 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 274 274 Name="Release|x64" 275 275 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 276 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"276 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 277 277 ConfigurationType="2" 278 278 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/NSCAAgent/NSCAAgent-2005.vcproj
r1d84e57 rc0522cd 191 191 <Configuration 192 192 Name="Release|Win32" 193 OutputDirectory="$( ConfigurationName)"194 IntermediateDirectory=" $(ConfigurationName)"193 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 194 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 195 195 ConfigurationType="2" 196 196 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 272 272 <Configuration 273 273 Name="Release|x64" 274 OutputDirectory="$( PlatformName)\$(ConfigurationName)"275 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"274 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 275 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 276 276 ConfigurationType="2" 277 277 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/NSClientListener/NSClientListener-2005.vcproj
r3f569d3 rc0522cd 190 190 Name="Release|Win32" 191 191 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 192 IntermediateDirectory=" $(ConfigurationName)"192 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 193 193 ConfigurationType="2" 194 194 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 270 270 Name="Release|x64" 271 271 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 272 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"272 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 273 273 ConfigurationType="2" 274 274 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/RemoteConfiguration/RemoteConfiguration-2005.vcproj
r3f569d3 rc0522cd 188 188 Name="Release|Win32" 189 189 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 190 IntermediateDirectory=" $(ConfigurationName)"190 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 191 191 ConfigurationType="2" 192 192 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 267 267 Name="Release|x64" 268 268 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 269 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"269 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 270 270 ConfigurationType="2" 271 271 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/SysTray/SysTray-2005.vcproj
r6b690bf rc0522cd 25 25 Name="Release|Win32" 26 26 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 27 IntermediateDirectory=" $(ConfigurationName)"27 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 28 28 ConfigurationType="2" 29 29 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" … … 104 104 Name="Release|x64" 105 105 OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 106 IntermediateDirectory=" $(PlatformName)\$(ConfigurationName)"106 IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 107 107 ConfigurationType="2" 108 108 InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" -
modules/SysTray/SysTray.cpp
r846bbe4 rc0522cd 24 24 #include <ServiceCmd.h> 25 25 #include <config.h> 26 #include <Winwlx.h> 27 #include <sysinfo.h> 26 28 27 29 SysTray gSysTray; … … 35 37 SysTray::SysTray() : icon(_T("SysTray")) {} 36 38 SysTray::~SysTray() {} 39 40 41 void SysTray::show() { 42 icon.createThread(); 43 } 37 44 bool SysTray::loadModule() { 38 try { 39 if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 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) { 40 52 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.")); 41 53 return true; 42 54 } 43 } catch (serviceControll::SCException e) {44 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."));45 return true;55 show(); 56 } else { 57 NSC_LOG_ERROR(_T("SysTray module is not used on windows XP and above (so you can remove it).")); 46 58 } 47 icon.createThread();48 59 return true; 49 60 } 50 bool SysTray::unloadModule() {61 void SysTray::hide() { 51 62 if (!icon.exitThread(20000)) { 52 63 std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl; 53 64 NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result...")); 54 return false; 65 } 66 } 67 bool SysTray::unloadModule() { 68 if (systemInfo::isBelowXP(systemInfo::getOSVersion())) { 69 hide(); 55 70 } 56 71 return true; … … 61 76 try { 62 77 serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS); 63 NSC_LOG_MESSAGE_STD(_T(MODULE_NAME) _T(" is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set."));78 std::wcout << _T(MODULE_NAME) << _T(" is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set.") << std::endl; 64 79 } catch (const serviceControll::SCException& e) { 65 NSC_LOG_ERROR_STD(_T("Could not modify service: ") + e.error_); 80 std::wcerr << _T("Could not modify service: ") << e.error_ << std::endl; 81 return -1; 82 } catch (...) { 83 std::wcerr << _T("Could not modify service: Unknown error!") << std::endl; 66 84 return -1; 67 85 } … … 69 87 try { 70 88 serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS); 71 NSC_LOG_MESSAGE_STD(_T(MODULE_NAME) _T(" is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset."));89 std::wcout << _T(" is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset.") << std::endl; 72 90 } catch (const serviceControll::SCException& e) { 73 NSC_LOG_ERROR_STD(_T("Could not modify service: ") + e.error_); 91 std::wcerr << _T("Could not modify service: ") << e.error_ << std::endl; 92 return -1; 93 } catch (...) { 94 std::wcerr << _T("Could not modify service: Unknown error!") << std::endl; 74 95 return -1; 75 96 } 76 97 } else { 77 NSC_LOG_ERROR_STD(_T("Undefined command, usage: install or uninstall"));98 std::wcerr << _T("Undefined command, usage: install or uninstall") << std::endl; 78 99 return -1; 79 100 } … … 120 141 } 121 142 122 123 124 143 extern void ShowIcon() { 144 gSysTray.show(); 145 } 146 extern void HideIcon() { 147 gSysTray.hide(); 148 } 125 149 NSC_WRAPPERS_MAIN_DEF(gSysTray); 126 150 NSC_WRAPPERS_HANDLE_MSG_DEF(gSysTray); -
modules/SysTray/SysTray.def
r6817602 rc0522cd 13 13 NSGetModuleDescription 14 14 NSCommandLineExec 15 ShowIcon 16 HideIcon -
modules/SysTray/SysTray.h
rb5ef837 rc0522cd 26 26 NSC_WRAPPERS_MAIN(); 27 27 NSC_WRAPPERS_CLI(); 28 28 29 29 30 … … 56 57 bool unloadModule(); 57 58 void setLogWindow(HWND hWnd); 59 void show(); 60 void hide(); 58 61 59 62 std::wstring getModuleName() { -
modules/SysTray/SysTray.rc
rde8ef76 rc0522cd 95 95 POPUP "POPUP" 96 96 BEGIN 97 MENUITEM "NSClient++", ID_POPUP_NSCLIENT, INACTIVE97 MENUITEM "NSClient++", ID_POPUP_NSCLIENT, INACTIVE 98 98 MENUITEM SEPARATOR 99 MENUITEM " Inject Command",ID_POPUP_INJECTCOMMAND100 MENUITEM "S top Service", ID_POPUP_STOPSERVICE99 MENUITEM "Run &Command", ID_POPUP_INJECTCOMMAND 100 MENUITEM "Show &Log", ID_POPUP_SHOWLOG 101 101 MENUITEM SEPARATOR 102 MENUITEM " Show Log", ID_POPUP_SHOWLOG102 MENUITEM "&Close", ID_POPUP_STOPSERVICE 103 103 END 104 104 END … … 225 225 ///////////////////////////////////////////////////////////////////////////// 226 226 #endif // not APSTUDIO_INVOKED 227 -
modules/SysTray/TrayIcon.cpp
r846bbe4 rc0522cd 50 50 if (fnChangeWindowMessageFilter == NULL) 51 51 fnChangeWindowMessageFilter = (LPFN_CHANGEWINDOWMESSAGEFILTER)GetProcAddress(GetModuleHandle(TEXT("user32")),"ChangeWindowMessageFilter"); 52 if (fnChangeWindowMessageFilter == NULL) 52 if (fnChangeWindowMessageFilter == NULL) { 53 NSC_DEBUG_MSG(_T("Failed to load: ChangeWindowMessageFilter aparently we are not on Vista...")); 53 54 return true; 55 } 56 NSC_DEBUG_MSG(_T("Chaning window message filters...")); 54 57 return fnChangeWindowMessageFilter(message,what); 55 58 } 56 59 60 void test() { 61 /* error 62 WTSQueryUserToken(dwSessionId, &hToken); 63 DuplicateTokenEx(hTokenNew,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&hTokenDup); 64 */ 65 /* 66 HANDLE hToken = NULL, hTokenDup = NULL; 67 HMODULE hmod = LoadLibrary("kernel32.dll"); 68 WTSGETACTIVECONSOLESESSIONID lpfnWTSGetActiveConsoleSessionId = (WTSGETACTIVECONSOLESESSIONID)GetProcAddress(hmod,"WTSGetActiveConsoleSessionId"); 69 DWORD dwSessionId = lpfnWTSGetActiveConsoleSessionId(); 70 WTSQueryUserToken(dwSessionId, &hToken); 71 //DuplicateTokenEx(hTokenNew,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&hTokenDup); 72 // 73 WriteToLog("Calling lpfnCreateEnvironmentBlock"); 74 ZeroMemory( &si, sizeof( STARTUPINFO ) ); 75 si.cb = sizeof( STARTUPINFO ); 76 si.lpDesktop = "winsta0\\default"; 77 78 79 LPVOID pEnv = NULL; 80 DWORD dwCreationFlag = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE; 81 HMODULE hModule = LoadLibrary("Userenv.dll"); 82 if(hModule ) 83 { 84 LPFN_CreateEnvironmentBlock lpfnCreateEnvironmentBlock = (LPFN_CreateEnvironmentBlock)GetProcAddress( hModule, "CreateEnvironmentBlock" ); 85 if( lpfnCreateEnvironmentBlock != NULL ) 86 { 87 if(lpfnCreateEnvironmentBlock(&pEnv, hTokenDup, FALSE)) 88 { 89 WriteToLog("CreateEnvironmentBlock Ok"); 90 dwCreationFlag |= CREATE_UNICODE_ENVIRONMENT; 91 } 92 else 93 { 94 pEnv = NULL; 95 } 96 } 97 } 98 // 99 ZeroMemory( &pi,sizeof(pi)); 100 101 if ( !CreateProcessAsUser( 102 hTokenDup, 103 NULL, 104 ( char * )pszCmd, 105 NULL, 106 NULL, 107 FALSE, 108 dwCreationFlag, 109 pEnv, 110 NULL, 111 &si, 112 &pi 113 ) ) 114 { 115 116 goto RESTORE; 117 } 118 */ 119 120 } 57 121 58 122 void IconWidget_::createDialog(void) { 59 ChangeWindowMessageFilter()60 123 hDlgWnd = ::CreateDialog(NSCModuleWrapper::getModule(),MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); 61 124 … … 64 127 NSC_LOG_ERROR_STD(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 65 128 } 66 ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD); 129 if (!ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD)) { 130 NSC_LOG_ERROR_STD(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 131 } 67 132 68 133 MSG Msg; … … 319 384 switch (cmd) { 320 385 case ID_POPUP_STOPSERVICE: 321 NSCModuleHelper:: StopService();386 NSCModuleHelper::Exit(); 322 387 break; 323 388 case ID_POPUP_INJECTCOMMAND:
Note: See TracChangeset
for help on using the changeset viewer.








