[SERVICES]
[reactos.git] / reactos / base / system / services / services.c
index 8572010..1245fd3 100644 (file)
@@ -8,10 +8,6 @@
  *
  */
 
-/* NOTE:
- * - Services.exe is NOT a native application, it is a GUI app.
- */
-
 /* INCLUDES *****************************************************************/
 
 #include "services.h"
@@ -327,28 +323,6 @@ StartScmNamedPipeThreadListener(VOID)
 }
 
 
-VOID FASTCALL
-AcquireLoadDriverPrivilege(VOID)
-{
-    HANDLE hToken;
-    TOKEN_PRIVILEGES tkp;
-
-    /* Get a token for this process */
-    if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
-    {
-        /* Get the LUID for the debug privilege */
-        LookupPrivilegeValue(NULL, SE_LOAD_DRIVER_NAME, &tkp.Privileges[0].Luid);
-
-        /* One privilege to set */
-        tkp.PrivilegeCount = 1;
-        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
-
-        /* Get the debug privilege for this process */
-        AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
-    }
-}
-
-
 BOOL WINAPI
 ShutdownHandlerRoutine(DWORD dwCtrlType)
 {
@@ -378,6 +352,7 @@ wWinMain(HINSTANCE hInstance,
 {
     HANDLE hScmStartEvent = NULL;
     SC_RPC_LOCK Lock = NULL;
+    BOOL bCanDeleteNamedPipeCriticalSection = FALSE;
     DWORD dwError;
 
     DPRINT("SERVICES: Service Control Manager\n");
@@ -399,6 +374,10 @@ wWinMain(HINSTANCE hInstance,
         goto done;
     }
 
+    /* Initialize our communication named pipe's critical section */
+    ScmInitNamedPipeCriticalSection();
+    bCanDeleteNamedPipeCriticalSection = TRUE;
+
 //    ScmInitThreadManager();
 
     /* FIXME: more initialization */
@@ -410,7 +389,7 @@ wWinMain(HINSTANCE hInstance,
         goto done;
     }
 
-    /* Create the service database */
+    /* Create the services database */
     dwError = ScmCreateServiceDatabase();
     if (dwError != ERROR_SUCCESS)
     {
@@ -418,15 +397,27 @@ wWinMain(HINSTANCE hInstance,
         goto done;
     }
 
-    /* Update service database */
+    /* Update the services database */
     ScmGetBootAndSystemDriverState();
 
+    /* Register the Service Control Manager process with CSRSS */
+    if (!RegisterServicesProcess(GetCurrentProcessId()))
+    {
+        DPRINT1("SERVICES: Could not register SCM process\n");
+        goto done;
+    }
+
+    /* Acquire the service start lock until autostart services have been started */
+    dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("SERVICES: failed to acquire the service start lock (Error %lu)\n", dwError);
+        goto done;
+    }
+
     /* Start the RPC server */
     ScmStartRpcServer();
 
-    /* Register service process with CSRSS */
-    RegisterServicesProcess(GetCurrentProcessId());
-
     DPRINT("SERVICES: Initialized.\n");
 
     /* Signal start event */
@@ -438,19 +429,6 @@ wWinMain(HINSTANCE hInstance,
     /* Wait for the LSA server */
     ScmWaitForLsa();
 
-    /* Acquire privileges to load drivers */
-    AcquireLoadDriverPrivilege();
-
-    ScmInitNamedPipeCriticalSection();
-
-    /* Acquire the service start lock until autostart services have been started */
-    dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
-    if (dwError != ERROR_SUCCESS)
-    {
-        DPRINT1("SERVICES: failed to acquire the service start lock (Error %lu)\n", dwError);
-        goto done;
-    }
-
     /* Start auto-start services */
     ScmAutoStartServices();
 
@@ -465,7 +443,9 @@ wWinMain(HINSTANCE hInstance,
     WaitForSingleObject(hScmShutdownEvent, INFINITE);
 
 done:
-    ScmDeleteNamedPipeCriticalSection();
+    /* Delete our communication named pipe's critical section */
+    if (bCanDeleteNamedPipeCriticalSection == TRUE)
+        ScmDeleteNamedPipeCriticalSection();
 
     /* Close the shutdown event */
     if (hScmShutdownEvent != NULL)