https://git.reactos.org/?p=reactos.git;a=commitdiff;h=94435b53d713e1df11751…
commit 94435b53d713e1df11751c1d8e83fde3adf82a76
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Mar 25 12:03:07 2018 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Mar 25 12:03:07 2018 +0200
[ADVAPI32] Revert unnecessary changes, clarify comments and clean-up inconsistencies
---
dll/win32/advapi32/service/eventlog.c | 73 +++++++++++++++--------------
dll/win32/advapi32/service/scm.c | 66 +++++++++++++-------------
dll/win32/advapi32/service/sctrl.c | 87 +++++++++++++++++------------------
3 files changed, 116 insertions(+), 110 deletions(-)
diff --git a/dll/win32/advapi32/service/eventlog.c
b/dll/win32/advapi32/service/eventlog.c
index d3afa467ce..9a4617a5ab 100644
--- a/dll/win32/advapi32/service/eventlog.c
+++ b/dll/win32/advapi32/service/eventlog.c
@@ -41,34 +41,34 @@ EVENTLOG_HANDLE_A_bind(EVENTLOG_HANDLE_A UNCServerName)
{
handle_t hBinding = NULL;
RPC_CSTR pszStringBinding;
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_A_bind() called\n");
- Status = RpcStringBindingComposeA(NULL,
+ status = RpcStringBindingComposeA(NULL,
(RPC_CSTR)"ncacn_np",
(RPC_CSTR)UNCServerName,
(RPC_CSTR)"\\pipe\\EventLog",
NULL,
&pszStringBinding);
- if (Status)
+ if (status)
{
- ERR("RpcStringBindingCompose returned 0x%x\n", Status);
+ ERR("RpcStringBindingCompose returned 0x%x\n", status);
return NULL;
}
/* Set the binding handle that will be used to bind to the server. */
- Status = RpcBindingFromStringBindingA(pszStringBinding,
+ status = RpcBindingFromStringBindingA(pszStringBinding,
&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);
- if (Status != RPC_S_OK)
+ status = RpcStringFreeA(&pszStringBinding);
+ if (status != RPC_S_OK)
{
- ERR("RpcStringFree returned 0x%x\n", Status);
+ ERR("RpcStringFree returned 0x%x\n", status);
}
return hBinding;
@@ -79,14 +79,14 @@ void __RPC_USER
EVENTLOG_HANDLE_A_unbind(EVENTLOG_HANDLE_A UNCServerName,
handle_t hBinding)
{
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_A_unbind() called\n");
- Status = RpcBindingFree(&hBinding);
- if (Status != RPC_S_OK)
+ status = RpcBindingFree(&hBinding);
+ 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;
RPC_WSTR pszStringBinding;
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_W_bind() called\n");
- Status = RpcStringBindingComposeW(NULL,
+ status = RpcStringBindingComposeW(NULL,
L"ncacn_np",
UNCServerName,
L"\\pipe\\EventLog",
NULL,
&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;
}
/* Set the binding handle that will be used to bind to the server. */
- Status = RpcBindingFromStringBindingW(pszStringBinding,
+ status = RpcBindingFromStringBindingW(pszStringBinding,
&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);
- if (Status != RPC_S_OK)
+ status = RpcStringFreeW(&pszStringBinding);
+ if (status != RPC_S_OK)
{
- ERR("RpcStringFree returned 0x%x\n", Status);
+ ERR("RpcStringFree returned 0x%x\n", status);
}
return hBinding;
@@ -134,14 +134,14 @@ void __RPC_USER
EVENTLOG_HANDLE_W_unbind(EVENTLOG_HANDLE_W UNCServerName,
handle_t hBinding)
{
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("EVENTLOG_HANDLE_W_unbind() called\n");
- Status = RpcBindingFree(&hBinding);
- if (Status != RPC_S_OK)
+ status = RpcBindingFree(&hBinding);
+ 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,
(PRPC_UNICODE_STRING)BackupFileNameU,
- 1, 1,
+ 1,
+ 1,
(IELF_HANDLE*)phEventLog);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@@ -851,7 +852,7 @@ OpenBackupEventLogW(IN LPCWSTR lpUNCServerName,
RtlInitUnicodeString(&UNCServerName, lpUNCServerName);
Status = ElfOpenBackupEventLogW(&UNCServerName, &FileName, &hEventLog);
-
+
if (FileName.Buffer != NULL)
RtlFreeHeap(RtlGetProcessHeap(), 0, FileName.Buffer);
@@ -901,7 +902,8 @@ ElfOpenEventLogA(IN PANSI_STRING UNCServerNameA,
Status = ElfrOpenELA(pUNCServerName,
(PRPC_STRING)SourceNameA,
&EmptyStringA,
- 1, 1,
+ 1,
+ 1,
(IELF_HANDLE*)phEventLog);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@@ -966,7 +968,8 @@ ElfOpenEventLogW(IN PUNICODE_STRING UNCServerNameU,
Status = ElfrOpenELW(pUNCServerName,
(PRPC_UNICODE_STRING)SourceNameU,
&EmptyStringU,
- 1, 1,
+ 1,
+ 1,
(IELF_HANDLE*)phEventLog);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@@ -1204,7 +1207,8 @@ ElfRegisterEventSourceA(IN PANSI_STRING UNCServerNameA,
Status = ElfrRegisterEventSourceA(pUNCServerName,
(PRPC_STRING)SourceNameA,
&EmptyStringA,
- 1, 1,
+ 1,
+ 1,
(IELF_HANDLE*)phEventLog);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
@@ -1274,7 +1278,8 @@ ElfRegisterEventSourceW(IN PUNICODE_STRING UNCServerNameU,
Status = ElfrRegisterEventSourceW(pUNCServerName,
(PRPC_UNICODE_STRING)SourceNameU,
&EmptyStringU,
- 1, 1,
+ 1,
+ 1,
(IELF_HANDLE*)phEventLog);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
diff --git a/dll/win32/advapi32/service/scm.c b/dll/win32/advapi32/service/scm.c
index 7fa0b8880b..92661c9581 100644
--- a/dll/win32/advapi32/service/scm.c
+++ b/dll/win32/advapi32/service/scm.c
@@ -10,7 +10,7 @@
/* INCLUDES ******************************************************************/
#include <advapi32.h>
-WINE_DEFAULT_DEBUG_CHANNEL(advapi_service);
+WINE_DEFAULT_DEBUG_CHANNEL(advapi);
/* FUNCTIONS *****************************************************************/
@@ -20,35 +20,35 @@ SVCCTL_HANDLEA_bind(SVCCTL_HANDLEA szMachineName)
{
handle_t hBinding = NULL;
RPC_CSTR pszStringBinding;
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("SVCCTL_HANDLEA_bind(%s)\n",
debugstr_a(szMachineName));
- Status = RpcStringBindingComposeA(NULL,
+ status = RpcStringBindingComposeA(NULL,
(RPC_CSTR)"ncacn_np",
(RPC_CSTR)szMachineName,
(RPC_CSTR)"\\pipe\\ntsvcs",
NULL,
&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;
}
/* Set the binding handle that will be used to bind to the server. */
- Status = RpcBindingFromStringBindingA(pszStringBinding,
+ status = RpcBindingFromStringBindingA(pszStringBinding,
&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);
- if (Status != RPC_S_OK)
+ status = RpcStringFreeA(&pszStringBinding);
+ if (status != RPC_S_OK)
{
- ERR("RpcStringFree returned 0x%x\n", Status);
+ ERR("RpcStringFree returned 0x%x\n", status);
}
return hBinding;
@@ -59,15 +59,15 @@ void __RPC_USER
SVCCTL_HANDLEA_unbind(SVCCTL_HANDLEA szMachineName,
handle_t hBinding)
{
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("SVCCTL_HANDLEA_unbind(%s %p)\n",
debugstr_a(szMachineName), hBinding);
- Status = RpcBindingFree(&hBinding);
- if (Status != RPC_S_OK)
+ status = RpcBindingFree(&hBinding);
+ 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;
RPC_WSTR pszStringBinding;
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("SVCCTL_HANDLEW_bind(%s)\n",
debugstr_w(szMachineName));
- Status = RpcStringBindingComposeW(NULL,
+ status = RpcStringBindingComposeW(NULL,
L"ncacn_np",
szMachineName,
L"\\pipe\\ntsvcs",
NULL,
&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;
}
/* Set the binding handle that will be used to bind to the server. */
- Status = RpcBindingFromStringBindingW(pszStringBinding,
+ status = RpcBindingFromStringBindingW(pszStringBinding,
&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);
- if (Status != RPC_S_OK)
+ status = RpcStringFreeW(&pszStringBinding);
+ if (status != RPC_S_OK)
{
- ERR("RpcStringFree returned 0x%x\n", Status);
+ ERR("RpcStringFree returned 0x%x\n", status);
}
return hBinding;
@@ -116,20 +116,19 @@ void __RPC_USER
SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName,
handle_t hBinding)
{
- RPC_STATUS Status;
+ RPC_STATUS status;
TRACE("SVCCTL_HANDLEW_unbind(%s %p)\n",
debugstr_w(szMachineName), hBinding);
- Status = RpcBindingFree(&hBinding);
- if (Status != RPC_S_OK)
+ status = RpcBindingFree(&hBinding);
+ 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
ScmRpcStatusToWinError(RPC_STATUS Status)
{
@@ -1638,6 +1637,7 @@ GetServiceKeyNameA(SC_HANDLE hSCManager,
}
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());
}
RpcEndExcept;
@@ -1797,11 +1797,13 @@ WaitForSCManager(VOID)
hEvent = OpenEventW(SYNCHRONIZE, FALSE, SCM_START_EVENT);
if (hEvent == NULL)
{
- if (GetLastError() != ERROR_FILE_NOT_FOUND) return;
+ if (GetLastError() != ERROR_FILE_NOT_FOUND)
+ return;
/* Try to create a new event */
hEvent = CreateEventW(NULL, TRUE, FALSE, SCM_START_EVENT);
- if (hEvent == NULL) return;
+ if (hEvent == NULL)
+ return;
}
/* Wait for 3 minutes */
diff --git a/dll/win32/advapi32/service/sctrl.c b/dll/win32/advapi32/service/sctrl.c
index c21540227d..40970f0811 100644
--- a/dll/win32/advapi32/service/sctrl.c
+++ b/dll/win32/advapi32/service/sctrl.c
@@ -12,7 +12,7 @@
/* INCLUDES ******************************************************************/
#include <advapi32.h>
-WINE_DEFAULT_DEBUG_CHANNEL(advapi_service);
+WINE_DEFAULT_DEBUG_CHANNEL(advapi);
/* TYPES *********************************************************************/
@@ -135,9 +135,8 @@ ScDestroyStatusBinding(VOID)
}
-static DWORD
-ScLookupServiceByServiceName(IN LPCWSTR lpServiceName,
- OUT PACTIVE_SERVICE* pService)
+static PACTIVE_SERVICE
+ScLookupServiceByServiceName(LPCWSTR lpServiceName)
{
DWORD i;
@@ -145,10 +144,7 @@ ScLookupServiceByServiceName(IN LPCWSTR lpServiceName,
lpServiceName);
if (lpActiveServices[0].bOwnProcess)
- {
- *pService = &lpActiveServices[0];
- return ERROR_SUCCESS;
- }
+ return &lpActiveServices[0];
for (i = 0; i < dwActiveServiceCount; i++)
{
@@ -156,14 +152,12 @@ ScLookupServiceByServiceName(IN LPCWSTR lpServiceName,
if (_wcsicmp(lpActiveServices[i].ServiceName.Buffer, lpServiceName) == 0)
{
TRACE("Found!\n");
- *pService = &lpActiveServices[i];
- return ERROR_SUCCESS;
+ return &lpActiveServices[i];
}
}
TRACE("No service found!\n");
- *pService = NULL;
- return ERROR_SERVICE_NOT_IN_EXE;
+ return NULL;
}
@@ -600,8 +594,8 @@ ScServiceDispatcher(HANDLE hPipe,
if (ControlPacket->dwControl == SERVICE_CONTROL_START_OWN)
lpActiveServices[0].bOwnProcess = TRUE;
- dwError = ScLookupServiceByServiceName(lpServiceName, &lpService);
- if ((dwError == ERROR_SUCCESS) && (lpService != NULL))
+ lpService = ScLookupServiceByServiceName(lpServiceName);
+ if (lpService != NULL)
{
/* Execute command */
switch (ControlPacket->dwControl)
@@ -623,6 +617,10 @@ ScServiceDispatcher(HANDLE hPipe,
break;
}
}
+ else
+ {
+ dwError = ERROR_SERVICE_NOT_IN_EXE;
+ }
}
ReplyPacket.dwError = dwError;
@@ -685,16 +683,15 @@ SERVICE_STATUS_HANDLE WINAPI
RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
LPHANDLER_FUNCTION lpHandlerProc)
{
- DWORD dwError;
PACTIVE_SERVICE Service;
TRACE("RegisterServiceCtrlHandlerW(%s %p %p)\n",
debugstr_w(lpServiceName), lpHandlerProc);
- dwError = ScLookupServiceByServiceName(lpServiceName, &Service);
- if ((dwError != ERROR_SUCCESS) || (Service == NULL))
+ Service = ScLookupServiceByServiceName(lpServiceName);
+ if (Service == NULL)
{
- SetLastError(dwError);
+ SetLastError(ERROR_SERVICE_NOT_IN_EXE);
return NULL;
}
@@ -704,7 +701,7 @@ RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName,
return NULL;
}
- Service->HandlerFunction = lpHandlerProc;
+ Service->HandlerFunction = lpHandlerProc;
Service->HandlerFunctionEx = NULL;
TRACE("RegisterServiceCtrlHandler returning %p\n",
Service->hServiceStatus);
@@ -757,16 +754,15 @@ RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
LPHANDLER_FUNCTION_EX lpHandlerProc,
LPVOID lpContext)
{
- DWORD dwError;
PACTIVE_SERVICE Service;
TRACE("RegisterServiceCtrlHandlerExW(%s %p %p)\n",
debugstr_w(lpServiceName), lpHandlerProc, lpContext);
- dwError = ScLookupServiceByServiceName(lpServiceName, &Service);
- if ((dwError != ERROR_SUCCESS) || (Service == NULL))
+ Service = ScLookupServiceByServiceName(lpServiceName);
+ if (Service == NULL)
{
- SetLastError(dwError);
+ SetLastError(ERROR_SERVICE_NOT_IN_EXE);
return NULL;
}
@@ -776,11 +772,11 @@ RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName,
return NULL;
}
- Service->HandlerFunction = NULL;
+ Service->HandlerFunction = NULL;
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;
}
@@ -996,7 +992,7 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA
*lpServiceStartTable)
dwActiveServiceCount = i;
- /* Initialize the service table */
+ /* Allocate the service table */
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
@@ -1017,13 +1013,12 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA
*lpServiceStartTable)
lpActiveServices[i].bOwnProcess = FALSE;
}
- /* Initialize the connection to the SCM */
-
+ /* Connect to the SCM */
dwError = ScConnectControlPipe(&hPipe);
if (dwError != ERROR_SUCCESS)
{
bRet = FALSE;
- goto Done;
+ goto done;
}
dwBufSize = sizeof(SCM_CONTROL_PACKET) +
@@ -1036,22 +1031,24 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA
*lpServiceStartTable)
{
dwError = ERROR_NOT_ENOUGH_MEMORY;
bRet = FALSE;
- goto Done;
+ goto done;
}
ScCreateStatusBinding();
- /* Start the dispatcher loop */
+ /* Call the dispatcher loop */
ScServiceDispatcher(hPipe, ControlPacket, dwBufSize);
- /* Close the connection */
+
ScDestroyStatusBinding();
+
+ /* Close the connection */
CloseHandle(hPipe);
/* Free the control packet */
RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket);
-Done:
+done:
/* Free the service table */
for (i = 0; i < dwActiveServiceCount; i++)
{
@@ -1061,7 +1058,8 @@ Done:
lpActiveServices = NULL;
dwActiveServiceCount = 0;
- if (!bRet) SetLastError(dwError);
+ if (!bRet)
+ SetLastError(dwError);
return bRet;
}
@@ -1093,7 +1091,7 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW
*lpServiceStartTable)
dwActiveServiceCount = i;
- /* Initialize the service table */
+ /* Allocate the service table */
lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
dwActiveServiceCount * sizeof(ACTIVE_SERVICE));
@@ -1114,13 +1112,12 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW
*lpServiceStartTable)
lpActiveServices[i].bOwnProcess = FALSE;
}
- /* Initialize the connection to the SCM */
-
+ /* Connect to the SCM */
dwError = ScConnectControlPipe(&hPipe);
if (dwError != ERROR_SUCCESS)
{
bRet = FALSE;
- goto Done;
+ goto done;
}
dwBufSize = sizeof(SCM_CONTROL_PACKET) +
@@ -1133,22 +1130,23 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW
*lpServiceStartTable)
{
dwError = ERROR_NOT_ENOUGH_MEMORY;
bRet = FALSE;
- goto Done;
+ goto done;
}
ScCreateStatusBinding();
- /* Start the dispatcher loop */
+ /* Call the dispatcher loop */
ScServiceDispatcher(hPipe, ControlPacket, dwBufSize);
- /* Close the connection */
ScDestroyStatusBinding();
+
+ /* Close the connection */
CloseHandle(hPipe);
/* Free the control packet */
RtlFreeHeap(RtlGetProcessHeap(), 0, ControlPacket);
-Done:
+done:
/* Free the service table */
for (i = 0; i < dwActiveServiceCount; i++)
{
@@ -1158,7 +1156,8 @@ Done:
lpActiveServices = NULL;
dwActiveServiceCount = 0;
- if (!bRet) SetLastError(dwError);
+ if (!bRet)
+ SetLastError(dwError);
return bRet;
}