[WIN32K:NTUSER] Add an extra optional "Process" parameter to the GetProcessLuid(...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 16 Jun 2018 17:44:27 +0000 (19:44 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 19 Aug 2018 20:18:30 +0000 (22:18 +0200)
win32ss/user/ntuser/misc.c
win32ss/user/ntuser/shutdown.c
win32ss/user/ntuser/userfuncs.h

index ceaa7cc..fee2e91 100644 (file)
@@ -766,30 +766,44 @@ GetW32ThreadInfo(VOID)
 NTSTATUS
 GetProcessLuid(
     IN PETHREAD Thread OPTIONAL,
+    IN PEPROCESS Process OPTIONAL,
     OUT PLUID Luid)
 {
     NTSTATUS Status;
-    PACCESS_TOKEN Token;
+    PACCESS_TOKEN Token = NULL;
     SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
     BOOLEAN CopyOnOpen, EffectiveOnly;
 
-    if (Thread == NULL)
+    if (Thread && Process)
+        return STATUS_INVALID_PARAMETER;
+
+    /* If nothing has been specified, use the current thread */
+    if (!Thread && !Process)
         Thread = PsGetCurrentThread();
 
-    /* Use a thread token */
-    Token = PsReferenceImpersonationToken(Thread,
-                                          &CopyOnOpen,
-                                          &EffectiveOnly,
-                                          &ImpersonationLevel);
-    if (Token == NULL)
+    if (Thread)
+    {
+        /* Use a thread token */
+        ASSERT(!Process);
+        Token = PsReferenceImpersonationToken(Thread,
+                                              &CopyOnOpen,
+                                              &EffectiveOnly,
+                                              &ImpersonationLevel);
+
+        /* If we don't have a thread token, use a process token */
+        if (!Token)
+            Process = PsGetThreadProcess(Thread);
+    }
+    if (!Token && Process)
     {
-        /* We don't have a thread token, use a process token */
-        Token = PsReferencePrimaryToken(PsGetThreadProcess(Thread));
+        /* Use a process token */
+        Token = PsReferencePrimaryToken(Process);
 
-        /* If no token, fail */
-        if (Token == NULL)
+        /* If we don't have a token, fail */
+        if (!Token)
             return STATUS_NO_TOKEN;
     }
+    ASSERT(Token);
 
     /* Query the LUID */
     Status = SeQueryAuthenticationIdToken(Token, Luid);
index a750a08..860db7c 100644 (file)
@@ -181,7 +181,7 @@ UserInitiateShutdown(IN PETHREAD Thread,
     TRACE("UserInitiateShutdown\n");
 
     /* Get the caller's LUID */
-    Status = GetProcessLuid(Thread, &CallerLuid);
+    Status = GetProcessLuid(Thread, NULL, &CallerLuid);
     if (!NT_SUCCESS(Status))
     {
         ERR("UserInitiateShutdown: GetProcessLuid failed\n");
@@ -302,10 +302,10 @@ UserEndShutdown(IN PETHREAD Thread,
      */
     //STUB;
 
-    Status = GetProcessLuid(Thread, &CallerLuid);
+    Status = GetProcessLuid(Thread, NULL, &CallerLuid);
     if (!NT_SUCCESS(Status))
     {
-        ERR("GetProcessLuid failed\n");
+        ERR("UserEndShutdown: GetProcessLuid failed\n");
         return Status;
     }
 
index 016180a..efa89ae 100644 (file)
@@ -108,6 +108,7 @@ HBRUSH FASTCALL GetControlColor(PWND,PWND,HDC,UINT);
 NTSTATUS
 GetProcessLuid(
     IN PETHREAD Thread OPTIONAL,
+    IN PEPROCESS Process OPTIONAL,
     OUT PLUID Luid);
 
 /*************** MESSAGE.C ***************/