Reactos

[NTDLL_APITEST] Implement NtAdjustGroupsToken API tests

+80
+1
modules/rostests/apitests/ntdll/CMakeLists.txt
··· 10 10 load_notifications.c 11 11 locale.c 12 12 NtAcceptConnectPort.c 13 + NtAdjustGroupsToken.c 13 14 NtAdjustPrivilegesToken.c 14 15 NtAllocateVirtualMemory.c 15 16 NtApphelpCacheControl.c
+77
modules/rostests/apitests/ntdll/NtAdjustGroupsToken.c
··· 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 NtAdjustGroupsToken API 5 + * COPYRIGHT: Copyright 2021 George Bișoc <george.bisoc@reactos.org> 6 + */ 7 + 8 + #include "precomp.h" 9 + 10 + static 11 + HANDLE 12 + GetProcessToken( 13 + _In_ DWORD Access) 14 + { 15 + BOOL Success; 16 + HANDLE Token; 17 + 18 + Success = OpenProcessToken(GetCurrentProcess(), Access, &Token); 19 + if (!Success) 20 + { 21 + skip("Failed to open the process' token (error code: %lu)!\n", GetLastError()); 22 + return NULL; 23 + } 24 + 25 + return Token; 26 + } 27 + 28 + START_TEST(NtAdjustGroupsToken) 29 + { 30 + HANDLE TokenHandle; 31 + NTSTATUS Status; 32 + 33 + /* Get the token from current process but with incorrect rights */ 34 + TokenHandle = GetProcessToken(TOKEN_DUPLICATE); 35 + 36 + /* We give an invalid handle */ 37 + Status = NtAdjustGroupsToken(NULL, 38 + TRUE, 39 + NULL, 40 + 0, 41 + NULL, 42 + NULL); 43 + ok_hex(Status, STATUS_INVALID_HANDLE); 44 + 45 + /* We're trying to adjust the token's groups with wrong rights */ 46 + Status = NtAdjustGroupsToken(TokenHandle, 47 + TRUE, 48 + NULL, 49 + 0, 50 + NULL, 51 + NULL); 52 + ok_hex(Status, STATUS_ACCESS_DENIED); 53 + 54 + /* Close our handle and open a new one with right access right */ 55 + CloseHandle(TokenHandle); 56 + TokenHandle = GetProcessToken(TOKEN_ADJUST_GROUPS); 57 + 58 + /* We don't give a list of groups to be adjusted in token */ 59 + Status = NtAdjustGroupsToken(TokenHandle, 60 + FALSE, 61 + NULL, 62 + 0, 63 + NULL, 64 + NULL); 65 + ok_hex(Status, STATUS_INVALID_PARAMETER); 66 + 67 + /* Reset the groups of an access token to default */ 68 + Status = NtAdjustGroupsToken(TokenHandle, 69 + TRUE, 70 + NULL, 71 + 0, 72 + NULL, 73 + NULL); 74 + ok_hex(Status, STATUS_SUCCESS); 75 + 76 + CloseHandle(TokenHandle); 77 + }
+2
modules/rostests/apitests/ntdll/testlist.c
··· 6 6 extern void func_LdrEnumResources(void); 7 7 extern void func_load_notifications(void); 8 8 extern void func_NtAcceptConnectPort(void); 9 + extern void func_NtAdjustGroupsToken(void); 9 10 extern void func_NtAdjustPrivilegesToken(void); 10 11 extern void func_NtAllocateVirtualMemory(void); 11 12 extern void func_NtApphelpCacheControl(void); ··· 92 93 { "LdrEnumResources", func_LdrEnumResources }, 93 94 { "load_notifications", func_load_notifications }, 94 95 { "NtAcceptConnectPort", func_NtAcceptConnectPort }, 96 + { "NtAdjustGroupsToken", func_NtAdjustGroupsToken }, 95 97 { "NtAdjustPrivilegesToken", func_NtAdjustPrivilegesToken }, 96 98 { "NtAllocateVirtualMemory", func_NtAllocateVirtualMemory }, 97 99 { "NtApphelpCacheControl", func_NtApphelpCacheControl },