https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2345d63ce3c88492a241ff8410056a4b75724ff4

commit 2345d63ce3c88492a241ff8410056a4b75724ff4
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sat Jun 16 19:44:27 2018 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun Aug 19 22:18:30 2018 +0200

    [WIN32K:NTUSER] Add an extra optional "Process" parameter to the 
GetProcessLuid() function to be used alternatively in place of "Thread" to 
retrieve the LUID.
---
 win32ss/user/ntuser/misc.c      | 38 ++++++++++++++++++++++++++------------
 win32ss/user/ntuser/shutdown.c  |  6 +++---
 win32ss/user/ntuser/userfuncs.h |  1 +
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/win32ss/user/ntuser/misc.c b/win32ss/user/ntuser/misc.c
index ceaa7ccc13..fee2e91388 100644
--- a/win32ss/user/ntuser/misc.c
+++ b/win32ss/user/ntuser/misc.c
@@ -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);
diff --git a/win32ss/user/ntuser/shutdown.c b/win32ss/user/ntuser/shutdown.c
index a750a08fb8..860db7cf50 100644
--- a/win32ss/user/ntuser/shutdown.c
+++ b/win32ss/user/ntuser/shutdown.c
@@ -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;
     }
 
diff --git a/win32ss/user/ntuser/userfuncs.h b/win32ss/user/ntuser/userfuncs.h
index 016180a598..efa89aec13 100644
--- a/win32ss/user/ntuser/userfuncs.h
+++ b/win32ss/user/ntuser/userfuncs.h
@@ -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 ***************/

Reply via email to