ReactOS  0.4.14-dev-52-g6116262
DuplicateTokenEx.c
Go to the documentation of this file.
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 "precomp.h"
9 
10 #define ok_luid_equal(Luid, Expected) \
11  ok(RtlEqualLuid((Luid), (Expected)), "Got wrong LUID %08lx%08lx, expected (%08lx%08lx).\n", \
12  (Luid)->HighPart, (Luid)->LowPart, (Expected)->HighPart, (Expected)->LowPart)
13 #define ok_luid_notequal(Luid, Comparand) \
14  ok(!RtlEqualLuid((Luid), (Comparand)), "LUID is %08lx%08lx and should not be.\n", \
15  (Luid)->HighPart, (Luid)->LowPart)
16 
18 {
19  HANDLE ProcessToken, TokenDup;
20  TOKEN_STATISTICS ProcessTokenStats, TokenDupStats;
21  BOOL Result;
23 
24  /* Get the current process token */
26  ok(Result, "OpenProcessToken failed. GLE: %lu.\n", GetLastError());
27  /* And its statistics */
28  Result = GetTokenInformation(ProcessToken,
30  &ProcessTokenStats,
31  sizeof(ProcessTokenStats),
32  &ReturnLength);
33  ok(Result, "GetTokenInformation failed. GLE: %lu.\n", GetLastError());
34  ok_size_t(ReturnLength, sizeof(ProcessTokenStats));
35 
36  /* Duplicate it as primary token with the same access rights. */
37  Result = DuplicateTokenEx(ProcessToken, 0, NULL, SecurityImpersonation, TokenPrimary, &TokenDup);
38  ok(Result, "DuplicateTokenEx failed. GLE: %lu.\n", GetLastError());
39  /* Get the stats */
40  Result = GetTokenInformation(TokenDup,
42  &TokenDupStats,
43  sizeof(ProcessTokenStats),
44  &ReturnLength);
45  ok(Result, "GetTokenInformation failed. GLE: %lu.\n", GetLastError());
46  ok_size_t(ReturnLength, sizeof(ProcessTokenStats));
47  /* And test them */
48  ok_luid_notequal(&TokenDupStats.TokenId, &ProcessTokenStats.TokenId);
49  ok_luid_equal(&TokenDupStats.AuthenticationId, &ProcessTokenStats.AuthenticationId);
50  ok(TokenDupStats.TokenType == TokenPrimary, "Duplicate token type is %d.\n", TokenDupStats.TokenType);
52  "Duplicate token impersonation level is %d.\n", TokenDupStats.ImpersonationLevel);
53  ok_dec(TokenDupStats.DynamicCharged, ProcessTokenStats.DynamicCharged);
54  ok_dec(TokenDupStats.DynamicAvailable, ProcessTokenStats.DynamicAvailable);
55  ok_dec(TokenDupStats.GroupCount, ProcessTokenStats.GroupCount);
56  ok_dec(TokenDupStats.PrivilegeCount, ProcessTokenStats.PrivilegeCount);
57  ok_luid_equal(&TokenDupStats.ModifiedId, &ProcessTokenStats.ModifiedId);
58 
59  CloseHandle(ProcessToken);
60  CloseHandle(TokenDup);
61 }
LUID AuthenticationId
Definition: setypes.h:1033
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define CloseHandle
Definition: compat.h:398
$ULONG GroupCount
Definition: setypes.h:1039
$ULONG DynamicCharged
Definition: setypes.h:1037
#define ok_luid_notequal(Luid, Comparand)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ok_luid_equal(Luid, Expected)
unsigned int BOOL
Definition: ntddk_ex.h:94
START_TEST(DuplicateTokenEx)
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
TOKEN_TYPE TokenType
Definition: setypes.h:1035
#define TOKEN_QUERY
Definition: setypes.h:874
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: setypes.h:1036
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DuplicateTokenEx(IN HANDLE ExistingTokenHandle, IN DWORD dwDesiredAccess, IN LPSECURITY_ATTRIBUTES lpTokenAttributes OPTIONAL, IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, IN TOKEN_TYPE TokenType, OUT PHANDLE DuplicateTokenHandle)
Definition: security.c:3394
#define ok_size_t(expression, result)
Definition: atltest.h:115
#define TOKEN_DUPLICATE
Definition: setypes.h:872
$ULONG PrivilegeCount
Definition: setypes.h:1040
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:413
$ULONG DynamicAvailable
Definition: setypes.h:1038
#define ok_dec(expression, result)
Definition: atltest.h:101