[NTDLL_APITEST]

- Add simple tests for NtOpenThreadToken[Ex] and NtOpenProcessToken[Ex]

svn path=/trunk/; revision=69329
This commit is contained in:
Thomas Faber 2015-09-23 15:14:25 +00:00
parent d7a9abc45b
commit 5e43107328
4 changed files with 128 additions and 0 deletions

View file

@ -10,6 +10,8 @@ list(APPEND SOURCE
NtFreeVirtualMemory.c
NtMapViewOfSection.c
NtMutant.c
NtOpenProcessToken.c
NtOpenThreadToken.c
NtProtectVirtualMemory.c
NtQueryKey.c
NtQuerySystemEnvironmentValue.c

View file

@ -0,0 +1,53 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
* PURPOSE: Test for NtOpenProcessToken[Ex]
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
*/
#include <apitest.h>
#include <ndk/obfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/sefuncs.h>
START_TEST(NtOpenProcessToken)
{
NTSTATUS Status;
HANDLE TokenHandle;
Status = NtOpenProcessToken(NtCurrentProcess(),
TOKEN_READ,
&TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
if (NT_SUCCESS(Status))
{
ok((LONG_PTR)TokenHandle > 0, "TokenHandle = %p\n", TokenHandle);
Status = NtClose(TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
}
Status = NtOpenProcessTokenEx(NtCurrentProcess(),
TOKEN_READ,
0,
&TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
if (NT_SUCCESS(Status))
{
ok((LONG_PTR)TokenHandle > 0, "TokenHandle = %p\n", TokenHandle);
Status = NtClose(TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
}
Status = NtOpenProcessTokenEx(NtCurrentProcess(),
TOKEN_READ,
OBJ_KERNEL_HANDLE,
&TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
if (NT_SUCCESS(Status))
{
ok((LONG_PTR)TokenHandle > 0, "TokenHandle = %p\n", TokenHandle);
Status = NtClose(TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
}
}

View file

@ -0,0 +1,69 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
* PURPOSE: Test for NtOpenThreadToken[Ex]
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
*/
#include <apitest.h>
#include <ndk/obfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/rtlfuncs.h>
START_TEST(NtOpenThreadToken)
{
NTSTATUS Status;
HANDLE TokenHandle;
BOOLEAN OpenAsSelf;
ULONG HandleAttributes[] = { 0, OBJ_KERNEL_HANDLE };
ULONG i;
TokenHandle = (HANDLE)0x55555555;
Status = NtOpenThreadToken(NtCurrentThread(),
TOKEN_READ,
TRUE,
&TokenHandle);
ok(Status == STATUS_NO_TOKEN, "Status = %lx\n", Status);
ok(TokenHandle == NULL, "TokenHandle = %p\n", TokenHandle);
Status = RtlImpersonateSelf(SecurityImpersonation);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
for (OpenAsSelf = FALSE; OpenAsSelf <= TRUE; OpenAsSelf++)
{
Status = NtOpenThreadToken(NtCurrentThread(),
TOKEN_READ,
OpenAsSelf,
&TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
if (NT_SUCCESS(Status))
{
ok((LONG_PTR)TokenHandle > 0, "TokenHandle = %p\n", TokenHandle);
Status = NtClose(TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
}
for (i = 0; i < RTL_NUMBER_OF(HandleAttributes); i++)
{
Status = NtOpenThreadTokenEx(NtCurrentThread(),
TOKEN_READ,
OpenAsSelf,
HandleAttributes[i],
&TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
if (NT_SUCCESS(Status))
{
ok((LONG_PTR)TokenHandle > 0, "TokenHandle = %p\n", TokenHandle);
Status = NtClose(TokenHandle);
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
}
}
}
TokenHandle = NULL;
Status = NtSetInformationThread(NtCurrentThread(),
ThreadImpersonationToken,
&TokenHandle,
sizeof(TokenHandle));
ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
}

View file

@ -13,6 +13,8 @@ extern void func_NtDeleteKey(void);
extern void func_NtFreeVirtualMemory(void);
extern void func_NtMapViewOfSection(void);
extern void func_NtMutant(void);
extern void func_NtOpenProcessToken(void);
extern void func_NtOpenThreadToken(void);
extern void func_NtProtectVirtualMemory(void);
extern void func_NtQueryKey(void);
extern void func_NtQuerySystemEnvironmentValue(void);
@ -50,6 +52,8 @@ const struct test winetest_testlist[] =
{ "NtFreeVirtualMemory", func_NtFreeVirtualMemory },
{ "NtMapViewOfSection", func_NtMapViewOfSection },
{ "NtMutant", func_NtMutant },
{ "NtOpenProcessToken", func_NtOpenProcessToken },
{ "NtOpenThreadToken", func_NtOpenThreadToken },
{ "NtProtectVirtualMemory", func_NtProtectVirtualMemory },
{ "NtQueryKey", func_NtQueryKey },
{ "NtQuerySystemEnvironmentValue", func_NtQuerySystemEnvironmentValue },