Sebastian Lackner : ntdll: Simplify RtlFormatCurrentUserKeyPath using GetCurrentThreadEffectiveToken.

Alexandre Julliard julliard at winehq.org
Fri Sep 2 11:41:43 CDT 2016


Module: wine
Branch: master
Commit: be74d3a5d52c713af061ea9030889345c887bcc5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=be74d3a5d52c713af061ea9030889345c887bcc5

Author: Sebastian Lackner <sebastian at fds-team.de>
Date:   Thu Sep  1 23:52:27 2016 +0200

ntdll: Simplify RtlFormatCurrentUserKeyPath using GetCurrentThreadEffectiveToken.

Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/reg.c | 47 +++++++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/dlls/ntdll/reg.c b/dlls/ntdll/reg.c
index 0d03300..6dc5d61 100644
--- a/dlls/ntdll/reg.c
+++ b/dlls/ntdll/reg.c
@@ -911,42 +911,33 @@ NTSTATUS WINAPI NtUnloadKey(IN POBJECT_ATTRIBUTES attr)
 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
 {
     static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
-    HANDLE token;
+    char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
+    DWORD len = sizeof(buffer);
     NTSTATUS status;
 
-    status = NtOpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token);
-    if (status == STATUS_NO_TOKEN)
-        status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token);
+    status = NtQueryInformationToken(GetCurrentThreadEffectiveToken(), TokenUser, buffer, len, &len);
     if (status == STATUS_SUCCESS)
     {
-        char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
-        DWORD len = sizeof(buffer);
-
-        status = NtQueryInformationToken(token, TokenUser, buffer, len, &len);
-        if (status == STATUS_SUCCESS)
+        KeyPath->MaximumLength = 0;
+        status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
+        if (status == STATUS_BUFFER_OVERFLOW)
         {
-            KeyPath->MaximumLength = 0;
-            status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
-            if (status == STATUS_BUFFER_OVERFLOW)
+            PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
+                                         sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
+            if (buf)
             {
-                PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
-                                             sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
-                if (buf)
-                {
-                    memcpy(buf, pathW, sizeof(pathW));
-                    KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
-                    KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
-                    status = RtlConvertSidToUnicodeString(KeyPath,
-                                                          ((TOKEN_USER *)buffer)->User.Sid, FALSE);
-                    KeyPath->Buffer = buf;
-                    KeyPath->Length += sizeof(pathW);
-                    KeyPath->MaximumLength += sizeof(pathW);
-                }
-                else
-                    status = STATUS_NO_MEMORY;
+                memcpy(buf, pathW, sizeof(pathW));
+                KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
+                KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
+                status = RtlConvertSidToUnicodeString(KeyPath,
+                                                      ((TOKEN_USER *)buffer)->User.Sid, FALSE);
+                KeyPath->Buffer = buf;
+                KeyPath->Length += sizeof(pathW);
+                KeyPath->MaximumLength += sizeof(pathW);
             }
+            else
+                status = STATUS_NO_MEMORY;
         }
-        NtClose(token);
     }
     return status;
 }




More information about the wine-cvs mailing list