ReactOS  0.4.14-dev-323-g6fe6a88
NtCreateKey.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Test for NtCreateKey
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
10 static
11 VOID
14  _In_ ACCESS_MASK ExpectedAccess,
15  _In_ PCSTR File,
16  _In_ INT Line)
17 {
19  OBJECT_BASIC_INFORMATION BasicInfo;
20  ULONG Length;
21 
24  &BasicInfo,
25  sizeof(BasicInfo),
26  &Length);
27  ok_(File, Line)(Status == STATUS_SUCCESS, "NtQueryObject returned 0x%lx\n", Status);
28  ok_(File, Line)(BasicInfo.GrantedAccess == ExpectedAccess,
29  "GrantedAccess is 0x%lx, expected 0x%lx\n",
30  BasicInfo.GrantedAccess, ExpectedAccess);
31 }
32 #define VerifyAccess(h, e) VerifyAccess_(h, e, __FILE__, __LINE__)
33 
34 static
35 VOID
38  _In_ ACCESS_MASK ExpectedAccess,
39  _In_ NTSTATUS ExpectedStatus,
40  _In_ PCSTR File,
41  _In_ INT Line)
42 {
45  UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software");
47 
49  &KeyName,
51  NULL,
52  NULL);
56  0,
57  NULL,
59  NULL);
60  ok_(File, Line)(Status == ExpectedStatus,
61  "NtCreateKey returned 0x%lx, expected 0x%lx\n",
62  Status, ExpectedStatus);
63  if (NT_SUCCESS(Status))
64  {
65  VerifyAccess_(KeyHandle, ExpectedAccess, File, Line);
68  "NtClose from NtCreateKey returned 0x%lx\n",
69  Status);
70  }
71  else if (NT_SUCCESS(ExpectedStatus))
72  {
73  skip_(File, Line)("NtCreateKey failed, skipping\n");
74  }
75 
79  ok_(File, Line)(Status == ExpectedStatus,
80  "NtOpenKey returned 0x%lx, expected 0x%lx\n",
81  Status, ExpectedStatus);
82  if (NT_SUCCESS(Status))
83  {
84  VerifyAccess_(KeyHandle, ExpectedAccess, File, Line);
87  "NtClose from NtOpenKey returned 0x%lx\n",
88  Status);
89  }
90  else if (NT_SUCCESS(ExpectedStatus))
91  {
92  skip_(File, Line)("NtOpenKey failed, skipping\n");
93  }
94 }
95 #define TestCreateOpen(d, ea, es) TestCreateOpen_(d, ea, es, __FILE__, __LINE__)
96 
98 {
102  TestCreateOpen(KEY_WOW64_32KEY | KEY_WOW64_64KEY, 0, STATUS_ACCESS_DENIED); // STATUS_INVALID_PARAMETER on Win7
106  TestCreateOpen(READ_CONTROL | KEY_WOW64_32KEY | KEY_WOW64_64KEY, READ_CONTROL, STATUS_SUCCESS); // STATUS_INVALID_PARAMETER on Win7
107 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
static VOID VerifyAccess_(_In_ HANDLE Handle, _In_ ACCESS_MASK ExpectedAccess, _In_ PCSTR File, _In_ INT Line)
Definition: NtCreateKey.c:12
static VOID TestCreateOpen_(_In_ ACCESS_MASK DesiredAccess, _In_ ACCESS_MASK ExpectedAccess, _In_ NTSTATUS ExpectedStatus, _In_ PCSTR File, _In_ INT Line)
Definition: NtCreateKey.c:36
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
LONG NTSTATUS
Definition: precomp.h:26
int32_t INT
Definition: typedefs.h:56
START_TEST(NtCreateKey)
Definition: NtCreateKey.c:97
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
#define TestCreateOpen(d, ea, es)
Definition: NtCreateKey.c:95
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define READ_CONTROL
Definition: nt_native.h:58
Definition: ncftp.h:79
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
ACCESS_MASK GrantedAccess
Definition: winternl.h:1251
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
const char * PCSTR
Definition: typedefs.h:51
Definition: File.h:15
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define skip_(test, file, line,...)
Definition: kmt_test.h:222
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define ok_(x1, x2)
Definition: atltest.h:61
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14