2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
2000-03-26 22:00:10 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/advapi32/service/sctrl.c
|
|
|
|
* PURPOSE: Service control manager functions
|
|
|
|
* PROGRAMMER: Emanuele Aliberti
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* 19990413 EA created
|
|
|
|
* 19990515 EA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2004-08-15 17:03:15 +00:00
|
|
|
#include "advapi32.h"
|
2005-01-28 13:28:56 +00:00
|
|
|
#include <services/services.h>
|
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
|
2000-03-26 22:00:10 +00:00
|
|
|
/* TYPES *********************************************************************/
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
typedef struct _ACTIVE_SERVICE
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2001-10-21 19:06:42 +00:00
|
|
|
DWORD ThreadId;
|
|
|
|
UNICODE_STRING ServiceName;
|
2005-01-28 13:28:56 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
LPSERVICE_MAIN_FUNCTIONA lpFuncA;
|
|
|
|
LPSERVICE_MAIN_FUNCTIONW lpFuncW;
|
|
|
|
} Main;
|
2002-07-20 13:31:34 +00:00
|
|
|
LPHANDLER_FUNCTION HandlerFunction;
|
2005-02-06 21:57:44 +00:00
|
|
|
LPHANDLER_FUNCTION_EX HandlerFunctionEx;
|
|
|
|
LPVOID HandlerContext;
|
2001-10-21 19:06:42 +00:00
|
|
|
SERVICE_STATUS ServiceStatus;
|
2005-01-28 13:28:56 +00:00
|
|
|
BOOL bUnicode;
|
|
|
|
LPWSTR Arguments;
|
2000-03-26 22:00:10 +00:00
|
|
|
} ACTIVE_SERVICE, *PACTIVE_SERVICE;
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
|
2000-03-26 22:00:10 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
static DWORD dwActiveServiceCount = 0;
|
|
|
|
static PACTIVE_SERVICE lpActiveServices = NULL;
|
2000-03-26 22:00:10 +00:00
|
|
|
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
2002-07-20 13:31:34 +00:00
|
|
|
|
|
|
|
static PACTIVE_SERVICE
|
|
|
|
ScLookupServiceByServiceName(LPWSTR lpServiceName)
|
2001-10-21 19:06:42 +00:00
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
for (i = 0; i < dwActiveServiceCount; i++)
|
2001-10-21 19:06:42 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
if (_wcsicmp(lpActiveServices[i].ServiceName.Buffer, lpServiceName) == 0)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
return &lpActiveServices[i];
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
}
|
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
return NULL;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static PACTIVE_SERVICE
|
|
|
|
ScLookupServiceByThreadId(DWORD ThreadId)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
for (i = 0; i < dwActiveServiceCount; i++)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
if (lpActiveServices[i].ThreadId == ThreadId)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
return &lpActiveServices[i];
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD WINAPI
|
|
|
|
ScServiceMainStub(LPVOID Context)
|
|
|
|
{
|
|
|
|
PACTIVE_SERVICE lpService;
|
2005-01-28 13:28:56 +00:00
|
|
|
DWORD dwArgCount = 0;
|
|
|
|
DWORD dwLength = 0;
|
2005-01-08 18:11:46 +00:00
|
|
|
|
|
|
|
lpService = (PACTIVE_SERVICE)Context;
|
|
|
|
|
|
|
|
DPRINT("ScServiceMainStub() called\n");
|
|
|
|
|
2005-01-28 13:28:56 +00:00
|
|
|
/* Count arguments */
|
|
|
|
while (lpService->Arguments[dwLength])
|
|
|
|
{
|
|
|
|
dwLength += wcslen(&lpService->Arguments[dwLength]) + 1;
|
|
|
|
dwArgCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the argument vector and call the main service routine */
|
|
|
|
if (lpService->bUnicode)
|
|
|
|
{
|
|
|
|
LPWSTR *lpArgVector;
|
|
|
|
LPWSTR Ptr;
|
|
|
|
|
|
|
|
lpArgVector = HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
(dwArgCount + 1) * sizeof(LPWSTR));
|
|
|
|
if (lpArgVector == NULL)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
dwArgCount = 0;
|
|
|
|
Ptr = lpService->Arguments;
|
|
|
|
while (*Ptr)
|
|
|
|
{
|
|
|
|
lpArgVector[dwArgCount] = Ptr;
|
2005-01-08 18:11:46 +00:00
|
|
|
|
2005-01-28 13:28:56 +00:00
|
|
|
dwArgCount++;
|
|
|
|
Ptr += (wcslen(Ptr) + 1);
|
|
|
|
}
|
|
|
|
lpArgVector[dwArgCount] = NULL;
|
2005-01-08 18:11:46 +00:00
|
|
|
|
2005-01-28 13:28:56 +00:00
|
|
|
(lpService->Main.lpFuncW)(dwArgCount, lpArgVector);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
lpArgVector);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(lpService->Main.lpFuncA)(0, NULL);
|
|
|
|
}
|
2005-01-08 18:11:46 +00:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD
|
|
|
|
ScConnectControlPipe(HANDLE *hPipe)
|
|
|
|
{
|
|
|
|
DWORD dwBytesWritten;
|
|
|
|
DWORD dwProcessId;
|
|
|
|
DWORD dwState;
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
if (!WaitNamedPipeW(L"\\\\.\\pipe\\net\\NtControlPipe", 15000))
|
|
|
|
{
|
|
|
|
DPRINT1("WaitNamedPipe() failed (Error %lu)\n", GetLastError());
|
|
|
|
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
|
|
|
}
|
2002-07-20 13:31:34 +00:00
|
|
|
|
|
|
|
*hPipe = CreateFileW(L"\\\\.\\pipe\\net\\NtControlPipe",
|
|
|
|
GENERIC_READ | GENERIC_WRITE,
|
2005-01-08 18:11:46 +00:00
|
|
|
0,
|
2002-07-20 13:31:34 +00:00
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
if (*hPipe == INVALID_HANDLE_VALUE)
|
2005-01-08 18:11:46 +00:00
|
|
|
{
|
|
|
|
DPRINT1("CreateFileW() failed (Error %lu)\n", GetLastError());
|
|
|
|
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
|
|
|
}
|
2002-07-20 13:31:34 +00:00
|
|
|
|
|
|
|
dwState = PIPE_READMODE_MESSAGE;
|
|
|
|
if (!SetNamedPipeHandleState(*hPipe, &dwState, NULL, NULL))
|
|
|
|
{
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
*hPipe = INVALID_HANDLE_VALUE;
|
2005-01-08 18:11:46 +00:00
|
|
|
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dwProcessId = GetCurrentProcessId();
|
|
|
|
WriteFile(*hPipe,
|
|
|
|
&dwProcessId,
|
|
|
|
sizeof(DWORD),
|
|
|
|
&dwBytesWritten,
|
|
|
|
NULL);
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
DPRINT("Sent process id %lu\n", dwProcessId);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-28 13:28:56 +00:00
|
|
|
|
|
|
|
static DWORD
|
|
|
|
ScStartService(PSCM_START_PACKET StartPacket)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
PACTIVE_SERVICE lpService;
|
|
|
|
HANDLE ThreadHandle;
|
|
|
|
|
2005-01-28 13:28:56 +00:00
|
|
|
DPRINT("Size: %lu\n", StartPacket->Size);
|
|
|
|
DPRINT("Service: %S\n", &StartPacket->Arguments[0]);
|
|
|
|
|
|
|
|
lpService = ScLookupServiceByServiceName(&StartPacket->Arguments[0]);
|
|
|
|
if (lpService == NULL)
|
|
|
|
return ERROR_SERVICE_DOES_NOT_EXIST;
|
2005-01-08 18:11:46 +00:00
|
|
|
|
2005-01-28 13:28:56 +00:00
|
|
|
lpService->Arguments = HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
StartPacket->Size);
|
|
|
|
if (lpService->Arguments == NULL)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
memcpy(lpService->Arguments,
|
|
|
|
StartPacket->Arguments,
|
|
|
|
StartPacket->Size * sizeof(WCHAR));
|
2005-01-08 18:11:46 +00:00
|
|
|
|
|
|
|
ThreadHandle = CreateThread(NULL,
|
|
|
|
0,
|
|
|
|
ScServiceMainStub,
|
|
|
|
lpService,
|
|
|
|
CREATE_SUSPENDED,
|
|
|
|
&lpService->ThreadId);
|
|
|
|
if (ThreadHandle == NULL)
|
2005-01-28 13:28:56 +00:00
|
|
|
return ERROR_SERVICE_NO_THREAD;
|
2005-01-08 18:11:46 +00:00
|
|
|
|
|
|
|
ResumeThread(ThreadHandle);
|
|
|
|
CloseHandle(ThreadHandle);
|
2002-07-20 13:31:34 +00:00
|
|
|
|
2005-01-28 13:28:56 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
ScServiceDispatcher(HANDLE hPipe,
|
|
|
|
PUCHAR lpBuffer,
|
|
|
|
DWORD dwBufferSize)
|
|
|
|
{
|
|
|
|
LPDWORD Buffer;
|
|
|
|
DWORD Count;
|
|
|
|
BOOL bResult;
|
|
|
|
|
|
|
|
DPRINT("ScDispatcherLoop() called\n");
|
|
|
|
|
|
|
|
Buffer = HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
1024);
|
|
|
|
if (Buffer == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Read command from the control pipe */
|
2005-01-28 13:28:56 +00:00
|
|
|
bResult = ReadFile(hPipe,
|
|
|
|
Buffer,
|
|
|
|
1024,
|
|
|
|
&Count,
|
|
|
|
NULL);
|
|
|
|
if (bResult == FALSE)
|
|
|
|
{
|
|
|
|
DPRINT1("Pipe read failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-20 13:31:34 +00:00
|
|
|
|
|
|
|
/* Execute command */
|
2005-01-28 13:28:56 +00:00
|
|
|
switch (Buffer[0])
|
|
|
|
{
|
|
|
|
case SCM_START_COMMAND:
|
|
|
|
DPRINT("Start command\n");
|
|
|
|
ScStartService((PSCM_START_PACKET)Buffer);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DPRINT1("Unknown command %lu", Buffer[0]);
|
|
|
|
break;
|
|
|
|
}
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
2005-01-28 13:28:56 +00:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
Buffer);
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
return TRUE;
|
2001-10-21 19:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-26 22:00:10 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* RegisterServiceCtrlHandlerA
|
2003-07-10 15:05:55 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2000-03-26 22:00:10 +00:00
|
|
|
*/
|
2002-07-20 13:31:34 +00:00
|
|
|
SERVICE_STATUS_HANDLE STDCALL
|
|
|
|
RegisterServiceCtrlHandlerA(LPCSTR lpServiceName,
|
|
|
|
LPHANDLER_FUNCTION lpHandlerProc)
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2002-07-20 13:31:34 +00:00
|
|
|
ANSI_STRING ServiceNameA;
|
|
|
|
UNICODE_STRING ServiceNameU;
|
|
|
|
SERVICE_STATUS_HANDLE SHandle;
|
|
|
|
|
|
|
|
RtlInitAnsiString(&ServiceNameA, (LPSTR)lpServiceName);
|
|
|
|
if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&ServiceNameU, &ServiceNameA, TRUE)))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
2005-01-08 18:11:46 +00:00
|
|
|
return (SERVICE_STATUS_HANDLE)0;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SHandle = RegisterServiceCtrlHandlerW(ServiceNameU.Buffer,
|
|
|
|
lpHandlerProc);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&ServiceNameU);
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
return SHandle;
|
2000-03-26 22:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* RegisterServiceCtrlHandlerW
|
2003-07-10 15:05:55 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2000-03-26 22:00:10 +00:00
|
|
|
*/
|
2002-07-20 13:31:34 +00:00
|
|
|
SERVICE_STATUS_HANDLE STDCALL
|
|
|
|
RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
|
|
|
|
LPHANDLER_FUNCTION lpHandlerProc)
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2001-10-21 19:06:42 +00:00
|
|
|
PACTIVE_SERVICE Service;
|
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
Service = ScLookupServiceByServiceName((LPWSTR)lpServiceName);
|
|
|
|
if (Service == NULL)
|
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
return (SERVICE_STATUS_HANDLE)NULL;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
Service->HandlerFunction = lpHandlerProc;
|
2005-02-06 21:57:44 +00:00
|
|
|
Service->HandlerFunctionEx = NULL;
|
|
|
|
|
|
|
|
return (SERVICE_STATUS_HANDLE)Service->ThreadId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* RegisterServiceCtrlHandlerExA
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
SERVICE_STATUS_HANDLE STDCALL
|
|
|
|
RegisterServiceCtrlHandlerExA(LPCSTR lpServiceName,
|
|
|
|
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
|
|
|
LPVOID lpContext)
|
|
|
|
{
|
|
|
|
ANSI_STRING ServiceNameA;
|
|
|
|
UNICODE_STRING ServiceNameU;
|
|
|
|
SERVICE_STATUS_HANDLE SHandle;
|
|
|
|
|
|
|
|
RtlInitAnsiString(&ServiceNameA, (LPSTR)lpServiceName);
|
|
|
|
if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&ServiceNameU, &ServiceNameA, TRUE)))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return (SERVICE_STATUS_HANDLE)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHandle = RegisterServiceCtrlHandlerExW(ServiceNameU.Buffer,
|
|
|
|
lpHandlerProc,
|
|
|
|
lpContext);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&ServiceNameU);
|
|
|
|
|
|
|
|
return SHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* RegisterServiceCtrlHandlerExW
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
SERVICE_STATUS_HANDLE STDCALL
|
|
|
|
RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
|
|
|
|
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
|
|
|
LPVOID lpContext)
|
|
|
|
{
|
|
|
|
PACTIVE_SERVICE Service;
|
|
|
|
|
|
|
|
Service = ScLookupServiceByServiceName((LPWSTR)lpServiceName);
|
|
|
|
if (Service == NULL)
|
|
|
|
{
|
|
|
|
return (SERVICE_STATUS_HANDLE)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Service->HandlerFunction = NULL;
|
|
|
|
Service->HandlerFunctionEx = lpHandlerProc;
|
|
|
|
Service->HandlerContext = lpContext;
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
return (SERVICE_STATUS_HANDLE)Service->ThreadId;
|
2000-03-26 22:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetServiceBits
|
2003-07-10 15:05:55 +00:00
|
|
|
*
|
|
|
|
* @unimplemented
|
2000-03-26 22:00:10 +00:00
|
|
|
*/
|
2002-07-20 13:31:34 +00:00
|
|
|
BOOL STDCALL
|
|
|
|
SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus,
|
|
|
|
DWORD dwServiceBits,
|
|
|
|
BOOL bSetBitsOn,
|
|
|
|
BOOL bUpdateImmediately)
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2002-07-20 13:31:34 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
2005-01-08 18:11:46 +00:00
|
|
|
return FALSE;
|
2000-03-26 22:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetServiceObjectSecurity
|
2003-07-10 15:05:55 +00:00
|
|
|
*
|
|
|
|
* @unimplemented
|
2000-03-26 22:00:10 +00:00
|
|
|
*/
|
2004-01-20 01:40:19 +00:00
|
|
|
BOOL STDCALL
|
2002-07-20 13:31:34 +00:00
|
|
|
SetServiceObjectSecurity(SC_HANDLE hService,
|
|
|
|
SECURITY_INFORMATION dwSecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR lpSecurityDescriptor)
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2002-07-20 13:31:34 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
2000-03-26 22:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetServiceStatus
|
2003-07-10 15:05:55 +00:00
|
|
|
*
|
|
|
|
* @implemented
|
2000-03-26 22:00:10 +00:00
|
|
|
*/
|
2002-07-20 13:31:34 +00:00
|
|
|
BOOL STDCALL
|
|
|
|
SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus,
|
|
|
|
LPSERVICE_STATUS lpServiceStatus)
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2001-10-21 19:06:42 +00:00
|
|
|
PACTIVE_SERVICE Service;
|
|
|
|
|
|
|
|
Service = ScLookupServiceByThreadId((DWORD)hServiceStatus);
|
|
|
|
if (!Service)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
2005-01-08 18:11:46 +00:00
|
|
|
return FALSE;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
RtlCopyMemory(&Service->ServiceStatus,
|
|
|
|
lpServiceStatus,
|
|
|
|
sizeof(SERVICE_STATUS));
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
return TRUE;
|
2000-03-26 22:00:10 +00:00
|
|
|
}
|
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
|
2000-03-26 22:00:10 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* StartServiceCtrlDispatcherA
|
2003-07-10 15:05:55 +00:00
|
|
|
*
|
|
|
|
* @unimplemented
|
2000-03-26 22:00:10 +00:00
|
|
|
*/
|
2002-07-20 13:31:34 +00:00
|
|
|
BOOL STDCALL
|
|
|
|
StartServiceCtrlDispatcherA(LPSERVICE_TABLE_ENTRYA lpServiceStartTable)
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
ULONG i;
|
|
|
|
HANDLE hPipe;
|
|
|
|
DWORD dwError;
|
|
|
|
PUCHAR lpMessageBuffer;
|
|
|
|
|
|
|
|
DPRINT("StartServiceCtrlDispatcherA() called\n");
|
2001-10-21 19:06:42 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (lpServiceStartTable[i].lpServiceProc != NULL)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
2005-01-08 18:11:46 +00:00
|
|
|
|
|
|
|
dwActiveServiceCount = i;
|
|
|
|
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
|
|
|
|
if (lpActiveServices == NULL)
|
2001-10-21 19:06:42 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
return FALSE;
|
2001-10-21 19:06:42 +00:00
|
|
|
}
|
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
/* Copy service names and start procedure */
|
|
|
|
for (i = 0; i < dwActiveServiceCount; i++)
|
|
|
|
{
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&lpActiveServices[i].ServiceName,
|
|
|
|
lpServiceStartTable[i].lpServiceName);
|
2005-01-28 13:28:56 +00:00
|
|
|
lpActiveServices[i].Main.lpFuncA = lpServiceStartTable[i].lpServiceProc;
|
|
|
|
lpActiveServices[i].bUnicode = FALSE;
|
2005-01-08 18:11:46 +00:00
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
dwError = ScConnectControlPipe(&hPipe);
|
|
|
|
if (dwError != ERROR_SUCCESS)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
/* Free the service table */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
|
|
|
lpActiveServices = NULL;
|
|
|
|
dwActiveServiceCount = 0;
|
|
|
|
return FALSE;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
256);
|
|
|
|
if (lpMessageBuffer == NULL)
|
|
|
|
{
|
|
|
|
/* Free the service table */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
|
|
|
lpActiveServices = NULL;
|
|
|
|
dwActiveServiceCount = 0;
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
|
|
|
|
/* Free the message buffer */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
|
|
|
|
|
|
|
|
/* Free the service table */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
|
|
|
lpActiveServices = NULL;
|
|
|
|
dwActiveServiceCount = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
2000-03-26 22:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* StartServiceCtrlDispatcherW
|
2003-07-10 15:05:55 +00:00
|
|
|
*
|
|
|
|
* @unimplemented
|
2000-03-26 22:00:10 +00:00
|
|
|
*/
|
2002-07-20 13:31:34 +00:00
|
|
|
BOOL STDCALL
|
|
|
|
StartServiceCtrlDispatcherW(LPSERVICE_TABLE_ENTRYW lpServiceStartTable)
|
2000-03-26 22:00:10 +00:00
|
|
|
{
|
2001-10-21 19:06:42 +00:00
|
|
|
ULONG i;
|
2002-07-20 13:31:34 +00:00
|
|
|
HANDLE hPipe;
|
|
|
|
DWORD dwError;
|
2005-01-08 18:11:46 +00:00
|
|
|
PUCHAR lpMessageBuffer;
|
2002-07-20 13:31:34 +00:00
|
|
|
|
2003-08-28 13:38:24 +00:00
|
|
|
DPRINT("StartServiceCtrlDispatcherW() called\n");
|
2001-10-21 19:06:42 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (lpServiceStartTable[i].lpServiceProc != NULL)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
dwActiveServiceCount = i;
|
|
|
|
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
|
|
|
|
if (lpActiveServices == NULL)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
return FALSE;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy service names and start procedure */
|
2005-01-08 18:11:46 +00:00
|
|
|
for (i = 0; i < dwActiveServiceCount; i++)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
RtlCreateUnicodeString(&lpActiveServices[i].ServiceName,
|
2002-07-20 13:31:34 +00:00
|
|
|
lpServiceStartTable[i].lpServiceName);
|
2005-01-28 13:28:56 +00:00
|
|
|
lpActiveServices[i].Main.lpFuncW = lpServiceStartTable[i].lpServiceProc;
|
|
|
|
lpActiveServices[i].bUnicode = TRUE;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dwError = ScConnectControlPipe(&hPipe);
|
2005-01-08 18:11:46 +00:00
|
|
|
if (dwError != ERROR_SUCCESS)
|
2002-07-20 13:31:34 +00:00
|
|
|
{
|
2005-01-08 18:11:46 +00:00
|
|
|
/* Free the service table */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
|
|
|
lpActiveServices = NULL;
|
|
|
|
dwActiveServiceCount = 0;
|
|
|
|
return FALSE;
|
2002-07-20 13:31:34 +00:00
|
|
|
}
|
2001-10-21 19:06:42 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
256);
|
|
|
|
if (lpMessageBuffer == NULL)
|
|
|
|
{
|
|
|
|
/* Free the service table */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
|
|
|
lpActiveServices = NULL;
|
|
|
|
dwActiveServiceCount = 0;
|
|
|
|
CloseHandle(hPipe);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-20 13:31:34 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
|
|
|
|
CloseHandle(hPipe);
|
2002-07-20 13:31:34 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
/* Free the message buffer */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
|
2002-07-20 13:31:34 +00:00
|
|
|
|
2005-01-08 18:11:46 +00:00
|
|
|
/* Free the service table */
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
|
|
|
lpActiveServices = NULL;
|
|
|
|
dwActiveServiceCount = 0;
|
2001-10-21 19:06:42 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2000-03-26 22:00:10 +00:00
|
|
|
}
|
|
|
|
|
2002-07-20 13:31:34 +00:00
|
|
|
/* EOF */
|