mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 05:53:05 +00:00
Fix indentation, no code changes.
svn path=/trunk/; revision=23867
This commit is contained in:
parent
a85e942346
commit
9e843c89fc
1 changed files with 352 additions and 352 deletions
|
@ -22,19 +22,19 @@
|
||||||
|
|
||||||
typedef struct _ACTIVE_SERVICE
|
typedef struct _ACTIVE_SERVICE
|
||||||
{
|
{
|
||||||
DWORD ThreadId;
|
DWORD ThreadId;
|
||||||
UNICODE_STRING ServiceName;
|
UNICODE_STRING ServiceName;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
LPSERVICE_MAIN_FUNCTIONA lpFuncA;
|
LPSERVICE_MAIN_FUNCTIONA lpFuncA;
|
||||||
LPSERVICE_MAIN_FUNCTIONW lpFuncW;
|
LPSERVICE_MAIN_FUNCTIONW lpFuncW;
|
||||||
} Main;
|
} Main;
|
||||||
LPHANDLER_FUNCTION HandlerFunction;
|
LPHANDLER_FUNCTION HandlerFunction;
|
||||||
LPHANDLER_FUNCTION_EX HandlerFunctionEx;
|
LPHANDLER_FUNCTION_EX HandlerFunctionEx;
|
||||||
LPVOID HandlerContext;
|
LPVOID HandlerContext;
|
||||||
SERVICE_STATUS ServiceStatus;
|
SERVICE_STATUS ServiceStatus;
|
||||||
BOOL bUnicode;
|
BOOL bUnicode;
|
||||||
LPWSTR Arguments;
|
LPWSTR Arguments;
|
||||||
} ACTIVE_SERVICE, *PACTIVE_SERVICE;
|
} ACTIVE_SERVICE, *PACTIVE_SERVICE;
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,195 +49,195 @@ static PACTIVE_SERVICE lpActiveServices = NULL;
|
||||||
static PACTIVE_SERVICE
|
static PACTIVE_SERVICE
|
||||||
ScLookupServiceByServiceName(LPWSTR lpServiceName)
|
ScLookupServiceByServiceName(LPWSTR lpServiceName)
|
||||||
{
|
{
|
||||||
DWORD i;
|
DWORD i;
|
||||||
|
|
||||||
for (i = 0; i < dwActiveServiceCount; i++)
|
for (i = 0; i < dwActiveServiceCount; i++)
|
||||||
{
|
{
|
||||||
if (_wcsicmp(lpActiveServices[i].ServiceName.Buffer, lpServiceName) == 0)
|
if (_wcsicmp(lpActiveServices[i].ServiceName.Buffer, lpServiceName) == 0)
|
||||||
{
|
{
|
||||||
return &lpActiveServices[i];
|
return &lpActiveServices[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
|
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PACTIVE_SERVICE
|
static PACTIVE_SERVICE
|
||||||
ScLookupServiceByThreadId(DWORD ThreadId)
|
ScLookupServiceByThreadId(DWORD ThreadId)
|
||||||
{
|
{
|
||||||
DWORD i;
|
DWORD i;
|
||||||
|
|
||||||
for (i = 0; i < dwActiveServiceCount; i++)
|
for (i = 0; i < dwActiveServiceCount; i++)
|
||||||
{
|
{
|
||||||
if (lpActiveServices[i].ThreadId == ThreadId)
|
if (lpActiveServices[i].ThreadId == ThreadId)
|
||||||
{
|
{
|
||||||
return &lpActiveServices[i];
|
return &lpActiveServices[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
|
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static DWORD WINAPI
|
static DWORD WINAPI
|
||||||
ScServiceMainStub(LPVOID Context)
|
ScServiceMainStub(LPVOID Context)
|
||||||
{
|
{
|
||||||
PACTIVE_SERVICE lpService;
|
PACTIVE_SERVICE lpService;
|
||||||
DWORD dwArgCount = 0;
|
DWORD dwArgCount = 0;
|
||||||
DWORD dwLength = 0;
|
DWORD dwLength = 0;
|
||||||
DWORD dwLen;
|
DWORD dwLen;
|
||||||
LPWSTR lpPtr;
|
LPWSTR lpPtr;
|
||||||
|
|
||||||
lpService = (PACTIVE_SERVICE)Context;
|
lpService = (PACTIVE_SERVICE)Context;
|
||||||
|
|
||||||
DPRINT("ScServiceMainStub() called\n");
|
DPRINT("ScServiceMainStub() called\n");
|
||||||
|
|
||||||
/* Count arguments */
|
/* Count arguments */
|
||||||
lpPtr = lpService->Arguments;
|
lpPtr = lpService->Arguments;
|
||||||
while (*lpPtr)
|
while (*lpPtr)
|
||||||
{
|
{
|
||||||
DPRINT("arg: %S\n", *lpPtr);
|
DPRINT("arg: %S\n", *lpPtr);
|
||||||
dwLen = wcslen(lpPtr) + 1;
|
dwLen = wcslen(lpPtr) + 1;
|
||||||
dwArgCount++;
|
dwArgCount++;
|
||||||
dwLength += dwLen;
|
dwLength += dwLen;
|
||||||
lpPtr += dwLen;
|
lpPtr += dwLen;
|
||||||
}
|
}
|
||||||
DPRINT("dwArgCount: %ld\ndwLength: %ld\n", dwArgCount, dwLength);
|
DPRINT("dwArgCount: %ld\ndwLength: %ld\n", dwArgCount, dwLength);
|
||||||
|
|
||||||
/* Build the argument vector and call the main service routine */
|
/* Build the argument vector and call the main service routine */
|
||||||
if (lpService->bUnicode)
|
if (lpService->bUnicode)
|
||||||
{
|
{
|
||||||
LPWSTR *lpArgVector;
|
LPWSTR *lpArgVector;
|
||||||
LPWSTR Ptr;
|
LPWSTR Ptr;
|
||||||
|
|
||||||
lpArgVector = HeapAlloc(GetProcessHeap(),
|
lpArgVector = HeapAlloc(GetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
(dwArgCount + 1) * sizeof(LPWSTR));
|
(dwArgCount + 1) * sizeof(LPWSTR));
|
||||||
if (lpArgVector == NULL)
|
if (lpArgVector == NULL)
|
||||||
return ERROR_OUTOFMEMORY;
|
return ERROR_OUTOFMEMORY;
|
||||||
|
|
||||||
dwArgCount = 0;
|
dwArgCount = 0;
|
||||||
Ptr = lpService->Arguments;
|
Ptr = lpService->Arguments;
|
||||||
while (*Ptr)
|
while (*Ptr)
|
||||||
{
|
{
|
||||||
lpArgVector[dwArgCount] = Ptr;
|
lpArgVector[dwArgCount] = Ptr;
|
||||||
|
|
||||||
dwArgCount++;
|
dwArgCount++;
|
||||||
Ptr += (wcslen(Ptr) + 1);
|
Ptr += (wcslen(Ptr) + 1);
|
||||||
}
|
}
|
||||||
lpArgVector[dwArgCount] = NULL;
|
lpArgVector[dwArgCount] = NULL;
|
||||||
|
|
||||||
(lpService->Main.lpFuncW)(dwArgCount, lpArgVector);
|
(lpService->Main.lpFuncW)(dwArgCount, lpArgVector);
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(),
|
HeapFree(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
lpArgVector);
|
lpArgVector);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LPSTR *lpArgVector;
|
LPSTR *lpArgVector;
|
||||||
LPSTR Ptr;
|
LPSTR Ptr;
|
||||||
LPSTR AnsiString;
|
LPSTR AnsiString;
|
||||||
DWORD AnsiLength;
|
DWORD AnsiLength;
|
||||||
|
|
||||||
AnsiLength = WideCharToMultiByte(CP_ACP,
|
AnsiLength = WideCharToMultiByte(CP_ACP,
|
||||||
0,
|
0,
|
||||||
lpService->Arguments,
|
lpService->Arguments,
|
||||||
dwLength,
|
dwLength,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
AnsiString = HeapAlloc(GetProcessHeap(),
|
AnsiString = HeapAlloc(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
AnsiLength);
|
AnsiLength);
|
||||||
WideCharToMultiByte(CP_ACP,
|
WideCharToMultiByte(CP_ACP,
|
||||||
0,
|
0,
|
||||||
lpService->Arguments,
|
lpService->Arguments,
|
||||||
dwLength,
|
dwLength,
|
||||||
AnsiString,
|
AnsiString,
|
||||||
AnsiLength,
|
AnsiLength,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
lpArgVector = HeapAlloc(GetProcessHeap(),
|
lpArgVector = HeapAlloc(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
(dwArgCount + 1) * sizeof(LPSTR));
|
(dwArgCount + 1) * sizeof(LPSTR));
|
||||||
|
|
||||||
dwArgCount = 0;
|
dwArgCount = 0;
|
||||||
Ptr = AnsiString;
|
Ptr = AnsiString;
|
||||||
while (*Ptr)
|
while (*Ptr)
|
||||||
{
|
{
|
||||||
lpArgVector[dwArgCount] = Ptr;
|
lpArgVector[dwArgCount] = Ptr;
|
||||||
|
|
||||||
dwArgCount++;
|
dwArgCount++;
|
||||||
Ptr += (strlen(Ptr) + 1);
|
Ptr += (strlen(Ptr) + 1);
|
||||||
}
|
}
|
||||||
lpArgVector[dwArgCount] = NULL;
|
lpArgVector[dwArgCount] = NULL;
|
||||||
|
|
||||||
(lpService->Main.lpFuncA)(dwArgCount, lpArgVector);
|
(lpService->Main.lpFuncA)(dwArgCount, lpArgVector);
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(),
|
HeapFree(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
lpArgVector);
|
lpArgVector);
|
||||||
HeapFree(GetProcessHeap(),
|
HeapFree(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
AnsiString);
|
AnsiString);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static DWORD
|
static DWORD
|
||||||
ScConnectControlPipe(HANDLE *hPipe)
|
ScConnectControlPipe(HANDLE *hPipe)
|
||||||
{
|
{
|
||||||
DWORD dwBytesWritten;
|
DWORD dwBytesWritten;
|
||||||
DWORD dwProcessId;
|
DWORD dwProcessId;
|
||||||
DWORD dwState;
|
DWORD dwState;
|
||||||
|
|
||||||
if (!WaitNamedPipeW(L"\\\\.\\pipe\\net\\NtControlPipe", 15000))
|
if (!WaitNamedPipeW(L"\\\\.\\pipe\\net\\NtControlPipe", 15000))
|
||||||
{
|
{
|
||||||
DPRINT1("WaitNamedPipe() failed (Error %lu)\n", GetLastError());
|
DPRINT1("WaitNamedPipe() failed (Error %lu)\n", GetLastError());
|
||||||
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
*hPipe = CreateFileW(L"\\\\.\\pipe\\net\\NtControlPipe",
|
*hPipe = CreateFileW(L"\\\\.\\pipe\\net\\NtControlPipe",
|
||||||
GENERIC_READ | GENERIC_WRITE,
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
NULL);
|
NULL);
|
||||||
if (*hPipe == INVALID_HANDLE_VALUE)
|
if (*hPipe == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
DPRINT1("CreateFileW() failed (Error %lu)\n", GetLastError());
|
DPRINT1("CreateFileW() failed (Error %lu)\n", GetLastError());
|
||||||
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwState = PIPE_READMODE_MESSAGE;
|
dwState = PIPE_READMODE_MESSAGE;
|
||||||
if (!SetNamedPipeHandleState(*hPipe, &dwState, NULL, NULL))
|
if (!SetNamedPipeHandleState(*hPipe, &dwState, NULL, NULL))
|
||||||
{
|
{
|
||||||
CloseHandle(hPipe);
|
CloseHandle(hPipe);
|
||||||
*hPipe = INVALID_HANDLE_VALUE;
|
*hPipe = INVALID_HANDLE_VALUE;
|
||||||
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
return ERROR_FAILED_SERVICE_CONTROLLER_CONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwProcessId = GetCurrentProcessId();
|
dwProcessId = GetCurrentProcessId();
|
||||||
WriteFile(*hPipe,
|
WriteFile(*hPipe,
|
||||||
&dwProcessId,
|
&dwProcessId,
|
||||||
sizeof(DWORD),
|
sizeof(DWORD),
|
||||||
&dwBytesWritten,
|
&dwBytesWritten,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
DPRINT("Sent process id %lu\n", dwProcessId);
|
DPRINT("Sent process id %lu\n", dwProcessId);
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -245,93 +245,93 @@ ScConnectControlPipe(HANDLE *hPipe)
|
||||||
static DWORD
|
static DWORD
|
||||||
ScStartService(PSCM_START_PACKET StartPacket)
|
ScStartService(PSCM_START_PACKET StartPacket)
|
||||||
{
|
{
|
||||||
PACTIVE_SERVICE lpService;
|
PACTIVE_SERVICE lpService;
|
||||||
HANDLE ThreadHandle;
|
HANDLE ThreadHandle;
|
||||||
|
|
||||||
DPRINT("ScStartService() called\n");
|
DPRINT("ScStartService() called\n");
|
||||||
DPRINT("Size: %lu\n", StartPacket->Size);
|
DPRINT("Size: %lu\n", StartPacket->Size);
|
||||||
DPRINT("Service: %S\n", &StartPacket->Arguments[0]);
|
DPRINT("Service: %S\n", &StartPacket->Arguments[0]);
|
||||||
|
|
||||||
lpService = ScLookupServiceByServiceName(&StartPacket->Arguments[0]);
|
lpService = ScLookupServiceByServiceName(&StartPacket->Arguments[0]);
|
||||||
if (lpService == NULL)
|
if (lpService == NULL)
|
||||||
return ERROR_SERVICE_DOES_NOT_EXIST;
|
return ERROR_SERVICE_DOES_NOT_EXIST;
|
||||||
|
|
||||||
lpService->Arguments = HeapAlloc(GetProcessHeap(),
|
lpService->Arguments = HeapAlloc(GetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
StartPacket->Size * sizeof(WCHAR));
|
StartPacket->Size * sizeof(WCHAR));
|
||||||
if (lpService->Arguments == NULL)
|
if (lpService->Arguments == NULL)
|
||||||
return ERROR_OUTOFMEMORY;
|
return ERROR_OUTOFMEMORY;
|
||||||
|
|
||||||
memcpy(lpService->Arguments,
|
memcpy(lpService->Arguments,
|
||||||
StartPacket->Arguments,
|
StartPacket->Arguments,
|
||||||
StartPacket->Size * sizeof(WCHAR));
|
StartPacket->Size * sizeof(WCHAR));
|
||||||
|
|
||||||
ThreadHandle = CreateThread(NULL,
|
ThreadHandle = CreateThread(NULL,
|
||||||
0,
|
0,
|
||||||
ScServiceMainStub,
|
ScServiceMainStub,
|
||||||
lpService,
|
lpService,
|
||||||
CREATE_SUSPENDED,
|
CREATE_SUSPENDED,
|
||||||
&lpService->ThreadId);
|
&lpService->ThreadId);
|
||||||
if (ThreadHandle == NULL)
|
if (ThreadHandle == NULL)
|
||||||
return ERROR_SERVICE_NO_THREAD;
|
return ERROR_SERVICE_NO_THREAD;
|
||||||
|
|
||||||
ResumeThread(ThreadHandle);
|
ResumeThread(ThreadHandle);
|
||||||
CloseHandle(ThreadHandle);
|
CloseHandle(ThreadHandle);
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
ScServiceDispatcher(HANDLE hPipe,
|
ScServiceDispatcher(HANDLE hPipe,
|
||||||
PUCHAR lpBuffer,
|
PUCHAR lpBuffer,
|
||||||
DWORD dwBufferSize)
|
DWORD dwBufferSize)
|
||||||
{
|
{
|
||||||
LPDWORD Buffer;
|
LPDWORD Buffer;
|
||||||
DWORD Count;
|
DWORD Count;
|
||||||
BOOL bResult;
|
BOOL bResult;
|
||||||
|
|
||||||
DPRINT("ScDispatcherLoop() called\n");
|
DPRINT("ScDispatcherLoop() called\n");
|
||||||
|
|
||||||
Buffer = HeapAlloc(GetProcessHeap(),
|
Buffer = HeapAlloc(GetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
1024);
|
1024);
|
||||||
if (Buffer == NULL)
|
if (Buffer == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
/* Read command from the control pipe */
|
/* Read command from the control pipe */
|
||||||
bResult = ReadFile(hPipe,
|
bResult = ReadFile(hPipe,
|
||||||
Buffer,
|
Buffer,
|
||||||
1024,
|
1024,
|
||||||
&Count,
|
&Count,
|
||||||
NULL);
|
NULL);
|
||||||
if (bResult == FALSE)
|
if (bResult == FALSE)
|
||||||
{
|
{
|
||||||
DPRINT1("Pipe read failed (Error: %lu)\n", GetLastError());
|
DPRINT1("Pipe read failed (Error: %lu)\n", GetLastError());
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute command */
|
/* Execute command */
|
||||||
switch (Buffer[0])
|
switch (Buffer[0])
|
||||||
{
|
{
|
||||||
case SCM_START_COMMAND:
|
case SCM_START_COMMAND:
|
||||||
DPRINT("Start command\n");
|
DPRINT("Start command\n");
|
||||||
ScStartService((PSCM_START_PACKET)Buffer);
|
ScStartService((PSCM_START_PACKET)Buffer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DPRINT1("Unknown command %lu", Buffer[0]);
|
DPRINT1("Unknown command %lu", Buffer[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(),
|
HeapFree(GetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
Buffer);
|
Buffer);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -342,25 +342,25 @@ ScServiceDispatcher(HANDLE hPipe,
|
||||||
*/
|
*/
|
||||||
SERVICE_STATUS_HANDLE STDCALL
|
SERVICE_STATUS_HANDLE STDCALL
|
||||||
RegisterServiceCtrlHandlerA(LPCSTR lpServiceName,
|
RegisterServiceCtrlHandlerA(LPCSTR lpServiceName,
|
||||||
LPHANDLER_FUNCTION lpHandlerProc)
|
LPHANDLER_FUNCTION lpHandlerProc)
|
||||||
{
|
{
|
||||||
ANSI_STRING ServiceNameA;
|
ANSI_STRING ServiceNameA;
|
||||||
UNICODE_STRING ServiceNameU;
|
UNICODE_STRING ServiceNameU;
|
||||||
SERVICE_STATUS_HANDLE SHandle;
|
SERVICE_STATUS_HANDLE SHandle;
|
||||||
|
|
||||||
RtlInitAnsiString(&ServiceNameA, (LPSTR)lpServiceName);
|
RtlInitAnsiString(&ServiceNameA, (LPSTR)lpServiceName);
|
||||||
if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&ServiceNameU, &ServiceNameA, TRUE)))
|
if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&ServiceNameU, &ServiceNameA, TRUE)))
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
return (SERVICE_STATUS_HANDLE)0;
|
return (SERVICE_STATUS_HANDLE)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHandle = RegisterServiceCtrlHandlerW(ServiceNameU.Buffer,
|
SHandle = RegisterServiceCtrlHandlerW(ServiceNameU.Buffer,
|
||||||
lpHandlerProc);
|
lpHandlerProc);
|
||||||
|
|
||||||
RtlFreeUnicodeString(&ServiceNameU);
|
RtlFreeUnicodeString(&ServiceNameU);
|
||||||
|
|
||||||
return SHandle;
|
return SHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -371,20 +371,20 @@ RegisterServiceCtrlHandlerA(LPCSTR lpServiceName,
|
||||||
*/
|
*/
|
||||||
SERVICE_STATUS_HANDLE STDCALL
|
SERVICE_STATUS_HANDLE STDCALL
|
||||||
RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
|
RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
|
||||||
LPHANDLER_FUNCTION lpHandlerProc)
|
LPHANDLER_FUNCTION lpHandlerProc)
|
||||||
{
|
{
|
||||||
PACTIVE_SERVICE Service;
|
PACTIVE_SERVICE Service;
|
||||||
|
|
||||||
Service = ScLookupServiceByServiceName((LPWSTR)lpServiceName);
|
Service = ScLookupServiceByServiceName((LPWSTR)lpServiceName);
|
||||||
if (Service == NULL)
|
if (Service == NULL)
|
||||||
{
|
{
|
||||||
return (SERVICE_STATUS_HANDLE)NULL;
|
return (SERVICE_STATUS_HANDLE)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Service->HandlerFunction = lpHandlerProc;
|
Service->HandlerFunction = lpHandlerProc;
|
||||||
Service->HandlerFunctionEx = NULL;
|
Service->HandlerFunctionEx = NULL;
|
||||||
|
|
||||||
return (SERVICE_STATUS_HANDLE)Service->ThreadId;
|
return (SERVICE_STATUS_HANDLE)Service->ThreadId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -395,27 +395,27 @@ RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
|
||||||
*/
|
*/
|
||||||
SERVICE_STATUS_HANDLE STDCALL
|
SERVICE_STATUS_HANDLE STDCALL
|
||||||
RegisterServiceCtrlHandlerExA(LPCSTR lpServiceName,
|
RegisterServiceCtrlHandlerExA(LPCSTR lpServiceName,
|
||||||
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
||||||
LPVOID lpContext)
|
LPVOID lpContext)
|
||||||
{
|
{
|
||||||
ANSI_STRING ServiceNameA;
|
ANSI_STRING ServiceNameA;
|
||||||
UNICODE_STRING ServiceNameU;
|
UNICODE_STRING ServiceNameU;
|
||||||
SERVICE_STATUS_HANDLE SHandle;
|
SERVICE_STATUS_HANDLE SHandle;
|
||||||
|
|
||||||
RtlInitAnsiString(&ServiceNameA, (LPSTR)lpServiceName);
|
RtlInitAnsiString(&ServiceNameA, (LPSTR)lpServiceName);
|
||||||
if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&ServiceNameU, &ServiceNameA, TRUE)))
|
if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&ServiceNameU, &ServiceNameA, TRUE)))
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
return (SERVICE_STATUS_HANDLE)0;
|
return (SERVICE_STATUS_HANDLE)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHandle = RegisterServiceCtrlHandlerExW(ServiceNameU.Buffer,
|
SHandle = RegisterServiceCtrlHandlerExW(ServiceNameU.Buffer,
|
||||||
lpHandlerProc,
|
lpHandlerProc,
|
||||||
lpContext);
|
lpContext);
|
||||||
|
|
||||||
RtlFreeUnicodeString(&ServiceNameU);
|
RtlFreeUnicodeString(&ServiceNameU);
|
||||||
|
|
||||||
return SHandle;
|
return SHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -426,22 +426,22 @@ RegisterServiceCtrlHandlerExA(LPCSTR lpServiceName,
|
||||||
*/
|
*/
|
||||||
SERVICE_STATUS_HANDLE STDCALL
|
SERVICE_STATUS_HANDLE STDCALL
|
||||||
RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
|
RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
|
||||||
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
||||||
LPVOID lpContext)
|
LPVOID lpContext)
|
||||||
{
|
{
|
||||||
PACTIVE_SERVICE Service;
|
PACTIVE_SERVICE Service;
|
||||||
|
|
||||||
Service = ScLookupServiceByServiceName((LPWSTR)lpServiceName);
|
Service = ScLookupServiceByServiceName((LPWSTR)lpServiceName);
|
||||||
if (Service == NULL)
|
if (Service == NULL)
|
||||||
{
|
{
|
||||||
return (SERVICE_STATUS_HANDLE)NULL;
|
return (SERVICE_STATUS_HANDLE)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Service->HandlerFunction = NULL;
|
Service->HandlerFunction = NULL;
|
||||||
Service->HandlerFunctionEx = lpHandlerProc;
|
Service->HandlerFunctionEx = lpHandlerProc;
|
||||||
Service->HandlerContext = lpContext;
|
Service->HandlerContext = lpContext;
|
||||||
|
|
||||||
return (SERVICE_STATUS_HANDLE)Service->ThreadId;
|
return (SERVICE_STATUS_HANDLE)Service->ThreadId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -452,12 +452,12 @@ RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
|
||||||
*/
|
*/
|
||||||
BOOL STDCALL
|
BOOL STDCALL
|
||||||
SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus,
|
SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus,
|
||||||
DWORD dwServiceBits,
|
DWORD dwServiceBits,
|
||||||
BOOL bSetBitsOn,
|
BOOL bSetBitsOn,
|
||||||
BOOL bUpdateImmediately)
|
BOOL bUpdateImmediately)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -468,22 +468,22 @@ SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus,
|
||||||
*/
|
*/
|
||||||
BOOL STDCALL
|
BOOL STDCALL
|
||||||
SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus,
|
SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus,
|
||||||
LPSERVICE_STATUS lpServiceStatus)
|
LPSERVICE_STATUS lpServiceStatus)
|
||||||
{
|
{
|
||||||
PACTIVE_SERVICE Service;
|
PACTIVE_SERVICE Service;
|
||||||
|
|
||||||
Service = ScLookupServiceByThreadId((DWORD)hServiceStatus);
|
Service = ScLookupServiceByThreadId((DWORD)hServiceStatus);
|
||||||
if (!Service)
|
if (!Service)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_INVALID_HANDLE);
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlCopyMemory(&Service->ServiceStatus,
|
RtlCopyMemory(&Service->ServiceStatus,
|
||||||
lpServiceStatus,
|
lpServiceStatus,
|
||||||
sizeof(SERVICE_STATUS));
|
sizeof(SERVICE_STATUS));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -495,72 +495,72 @@ SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus,
|
||||||
BOOL STDCALL
|
BOOL STDCALL
|
||||||
StartServiceCtrlDispatcherA(LPSERVICE_TABLE_ENTRYA lpServiceStartTable)
|
StartServiceCtrlDispatcherA(LPSERVICE_TABLE_ENTRYA lpServiceStartTable)
|
||||||
{
|
{
|
||||||
ULONG i;
|
ULONG i;
|
||||||
HANDLE hPipe;
|
HANDLE hPipe;
|
||||||
DWORD dwError;
|
DWORD dwError;
|
||||||
PUCHAR lpMessageBuffer;
|
PUCHAR lpMessageBuffer;
|
||||||
|
|
||||||
DPRINT("StartServiceCtrlDispatcherA() called\n");
|
DPRINT("StartServiceCtrlDispatcherA() called\n");
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (lpServiceStartTable[i].lpServiceProc != NULL)
|
while (lpServiceStartTable[i].lpServiceProc != NULL)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwActiveServiceCount = i;
|
dwActiveServiceCount = i;
|
||||||
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
|
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
|
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
|
||||||
if (lpActiveServices == NULL)
|
if (lpActiveServices == NULL)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy service names and start procedure */
|
/* Copy service names and start procedure */
|
||||||
for (i = 0; i < dwActiveServiceCount; i++)
|
for (i = 0; i < dwActiveServiceCount; i++)
|
||||||
{
|
{
|
||||||
RtlCreateUnicodeStringFromAsciiz(&lpActiveServices[i].ServiceName,
|
RtlCreateUnicodeStringFromAsciiz(&lpActiveServices[i].ServiceName,
|
||||||
lpServiceStartTable[i].lpServiceName);
|
lpServiceStartTable[i].lpServiceName);
|
||||||
lpActiveServices[i].Main.lpFuncA = lpServiceStartTable[i].lpServiceProc;
|
lpActiveServices[i].Main.lpFuncA = lpServiceStartTable[i].lpServiceProc;
|
||||||
lpActiveServices[i].bUnicode = FALSE;
|
lpActiveServices[i].bUnicode = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwError = ScConnectControlPipe(&hPipe);
|
dwError = ScConnectControlPipe(&hPipe);
|
||||||
if (dwError != ERROR_SUCCESS)
|
if (dwError != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Free the service table */
|
/* Free the service table */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
||||||
lpActiveServices = NULL;
|
lpActiveServices = NULL;
|
||||||
dwActiveServiceCount = 0;
|
dwActiveServiceCount = 0;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
256);
|
256);
|
||||||
if (lpMessageBuffer == NULL)
|
if (lpMessageBuffer == NULL)
|
||||||
{
|
{
|
||||||
/* Free the service table */
|
/* Free the service table */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
||||||
lpActiveServices = NULL;
|
lpActiveServices = NULL;
|
||||||
dwActiveServiceCount = 0;
|
dwActiveServiceCount = 0;
|
||||||
CloseHandle(hPipe);
|
CloseHandle(hPipe);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
|
ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
|
||||||
CloseHandle(hPipe);
|
CloseHandle(hPipe);
|
||||||
|
|
||||||
/* Free the message buffer */
|
/* Free the message buffer */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
|
||||||
|
|
||||||
/* Free the service table */
|
/* Free the service table */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
||||||
lpActiveServices = NULL;
|
lpActiveServices = NULL;
|
||||||
dwActiveServiceCount = 0;
|
dwActiveServiceCount = 0;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -572,72 +572,72 @@ StartServiceCtrlDispatcherA(LPSERVICE_TABLE_ENTRYA lpServiceStartTable)
|
||||||
BOOL STDCALL
|
BOOL STDCALL
|
||||||
StartServiceCtrlDispatcherW(LPSERVICE_TABLE_ENTRYW lpServiceStartTable)
|
StartServiceCtrlDispatcherW(LPSERVICE_TABLE_ENTRYW lpServiceStartTable)
|
||||||
{
|
{
|
||||||
ULONG i;
|
ULONG i;
|
||||||
HANDLE hPipe;
|
HANDLE hPipe;
|
||||||
DWORD dwError;
|
DWORD dwError;
|
||||||
PUCHAR lpMessageBuffer;
|
PUCHAR lpMessageBuffer;
|
||||||
|
|
||||||
DPRINT("StartServiceCtrlDispatcherW() called\n");
|
DPRINT("StartServiceCtrlDispatcherW() called\n");
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (lpServiceStartTable[i].lpServiceProc != NULL)
|
while (lpServiceStartTable[i].lpServiceProc != NULL)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwActiveServiceCount = i;
|
dwActiveServiceCount = i;
|
||||||
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
|
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
|
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
|
||||||
if (lpActiveServices == NULL)
|
if (lpActiveServices == NULL)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy service names and start procedure */
|
/* Copy service names and start procedure */
|
||||||
for (i = 0; i < dwActiveServiceCount; i++)
|
for (i = 0; i < dwActiveServiceCount; i++)
|
||||||
{
|
{
|
||||||
RtlCreateUnicodeString(&lpActiveServices[i].ServiceName,
|
RtlCreateUnicodeString(&lpActiveServices[i].ServiceName,
|
||||||
lpServiceStartTable[i].lpServiceName);
|
lpServiceStartTable[i].lpServiceName);
|
||||||
lpActiveServices[i].Main.lpFuncW = lpServiceStartTable[i].lpServiceProc;
|
lpActiveServices[i].Main.lpFuncW = lpServiceStartTable[i].lpServiceProc;
|
||||||
lpActiveServices[i].bUnicode = TRUE;
|
lpActiveServices[i].bUnicode = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwError = ScConnectControlPipe(&hPipe);
|
dwError = ScConnectControlPipe(&hPipe);
|
||||||
if (dwError != ERROR_SUCCESS)
|
if (dwError != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Free the service table */
|
/* Free the service table */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
||||||
lpActiveServices = NULL;
|
lpActiveServices = NULL;
|
||||||
dwActiveServiceCount = 0;
|
dwActiveServiceCount = 0;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
256);
|
256);
|
||||||
if (lpMessageBuffer == NULL)
|
if (lpMessageBuffer == NULL)
|
||||||
{
|
{
|
||||||
/* Free the service table */
|
/* Free the service table */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
||||||
lpActiveServices = NULL;
|
lpActiveServices = NULL;
|
||||||
dwActiveServiceCount = 0;
|
dwActiveServiceCount = 0;
|
||||||
CloseHandle(hPipe);
|
CloseHandle(hPipe);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
|
ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
|
||||||
CloseHandle(hPipe);
|
CloseHandle(hPipe);
|
||||||
|
|
||||||
/* Free the message buffer */
|
/* Free the message buffer */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
|
||||||
|
|
||||||
/* Free the service table */
|
/* Free the service table */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
|
||||||
lpActiveServices = NULL;
|
lpActiveServices = NULL;
|
||||||
dwActiveServiceCount = 0;
|
dwActiveServiceCount = 0;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue