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