https://git.reactos.org/?p=reactos.git;a=commitdiff;h=07d48d88086b396cc33db540a713e11c289f4196

commit 07d48d88086b396cc33db540a713e11c289f4196
Author:     Eric Kohl <[email protected]>
AuthorDate: Wed Jan 8 00:14:50 2020 +0100
Commit:     Eric Kohl <[email protected]>
CommitDate: Wed Jan 8 00:15:52 2020 +0100

    [SERVICES] Use the local system account to run all services on a LiveCD
    
    This fixes CORE-16589.
---
 base/system/services/database.c |  2 +-
 base/system/services/services.c | 72 +++++++++++++++++++++++++++++++++++++++++
 base/system/services/services.h |  1 +
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/base/system/services/database.c b/base/system/services/database.c
index fc3d673c347..6b710926205 100644
--- a/base/system/services/database.c
+++ b/base/system/services/database.c
@@ -370,7 +370,7 @@ ScmLogonService(
     DPRINT("ScmLogonService(%p %p)\n", pService, pImage);
     DPRINT("Service %S\n", pService->lpServiceName);
 
-    if (ScmIsLocalSystemAccount(pImage->pszAccountName))
+    if (ScmIsLocalSystemAccount(pImage->pszAccountName) || ScmLiveSetup)
         return ERROR_SUCCESS;
 
     /* Get the user and domain names */
diff --git a/base/system/services/services.c b/base/system/services/services.c
index 81725260253..7721eb95042 100644
--- a/base/system/services/services.c
+++ b/base/system/services/services.c
@@ -27,6 +27,7 @@ int WINAPI RegisterServicesProcess(DWORD ServicesProcessId);
 
 BOOL ScmInitialize = FALSE;
 BOOL ScmShutdown = FALSE;
+BOOL ScmLiveSetup = FALSE;
 static HANDLE hScmShutdownEvent = NULL;
 static HANDLE hScmSecurityServicesEvent = NULL;
 
@@ -48,6 +49,70 @@ PrintString(LPCSTR fmt, ...)
 #endif
 }
 
+DWORD
+CheckForLiveCD(VOID)
+{
+    WCHAR CommandLine[MAX_PATH];
+    HKEY hSetupKey;
+    DWORD dwSetupType;
+    DWORD dwType;
+    DWORD dwSize;
+    DWORD dwError;
+
+    DPRINT1("CheckSetup()\n");
+
+    /* Open the Setup key */
+    dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                            L"SYSTEM\\Setup",
+                            0,
+                            KEY_QUERY_VALUE,
+                            &hSetupKey);
+    if (dwError != ERROR_SUCCESS)
+        return dwError;
+
+    /* Read the SetupType value */
+    dwSize = sizeof(DWORD);
+    dwError = RegQueryValueExW(hSetupKey,
+                               L"SetupType",
+                               NULL,
+                               &dwType,
+                               (LPBYTE)&dwSetupType,
+                               &dwSize);
+
+    if (dwError != ERROR_SUCCESS ||
+        dwType != REG_DWORD ||
+        dwSize != sizeof(DWORD) ||
+        dwSetupType == 0)
+        goto done;
+
+    /* Read the CmdLine value */
+    dwSize = sizeof(CommandLine);
+    dwError = RegQueryValueExW(hSetupKey,
+                               L"CmdLine",
+                               NULL,
+                               &dwType,
+                               (LPBYTE)CommandLine,
+                               &dwSize);
+
+    if (dwError != ERROR_SUCCESS ||
+        (dwType != REG_SZ &&
+         dwType != REG_EXPAND_SZ &&
+         dwType != REG_MULTI_SZ))
+        goto done;
+
+    /* Check for the '-mini' option */
+    if (wcsstr(CommandLine, L" -mini") != NULL)
+    {
+        DPRINT1("Running on LiveCD!\n");
+        ScmLiveSetup = TRUE;
+    }
+
+done:
+    RegCloseKey(hSetupKey);
+
+    return dwError;
+}
+
 
 DWORD
 SetSecurityServicesEvent(VOID)
@@ -169,6 +234,13 @@ wWinMain(HINSTANCE hInstance,
 
     DPRINT("SERVICES: Service Control Manager\n");
 
+    dwError = CheckForLiveCD();
+    if (dwError != ERROR_SUCCESS)
+    {
+        DPRINT1("SERVICES: Failed to check for LiveCD (Error %lu)\n", dwError);
+        goto done;
+    }
+
     /* Make us critical */
     RtlSetProcessIsCritical(TRUE, NULL, TRUE);
 
diff --git a/base/system/services/services.h b/base/system/services/services.h
index 845ea020da1..6a9dd5d3783 100644
--- a/base/system/services/services.h
+++ b/base/system/services/services.h
@@ -101,6 +101,7 @@ extern LIST_ENTRY GroupListHead;
 extern LIST_ENTRY ImageListHead;
 extern BOOL ScmInitialize;
 extern BOOL ScmShutdown;
+extern BOOL ScmLiveSetup;
 extern PSECURITY_DESCRIPTOR pPipeSD;
 
 

Reply via email to