2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for NtSaveKey
5 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12 #include <ndk/cmfuncs.h>
13 #include <ndk/obfuncs.h>
14 #include <ndk/setypes.h>
18 OpenRegistryKeyHandle(PHANDLE KeyHandle
,
19 ACCESS_MASK AccessMask
,
22 UNICODE_STRING KeyName
;
23 OBJECT_ATTRIBUTES Attributes
;
25 RtlInitUnicodeString(&KeyName
, RegistryPath
);
26 InitializeObjectAttributes(&Attributes
,
32 return NtOpenKey(KeyHandle
, AccessMask
, &Attributes
);
40 BOOLEAN OldPrivilegeStatus
;
43 FileHandle
= CreateFileW(L
"saved_key.dat",
44 GENERIC_READ
| GENERIC_WRITE
,
48 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_DELETE_ON_CLOSE
,
50 if (FileHandle
== INVALID_HANDLE_VALUE
)
52 skip("CreateFileW failed with error: %lu\n", GetLastError());
56 /* Try saving HKEY_LOCAL_MACHINE\Hardware */
57 Status
= OpenRegistryKeyHandle(&KeyHandle
, KEY_READ
, L
"\\Registry\\Machine\\Hardware");
58 if (!NT_SUCCESS(Status
))
60 skip("NtOpenKey failed with status: 0x%08lX\n", Status
);
65 Status
= NtSaveKey(KeyHandle
, FileHandle
);
66 ok_ntstatus(Status
, STATUS_PRIVILEGE_NOT_HELD
);
70 /* Set the SeBackupPrivilege */
71 Status
= RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE
,
75 if (!NT_SUCCESS(Status
))
77 skip("RtlAdjustPrivilege failed with status: 0x%08lX\n", (ULONG
)Status
);
82 /* Try saving HKEY_LOCAL_MACHINE\Hardware again */
83 Status
= OpenRegistryKeyHandle(&KeyHandle
, KEY_READ
, L
"\\Registry\\Machine\\Hardware");
84 if (!NT_SUCCESS(Status
))
86 skip("NtOpenKey failed with status: 0x%08lX\n", Status
);
90 Status
= NtSaveKey(KeyHandle
, FileHandle
);
91 ok_ntstatus(Status
, STATUS_SUCCESS
);
95 /* Try saving HKEY_LOCAL_MACHINE */
96 Status
= OpenRegistryKeyHandle(&KeyHandle
, KEY_READ
, L
"\\Registry\\Machine");
97 if (!NT_SUCCESS(Status
))
99 skip("NtOpenKey failed with status: 0x%08lX\n", Status
);
103 Status
= NtSaveKey(KeyHandle
, FileHandle
);
104 ok_ntstatus(Status
, STATUS_ACCESS_DENIED
);
108 /* Try saving HKEY_USERS */
109 Status
= OpenRegistryKeyHandle(&KeyHandle
, KEY_READ
, L
"\\Registry\\User");
110 if (!NT_SUCCESS(Status
))
112 skip("NtOpenKey failed with status: 0x%08lX\n", Status
);
116 Status
= NtSaveKey(KeyHandle
, FileHandle
);
117 ok_ntstatus(Status
, STATUS_ACCESS_DENIED
);
123 /* Restore the SeBackupPrivilege */
124 RtlAdjustPrivilege(SE_BACKUP_PRIVILEGE
,
127 &OldPrivilegeStatus
);
129 /* Close the file handle */