ReactOS  0.4.15-dev-3451-gf606fec
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 
10 static
11 BOOL
15 {
16  PRIVILEGE_SET PrivSet;
18  LUID Priv;
19 
21 
22  PrivSet.PrivilegeCount = 1;
24  PrivSet.Privilege[0].Luid = Priv;
25  PrivSet.Privilege[0].Attributes = 0;
26 
28  if (!Success)
29  {
30  skip("Failed to check the privilege (error code: %lu)\n", GetLastError());
31  return FALSE;
32  }
33 
34  return Result;
35 }
36 
37 static
38 VOID
40 {
42  HANDLE Token;
43  TOKEN_PRIVILEGES Priv;
45  LUID PrivLuid;
46 
49  &Token);
50  if (!Success)
51  {
52  skip("OpenProcessToken() has failed to get the process' token (error code: %lu)!\n", GetLastError());
53  return;
54  }
55 
56  Success = LookupPrivilegeValueW(NULL, L"SeImpersonatePrivilege", &PrivLuid);
57  if (!Success)
58  {
59  skip("LookupPrivilegeValueW() has failed to locate the privilege value (error code: %lu)!\n", GetLastError());
60  return;
61  }
62 
63  Priv.PrivilegeCount = 1;
64  Priv.Privileges[0].Luid = PrivLuid;
65  Priv.Privileges[0].Attributes = 0;
66 
68  trace("The privilege is %s!\n", IsEnabled ? "enabled" : "disabled");
69 
71  FALSE,
72  &Priv,
73  0,
74  NULL,
75  NULL);
77 
79  trace("The privilege is %s!\n", IsEnabled ? "enabled" : "disabled");
80 
82 }
83 
85 {
87 }
#define CloseHandle
Definition: compat.h:598
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
LONG NTSTATUS
Definition: precomp.h:26
BOOL WINAPI PrivilegeCheck(HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
Definition: security.c:1865
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE Token
$ULONG PrivilegeCount
Definition: setypes.h:1001
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
$ULONG Control
Definition: setypes.h:87
#define ok_hex(expression, result)
Definition: atltest.h:94
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define PRIVILEGE_SET_ALL_NECESSARY
Definition: setypes.h:83
_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
#define _In_
Definition: ms_sal.h:308
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:715
$ULONG PrivilegeCount
Definition: setypes.h:86
Status
Definition: gdiplustypes.h:24
#define trace
Definition: atltest.h:70
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
return pProvider IsEnabled(ProviderControl)
#define TOKEN_READ
Definition: setypes.h:929
#define GetCurrentProcess()
Definition: compat.h:618
START_TEST(NtAdjustPrivilegesToken)
#define SE_IMPERSONATE_PRIVILEGE
Definition: security.c:683
#define NULL
Definition: types.h:112
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:1002
#define skip(...)
Definition: atltest.h:64
static VOID AdjustEnableDefaultPriv(VOID)
LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY]
Definition: setypes.h:88
unsigned int ULONG
Definition: retypes.h:1
#define ConvertPrivLongToLuid(PrivilegeVal, ConvertedPrivLuid)
Definition: precomp.h:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:908
static BOOL IsPrivilegeEnabled(_In_ HANDLE TokenHandle, _In_ ULONG Privilege)
_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: token.c:5695