[ADVAPI32] Revert unnecessary changes, clarify comments and clean-up inconsistencies

This commit is contained in:
Eric Kohl 2018-03-25 12:03:07 +02:00
parent 32bb592e12
commit 94435b53d7
3 changed files with 116 additions and 110 deletions

View file

@ -41,34 +41,34 @@ EVENTLOG_HANDLE_A_bind(EVENTLOG_HANDLE_A UNCServerName)
{ {
handle_t hBinding = NULL; handle_t hBinding = NULL;
RPC_CSTR pszStringBinding; RPC_CSTR pszStringBinding;
RPC_STATUS Status; RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_A_bind() called\n"); TRACE("EVENTLOG_HANDLE_A_bind() called\n");
Status = RpcStringBindingComposeA(NULL, status = RpcStringBindingComposeA(NULL,
(RPC_CSTR)"ncacn_np", (RPC_CSTR)"ncacn_np",
(RPC_CSTR)UNCServerName, (RPC_CSTR)UNCServerName,
(RPC_CSTR)"\\pipe\\EventLog", (RPC_CSTR)"\\pipe\\EventLog",
NULL, NULL,
&pszStringBinding); &pszStringBinding);
if (Status) if (status)
{ {
ERR("RpcStringBindingCompose returned 0x%x\n", Status); ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL; return NULL;
} }
/* Set the binding handle that will be used to bind to the server. */ /* Set the binding handle that will be used to bind to the server. */
Status = RpcBindingFromStringBindingA(pszStringBinding, status = RpcBindingFromStringBindingA(pszStringBinding,
&hBinding); &hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFromStringBinding returned 0x%x\n", Status); ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
} }
Status = RpcStringFreeA(&pszStringBinding); status = RpcStringFreeA(&pszStringBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcStringFree returned 0x%x\n", Status); ERR("RpcStringFree returned 0x%x\n", status);
} }
return hBinding; return hBinding;
@ -79,14 +79,14 @@ void __RPC_USER
EVENTLOG_HANDLE_A_unbind(EVENTLOG_HANDLE_A UNCServerName, EVENTLOG_HANDLE_A_unbind(EVENTLOG_HANDLE_A UNCServerName,
handle_t hBinding) handle_t hBinding)
{ {
RPC_STATUS Status; RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_A_unbind() called\n"); TRACE("EVENTLOG_HANDLE_A_unbind() called\n");
Status = RpcBindingFree(&hBinding); status = RpcBindingFree(&hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFree returned 0x%x\n", Status); ERR("RpcBindingFree returned 0x%x\n", status);
} }
} }
@ -96,34 +96,34 @@ EVENTLOG_HANDLE_W_bind(EVENTLOG_HANDLE_W UNCServerName)
{ {
handle_t hBinding = NULL; handle_t hBinding = NULL;
RPC_WSTR pszStringBinding; RPC_WSTR pszStringBinding;
RPC_STATUS Status; RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_W_bind() called\n"); TRACE("EVENTLOG_HANDLE_W_bind() called\n");
Status = RpcStringBindingComposeW(NULL, status = RpcStringBindingComposeW(NULL,
L"ncacn_np", L"ncacn_np",
UNCServerName, UNCServerName,
L"\\pipe\\EventLog", L"\\pipe\\EventLog",
NULL, NULL,
&pszStringBinding); &pszStringBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcStringBindingCompose returned 0x%x\n", Status); ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL; return NULL;
} }
/* Set the binding handle that will be used to bind to the server. */ /* Set the binding handle that will be used to bind to the server. */
Status = RpcBindingFromStringBindingW(pszStringBinding, status = RpcBindingFromStringBindingW(pszStringBinding,
&hBinding); &hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFromStringBinding returned 0x%x\n", Status); ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
} }
Status = RpcStringFreeW(&pszStringBinding); status = RpcStringFreeW(&pszStringBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcStringFree returned 0x%x\n", Status); ERR("RpcStringFree returned 0x%x\n", status);
} }
return hBinding; return hBinding;
@ -134,14 +134,14 @@ void __RPC_USER
EVENTLOG_HANDLE_W_unbind(EVENTLOG_HANDLE_W UNCServerName, EVENTLOG_HANDLE_W_unbind(EVENTLOG_HANDLE_W UNCServerName,
handle_t hBinding) handle_t hBinding)
{ {
RPC_STATUS Status; RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_W_unbind() called\n"); TRACE("EVENTLOG_HANDLE_W_unbind() called\n");
Status = RpcBindingFree(&hBinding); status = RpcBindingFree(&hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFree returned 0x%x\n", Status); ERR("RpcBindingFree returned 0x%x\n", status);
} }
} }
@ -813,7 +813,8 @@ ElfOpenBackupEventLogW(IN PUNICODE_STRING UNCServerNameU,
{ {
Status = ElfrOpenBELW(pUNCServerName, Status = ElfrOpenBELW(pUNCServerName,
(PRPC_UNICODE_STRING)BackupFileNameU, (PRPC_UNICODE_STRING)BackupFileNameU,
1, 1, 1,
1,
(IELF_HANDLE*)phEventLog); (IELF_HANDLE*)phEventLog);
} }
RpcExcept(EXCEPTION_EXECUTE_HANDLER) RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@ -901,7 +902,8 @@ ElfOpenEventLogA(IN PANSI_STRING UNCServerNameA,
Status = ElfrOpenELA(pUNCServerName, Status = ElfrOpenELA(pUNCServerName,
(PRPC_STRING)SourceNameA, (PRPC_STRING)SourceNameA,
&EmptyStringA, &EmptyStringA,
1, 1, 1,
1,
(IELF_HANDLE*)phEventLog); (IELF_HANDLE*)phEventLog);
} }
RpcExcept(EXCEPTION_EXECUTE_HANDLER) RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@ -966,7 +968,8 @@ ElfOpenEventLogW(IN PUNICODE_STRING UNCServerNameU,
Status = ElfrOpenELW(pUNCServerName, Status = ElfrOpenELW(pUNCServerName,
(PRPC_UNICODE_STRING)SourceNameU, (PRPC_UNICODE_STRING)SourceNameU,
&EmptyStringU, &EmptyStringU,
1, 1, 1,
1,
(IELF_HANDLE*)phEventLog); (IELF_HANDLE*)phEventLog);
} }
RpcExcept(EXCEPTION_EXECUTE_HANDLER) RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@ -1204,7 +1207,8 @@ ElfRegisterEventSourceA(IN PANSI_STRING UNCServerNameA,
Status = ElfrRegisterEventSourceA(pUNCServerName, Status = ElfrRegisterEventSourceA(pUNCServerName,
(PRPC_STRING)SourceNameA, (PRPC_STRING)SourceNameA,
&EmptyStringA, &EmptyStringA,
1, 1, 1,
1,
(IELF_HANDLE*)phEventLog); (IELF_HANDLE*)phEventLog);
} }
RpcExcept(EXCEPTION_EXECUTE_HANDLER) RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@ -1274,7 +1278,8 @@ ElfRegisterEventSourceW(IN PUNICODE_STRING UNCServerNameU,
Status = ElfrRegisterEventSourceW(pUNCServerName, Status = ElfrRegisterEventSourceW(pUNCServerName,
(PRPC_UNICODE_STRING)SourceNameU, (PRPC_UNICODE_STRING)SourceNameU,
&EmptyStringU, &EmptyStringU,
1, 1, 1,
1,
(IELF_HANDLE*)phEventLog); (IELF_HANDLE*)phEventLog);
} }
RpcExcept(EXCEPTION_EXECUTE_HANDLER) RpcExcept(EXCEPTION_EXECUTE_HANDLER)

