ReactOS  0.4.15-dev-3165-gdf6fff7
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 OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
_In_ ACCESS_MASK AccessMask
Definition: exfuncs.h:186
#define NULL
Definition: types.h:112
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)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes

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 
120 Cleanup:
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
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
NTSTATUS NTAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
Definition: ntapi.c:1634
HANDLE FileHandle
Definition: stats.c:38
#define FALSE
Definition: types.h:117
#define GENERIC_WRITE
Definition: nt_native.h:90
unsigned char BOOLEAN
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:135
static const WCHAR Cleanup[]
Definition: register.c:80
#define CREATE_ALWAYS
Definition: disk.h:72
#define ok(value,...)
Definition: atltest.h:57
static NTSTATUS OpenRegistryKeyHandle(PHANDLE KeyHandle, ACCESS_MASK AccessMask, PWCHAR RegistryPath)
Definition: NtSaveKey.c:12
#define NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:600
#define skip(...)
Definition: atltest.h:64
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
unsigned int ULONG
Definition: retypes.h:1
#define SE_BACKUP_PRIVILEGE
Definition: security.c:671
#define STATUS_SUCCESS
Definition: shellext.h:65