ReactOS 0.4.16-dev-91-g764881a
NtCompareTokens.c File Reference
#include "precomp.h"
Include dependency graph for NtCompareTokens.c:

Go to the source code of this file.

Functions

static HANDLE GetTokenFromCurrentProcess (VOID)
 
static HANDLE GetDuplicateToken (_In_ HANDLE Token)
 
static VOID DisableTokenPrivileges (_In_ HANDLE Token)
 
 START_TEST (NtCompareTokens)
 

Function Documentation

◆ DisableTokenPrivileges()

static VOID DisableTokenPrivileges ( _In_ HANDLE  Token)
static

Definition at line 48 of file NtCompareTokens.c.

49{
51
53 if (!Success)
54 {
55 skip("AdjustTokenPrivileges() has failed to disable the privileges (error code: %lu)!\n", GetLastError());
56 return;
57 }
58}
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ GetDuplicateToken()

static HANDLE GetDuplicateToken ( _In_ HANDLE  Token)
static

Definition at line 31 of file NtCompareTokens.c.

32{
34 HANDLE ReturnedToken;
35
37 if (!Success)
38 {
39 skip("DuplicateToken() has failed to get the process' token (error code: %lu)!\n", GetLastError());
40 return NULL;
41 }
42
43 return ReturnedToken;
44}
BOOL WINAPI DuplicateToken(IN HANDLE ExistingTokenHandle, IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, OUT PHANDLE DuplicateTokenHandle)
Definition: security.c:3919
@ SecurityIdentification
Definition: lsa.idl:56

Referenced by START_TEST().

◆ GetTokenFromCurrentProcess()

static HANDLE GetTokenFromCurrentProcess ( VOID  )
static

Definition at line 12 of file NtCompareTokens.c.

13{
16
19 &Token);
20 if (!Success)
21 {
22 skip("OpenProcessToken() has failed to get the process' token (error code: %lu)!\n", GetLastError());
23 return NULL;
24 }
25
26 return Token;
27}
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define GetCurrentProcess()
Definition: compat.h:759
#define TOKEN_DUPLICATE
Definition: setypes.h:926
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_READ
Definition: setypes.h:951

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( NtCompareTokens  )

Definition at line 60 of file NtCompareTokens.c.

61{
63 HANDLE ProcessToken = NULL;
64 HANDLE DuplicatedToken = NULL;
66
67 /* Obtain some tokens from current process */
68 ProcessToken = GetTokenFromCurrentProcess();
69 DuplicatedToken = GetDuplicateToken(ProcessToken);
70
71 /*
72 * Give invalid token handles and don't output
73 * the returned value in the last parameter.
74 */
77
78 /*
79 * Token handles are valid but don't output
80 * the returned value.
81 */
82 Status = NtCompareTokens(ProcessToken, ProcessToken, NULL);
84
85 /* The tokens are the same */
86 Status = NtCompareTokens(ProcessToken, ProcessToken, &IsEqual);
88 ok(IsEqual == TRUE, "Equal tokens expected but they aren't (current value: %u)!\n", IsEqual);
89
90 /* A token is duplicated with equal SIDs and privileges */
91 Status = NtCompareTokens(ProcessToken, DuplicatedToken, &IsEqual);
93 ok(IsEqual == TRUE, "Equal tokens expected but they aren't (current value: %u)!\n", IsEqual);
94
95 /* Disable all the privileges for token. */
96 DisableTokenPrivileges(ProcessToken);
97
98 /*
99 * The main token has privileges disabled but the
100 * duplicated one has them enabled still.
101 */
102 Status = NtCompareTokens(ProcessToken, DuplicatedToken, &IsEqual);
104 ok(IsEqual == FALSE, "Tokens mustn't be equal (current value: %u)!\n", IsEqual);
105
106 /* We finished our tests, close the tokens */
107 CloseHandle(ProcessToken);
108 CloseHandle(DuplicatedToken);
109}
static VOID DisableTokenPrivileges(_In_ HANDLE Token)
static HANDLE GetDuplicateToken(_In_ HANDLE Token)
static HANDLE GetTokenFromCurrentProcess(VOID)
unsigned char BOOLEAN
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
@ IsEqual
Definition: fatprocs.h:1887
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI NtCompareTokens(_In_ HANDLE FirstTokenHandle, _In_ HANDLE SecondTokenHandle, _Out_ PBOOLEAN Equal)
Compares tokens if they're equal or not.
Definition: token.c:2503
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_SUCCESS
Definition: shellext.h:65