Author: ekohl
Date: Sun Jul 15 18:27:29 2012
New Revision: 56900
URL:
http://svn.reactos.org/svn/reactos?rev=56900&view=rev
Log:
[SERVICES]
Implement check for SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS type.
Patch by Hermes Belusca.
See issue #7179 for more details.
Modified:
trunk/reactos/base/system/services/database.c
trunk/reactos/dll/win32/advapi32/service/sctrl.c
trunk/reactos/include/reactos/services/services.h
Modified: trunk/reactos/base/system/services/database.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/datab…
==============================================================================
--- trunk/reactos/base/system/services/database.c [iso-8859-1] (original)
+++ trunk/reactos/base/system/services/database.c [iso-8859-1] Sun Jul 15 18:27:29 2012
@@ -1116,8 +1116,8 @@
DPRINT("ScmSendStartCommand() called\n");
/* Calculate the total length of the start command line */
- PacketSize = sizeof(SCM_CONTROL_PACKET);
- PacketSize += (wcslen(Service->lpServiceName) + 1) * sizeof(WCHAR);
+ PacketSize = sizeof(SCM_CONTROL_PACKET) +
+ (wcslen(Service->lpServiceName) + 1) * sizeof(WCHAR);
/* Calculate the required packet size for the start arguments */
if (argc > 0 && argv != NULL)
@@ -1140,7 +1140,9 @@
return ERROR_NOT_ENOUGH_MEMORY;
ControlPacket->dwSize = PacketSize;
- ControlPacket->dwControl = SERVICE_CONTROL_START;
+ ControlPacket->dwControl = (Service->Status.dwServiceType &
SERVICE_WIN32_OWN_PROCESS)
+ ? SERVICE_CONTROL_START_OWN
+ : SERVICE_CONTROL_START_SHARE;
ControlPacket->hServiceStatus = (SERVICE_STATUS_HANDLE)Service;
ControlPacket->dwServiceNameOffset = sizeof(SCM_CONTROL_PACKET);
Modified: trunk/reactos/dll/win32/advapi32/service/sctrl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/service…
==============================================================================
--- trunk/reactos/dll/win32/advapi32/service/sctrl.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/service/sctrl.c [iso-8859-1] Sun Jul 15 18:27:29
2012
@@ -47,6 +47,7 @@
LPHANDLER_FUNCTION_EX HandlerFunctionEx;
LPVOID HandlerContext;
BOOL bUnicode;
+ BOOL bOwnProcess;
} ACTIVE_SERVICE, *PACTIVE_SERVICE;
@@ -141,6 +142,9 @@
DWORD i;
TRACE("ScLookupServiceByServiceName(%S) called\n", lpServiceName);
+
+ if (lpActiveServices[0].bOwnProcess)
+ return &lpActiveServices[0];
for (i = 0; i < dwActiveServiceCount; i++)
{
@@ -488,10 +492,9 @@
static BOOL
ScServiceDispatcher(HANDLE hPipe,
- PUCHAR lpBuffer,
+ PSCM_CONTROL_PACKET ControlPacket,
DWORD dwBufferSize)
{
- PSCM_CONTROL_PACKET ControlPacket;
DWORD Count;
BOOL bResult;
DWORD dwRunningServices = 0;
@@ -502,18 +505,12 @@
TRACE("ScDispatcherLoop() called\n");
- ControlPacket = HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- 1024);
- if (ControlPacket == NULL)
- return FALSE;
-
while (TRUE)
{
/* Read command from the control pipe */
bResult = ReadFile(hPipe,
ControlPacket,
- 1024,
+ dwBufferSize,
&Count,
NULL);
if (bResult == FALSE)
@@ -525,13 +522,17 @@
lpServiceName = (LPWSTR)((PBYTE)ControlPacket +
ControlPacket->dwServiceNameOffset);
TRACE("Service: %S\n", lpServiceName);
+ if (ControlPacket->dwControl == SERVICE_CONTROL_START_OWN)
+ lpActiveServices[0].bOwnProcess = TRUE;
+
lpService = ScLookupServiceByServiceName(lpServiceName);
if (lpService != NULL)
{
/* Execute command */
switch (ControlPacket->dwControl)
{
- case SERVICE_CONTROL_START:
+ case SERVICE_CONTROL_START_SHARE:
+ case SERVICE_CONTROL_START_OWN:
TRACE("Start command - recieved SERVICE_CONTROL_START\n");
dwError = ScStartService(lpService, ControlPacket);
if (dwError == ERROR_SUCCESS)
@@ -832,12 +833,14 @@
* @implemented
*/
BOOL WINAPI
-StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA * lpServiceStartTable)
+StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
{
ULONG i;
HANDLE hPipe;
DWORD dwError;
- PUCHAR lpMessageBuffer;
+ PSCM_CONTROL_PACKET ControlPacket;
+ DWORD dwBufSize;
+ BOOL bRet = TRUE;
TRACE("StartServiceCtrlDispatcherA() called\n");
@@ -864,50 +867,40 @@
lpActiveServices[i].ThreadParams.A.lpServiceMain =
lpServiceStartTable[i].lpServiceProc;
lpActiveServices[i].hServiceStatus = 0;
lpActiveServices[i].bUnicode = FALSE;
+ lpActiveServices[i].bOwnProcess = FALSE;
}
dwError = ScConnectControlPipe(&hPipe);
if (dwError != ERROR_SUCCESS)
{
- /* Free the service table */
- for (i = 0; i < dwActiveServiceCount; i++)
- {
- RtlFreeUnicodeString(&lpActiveServices[i].ServiceName);
- }
- RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
- lpActiveServices = NULL;
- dwActiveServiceCount = 0;
- return FALSE;
- }
-
- lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
- HEAP_ZERO_MEMORY,
- 256);
- if (lpMessageBuffer == NULL)
- {
- /* Free the service table */
- for (i = 0; i < dwActiveServiceCount; i++)
- {
- RtlFreeUnicodeString(&lpActiveServices[i].ServiceName);
- }
- RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
- lpActiveServices = NULL;
- dwActiveServiceCount = 0;
- CloseHandle(hPipe);
- return FALSE;
+ bRet = FALSE;
+ goto done;
+ }
+
+ dwBufSize = sizeof(SCM_CONTROL_PACKET) +
+ (MAX_SERVICE_NAME_LENGTH + 1) * sizeof(WCHAR);
+
+ ControlPacket = RtlAllocateHeap(RtlGetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ dwBufSize);
+ if (ControlPacket == NULL)
+ {
+ bRet = FALSE;
+ goto done;
}
ScCreateStatusBinding();
- ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
+ ScServiceDispatcher(hPipe, ControlPacket, dwBufSize);
ScDestroyStatusBinding();
CloseHandle(hPipe);
- /* Free the message buffer */
- RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
-
+ /* Free the control packet */
+ RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket);
+
+done:
/* Free the service table */
for (i = 0; i < dwActiveServiceCount; i++)
{
@@ -917,7 +910,7 @@
lpActiveServices = NULL;
dwActiveServiceCount = 0;
- return TRUE;
+ return bRet;
}
@@ -927,12 +920,14 @@
* @implemented
*/
BOOL WINAPI
-StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW * lpServiceStartTable)
+StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
{
ULONG i;
HANDLE hPipe;
DWORD dwError;
- PUCHAR lpMessageBuffer;
+ PSCM_CONTROL_PACKET ControlPacket;
+ DWORD dwBufSize;
+ BOOL bRet = TRUE;
TRACE("StartServiceCtrlDispatcherW() called\n");
@@ -959,50 +954,40 @@
lpActiveServices[i].ThreadParams.W.lpServiceMain =
lpServiceStartTable[i].lpServiceProc;
lpActiveServices[i].hServiceStatus = 0;
lpActiveServices[i].bUnicode = TRUE;
+ lpActiveServices[i].bOwnProcess = FALSE;
}
dwError = ScConnectControlPipe(&hPipe);
if (dwError != ERROR_SUCCESS)
{
- /* Free the service table */
- for (i = 0; i < dwActiveServiceCount; i++)
- {
- RtlFreeUnicodeString(&lpActiveServices[i].ServiceName);
- }
- RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
- lpActiveServices = NULL;
- dwActiveServiceCount = 0;
- return FALSE;
- }
-
- lpMessageBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
- HEAP_ZERO_MEMORY,
- 256);
- if (lpMessageBuffer == NULL)
- {
- /* Free the service table */
- for (i = 0; i < dwActiveServiceCount; i++)
- {
- RtlFreeUnicodeString(&lpActiveServices[i].ServiceName);
- }
- RtlFreeHeap(RtlGetProcessHeap(), 0, lpActiveServices);
- lpActiveServices = NULL;
- dwActiveServiceCount = 0;
- CloseHandle(hPipe);
- return FALSE;
+ bRet = FALSE;
+ goto done;
+ }
+
+ dwBufSize = sizeof(SCM_CONTROL_PACKET) +
+ (MAX_SERVICE_NAME_LENGTH + 1) * sizeof(WCHAR);
+
+ ControlPacket = RtlAllocateHeap(RtlGetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ dwBufSize);
+ if (ControlPacket == NULL)
+ {
+ bRet = FALSE;
+ goto done;
}
ScCreateStatusBinding();
- ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
+ ScServiceDispatcher(hPipe, ControlPacket, dwBufSize);
ScDestroyStatusBinding();
CloseHandle(hPipe);
- /* Free the message buffer */
- RtlFreeHeap(RtlGetProcessHeap(), 0, lpMessageBuffer);
-
+ /* Free the control packet */
+ RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket);
+
+done:
/* Free the service table */
for (i = 0; i < dwActiveServiceCount; i++)
{
@@ -1012,7 +997,7 @@
lpActiveServices = NULL;
dwActiveServiceCount = 0;
- return TRUE;
+ return bRet;
}
/* EOF */
Modified: trunk/reactos/include/reactos/services/services.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/services/s…
==============================================================================
--- trunk/reactos/include/reactos/services/services.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/services/services.h [iso-8859-1] Sun Jul 15 18:27:29
2012
@@ -9,7 +9,15 @@
#ifndef __SERVICES_SERVICES_H__
#define __SERVICES_SERVICES_H__
-#define SERVICE_CONTROL_START 0
+/*
+ * Internal control codes.
+ * Neither in the range of public control codes (1-10 and 11-14 or 16 or 32 or 64)
+ * nor in the range of user-defined control codes (128-255).
+ */
+/* Start a service that shares a process with other services */
+#define SERVICE_CONTROL_START_SHARE 80
+/* Start a service that runs in its own process */
+#define SERVICE_CONTROL_START_OWN 81
typedef struct _SCM_CONTROL_PACKET
{