|
|
|
@ -18,7 +18,7 @@ VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl) |
|
|
|
|
{ |
|
|
|
|
// Handle the requested control code.
|
|
|
|
|
|
|
|
|
|
switch(dwCtrl) |
|
|
|
|
switch (dwCtrl) |
|
|
|
|
{ |
|
|
|
|
case SERVICE_CONTROL_STOP: |
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN: |
|
|
|
@ -28,10 +28,9 @@ VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl) |
|
|
|
|
|
|
|
|
|
// Remove PID file and free ressources
|
|
|
|
|
cleanup(); |
|
|
|
|
# ifdef USE_MSRPC |
|
|
|
|
# if __CYGWIN__ || defined(USE_MSRPC) |
|
|
|
|
ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0); |
|
|
|
|
# endif // !USE_MSRPC
|
|
|
|
|
return; |
|
|
|
|
# endif // __CYGWIN__
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
@ -42,14 +41,8 @@ static VOID WINAPI ServiceMain(const int argc_unused, CARGV argv_unused) |
|
|
|
|
{ |
|
|
|
|
// Register the handler function for the service
|
|
|
|
|
|
|
|
|
|
gSvcStatusHandle = RegisterServiceCtrlHandler( |
|
|
|
|
NT_SERVICE_NAME, |
|
|
|
|
ServiceCtrlHandler |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if(!gSvcStatusHandle) |
|
|
|
|
if (!((gSvcStatusHandle = RegisterServiceCtrlHandler(NT_SERVICE_NAME, ServiceCtrlHandler)))) |
|
|
|
|
{ |
|
|
|
|
//ServiceReportEvent(RegisterServiceCtrlHandler);
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -65,7 +58,7 @@ static VOID WINAPI ServiceMain(const int argc_unused, CARGV argv_unused) |
|
|
|
|
SERVICE_TABLE_ENTRY NTServiceDispatchTable[] = { |
|
|
|
|
{ |
|
|
|
|
(LPSTR)NT_SERVICE_NAME, |
|
|
|
|
(LPSERVICE_MAIN_FUNCTION) ServiceMain |
|
|
|
|
(LPSERVICE_MAIN_FUNCTION)ServiceMain |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
NULL, |
|
|
|
@ -88,8 +81,8 @@ VOID ReportServiceStatus(const DWORD dwCurrentState, const DWORD dwWin32ExitCode |
|
|
|
|
else |
|
|
|
|
gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; |
|
|
|
|
|
|
|
|
|
if ( (dwCurrentState == SERVICE_RUNNING) || |
|
|
|
|
(dwCurrentState == SERVICE_STOPPED) ) |
|
|
|
|
if ((dwCurrentState == SERVICE_RUNNING) || |
|
|
|
|
(dwCurrentState == SERVICE_STOPPED)) |
|
|
|
|
gSvcStatus.dwCheckPoint = 0; |
|
|
|
|
else |
|
|
|
|
gSvcStatus.dwCheckPoint = dwCheckPoint++; |
|
|
|
@ -192,10 +185,10 @@ static VOID ServiceInstaller(const char *restrict ServiceUser, const char *const |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
strcat(szPath,"\""); |
|
|
|
|
strcat(szPath, "\""); |
|
|
|
|
|
|
|
|
|
int i; |
|
|
|
|
for (i = 1; i < global_argc; i ++) |
|
|
|
|
for (i = 1; i < global_argc; i++) |
|
|
|
|
{ |
|
|
|
|
// Strip unneccessary parameters, especially the password
|
|
|
|
|
if (!strcmp(global_argv[i], "-s")) continue; |
|
|
|
@ -235,8 +228,8 @@ static VOID ServiceInstaller(const char *restrict ServiceUser, const char *const |
|
|
|
|
if (ServiceUser) |
|
|
|
|
{ |
|
|
|
|
// Shortcuts for some well known users
|
|
|
|
|
if (!strcasecmp(ServiceUser, "/l")) ServiceUser="NT AUTHORITY\\LocalService"; |
|
|
|
|
if (!strcasecmp(ServiceUser, "/n")) ServiceUser="NT AUTHORITY\\NetworkService"; |
|
|
|
|
if (!strcasecmp(ServiceUser, "/l")) ServiceUser = "NT AUTHORITY\\LocalService"; |
|
|
|
|
if (!strcasecmp(ServiceUser, "/n")) ServiceUser = "NT AUTHORITY\\NetworkService"; |
|
|
|
|
|
|
|
|
|
// Allow Local Users without .\ , e.g. "johndoe" instead of ".\johndoe"
|
|
|
|
|
if (!strchr(ServiceUser, '\\')) |
|
|
|
@ -322,7 +315,7 @@ int NtServiceInstallation(const int_fast8_t installService, const char *restrict |
|
|
|
|
|
|
|
|
|
if (installService == 2) // Remove
|
|
|
|
|
{ |
|
|
|
|
switch(OpenAndRemoveService(NULL, NULL)) |
|
|
|
|
switch (OpenAndRemoveService(NULL, NULL)) |
|
|
|
|
{ |
|
|
|
|
case 0: |
|
|
|
|
errorout("Error removing service %s\n", NT_SERVICE_NAME); |
|
|
|
|