[ADVAPI32_APITESTS]
[reactos.git] / rostests / apitests / advapi32 / DuplicateTokenEx.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for DupicateTokenEx
5 * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
6 */
7
8 #include <apitest.h>
9 #include <winbase.h>
10 #include <rtlfuncs.h>
11
12 #define ok_luid_equal(Luid, Expected) \
13 ok(RtlEqualLuid((Luid), (Expected)), "Got wrong LUID %08lx%08lx, expected (%08lx%08lx).\n", \
14 (Luid)->HighPart, (Luid)->LowPart, (Expected)->HighPart, (Expected)->LowPart)
15 #define ok_luid_notequal(Luid, Comparand) \
16 ok(!RtlEqualLuid((Luid), (Comparand)), "LUID is %08lx%08lx and should not be.\n", \
17 (Luid)->HighPart, (Luid)->LowPart)
18
19 START_TEST(DuplicateTokenEx)
20 {
21 HANDLE ProcessToken, TokenDup;
22 TOKEN_STATISTICS ProcessTokenStats, TokenDupStats;
23 BOOL Result;
24 DWORD ReturnLength;
25
26 /* Get the current process token */
27 Result = OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE | TOKEN_QUERY, &ProcessToken);
28 ok(Result, "OpenProcessToken failed. GLE: %lu.\n", GetLastError());
29 /* And its statistics */
30 Result = GetTokenInformation(ProcessToken,
31 TokenStatistics,
32 &ProcessTokenStats,
33 sizeof(ProcessTokenStats),
34 &ReturnLength);
35 ok(Result, "GetTokenInformation failed. GLE: %lu.\n", GetLastError());
36 ok_size_t(ReturnLength, sizeof(ProcessTokenStats));
37
38 /* Duplicate it as primary token with the same access rights. */
39 Result = DuplicateTokenEx(ProcessToken, 0, NULL, SecurityImpersonation, TokenPrimary, &TokenDup);
40 ok(Result, "DuplicateTokenEx failed. GLE: %lu.\n", GetLastError());
41 /* Get the stats */
42 Result = GetTokenInformation(TokenDup,
43 TokenStatistics,
44 &TokenDupStats,
45 sizeof(ProcessTokenStats),
46 &ReturnLength);
47 ok(Result, "GetTokenInformation failed. GLE: %lu.\n", GetLastError());
48 ok_size_t(ReturnLength, sizeof(ProcessTokenStats));
49 /* And test them */
50 ok_luid_notequal(&TokenDupStats.TokenId, &ProcessTokenStats.TokenId);
51 ok_luid_equal(&TokenDupStats.AuthenticationId, &ProcessTokenStats.AuthenticationId);
52 ok(TokenDupStats.TokenType == TokenPrimary, "Duplicate token type is %d.\n", TokenDupStats.TokenType);
53 ok(TokenDupStats.ImpersonationLevel == SecurityImpersonation,
54 "Duplicate token impersonation level is %d.\n", TokenDupStats.ImpersonationLevel);
55 ok_dec(TokenDupStats.DynamicCharged, ProcessTokenStats.DynamicCharged);
56 ok_dec(TokenDupStats.DynamicAvailable, ProcessTokenStats.DynamicAvailable);
57 ok_dec(TokenDupStats.GroupCount, ProcessTokenStats.GroupCount);
58 ok_dec(TokenDupStats.PrivilegeCount, ProcessTokenStats.PrivilegeCount);
59 ok_luid_equal(&TokenDupStats.ModifiedId, &ProcessTokenStats.ModifiedId);
60
61 CloseHandle(ProcessToken);
62 CloseHandle(TokenDup);
63 }