ReactOS  0.4.14-dev-358-gbef841c
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 OldPrivilegeStatus;
35 
36  /* Open the file */
37  FileHandle = CreateFileW(L"saved_key.dat",
39  0,
40  NULL,
43  NULL);
45  {
46  skip("CreateFileW failed with error: %lu\n", GetLastError());
47  return;
48  }
49 
50  /* Try saving HKEY_LOCAL_MACHINE\Hardware */
51  Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\Machine\\Hardware");
52  if (!NT_SUCCESS(Status))
53  {
54  skip("NtOpenKey failed with status: 0x%08lX\n", Status);
56  return;
57  }
58 
61 
63 
64  /* Set the SeBackupPrivilege */
66  TRUE,
67  FALSE,
68  &OldPrivilegeStatus);
69  if (!NT_SUCCESS(Status))
70  {
71  skip("RtlAdjustPrivilege failed with status: 0x%08lX\n", (ULONG)Status);
73  return;
74  }
75 
76  /* Try saving HKEY_LOCAL_MACHINE\Hardware again */
77  Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\Machine\\Hardware");
78  if (!NT_SUCCESS(Status))
79  {
80  skip("NtOpenKey failed with status: 0x%08lX\n", Status);
81  goto Cleanup;
82  }
83 
86 
88 
89  /* Try saving HKEY_LOCAL_MACHINE */
90  Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\Machine");
91  if (!NT_SUCCESS(Status))
92  {
93  skip("NtOpenKey failed with status: 0x%08lX\n", Status);
94  goto Cleanup;
95  }
96 
99 
101 
102  /* Try saving HKEY_USERS */
103  Status = OpenRegistryKeyHandle(&KeyHandle, KEY_READ, L"\\Registry\\User");
104  if (!NT_SUCCESS(Status))
105  {
106  skip("NtOpenKey failed with status: 0x%08lX\n", Status);
107  goto Cleanup;
108  }
109 
112 
114 
115 Cleanup:
116 
117  /* Restore the SeBackupPrivilege */
119  OldPrivilegeStatus,
120  FALSE,
121  &OldPrivilegeStatus);
122 
123  /* Close the file handle */
125 }
_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:1602
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
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