ReactOS  0.4.14-dev-843-g15bc263
NtSaveKey.c
Go to the documentation of this file.
1 /*
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>
6  */
7 
8 #include "precomp.h"
9 
10 static
15 {
18 
21  &KeyName,
23  NULL,
24  NULL);
25 
27 }
28 
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 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
_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
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
uint16_t * PWCHAR
Definition: typedefs.h:54
NTSTATUS NTAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
Definition: ntapi.c:1614
HANDLE FileHandle
Definition: stats.c:38
#define GENERIC_WRITE
Definition: nt_native.h:90
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
START_TEST(NtSaveKey)
Definition: NtSaveKey.c:29
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ACCESS_MASK AccessMask
Definition: exfuncs.h:186
#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:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
#define GENERIC_READ
Definition: compat.h:124
static const WCHAR Cleanup[]
Definition: register.c:80
Status
Definition: gdiplustypes.h:24
#define CREATE_ALWAYS
Definition: disk.h:72
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
#define ok(value,...)
Definition: atltest.h:57
static NTSTATUS OpenRegistryKeyHandle(PHANDLE KeyHandle, ACCESS_MASK AccessMask, PWCHAR RegistryPath)
Definition: NtSaveKey.c:12
#define CreateFileW
Definition: compat.h:408
#define skip(...)
Definition: atltest.h:64
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
unsigned int ULONG
Definition: retypes.h:1
#define SE_BACKUP_PRIVILEGE
Definition: security.c:671
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG ACCESS_MASK
Definition: nt_native.h:40