Robert Shearman : advapi32: Add tests for getting the groups, user and privileges of a token.

Alexandre Julliard julliard at wine.codeweavers.com
Mon May 15 07:35:01 CDT 2006


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

Author: Robert Shearman <rob at codeweavers.com>
Date:   Sat May 13 16:56:59 2006 +0100

advapi32: Add tests for getting the groups, user and privileges of a token.

---

 dlls/advapi32/tests/security.c |   70 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index 1c9ab5d..df2ba61 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -26,6 +26,7 @@ #include "winbase.h"
 #include "winerror.h"
 #include "aclapi.h"
 #include "winnt.h"
+#include "sddl.h"
 
 typedef VOID (WINAPI *fnBuildTrusteeWithSidA)( PTRUSTEEA pTrustee, PSID pSid );
 typedef VOID (WINAPI *fnBuildTrusteeWithNameA)( PTRUSTEEA pTrustee, LPSTR pName );
@@ -693,6 +694,74 @@ static void test_AccessCheck(void)
     HeapFree(GetProcessHeap(), 0, PrivSet);
 }
 
+/* test GetTokenInformation for the various attributes */
+static void test_token_attr(void)
+{
+    HANDLE Token;
+    DWORD Size;
+    TOKEN_PRIVILEGES *Privileges;
+    TOKEN_GROUPS *Groups;
+    TOKEN_USER *User;
+    BOOL ret;
+    DWORD i;
+    LPTSTR SidString;
+
+    ret = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token);
+    ok(ret, "OpenProcessToken failed with error %ld\n", GetLastError());
+
+    /* groups */
+    ret = GetTokenInformation(Token, TokenGroups, NULL, 0, &Size);
+    Groups = HeapAlloc(GetProcessHeap(), 0, Size);
+    ret = GetTokenInformation(Token, TokenGroups, Groups, Size, &Size);
+    ok(ret, "GetTokenInformation(TokenGroups) failed with error %ld\n", GetLastError());
+    trace("TokenGroups:\n");
+    for (i = 0; i < Groups->GroupCount; i++)
+    {
+        DWORD NameLength = 255;
+        TCHAR Name[255];
+        DWORD DomainLength = 255;
+        TCHAR Domain[255];
+        SID_NAME_USE SidNameUse;
+        ConvertSidToStringSid(Groups->Groups[i].Sid, &SidString);
+        Name[0] = '\0';
+        Domain[0] = '\0';
+        ret = LookupAccountSid(NULL, Groups->Groups[i].Sid, Name, &NameLength, Domain, &DomainLength, &SidNameUse);
+        ok(ret, "LookupAccountSid failed with error %ld\n", GetLastError());
+        trace("\t%s, %s\\%s attr: 0x%08lx\n", SidString, Domain, Name, Groups->Groups[i].Attributes);
+        LocalFree(SidString);
+    }
+
+    /* user */
+    ret = GetTokenInformation(Token, TokenUser, NULL, 0, &Size);
+    ok(!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
+        "GetTokenInformation(TokenUser) failed with error %ld\n", GetLastError());
+    User = HeapAlloc(GetProcessHeap(), 0, Size);
+    ret = GetTokenInformation(Token, TokenUser, User, Size, &Size);
+    ok(ret,
+        "GetTokenInformation(TokenUser) failed with error %ld\n", GetLastError());
+
+    ConvertSidToStringSid(User->User.Sid, &SidString);
+    trace("TokenUser: %s attr: 0x%08lx\n", SidString, User->User.Attributes);
+    LocalFree(SidString);
+
+    /* privileges */
+    ret = GetTokenInformation(Token, TokenPrivileges, NULL, 0, &Size);
+    ok(!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
+        "GetTokenInformation(TokenPrivileges) failed with error %ld\n", GetLastError());
+    Privileges = HeapAlloc(GetProcessHeap(), 0, Size);
+    ret = GetTokenInformation(Token, TokenPrivileges, Privileges, Size, &Size);
+    ok(ret,
+        "GetTokenInformation(TokenPrivileges) failed with error %ld\n", GetLastError());
+    trace("TokenPrivileges:\n");
+    for (i = 0; i < Privileges->PrivilegeCount; i++)
+    {
+        TCHAR Name[256];
+        DWORD NameLen = sizeof(Name)/sizeof(Name[0]);
+        LookupPrivilegeName(NULL, &Privileges->Privileges[i].Luid, Name, &NameLen);
+        trace("\t%s, 0x%lx\n", Name, Privileges->Privileges[i].Attributes);
+    }
+}
+
 START_TEST(security)
 {
     init();
@@ -702,4 +771,5 @@ START_TEST(security)
     test_luid();
     test_FileSecurity();
     test_AccessCheck();
+    test_token_attr();
 }




More information about the wine-cvs mailing list