ReactOS 0.4.15-dev-8222-g9164419
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;
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),
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),
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}
#define ok_luid_notequal(Luid, Comparand)
#define ok_luid_equal(Luid, Expected)
#define ok(value,...)
Definition: atltest.h:57
#define ok_size_t(expression, result)
Definition: atltest.h:115
#define ok_dec(expression, result)
Definition: atltest.h:101
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:411
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
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:3859
#define CloseHandle
Definition: compat.h:739
#define GetCurrentProcess()
Definition: compat.h:759
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
@ SecurityImpersonation
Definition: lsa.idl:57
@ TokenPrimary
Definition: imports.h:273
LUID AuthenticationId
Definition: setypes.h:1087
TOKEN_TYPE TokenType
Definition: setypes.h:1089
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: setypes.h:1090
$ULONG DynamicAvailable
Definition: setypes.h:1092
$ULONG PrivilegeCount
Definition: setypes.h:1094
$ULONG DynamicCharged
Definition: setypes.h:1091
$ULONG GroupCount
Definition: setypes.h:1093
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_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:409
#define TOKEN_DUPLICATE
Definition: setypes.h:926
#define TOKEN_QUERY
Definition: setypes.h:928
@ TokenStatistics
Definition: setypes.h:975