*
*/
-/* NOTE:
- * - Services.exe is NOT a native application, it is a GUI app.
- */
-
/* INCLUDES *****************************************************************/
#include "services.h"
}
-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)
{
{
HANDLE hScmStartEvent = NULL;
SC_RPC_LOCK Lock = NULL;
+ BOOL bCanDeleteNamedPipeCriticalSection = FALSE;
DWORD dwError;
DPRINT("SERVICES: Service Control Manager\n");
goto done;
}
+ /* Initialize our communication named pipe's critical section */
+ ScmInitNamedPipeCriticalSection();
+ bCanDeleteNamedPipeCriticalSection = TRUE;
+
// ScmInitThreadManager();
/* FIXME: more initialization */
goto done;
}
- /* Create the service database */
+ /* Create the services database */
dwError = ScmCreateServiceDatabase();
if (dwError != ERROR_SUCCESS)
{
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 */
/* 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();
WaitForSingleObject(hScmShutdownEvent, INFINITE);
done:
- ScmDeleteNamedPipeCriticalSection();
+ /* Delete our communication named pipe's critical section */
+ if (bCanDeleteNamedPipeCriticalSection == TRUE)
+ ScmDeleteNamedPipeCriticalSection();
/* Close the shutdown event */
if (hScmShutdownEvent != NULL)