View file

@ -10,7 +10,7 @@
/* INCLUDES ******************************************************************/ /* INCLUDES ******************************************************************/
#include <advapi32.h> #include <advapi32.h>
WINE_DEFAULT_DEBUG_CHANNEL(advapi_service); WINE_DEFAULT_DEBUG_CHANNEL(advapi);
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
@ -20,35 +20,35 @@ SVCCTL_HANDLEA_bind(SVCCTL_HANDLEA szMachineName)
{ {
handle_t hBinding = NULL; handle_t hBinding = NULL;
RPC_CSTR pszStringBinding; RPC_CSTR pszStringBinding;
RPC_STATUS Status; RPC_STATUS status;
TRACE("SVCCTL_HANDLEA_bind(%s)\n", TRACE("SVCCTL_HANDLEA_bind(%s)\n",
debugstr_a(szMachineName)); debugstr_a(szMachineName));
Status = RpcStringBindingComposeA(NULL, status = RpcStringBindingComposeA(NULL,
(RPC_CSTR)"ncacn_np", (RPC_CSTR)"ncacn_np",
(RPC_CSTR)szMachineName, (RPC_CSTR)szMachineName,
(RPC_CSTR)"\\pipe\\ntsvcs", (RPC_CSTR)"\\pipe\\ntsvcs",
NULL, NULL,
&pszStringBinding); &pszStringBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcStringBindingCompose returned 0x%x\n", Status); ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL; return NULL;
} }
/* Set the binding handle that will be used to bind to the server. */ /* Set the binding handle that will be used to bind to the server. */
Status = RpcBindingFromStringBindingA(pszStringBinding, status = RpcBindingFromStringBindingA(pszStringBinding,
&hBinding); &hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFromStringBinding returned 0x%x\n", Status); ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
} }
Status = RpcStringFreeA(&pszStringBinding); status = RpcStringFreeA(&pszStringBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcStringFree returned 0x%x\n", Status); ERR("RpcStringFree returned 0x%x\n", status);
} }
return hBinding; return hBinding;
@ -59,15 +59,15 @@ void __RPC_USER
SVCCTL_HANDLEA_unbind(SVCCTL_HANDLEA szMachineName, SVCCTL_HANDLEA_unbind(SVCCTL_HANDLEA szMachineName,
handle_t hBinding) handle_t hBinding)
{ {
RPC_STATUS Status; RPC_STATUS status;
TRACE("SVCCTL_HANDLEA_unbind(%s %p)\n", TRACE("SVCCTL_HANDLEA_unbind(%s %p)\n",
debugstr_a(szMachineName), hBinding); debugstr_a(szMachineName), hBinding);
Status = RpcBindingFree(&hBinding); status = RpcBindingFree(&hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFree returned 0x%x\n", Status); ERR("RpcBindingFree returned 0x%x\n", status);
} }
} }
@ -77,35 +77,35 @@ SVCCTL_HANDLEW_bind(SVCCTL_HANDLEW szMachineName)
{ {
handle_t hBinding = NULL; handle_t hBinding = NULL;
RPC_WSTR pszStringBinding; RPC_WSTR pszStringBinding;
RPC_STATUS Status; RPC_STATUS status;
TRACE("SVCCTL_HANDLEW_bind(%s)\n", TRACE("SVCCTL_HANDLEW_bind(%s)\n",
debugstr_w(szMachineName)); debugstr_w(szMachineName));
Status = RpcStringBindingComposeW(NULL, status = RpcStringBindingComposeW(NULL,
L"ncacn_np", L"ncacn_np",
szMachineName, szMachineName,
L"\\pipe\\ntsvcs", L"\\pipe\\ntsvcs",
NULL, NULL,
&pszStringBinding); &pszStringBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcStringBindingCompose returned 0x%x\n", Status); ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL; return NULL;
} }
/* Set the binding handle that will be used to bind to the server. */ /* Set the binding handle that will be used to bind to the server. */
Status = RpcBindingFromStringBindingW(pszStringBinding, status = RpcBindingFromStringBindingW(pszStringBinding,
&hBinding); &hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFromStringBinding returned 0x%x\n", Status); ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
} }
Status = RpcStringFreeW(&pszStringBinding); status = RpcStringFreeW(&pszStringBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcStringFree returned 0x%x\n", Status); ERR("RpcStringFree returned 0x%x\n", status);
} }
return hBinding; return hBinding;
@ -116,20 +116,19 @@ void __RPC_USER
SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName, SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName,
handle_t hBinding) handle_t hBinding)
{ {
RPC_STATUS Status; RPC_STATUS status;
TRACE("SVCCTL_HANDLEW_unbind(%s %p)\n", TRACE("SVCCTL_HANDLEW_unbind(%s %p)\n",
debugstr_w(szMachineName), hBinding); debugstr_w(szMachineName), hBinding);
Status = RpcBindingFree(&hBinding); status = RpcBindingFree(&hBinding);
if (Status != RPC_S_OK) if (status != RPC_S_OK)
{ {
ERR("RpcBindingFree returned 0x%x\n", Status); ERR("RpcBindingFree returned 0x%x\n", status);
} }
} }
/* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
DWORD DWORD
ScmRpcStatusToWinError(RPC_STATUS Status) ScmRpcStatusToWinError(RPC_STATUS Status)
{ {
@ -1638,6 +1637,7 @@ GetServiceKeyNameA(SC_HANDLE hSCManager,
} }
RpcExcept(EXCEPTION_EXECUTE_HANDLER) RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{ {
/* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
dwError = ScmRpcStatusToWinError(RpcExceptionCode()); dwError = ScmRpcStatusToWinError(RpcExceptionCode());
} }
RpcEndExcept; RpcEndExcept;
@ -1797,11 +1797,13 @@ WaitForSCManager(VOID)
hEvent = OpenEventW(SYNCHRONIZE, FALSE, SCM_START_EVENT); hEvent = OpenEventW(SYNCHRONIZE, FALSE, SCM_START_EVENT);
if (hEvent == NULL) if (hEvent == NULL)
{ {
if (GetLastError() != ERROR_FILE_NOT_FOUND) return; if (GetLastError() != ERROR_FILE_NOT_FOUND)
return;
/* Try to create a new event */ /* Try to create a new event */
hEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT); hEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
if (hEvent == NULL) return; if (hEvent == NULL)
return;
} }
/* Wait for 3 minutes */ /* Wait for 3 minutes */

