[ADVAPI32]
authorEric Kohl <eric.kohl@reactos.org>
Tue, 16 Mar 2010 23:10:03 +0000 (23:10 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Tue, 16 Mar 2010 23:10:03 +0000 (23:10 +0000)
- Create a service status handle when a service starts and destroy it after it has been stopped.

svn path=/trunk/; revision=46233

reactos/dll/win32/advapi32/service/scm.c
reactos/dll/win32/advapi32/service/sctrl.c

index e10e7f1..c3a05da 100644 (file)
@@ -131,61 +131,6 @@ SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName,
 }
 
 
-handle_t __RPC_USER
-RPC_SERVICE_STATUS_HANDLE_bind(RPC_SERVICE_STATUS_HANDLE hServiceStatus)
-{
-    handle_t hBinding = NULL;
-    LPWSTR pszStringBinding;
-    RPC_STATUS status;
-
-    TRACE("RPC_SERVICE_STATUS_HANDLE_bind() called\n");
-
-    status = RpcStringBindingComposeW(NULL,
-                                      L"ncacn_np",
-                                      NULL,
-                                      L"\\pipe\\ntsvcs",
-                                      NULL,
-                                      &pszStringBinding);
-    if (status != RPC_S_OK)
-    {
-        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,
-                                          &hBinding);
-    if (status != RPC_S_OK)
-    {
-        ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
-    }
-
-    status = RpcStringFreeW(&pszStringBinding);
-    if (status != RPC_S_OK)
-    {
-        ERR("RpcStringFree returned 0x%x\n", status);
-    }
-
-    return hBinding;
-}
-
-
-void __RPC_USER
-RPC_SERVICE_STATUS_HANDLE_unbind(RPC_SERVICE_STATUS_HANDLE hServiceStatus,
-                                 handle_t hBinding)
-{
-    RPC_STATUS status;
-
-    TRACE("RPC_SERVICE_STATUS_HANDLE_unbind() called\n");
-
-    status = RpcBindingFree(&hBinding);
-    if (status != RPC_S_OK)
-    {
-        ERR("RpcBindingFree returned 0x%x\n", status);
-    }
-}
-
-
 DWORD
 ScmRpcStatusToWinError(RPC_STATUS Status)
 {
index ca6f164..90810bc 100644 (file)
@@ -41,10 +41,87 @@ typedef struct _ACTIVE_SERVICE
 
 static DWORD dwActiveServiceCount = 0;
 static PACTIVE_SERVICE lpActiveServices = NULL;
+static handle_t hStatusBinding = NULL;
 
 
 /* FUNCTIONS *****************************************************************/
 
+handle_t __RPC_USER
+RPC_SERVICE_STATUS_HANDLE_bind(RPC_SERVICE_STATUS_HANDLE hServiceStatus)
+{
+    return hStatusBinding;
+}
+
+
+void __RPC_USER
+RPC_SERVICE_STATUS_HANDLE_unbind(RPC_SERVICE_STATUS_HANDLE hServiceStatus,
+                                 handle_t hBinding)
+{
+}
+
+
+static RPC_STATUS
+ScCreateStatusBinding(VOID)
+{
+    LPWSTR pszStringBinding;
+    RPC_STATUS status;
+
+    TRACE("ScCreateStatusBinding() called\n");
+
+    status = RpcStringBindingComposeW(NULL,
+                                      L"ncacn_np",
+                                      NULL,
+                                      L"\\pipe\\ntsvcs",
+                                      NULL,
+                                      &pszStringBinding);
+    if (status != RPC_S_OK)
+    {
+        ERR("RpcStringBindingCompose returned 0x%x\n", status);
+        return status;
+    }
+
+    /* Set the binding handle that will be used to bind to the server. */
+    status = RpcBindingFromStringBindingW(pszStringBinding,
+                                          &hStatusBinding);
+    if (status != RPC_S_OK)
+    {
+        ERR("RpcBindingFromStringBinding returned 0x%x\n", status);
+    }
+
+    status = RpcStringFreeW(&pszStringBinding);
+    if (status != RPC_S_OK)
+    {
+        ERR("RpcStringFree returned 0x%x\n", status);
+    }
+
+    return status;
+}
+
+
+static RPC_STATUS
+ScDestroyStatusBinding(VOID)
+{
+    RPC_STATUS status;
+
+    TRACE("ScDestroyStatusBinding() called\n");
+
+    if (hStatusBinding == NULL)
+        return RPC_S_OK;
+
+    status = RpcBindingFree(&hStatusBinding);
+    if (status != RPC_S_OK)
+    {
+        ERR("RpcBindingFree returned 0x%x\n", status);
+    }
+    else
+    {
+        hStatusBinding = NULL;
+    }
+
+    return status;
+}
+
+
 static PACTIVE_SERVICE
 ScLookupServiceByServiceName(LPCWSTR lpServiceName)
 {
@@ -259,7 +336,6 @@ ScConnectControlPipe(HANDLE *hPipe)
 
     TRACE("Sent Process ID %lu\n", dwProcessId);
 
-
     return ERROR_SUCCESS;
 }
 
@@ -403,7 +479,7 @@ ScServiceDispatcher(HANDLE hPipe,
         }
         else
         {
-            dwError = ERROR_NOT_FOUND;
+            dwError = ERROR_SERVICE_DOES_NOT_EXIST;
         }
 
         ReplyPacket.dwError = dwError;
@@ -747,7 +823,12 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA * lpServiceStartTable)
         return FALSE;
     }
 
+    ScCreateStatusBinding();
+
     ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
+
+    ScDestroyStatusBinding();
+
     CloseHandle(hPipe);
 
     /* Free the message buffer */
@@ -837,7 +918,12 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW * lpServiceStartTable)
         return FALSE;
     }
 
+    ScCreateStatusBinding();
+
     ScServiceDispatcher(hPipe, lpMessageBuffer, 256);
+
+    ScDestroyStatusBinding();
+
     CloseHandle(hPipe);
 
     /* Free the message buffer */