ReactOS 0.4.16-dev-292-gbbdcc14
NtSaveKey.c File Reference
#include "precomp.h"
Include dependency graph for NtSaveKey.c:

Go to the source code of this file.

Functions

static NTSTATUS OpenRegistryKeyHandle (PHANDLE KeyHandle, ACCESS_MASK AccessMask, PWCHAR RegistryPath)
 
 START_TEST (NtSaveKey)
 

Function Documentation

◆ OpenRegistryKeyHandle()

static NTSTATUS OpenRegistryKeyHandle ( PHANDLE  KeyHandle,
ACCESS_MASK  AccessMask,
PWCHAR  RegistryPath 
)
static

Definition at line 12 of file NtSaveKey.c.

15{
18
21 &KeyName,
23 NULL,
24 NULL);
25
27}
#define NULL
Definition: types.h:112
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
_In_ ACCESS_MASK AccessMask
Definition: exfuncs.h:186
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( NtSaveKey  )

Definition at line 29 of file NtSaveKey.c.

30{
34 BOOLEAN PrivilegeEnabled = FALSE;
35 BOOLEAN OldPrivilegeStatus;
36
37 /* Make sure we don't have backup privileges initially, otherwise WHS testbot fails */
39 ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
40
41 /* Open the file */
42 FileHandle = CreateFileW(L"saved_key.dat",
44 0,
45 NULL,
48 NULL);
50 {
51 skip("CreateFileW failed with error: %lu\n", GetLastError());
52 return;
53 }
54
55 /* Try saving HKEY_LOCAL_MACHINE\Hardware */
56 Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\Machine\\Hardware");
57 if (!NT_SUCCESS(Status))
58 {
59 skip("NtOpenKey failed with status: 0x%08lX\n", Status);
61 return;
62 }
63
66
68
69 /* Set the SeBackupPrivilege */
71 TRUE,
72 FALSE,
73 &OldPrivilegeStatus);
74 if (!NT_SUCCESS(Status))
75 {
76 skip("RtlAdjustPrivilege failed with status: 0x%08lX\n", (ULONG)Status);
78 return;
79 }
80
81 /* Try saving HKEY_LOCAL_MACHINE\Hardware again */
82 Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\Machine\\Hardware");
83 if (!NT_SUCCESS(Status))
84 {
85 skip("NtOpenKey failed with status: 0x%08lX\n", Status);
86 goto Cleanup;
87 }
88
91
93
94 /* Try saving HKEY_LOCAL_MACHINE */
95 Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\Machine");
96 if (!NT_SUCCESS(Status))
97 {
98 skip("NtOpenKey failed with status: 0x%08lX\n", Status);
99 goto Cleanup;
100 }
101
104
106
107 /* Try saving HKEY_USERS */
108 Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\User");
109 if (!NT_SUCCESS(Status))
110 {
111 skip("NtOpenKey failed with status: 0x%08lX\n", Status);
112 goto Cleanup;
113 }
114
117
119
120Cleanup:
121
122 /* Restore the SeBackupPrivilege */
124 OldPrivilegeStatus,
125 FALSE,
126 &OldPrivilegeStatus);
127
128 /* Close the file handle */
130}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
static NTSTATUS OpenRegistryKeyHandle(PHANDLE KeyHandle, ACCESS_MASK AccessMask, PWCHAR RegistryPath)
Definition: NtSaveKey.c:12
unsigned char BOOLEAN
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static const WCHAR Cleanup[]
Definition: register.c:80
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
Status
Definition: gdiplustypes.h:25
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define SE_BACKUP_PRIVILEGE
Definition: security.c:671
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
#define KEY_READ
Definition: nt_native.h:1023
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define GENERIC_WRITE
Definition: nt_native.h:90
NTSTATUS NTAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
Definition: ntapi.c:1634
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
DWORD WINAPI GetLastError(void)
Definition: except.c:1042