ReactOS 0.4.15-dev-8348-gc1b9bb5
NtAdjustPrivilegesToken.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for the NtAdjustPrivilegesToken API
5 * COPYRIGHT: Copyright 2021 George Bișoc <george.bisoc@reactos.org>
6 */
7
8#include "precomp.h"
9
10static
11BOOL
15{
16 PRIVILEGE_SET PrivSet;
18
19 PrivSet.PrivilegeCount = 1;
22 PrivSet.Privilege[0].Attributes = 0;
23
25 if (!Success)
26 {
27 skip("Failed to check the privilege (error code: %lu)\n", GetLastError());
28 return FALSE;
29 }
30
31 return Result;
32}
33
34static
35VOID
37{
42 LUID PrivLuid;
43
46 &Token);
47 if (!Success)
48 {
49 skip("OpenProcessToken() has failed to get the process' token (error code: %lu)!\n", GetLastError());
50 return;
51 }
52
53 Success = LookupPrivilegeValueW(NULL, L"SeImpersonatePrivilege", &PrivLuid);
54 if (!Success)
55 {
56 skip("LookupPrivilegeValueW() has failed to locate the privilege value (error code: %lu)!\n", GetLastError());
57 return;
58 }
59
60 Priv.PrivilegeCount = 1;
61 Priv.Privileges[0].Luid = PrivLuid;
62 Priv.Privileges[0].Attributes = 0;
63
65 trace("The privilege is %s!\n", IsEnabled ? "enabled" : "disabled");
66
68 FALSE,
69 &Priv,
70 0,
71 NULL,
72 NULL);
74
76 trace("The privilege is %s!\n", IsEnabled ? "enabled" : "disabled");
77
79}
80
82{
84}
static BOOL IsPrivilegeEnabled(_In_ HANDLE TokenHandle, _In_ ULONG Privilege)
static VOID AdjustEnableDefaultPriv(VOID)
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI PrivilegeCheck(HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
Definition: security.c:2066
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define CloseHandle
Definition: compat.h:739
#define GetCurrentProcess()
Definition: compat.h:759
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
return pProvider IsEnabled(ProviderControl)
Status
Definition: gdiplustypes.h:25
#define SE_IMPERSONATE_PRIVILEGE
Definition: security.c:683
#define _In_
Definition: ms_sal.h:308
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:726
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY]
Definition: setypes.h:88
$ULONG Control
Definition: setypes.h:87
$ULONG PrivilegeCount
Definition: setypes.h:86
$ULONG PrivilegeCount
Definition: setypes.h:1023
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:1024
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtAdjustPrivilegesToken(_In_ HANDLE TokenHandle, _In_ BOOLEAN DisableAllPrivileges, _In_opt_ PTOKEN_PRIVILEGES NewState, _In_ ULONG BufferLength, _Out_writes_bytes_to_opt_(BufferLength, *ReturnLength) PTOKEN_PRIVILEGES PreviousState, _When_(PreviousState!=NULL, _Out_) PULONG ReturnLength)
Removes a certain amount of privileges of a token based upon the request by the caller.
Definition: tokenadj.c:451
uint32_t ULONG
Definition: typedefs.h:59
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
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
FORCEINLINE LUID NTAPI_INLINE RtlConvertUlongToLuid(_In_ ULONG Val)
Definition: rtlfuncs.h:3541
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_READ
Definition: setypes.h:951
#define PRIVILEGE_SET_ALL_NECESSARY
Definition: setypes.h:83