View file

@ -12,7 +12,7 @@
/* INCLUDES ******************************************************************/ /* INCLUDES ******************************************************************/
#include <advapi32.h> #include <advapi32.h>
WINE_DEFAULT_DEBUG_CHANNEL(advapi_service); WINE_DEFAULT_DEBUG_CHANNEL(advapi);
/* TYPES *********************************************************************/ /* TYPES *********************************************************************/
@ -135,9 +135,8 @@ ScDestroyStatusBinding(VOID)
} }
static DWORD static PACTIVE_SERVICE
ScLookupServiceByServiceName(IN LPCWSTR lpServiceName, ScLookupServiceByServiceName(LPCWSTR lpServiceName)
OUT PACTIVE_SERVICE* pService)
{ {
DWORD i; DWORD i;
@ -145,10 +144,7 @@ ScLookupServiceByServiceName(IN LPCWSTR lpServiceName,
lpServiceName); lpServiceName);
if (lpActiveServices[0].bOwnProcess) if (lpActiveServices[0].bOwnProcess)
{ return &lpActiveServices[0];
*pService = &lpActiveServices[0];
return ERROR_SUCCESS;
}
for (i = 0; i < dwActiveServiceCount; i++) for (i = 0; i < dwActiveServiceCount; i++)
{ {
@ -156,14 +152,12 @@ ScLookupServiceByServiceName(IN LPCWSTR lpServiceName,
if (_wcsicmp(lpActiveServices[i].ServiceName.Buffer, lpServiceName) == 0) if (_wcsicmp(lpActiveServices[i].ServiceName.Buffer, lpServiceName) == 0)
{ {
TRACE("Found!\n"); TRACE("Found!\n");
*pService = &lpActiveServices[i]; return &lpActiveServices[i];
return ERROR_SUCCESS;
} }
} }
TRACE("No service found!\n"); TRACE("No service found!\n");
*pService = NULL; return NULL;
return ERROR_SERVICE_NOT_IN_EXE;
} }
@ -600,8 +594,8 @@ ScServiceDispatcher(HANDLE hPipe,
if (ControlPacket->dwControl == SERVICE_CONTROL_START_OWN) if (ControlPacket->dwControl == SERVICE_CONTROL_START_OWN)
lpActiveServices[0].bOwnProcess = TRUE; lpActiveServices[0].bOwnProcess = TRUE;
dwError = ScLookupServiceByServiceName(lpServiceName, &lpService); lpService = ScLookupServiceByServiceName(lpServiceName);
if ((dwError == ERROR_SUCCESS) && (lpService != NULL)) if (lpService != NULL)
{ {
/* Execute command */ /* Execute command */
switch (ControlPacket->dwControl) switch (ControlPacket->dwControl)
@ -623,6 +617,10 @@ ScServiceDispatcher(HANDLE hPipe,
break; break;
} }
} }
else
{
dwError = ERROR_SERVICE_NOT_IN_EXE;
}
} }
ReplyPacket.dwError = dwError; ReplyPacket.dwError = dwError;
@ -685,16 +683,15 @@ SERVICE_STATUS_HANDLE WINAPI
RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName, RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
LPHANDLER_FUNCTION lpHandlerProc) LPHANDLER_FUNCTION lpHandlerProc)
{ {
DWORD dwError;
PACTIVE_SERVICE Service; PACTIVE_SERVICE Service;
TRACE("RegisterServiceCtrlHandlerW(%s %p %p)\n", TRACE("RegisterServiceCtrlHandlerW(%s %p %p)\n",
debugstr_w(lpServiceName), lpHandlerProc); debugstr_w(lpServiceName), lpHandlerProc);
dwError = ScLookupServiceByServiceName(lpServiceName, &Service); Service = ScLookupServiceByServiceName(lpServiceName);
if ((dwError != ERROR_SUCCESS) || (Service == NULL)) if (Service == NULL)
{ {
SetLastError(dwError); SetLastError(ERROR_SERVICE_NOT_IN_EXE);
return NULL; return NULL;
} }
@ -704,7 +701,7 @@ RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
return NULL; return NULL;
} }
Service->HandlerFunction = lpHandlerProc; Service->HandlerFunction = lpHandlerProc;
Service->HandlerFunctionEx = NULL; Service->HandlerFunctionEx = NULL;
TRACE("RegisterServiceCtrlHandler returning %p\n", Service->hServiceStatus); TRACE("RegisterServiceCtrlHandler returning %p\n", Service->hServiceStatus);
@ -757,16 +754,15 @@ RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
LPHANDLER_FUNCTION_EX lpHandlerProc, LPHANDLER_FUNCTION_EX lpHandlerProc,
LPVOID lpContext) LPVOID lpContext)
{ {
DWORD dwError;
PACTIVE_SERVICE Service; PACTIVE_SERVICE Service;
TRACE("RegisterServiceCtrlHandlerExW(%s %p %p)\n", TRACE("RegisterServiceCtrlHandlerExW(%s %p %p)\n",
debugstr_w(lpServiceName), lpHandlerProc, lpContext); debugstr_w(lpServiceName), lpHandlerProc, lpContext);
dwError = ScLookupServiceByServiceName(lpServiceName, &Service); Service = ScLookupServiceByServiceName(lpServiceName);
if ((dwError != ERROR_SUCCESS) || (Service == NULL)) if (Service == NULL)
{ {
SetLastError(dwError); SetLastError(ERROR_SERVICE_NOT_IN_EXE);
return NULL; return NULL;
} }
@ -776,11 +772,11 @@ RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
return NULL; return NULL;
} }
Service->HandlerFunction = NULL; Service->HandlerFunction = NULL;
Service->HandlerFunctionEx = lpHandlerProc; Service->HandlerFunctionEx = lpHandlerProc;
Service->HandlerContext = lpContext; Service->HandlerContext = lpContext;
TRACE("RegisterServiceCtrlHandlerEx returning 0x%p\n", Service->hServiceStatus); TRACE("RegisterServiceCtrlHandlerEx returning %p\n", Service->hServiceStatus);
return Service->hServiceStatus; return Service->hServiceStatus;
} }
@ -996,7 +992,7 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
dwActiveServiceCount = i; dwActiveServiceCount = i;
/* Initialize the service table */ /* Allocate the service table */
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(), lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
dwActiveServiceCount * sizeof(ACTIVE_SERVICE)); dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
@ -1017,13 +1013,12 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
lpActiveServices[i].bOwnProcess = FALSE; lpActiveServices[i].bOwnProcess = FALSE;
} }
/* Initialize the connection to the SCM */ /* Connect to the SCM */
dwError = ScConnectControlPipe(&hPipe); dwError = ScConnectControlPipe(&hPipe);
if (dwError != ERROR_SUCCESS) if (dwError != ERROR_SUCCESS)
{ {
bRet = FALSE; bRet = FALSE;
goto Done; goto done;
} }
dwBufSize = sizeof(SCM_CONTROL_PACKET) + dwBufSize = sizeof(SCM_CONTROL_PACKET) +
@ -1036,22 +1031,24 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable)
{ {
dwError = ERROR_NOT_ENOUGH_MEMORY; dwError = ERROR_NOT_ENOUGH_MEMORY;
bRet = FALSE; bRet = FALSE;
goto Done; goto done;
} }
ScCreateStatusBinding(); ScCreateStatusBinding();
/* Start the dispatcher loop */ /* Call the dispatcher loop */
ScServiceDispatcher(hPipe, ControlPacket, dwBufSize); ScServiceDispatcher(hPipe, ControlPacket, dwBufSize);
/* Close the connection */
ScDestroyStatusBinding(); ScDestroyStatusBinding();
/* Close the connection */
CloseHandle(hPipe); CloseHandle(hPipe);
/* Free the control packet */ /* Free the control packet */
RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket); RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket);
Done: done:
/* Free the service table */ /* Free the service table */
for (i = 0; i < dwActiveServiceCount; i++) for (i = 0; i < dwActiveServiceCount; i++)
{ {
@ -1061,7 +1058,8 @@ Done:
lpActiveServices = NULL; lpActiveServices = NULL;
dwActiveServiceCount = 0; dwActiveServiceCount = 0;
if (!bRet) SetLastError(dwError); if (!bRet)
SetLastError(dwError);
return bRet; return bRet;
} }
@ -1093,7 +1091,7 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
dwActiveServiceCount = i; dwActiveServiceCount = i;
/* Initialize the service table */ /* Allocate the service table */
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(), lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
dwActiveServiceCount * sizeof(ACTIVE_SERVICE)); dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
@ -1114,13 +1112,12 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
lpActiveServices[i].bOwnProcess = FALSE; lpActiveServices[i].bOwnProcess = FALSE;
} }
/* Initialize the connection to the SCM */ /* Connect to the SCM */
dwError = ScConnectControlPipe(&hPipe); dwError = ScConnectControlPipe(&hPipe);
if (dwError != ERROR_SUCCESS) if (dwError != ERROR_SUCCESS)
{ {
bRet = FALSE; bRet = FALSE;
goto Done; goto done;
} }
dwBufSize = sizeof(SCM_CONTROL_PACKET) + dwBufSize = sizeof(SCM_CONTROL_PACKET) +
@ -1133,22 +1130,23 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
{ {
dwError = ERROR_NOT_ENOUGH_MEMORY; dwError = ERROR_NOT_ENOUGH_MEMORY;
bRet = FALSE; bRet = FALSE;
goto Done; goto done;
} }
ScCreateStatusBinding(); ScCreateStatusBinding();
/* Start the dispatcher loop */ /* Call the dispatcher loop */
ScServiceDispatcher(hPipe, ControlPacket, dwBufSize); ScServiceDispatcher(hPipe, ControlPacket, dwBufSize);
/* Close the connection */
ScDestroyStatusBinding(); ScDestroyStatusBinding();
/* Close the connection */
CloseHandle(hPipe); CloseHandle(hPipe);
/* Free the control packet */ /* Free the control packet */
RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket); RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket);
Done: done:
/* Free the service table */ /* Free the service table */
for (i = 0; i < dwActiveServiceCount; i++) for (i = 0; i < dwActiveServiceCount; i++)
{ {
@ -1158,7 +1156,8 @@ Done:
lpActiveServices = NULL; lpActiveServices = NULL;
dwActiveServiceCount = 0; dwActiveServiceCount = 0;
if (!bRet) SetLastError(dwError); if (!bRet)
SetLastError(dwError);
return bRet; return bRet;
} }