···11+/*
22+ * PROJECT: ReactOS API tests
33+ * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
44+ * PURPOSE: Tests for the NtAdjustGroupsToken API
55+ * COPYRIGHT: Copyright 2021 George Bișoc <george.bisoc@reactos.org>
66+ */
77+88+#include "precomp.h"
99+1010+static
1111+HANDLE
1212+GetProcessToken(
1313+ _In_ DWORD Access)
1414+{
1515+ BOOL Success;
1616+ HANDLE Token;
1717+1818+ Success = OpenProcessToken(GetCurrentProcess(), Access, &Token);
1919+ if (!Success)
2020+ {
2121+ skip("Failed to open the process' token (error code: %lu)!\n", GetLastError());
2222+ return NULL;
2323+ }
2424+2525+ return Token;
2626+}
2727+2828+START_TEST(NtAdjustGroupsToken)
2929+{
3030+ HANDLE TokenHandle;
3131+ NTSTATUS Status;
3232+3333+ /* Get the token from current process but with incorrect rights */
3434+ TokenHandle = GetProcessToken(TOKEN_DUPLICATE);
3535+3636+ /* We give an invalid handle */
3737+ Status = NtAdjustGroupsToken(NULL,
3838+ TRUE,
3939+ NULL,
4040+ 0,
4141+ NULL,
4242+ NULL);
4343+ ok_hex(Status, STATUS_INVALID_HANDLE);
4444+4545+ /* We're trying to adjust the token's groups with wrong rights */
4646+ Status = NtAdjustGroupsToken(TokenHandle,
4747+ TRUE,
4848+ NULL,
4949+ 0,
5050+ NULL,
5151+ NULL);
5252+ ok_hex(Status, STATUS_ACCESS_DENIED);
5353+5454+ /* Close our handle and open a new one with right access right */
5555+ CloseHandle(TokenHandle);
5656+ TokenHandle = GetProcessToken(TOKEN_ADJUST_GROUPS);
5757+5858+ /* We don't give a list of groups to be adjusted in token */
5959+ Status = NtAdjustGroupsToken(TokenHandle,
6060+ FALSE,
6161+ NULL,
6262+ 0,
6363+ NULL,
6464+ NULL);
6565+ ok_hex(Status, STATUS_INVALID_PARAMETER);
6666+6767+ /* Reset the groups of an access token to default */
6868+ Status = NtAdjustGroupsToken(TokenHandle,
6969+ TRUE,
7070+ NULL,
7171+ 0,
7272+ NULL,
7373+ NULL);
7474+ ok_hex(Status, STATUS_SUCCESS);
7575+7676+ CloseHandle(TokenHandle);
7777+}