[NTDLL_APITEST]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 15 Oct 2016 18:33:21 +0000 (18:33 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 15 Oct 2016 18:33:21 +0000 (18:33 +0000)
- Show that NtOpenKey and NtCreateKey accept, but ignore, KEY_WOW64_32KEY and KEY_WOW64_64KEY
CORE-9691

svn path=/trunk/; revision=72974

rostests/apitests/ntdll/CMakeLists.txt
rostests/apitests/ntdll/NtCreateKey.c [new file with mode: 0644]
rostests/apitests/ntdll/testlist.c

index ce42c7b..9f2498d 100644 (file)
@@ -5,6 +5,7 @@ list(APPEND SOURCE
     NtApphelpCacheControl.c
     NtContinue.c
     NtCreateFile.c
     NtApphelpCacheControl.c
     NtContinue.c
     NtCreateFile.c
+    NtCreateKey.c
     NtCreateThread.c
     NtDeleteKey.c
     NtFreeVirtualMemory.c
     NtCreateThread.c
     NtDeleteKey.c
     NtFreeVirtualMemory.c
diff --git a/rostests/apitests/ntdll/NtCreateKey.c b/rostests/apitests/ntdll/NtCreateKey.c
new file mode 100644 (file)
index 0000000..a8ead33
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * PROJECT:         ReactOS API tests
+ * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE:         Test for NtCreateKey
+ * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
+ */
+
+#include <apitest.h>
+
+#include <winreg.h>
+#include <ndk/cmfuncs.h>
+#include <ndk/obfuncs.h>
+
+static
+VOID
+VerifyAccess_(
+    _In_ HANDLE Handle,
+    _In_ ACCESS_MASK ExpectedAccess,
+    _In_ PCSTR File,
+    _In_ INT Line)
+{
+    NTSTATUS Status;
+    OBJECT_BASIC_INFORMATION BasicInfo;
+    ULONG Length;
+
+    Status = NtQueryObject(Handle,
+                           ObjectBasicInformation,
+                           &BasicInfo,
+                           sizeof(BasicInfo),
+                           &Length);
+    ok_(File, Line)(Status == STATUS_SUCCESS, "NtQueryObject returned 0x%lx\n", Status);
+    ok_(File, Line)(BasicInfo.GrantedAccess == ExpectedAccess,
+                    "GrantedAccess is 0x%lx, expected 0x%lx\n",
+                    BasicInfo.GrantedAccess, ExpectedAccess);
+}
+#define VerifyAccess(h, e) VerifyAccess_(h, e, __FILE__, __LINE__)
+
+static
+VOID
+TestCreateOpen_(
+    _In_ ACCESS_MASK DesiredAccess,
+    _In_ ACCESS_MASK ExpectedAccess,
+    _In_ NTSTATUS ExpectedStatus,
+    _In_ PCSTR File,
+    _In_ INT Line)
+{
+    NTSTATUS Status;
+    HANDLE KeyHandle;
+    UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software");
+    OBJECT_ATTRIBUTES ObjectAttributes;
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &KeyName,
+                               OBJ_CASE_INSENSITIVE,
+                               NULL,
+                               NULL);
+    Status = NtCreateKey(&KeyHandle,
+                         DesiredAccess,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         REG_OPTION_NON_VOLATILE,
+                         NULL);
+    ok_(File, Line)(Status == ExpectedStatus,
+                    "NtCreateKey returned 0x%lx, expected 0x%lx\n",
+                    Status, ExpectedStatus);
+    if (NT_SUCCESS(Status))
+    {
+        VerifyAccess_(KeyHandle, ExpectedAccess, File, Line);
+        Status = NtClose(KeyHandle);
+        ok_(File, Line)(Status == STATUS_SUCCESS,
+                        "NtClose from NtCreateKey returned 0x%lx\n",
+                        Status);
+    }
+    else if (NT_SUCCESS(ExpectedStatus))
+    {
+        skip_(File, Line)("NtCreateKey failed, skipping\n");
+    }
+
+    Status = NtOpenKey(&KeyHandle,
+                       DesiredAccess,
+                       &ObjectAttributes);
+    ok_(File, Line)(Status == ExpectedStatus,
+                    "NtOpenKey returned 0x%lx, expected 0x%lx\n",
+                    Status, ExpectedStatus);
+    if (NT_SUCCESS(Status))
+    {
+        VerifyAccess_(KeyHandle, ExpectedAccess, File, Line);
+        Status = NtClose(KeyHandle);
+        ok_(File, Line)(Status == STATUS_SUCCESS,
+                        "NtClose from NtOpenKey returned 0x%lx\n",
+                        Status);
+    }
+    else if (NT_SUCCESS(ExpectedStatus))
+    {
+        skip_(File, Line)("NtOpenKey failed, skipping\n");
+    }
+}
+#define TestCreateOpen(d, ea, es) TestCreateOpen_(d, ea, es, __FILE__, __LINE__)
+
+START_TEST(NtCreateKey)
+{
+    TestCreateOpen(0, 0, STATUS_ACCESS_DENIED);
+    TestCreateOpen(KEY_WOW64_32KEY, 0, STATUS_ACCESS_DENIED);
+    TestCreateOpen(KEY_WOW64_64KEY, 0, STATUS_ACCESS_DENIED);
+    TestCreateOpen(KEY_WOW64_32KEY | KEY_WOW64_64KEY, 0, STATUS_ACCESS_DENIED); // STATUS_INVALID_PARAMETER on Win7
+    TestCreateOpen(READ_CONTROL, READ_CONTROL, STATUS_SUCCESS);
+    TestCreateOpen(READ_CONTROL | KEY_WOW64_32KEY, READ_CONTROL, STATUS_SUCCESS);
+    TestCreateOpen(READ_CONTROL | KEY_WOW64_64KEY, READ_CONTROL, STATUS_SUCCESS);
+    TestCreateOpen(READ_CONTROL | KEY_WOW64_32KEY | KEY_WOW64_64KEY, READ_CONTROL, STATUS_SUCCESS); // STATUS_INVALID_PARAMETER on Win7
+}
index 1b4c547..a3e17a6 100644 (file)
@@ -8,6 +8,7 @@ extern void func_NtAllocateVirtualMemory(void);
 extern void func_NtApphelpCacheControl(void);
 extern void func_NtContinue(void);
 extern void func_NtCreateFile(void);
 extern void func_NtApphelpCacheControl(void);
 extern void func_NtContinue(void);
 extern void func_NtCreateFile(void);
+extern void func_NtCreateKey(void);
 extern void func_NtCreateThread(void);
 extern void func_NtDeleteKey(void);
 extern void func_NtFreeVirtualMemory(void);
 extern void func_NtCreateThread(void);
 extern void func_NtDeleteKey(void);
 extern void func_NtFreeVirtualMemory(void);
@@ -53,6 +54,7 @@ const struct test winetest_testlist[] =
     { "NtApphelpCacheControl",          func_NtApphelpCacheControl },
     { "NtContinue",                     func_NtContinue },
     { "NtCreateFile",                   func_NtCreateFile },
     { "NtApphelpCacheControl",          func_NtApphelpCacheControl },
     { "NtContinue",                     func_NtContinue },
     { "NtCreateFile",                   func_NtCreateFile },
+    { "NtCreateKey",                    func_NtCreateKey },
     { "NtCreateThread",                 func_NtCreateThread },
     { "NtDeleteKey",                    func_NtDeleteKey },
     { "NtFreeVirtualMemory",            func_NtFreeVirtualMemory },
     { "NtCreateThread",                 func_NtCreateThread },
     { "NtDeleteKey",                    func_NtDeleteKey },
     { "NtFreeVirtualMemory",            func_NtFreeVirtualMemory },