Author: tfaber
Date: Wed Sep 23 15:14:25 2015
New Revision: 69329
URL:
http://svn.reactos.org/svn/reactos?rev=69329&view=rev
Log:
[NTDLL_APITEST]
- Add simple tests for NtOpenThreadToken[Ex] and NtOpenProcessToken[Ex]
Added:
trunk/rostests/apitests/ntdll/NtOpenProcessToken.c (with props)
trunk/rostests/apitests/ntdll/NtOpenThreadToken.c (with props)
Modified:
trunk/rostests/apitests/ntdll/CMakeLists.txt
trunk/rostests/apitests/ntdll/testlist.c
Modified: trunk/rostests/apitests/ntdll/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/CMakeLists…
==============================================================================
--- trunk/rostests/apitests/ntdll/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/apitests/ntdll/CMakeLists.txt [iso-8859-1] Wed Sep 23 15:14:25 2015
@@ -10,6 +10,8 @@
NtFreeVirtualMemory.c
NtMapViewOfSection.c
NtMutant.c
+ NtOpenProcessToken.c
+ NtOpenThreadToken.c
NtProtectVirtualMemory.c
NtQueryKey.c
NtQuerySystemEnvironmentValue.c
Added: trunk/rostests/apitests/ntdll/NtOpenProcessToken.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/NtOpenProc…
==============================================================================
--- trunk/rostests/apitests/ntdll/NtOpenProcessToken.c (added)
+++ trunk/rostests/apitests/ntdll/NtOpenProcessToken.c [iso-8859-1] Wed Sep 23 15:14:25
2015
@@ -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(a)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);
+ }
+}
Propchange: trunk/rostests/apitests/ntdll/NtOpenProcessToken.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/ntdll/NtOpenThreadToken.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/NtOpenThre…
==============================================================================
--- trunk/rostests/apitests/ntdll/NtOpenThreadToken.c (added)
+++ trunk/rostests/apitests/ntdll/NtOpenThreadToken.c [iso-8859-1] Wed Sep 23 15:14:25
2015
@@ -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(a)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);
+}
Propchange: trunk/rostests/apitests/ntdll/NtOpenThreadToken.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/rostests/apitests/ntdll/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/testlist.c…
==============================================================================
--- trunk/rostests/apitests/ntdll/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/ntdll/testlist.c [iso-8859-1] Wed Sep 23 15:14:25 2015
@@ -13,6 +13,8 @@
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 @@
{ "NtFreeVirtualMemory", func_NtFreeVirtualMemory },
{ "NtMapViewOfSection", func_NtMapViewOfSection },
{ "NtMutant", func_NtMutant },
+ { "NtOpenProcessToken", func_NtOpenProcessToken },
+ { "NtOpenThreadToken", func_NtOpenThreadToken },
{ "NtProtectVirtualMemory", func_NtProtectVirtualMemory },
{ "NtQueryKey", func_NtQueryKey },
{ "NtQuerySystemEnvironmentValue", func_NtQuerySystemEnvironmentValue },