From 7e73f449d158f0d6a6b6b421d073dbaf1741e1c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Mon, 7 Aug 2017 02:22:11 +0200
Subject: server: Correctly treat zero access mask in duplicate_token
 wineserver call.

---
 dlls/advapi32/tests/security.c | 14 +++++++-------
 server/token.c                 |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index 4a03db27e69..f1a64e29dea 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -7438,7 +7438,7 @@ static void test_token_security_descriptor(void)
             ret = DuplicateTokenEx(token4, 0, NULL, SecurityImpersonation, TokenImpersonation, &token5);
             ok(ret, "DuplicateTokenEx failed with error %u\n", GetLastError());
             ret = SetThreadToken(NULL, token5);
-            todo_wine ok(ret, "SetThreadToken failed with error %u\n", GetLastError());
+            ok(ret, "SetThreadToken failed with error %u\n", GetLastError());
             CloseHandle(token4);
 
             /* Restrict current process token while impersonating a medium integrity token */
@@ -7503,16 +7503,16 @@ static void test_token_security_descriptor(void)
 
             size = 0;
             ret = GetKernelObjectSecurity(token6, LABEL_SECURITY_INFORMATION, NULL, 0, &size);
-            todo_wine ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
+            ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
                "Unexpected GetKernelObjectSecurity return value %u, error %u\n", ret, GetLastError());
 
             sd3 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
             ret = GetKernelObjectSecurity(token6, LABEL_SECURITY_INFORMATION, sd3, size, &size);
-            todo_wine ok(ret, "GetKernelObjectSecurity failed with error %u\n", GetLastError());
+            ok(ret, "GetKernelObjectSecurity failed with error %u\n", GetLastError());
 
             sacl = NULL;
             ret = GetSecurityDescriptorSacl(sd3, &present, &sacl, &defaulted);
-            todo_wine ok(ret, "GetSecurityDescriptorSacl failed with error %u\n", GetLastError());
+            ok(ret, "GetSecurityDescriptorSacl failed with error %u\n", GetLastError());
             todo_wine ok(present, "No SACL in the security descriptor\n");
             todo_wine ok(sacl != NULL, "NULL SACL in the security descriptor\n");
 
@@ -7606,16 +7606,16 @@ static void test_token_security_descriptor(void)
 
         size = 0;
         ret = GetKernelObjectSecurity(token4, LABEL_SECURITY_INFORMATION, NULL, 0, &size);
-        todo_wine ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
+        ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
            "Unexpected GetKernelObjectSecurity return value %u, error %u\n", ret, GetLastError());
 
         sd3 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
         ret = GetKernelObjectSecurity(token4, LABEL_SECURITY_INFORMATION, sd3, size, &size);
-        todo_wine ok(ret, "GetKernelObjectSecurity failed with error %u\n", GetLastError());
+        ok(ret, "GetKernelObjectSecurity failed with error %u\n", GetLastError());
 
         sacl = NULL;
         ret = GetSecurityDescriptorSacl(sd3, &present, &sacl, &defaulted);
-        todo_wine ok(ret, "GetSecurityDescriptorSacl failed with error %u\n", GetLastError());
+        ok(ret, "GetSecurityDescriptorSacl failed with error %u\n", GetLastError());
         todo_wine ok(present, "No SACL in the security descriptor\n");
         todo_wine ok(sacl != NULL, "NULL SACL in the security descriptor\n");
 
diff --git a/server/token.c b/server/token.c
index 6a1085bae12..292e1df80fd 100644
--- a/server/token.c
+++ b/server/token.c
@@ -1376,7 +1376,8 @@ DECL_HANDLER(duplicate_token)
         struct token *token = token_duplicate( src_token, req->primary, req->impersonation_level, sd, NULL, 0, NULL, 0 );
         if (token)
         {
-            reply->new_handle = alloc_handle_no_access_check( current->process, token, req->access, objattr->attributes );
+            unsigned int access = req->access ? req->access : get_handle_access( current->process, req->handle );
+            reply->new_handle = alloc_handle_no_access_check( current->process, token, access, objattr->attributes );
             release_object( token );
         }
         release_object( src_token );
-- 
2.13.1

