ReactOS  r76032
ntapi.c File Reference
#include "ntoskrnl.h"
#include "debug.h"
Include dependency graph for ntapi.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define PRODUCT_ACTIVATION_VERSION   7749
 

Functions

NTSTATUS NTAPI NtCreateKey (OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
 
NTSTATUS NTAPI NtOpenKey (OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
 
NTSTATUS NTAPI NtDeleteKey (IN HANDLE KeyHandle)
 
NTSTATUS NTAPI NtEnumerateKey (IN HANDLE KeyHandle, IN ULONG Index, IN KEY_INFORMATION_CLASS KeyInformationClass, OUT PVOID KeyInformation, IN ULONG Length, OUT PULONG ResultLength)
 
NTSTATUS NTAPI NtEnumerateValueKey (IN HANDLE KeyHandle, IN ULONG Index, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, OUT PVOID KeyValueInformation, IN ULONG Length, OUT PULONG ResultLength)
 
NTSTATUS NTAPI NtQueryKey (IN HANDLE KeyHandle, IN KEY_INFORMATION_CLASS KeyInformationClass, OUT PVOID KeyInformation, IN ULONG Length, OUT PULONG ResultLength)
 
NTSTATUS NTAPI NtQueryValueKey (IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, OUT PVOID KeyValueInformation, IN ULONG Length, OUT PULONG ResultLength)
 
NTSTATUS NTAPI NtSetValueKey (IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
 
NTSTATUS NTAPI NtDeleteValueKey (IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName)
 
NTSTATUS NTAPI NtFlushKey (IN HANDLE KeyHandle)
 
NTSTATUS NTAPI NtLoadKey (IN POBJECT_ATTRIBUTES KeyObjectAttributes, IN POBJECT_ATTRIBUTES FileObjectAttributes)
 
NTSTATUS NTAPI NtLoadKey2 (IN POBJECT_ATTRIBUTES KeyObjectAttributes, IN POBJECT_ATTRIBUTES FileObjectAttributes, IN ULONG Flags)
 
NTSTATUS NTAPI NtLoadKeyEx (IN POBJECT_ATTRIBUTES TargetKey, IN POBJECT_ATTRIBUTES SourceFile, IN ULONG Flags, IN HANDLE TrustClassKey)
 
NTSTATUS NTAPI NtNotifyChangeKey (IN HANDLE KeyHandle, IN HANDLE Event, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG CompletionFilter, IN BOOLEAN WatchTree, OUT PVOID Buffer, IN ULONG Length, IN BOOLEAN Asynchronous)
 
NTSTATUS NTAPI NtInitializeRegistry (IN USHORT Flag)
 
NTSTATUS NTAPI NtCompactKeys (IN ULONG Count, IN PHANDLE KeyArray)
 
NTSTATUS NTAPI NtCompressKey (IN HANDLE Key)
 
NTSTATUS NTAPI NtLockProductActivationKeys (IN PULONG pPrivateVer, IN PULONG pSafeMode)
 
NTSTATUS NTAPI NtLockRegistryKey (IN HANDLE KeyHandle)
 
NTSTATUS NTAPI NtNotifyChangeMultipleKeys (IN HANDLE MasterKeyHandle, IN ULONG Count, IN POBJECT_ATTRIBUTES SlaveObjects, IN HANDLE Event, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG CompletionFilter, IN BOOLEAN WatchTree, OUT PVOID Buffer, IN ULONG Length, IN BOOLEAN Asynchronous)
 
NTSTATUS NTAPI NtQueryMultipleValueKey (IN HANDLE KeyHandle, IN OUT PKEY_VALUE_ENTRY ValueList, IN ULONG NumberOfValues, OUT PVOID Buffer, IN OUT PULONG Length, OUT PULONG ReturnLength)
 
NTSTATUS NTAPI NtQueryOpenSubKeys (IN POBJECT_ATTRIBUTES TargetKey, OUT PULONG HandleCount)
 
NTSTATUS NTAPI NtQueryOpenSubKeysEx (IN POBJECT_ATTRIBUTES TargetKey, IN ULONG BufferLength, IN PVOID Buffer, IN PULONG RequiredSize)
 
NTSTATUS NTAPI NtRenameKey (IN HANDLE KeyHandle, IN PUNICODE_STRING ReplacementName)
 
NTSTATUS NTAPI NtReplaceKey (IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE Key, IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
 
NTSTATUS NTAPI NtRestoreKey (IN HANDLE KeyHandle, IN HANDLE FileHandle, IN ULONG RestoreFlags)
 
NTSTATUS NTAPI NtSaveKey (IN HANDLE KeyHandle, IN HANDLE FileHandle)
 
NTSTATUS NTAPI NtSaveKeyEx (IN HANDLE KeyHandle, IN HANDLE FileHandle, IN ULONG Flags)
 
NTSTATUS NTAPI NtSaveMergedKeys (IN HANDLE HighPrecedenceKeyHandle, IN HANDLE LowPrecedenceKeyHandle, IN HANDLE FileHandle)
 
NTSTATUS NTAPI NtSetInformationKey (IN HANDLE KeyHandle, IN KEY_SET_INFORMATION_CLASS KeyInformationClass, IN PVOID KeyInformation, IN ULONG KeyInformationLength)
 
NTSTATUS NTAPI NtUnloadKey (IN POBJECT_ATTRIBUTES KeyObjectAttributes)
 
NTSTATUS NTAPI NtUnloadKey2 (IN POBJECT_ATTRIBUTES TargetKey, IN ULONG Flags)
 
NTSTATUS NTAPI NtUnloadKeyEx (IN POBJECT_ATTRIBUTES TargetKey, IN HANDLE Event)
 

Variables

BOOLEAN CmBootAcceptFirstTime = TRUE
 
BOOLEAN CmFirstTime = TRUE
 
ULONG InitSafeBootMode
 

Macro Definition Documentation

#define NDEBUG

Definition at line 13 of file ntapi.c.

#define PRODUCT_ACTIVATION_VERSION   7749

Definition at line 1027 of file ntapi.c.

Referenced by NtLockProductActivationKeys().

Function Documentation

NTSTATUS NTAPI NtCompactKeys ( IN ULONG  Count,
IN PHANDLE  KeyArray 
)

Definition at line 1011 of file ntapi.c.

1013 {
1014  UNIMPLEMENTED;
1015  return STATUS_NOT_IMPLEMENTED;
1016 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtCompressKey ( IN HANDLE  Key)

Definition at line 1020 of file ntapi.c.

1021 {
1022  UNIMPLEMENTED;
1023  return STATUS_NOT_IMPLEMENTED;
1024 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtCreateKey ( OUT PHANDLE  KeyHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN ULONG  TitleIndex,
IN PUNICODE_STRING Class  OPTIONAL,
IN ULONG  CreateOptions,
OUT PULONG Disposition  OPTIONAL 
)

Definition at line 24 of file ntapi.c.

Referenced by AddHotkeySettings(), AddKbLayoutsToRegistry(), BasepMoveFileDelayed(), CmInitSystem1(), CmpCreateControlSet(), CmpCreateHardwareProfile(), CmpInitializeHardwareConfiguration(), CmpInitializeMachineDependentConfiguration(), CmpInitializeRegistryNode(), CmpSetVersionData(), create_key(), create_registry_key(), CreateKeyTest(), CreateNestedKey(), CreateRegistryKeyHandle(), CreateRegKey(), EventThread(), InitFunctionPtrs(), InstallDriver(), LsapCreateDatabaseKeys(), LsapCreateDbObject(), LsapSetObjectAttribute(), RegpCopyTree(), SetMountedDeviceValue(), SetUserGeoID(), SetValueTest1(), SetValueTest2(), START_TEST(), test2(), test3(), test6(), test7(), Test_KeyFullInformation(), and TestCreateOpen_().

31 {
34  CM_PARSE_CONTEXT ParseContext = {0};
35  HANDLE Handle;
36  PAGED_CODE();
37 
38  DPRINT("NtCreateKey(Path: %wZ, Root %x, Access: %x, CreateOptions %x)\n",
39  ObjectAttributes->ObjectName, ObjectAttributes->RootDirectory,
41 
42  /* Ignore the WOW64 flag, it's not valid in the kernel */
44 
45  /* Check for user-mode caller */
46  if (PreviousMode != KernelMode)
47  {
48  /* Prepare to probe parameters */
49  _SEH2_TRY
50  {
51  /* Check if we have a class */
52  if (Class)
53  {
54  /* Probe it */
55  ParseContext.Class = ProbeForReadUnicodeString(Class);
56  ProbeForRead(ParseContext.Class.Buffer,
57  ParseContext.Class.Length,
58  sizeof(WCHAR));
59  }
60 
61  /* Probe the key handle */
63  *KeyHandle = NULL;
64 
65  /* Probe object attributes */
67  sizeof(OBJECT_ATTRIBUTES),
68  sizeof(ULONG));
69 
70  if (Disposition)
72  }
74  {
75  /* Return the exception code */
77  }
78  _SEH2_END;
79  }
80  else
81  {
82  /* Save the class directly */
83  if (Class) ParseContext.Class = *Class;
84  }
85 
86  /* Setup the parse context */
87  ParseContext.CreateOperation = TRUE;
88  ParseContext.CreateOptions = CreateOptions;
89 
90  /* Do the create */
93  PreviousMode,
94  NULL,
96  &ParseContext,
97  &Handle);
98 
99  _SEH2_TRY
100  {
101  /* Return data to user */
102  if (NT_SUCCESS(Status)) *KeyHandle = Handle;
103  if (Disposition) *Disposition = ParseContext.Disposition;
104  }
106  {
107  /* Get the status */
108  Status = _SEH2_GetExceptionCode();
109  }
110  _SEH2_END;
111 
112  DPRINT("Returning handle %x, Status %x.\n", Handle, Status);
113 
114  /* Return status */
115  return Status;
116 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2522
static const WCHAR Class[]
Definition: cfgmgr.c:31
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
#define KEY_WOW64_RES
Definition: cmtypes.h:47
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
__wchar_t WCHAR
Definition: xmlstorage.h:180
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK DesiredAccess
Definition: creport.c:28
ULONG CreateOptions
Definition: cm.h:484
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
ULONG Disposition
Definition: cm.h:485
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
UNICODE_STRING Class
Definition: cm.h:483
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG CreateOptions
Definition: fltkernel.h:1230
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:52
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
unsigned int ULONG
Definition: retypes.h:1
#define CmpKeyObjectType
Definition: ObTypes.c:132
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
BOOLEAN CreateOperation
Definition: cm.h:489
NTSTATUS NTAPI NtDeleteKey ( IN HANDLE  KeyHandle)

Definition at line 192 of file ntapi.c.

Referenced by DeleteKeyTest(), DestroyProtoHive(), do_reg_operation(), InitFunctionPtrs(), LsapRegDeleteKey(), LsapRegDeleteSubKey(), RegDeleteKeyExW(), SampRegDeleteKey(), START_TEST(), test2(), test3(), test7(), and Test_KeyFullInformation().

193 {
194  PCM_KEY_BODY KeyObject;
196  REG_DELETE_KEY_INFORMATION DeleteKeyInfo;
197  REG_POST_OPERATION_INFORMATION PostOperationInfo;
198  PAGED_CODE();
199  DPRINT("NtDeleteKey(KH 0x%p)\n", KeyHandle);
200 
201  /* Verify that the handle is valid and is a registry key */
203  DELETE,
206  (PVOID*)&KeyObject,
207  NULL);
208  if (!NT_SUCCESS(Status)) return Status;
209 
210  /* Setup the callback */
211  PostOperationInfo.Object = (PVOID)KeyObject;
212  DeleteKeyInfo.Object = (PVOID)KeyObject;
213  Status = CmiCallRegisteredCallbacks(RegNtPreDeleteKey, &DeleteKeyInfo);
214  if (NT_SUCCESS(Status))
215  {
216  /* Check if we are read-only */
217  if ((KeyObject->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY) ||
218  (KeyObject->KeyControlBlock->ParentKcb->ExtFlags & CM_KCB_READ_ONLY_KEY))
219  {
220  /* Fail */
221  Status = STATUS_ACCESS_DENIED;
222  }
223  else
224  {
225  /* Call the internal API */
226  Status = CmDeleteKey(KeyObject);
227  }
228 
229  /* Do post callback */
230  PostOperationInfo.Status = Status;
231  CmiCallRegisteredCallbacks(RegNtPostDeleteKey, &PostOperationInfo);
232  }
233 
234  /* Dereference the object */
235  ObDereferenceObject(KeyObject);
236  return Status;
237 }
DWORD *typedef PVOID
Definition: winlogon.h:52
Definition: cmtypes.h:856
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define CM_KCB_READ_ONLY_KEY
Definition: cm.h:61
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
NTSTATUS Status
Definition: cmtypes.h:858
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define PAGED_CODE()
Definition: video.h:57
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
NTSTATUS NTAPI CmDeleteKey(IN PCM_KEY_BODY KeyBody)
Definition: cmapi.c:1824
PVOID Object
Definition: cmtypes.h:857
#define DELETE
Definition: nt_native.h:57
NTSTATUS NTAPI NtDeleteValueKey ( IN HANDLE  KeyHandle,
IN PUNICODE_STRING  ValueName 
)

Definition at line 744 of file ntapi.c.

Referenced by CmpSetVersionData(), DeleteValueTest(), InitFunctionPtrs(), LsapRegDeleteValue(), RegDeleteKeyValueW(), RegDeleteValueA(), RegDeleteValueW(), RtlApplyRXact(), RtlInitializeRXact(), SampRegDeleteValue(), SdbDeletePermLayerKeys(), SmpLoadDataFromRegistry(), START_TEST(), and test7().

746 {
747  PCM_KEY_BODY KeyObject;
749  REG_DELETE_VALUE_KEY_INFORMATION DeleteValueKeyInfo;
750  REG_POST_OPERATION_INFORMATION PostOperationInfo;
752  UNICODE_STRING ValueNameCopy = *ValueName;
753  PAGED_CODE();
754 
755  /* Verify that the handle is valid and is a registry key */
759  PreviousMode,
760  (PVOID *)&KeyObject,
761  NULL);
762  if (!NT_SUCCESS(Status)) return Status;
763 
764  /* Don't touch read-only keys */
765  if (KeyObject->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY)
766  {
767  /* Fail */
768  ObDereferenceObject(KeyObject);
769  return STATUS_ACCESS_DENIED;
770  }
771 
772  /* Make sure the name is aligned properly */
773  if ((ValueNameCopy.Length & (sizeof(WCHAR) - 1)))
774  {
775  /* It isn't, so we'll fail */
776  ObDereferenceObject(KeyObject);
778  }
779 
780  /* Do the callback */
781  DeleteValueKeyInfo.Object = (PVOID)KeyObject;
782  DeleteValueKeyInfo.ValueName = ValueName;
784  &DeleteValueKeyInfo);
785  if (NT_SUCCESS(Status))
786  {
787  /* Call the internal API */
788  Status = CmDeleteValueKey(KeyObject->KeyControlBlock, ValueNameCopy);
789 
790  /* Do the post callback */
791  PostOperationInfo.Object = (PVOID)KeyObject;
792  PostOperationInfo.Status = Status;
794  &PostOperationInfo);
795  }
796 
797  /* Dereference the key body */
798  ObDereferenceObject(KeyObject);
799  return Status;
800 }
DWORD *typedef PVOID
Definition: winlogon.h:52
Definition: cmtypes.h:856
#define KEY_SET_VALUE
Definition: nt_native.h:1017
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSTATUS NTAPI CmDeleteValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN UNICODE_STRING ValueName)
Definition: cmapi.c:916
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define CM_KCB_READ_ONLY_KEY
Definition: cm.h:61
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
smooth NULL
Definition: ftsmooth.c:557
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS Status
Definition: cmtypes.h:858
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
PVOID Object
Definition: cmtypes.h:857
NTSTATUS NTAPI NtEnumerateKey ( IN HANDLE  KeyHandle,
IN ULONG  Index,
IN KEY_INFORMATION_CLASS  KeyInformationClass,
OUT PVOID  KeyInformation,
IN ULONG  Length,
OUT PULONG  ResultLength 
)

Definition at line 241 of file ntapi.c.

247 {
250  PCM_KEY_BODY KeyObject;
251  REG_ENUMERATE_KEY_INFORMATION EnumerateKeyInfo;
252  REG_POST_OPERATION_INFORMATION PostOperationInfo;
253  PAGED_CODE();
254  DPRINT("NtEnumerateKey() KH 0x%p, Index 0x%x, KIC %d, Length %lu\n",
256 
257  /* Reject classes we don't know about */
261  {
262  /* Fail */
264  }
265 
266  /* Verify that the handle is valid and is a registry key */
271  (PVOID*)&KeyObject,
272  NULL);
273  if (!NT_SUCCESS(Status)) return Status;
274 
275  if (PreviousMode != KernelMode)
276  {
277  _SEH2_TRY
278  {
280  ProbeForWrite(KeyInformation,
281  Length,
282  sizeof(ULONG));
283  }
285  {
286  /* Dereference and return status */
287  ObDereferenceObject(KeyObject);
289  }
290  _SEH2_END;
291  }
292 
293  /* Setup the callback */
294  PostOperationInfo.Object = (PVOID)KeyObject;
295  EnumerateKeyInfo.Object = (PVOID)KeyObject;
296  EnumerateKeyInfo.Index = Index;
297  EnumerateKeyInfo.KeyInformationClass = KeyInformationClass;
298  EnumerateKeyInfo.Length = Length;
299  EnumerateKeyInfo.ResultLength = ResultLength;
300 
301  /* Do the callback */
302  Status = CmiCallRegisteredCallbacks(RegNtPreEnumerateKey, &EnumerateKeyInfo);
303  if (NT_SUCCESS(Status))
304  {
305  /* Call the internal API */
306  Status = CmEnumerateKey(KeyObject->KeyControlBlock,
307  Index,
309  KeyInformation,
310  Length,
311  ResultLength);
312 
313  /* Do the post callback */
314  PostOperationInfo.Status = Status;
316  }
317 
318  /* Dereference and return status */
319  ObDereferenceObject(KeyObject);
320  DPRINT("Returning status %x.\n", Status);
321  return Status;
322 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
DWORD *typedef PVOID
Definition: winlogon.h:52
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
Definition: cmtypes.h:856
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
_In_ ULONG _In_ KEY_INFORMATION_CLASS KeyInformationClass
Definition: zwfuncs.h:166
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
_Must_inspect_result_ _In_ ULONG Index
Definition: fltkernel.h:1824
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
KEY_INFORMATION_CLASS KeyInformationClass
Definition: cmtypes.h:742
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS Status
Definition: cmtypes.h:858
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
unsigned int ULONG
Definition: retypes.h:1
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NTSTATUS NTAPI CmEnumerateKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN ULONG Index, IN KEY_INFORMATION_CLASS KeyInformationClass, IN PVOID KeyInformation, IN ULONG Length, IN PULONG ResultLength)
Definition: cmapi.c:1735
PVOID Object
Definition: cmtypes.h:857
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
NTSTATUS NTAPI NtEnumerateValueKey ( IN HANDLE  KeyHandle,
IN ULONG  Index,
IN KEY_VALUE_INFORMATION_CLASS  KeyValueInformationClass,
OUT PVOID  KeyValueInformation,
IN ULONG  Length,
OUT PULONG  ResultLength 
)

Definition at line 326 of file ntapi.c.

Referenced by EnumerateValueTest(), InitializeFmIfsOnce(), NLS_RegEnumValue(), RegEnumValueW(), RegpCopyTree(), test1(), test2(), test3(), and test9().

332 {
335  PCM_KEY_BODY KeyObject;
336  REG_ENUMERATE_VALUE_KEY_INFORMATION EnumerateValueKeyInfo;
337  REG_POST_OPERATION_INFORMATION PostOperationInfo;
338  PAGED_CODE();
339  DPRINT("NtEnumerateValueKey() KH 0x%p, Index 0x%x, KVIC %d, Length %lu\n",
341 
342  /* Reject classes we don't know about */
346  {
347  /* Fail */
349  }
350 
351  /* Verify that the handle is valid and is a registry key */
356  (PVOID*)&KeyObject,
357  NULL);
358  if (!NT_SUCCESS(Status)) return Status;
359 
360  if (PreviousMode != KernelMode)
361  {
362  _SEH2_TRY
363  {
365  ProbeForWrite(KeyValueInformation,
366  Length,
367  sizeof(ULONG));
368  }
370  {
371  /* Dereference and return status */
372  ObDereferenceObject(KeyObject);
374  }
375  _SEH2_END;
376  }
377 
378  /* Setup the callback */
379  PostOperationInfo.Object = (PVOID)KeyObject;
380  EnumerateValueKeyInfo.Object = (PVOID)KeyObject;
381  EnumerateValueKeyInfo.Index = Index;
382  EnumerateValueKeyInfo.KeyValueInformationClass = KeyValueInformationClass;
383  EnumerateValueKeyInfo.KeyValueInformation = KeyValueInformation;
384  EnumerateValueKeyInfo.Length = Length;
385  EnumerateValueKeyInfo.ResultLength = ResultLength;
386 
387  /* Do the callback */
389  &EnumerateValueKeyInfo);
390  if (NT_SUCCESS(Status))
391  {
392  /* Call the internal API */
393  Status = CmEnumerateValueKey(KeyObject->KeyControlBlock,
394  Index,
396  KeyValueInformation,
397  Length,
398  ResultLength);
399 
400  /* Do the post callback */
401  PostOperationInfo.Status = Status;
403  }
404 
405  ObDereferenceObject(KeyObject);
406  return Status;
407 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
DWORD *typedef PVOID
Definition: winlogon.h:52
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
Definition: cmtypes.h:856
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI CmEnumerateValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN ULONG Index, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
Definition: cmapi.c:1192
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
_Must_inspect_result_ _In_ ULONG Index
Definition: fltkernel.h:1824
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS Status
Definition: cmtypes.h:858
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define _SEH2_TRY
Definition: pseh2_64.h:5
unsigned int ULONG
Definition: retypes.h:1
KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmtypes.h:754
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
PVOID Object
Definition: cmtypes.h:857
_In_ ULONG _In_ KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmfuncs.h:93
NTSTATUS NTAPI NtFlushKey ( IN HANDLE  KeyHandle)

Definition at line 804 of file ntapi.c.

Referenced by CreateProtoHive(), InitFunctionPtrs(), RegFlushKey(), RtlApplyRXact(), SetComputerNameToRegistry(), START_TEST(), and test5().

805 {
807  PCM_KEY_BODY KeyObject;
808  PAGED_CODE();
809 
810  /* Get the key object */
812  0,
815  (PVOID*)&KeyObject,
816  NULL);
817  if (!NT_SUCCESS(Status)) return Status;
818 
819  /* Lock the registry */
820  CmpLockRegistry();
821 
822  /* Lock the KCB */
824 
825  /* Make sure KCB isn't deleted */
826  if (KeyObject->KeyControlBlock->Delete)
827  {
828  /* Fail */
829  Status = STATUS_KEY_DELETED;
830  }
831  else
832  {
833  /* Call the internal API */
834  Status = CmFlushKey(KeyObject->KeyControlBlock, FALSE);
835  }
836 
837  /* Release the locks */
840 
841  /* Dereference the object and return status */
842  ObDereferenceObject(KeyObject);
843  return Status;
844 }
DWORD *typedef PVOID
Definition: winlogon.h:52
NTSTATUS NTAPI CmFlushKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN BOOLEAN ExclusiveLock)
Definition: cmapi.c:1938
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define CmpAcquireKcbLockShared(k)
Definition: cm_x.h:121
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
#define STATUS_KEY_DELETED
Definition: ntstatus.h:599
FORCEINLINE VOID CmpReleaseKcbLock(PCM_KEY_CONTROL_BLOCK Kcb)
Definition: cm_x.h:169
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID NTAPI CmpUnlockRegistry(VOID)
Definition: cmsysini.c:2016
#define PAGED_CODE()
Definition: video.h:57
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define CmpKeyObjectType
Definition: ObTypes.c:132
VOID NTAPI CmpLockRegistry(VOID)
Definition: cmsysini.c:1930
NTSTATUS NTAPI NtInitializeRegistry ( IN USHORT  Flag)

Definition at line 946 of file ntapi.c.

Referenced by RegistryPage(), SmpLoadDataFromRegistry(), and WinMain().

947 {
948  BOOLEAN SetupBoot;
950  PAGED_CODE();
951 
952  /* Always do this as kernel mode */
953  if (KeGetPreviousMode() == UserMode) return ZwInitializeRegistry(Flag);
954 
955  /* Enough of the system has booted by now */
956  Ki386PerfEnd();
957 
958  /* Validate flag */
959  if (Flag > CM_BOOT_FLAG_MAX) return STATUS_INVALID_PARAMETER;
960 
961  /* Check if boot was accepted */
962  if ((Flag >= CM_BOOT_FLAG_ACCEPTED) && (Flag <= CM_BOOT_FLAG_MAX))
963  {
964  /* Only allow once */
967 
968  /* Get the control set accepted */
969  Flag -= CM_BOOT_FLAG_ACCEPTED;
970  if (Flag)
971  {
972  /* FIXME: Save the last known good boot */
973  //Status = CmpSaveBootControlSet(Flag);
974 
975  /* Notify HAL */
976  HalEndOfBoot();
977 
978  /* Enable lazy flush */
980  CmpLazyFlush();
981  return Status;
982  }
983 
984  /* Otherwise, invalid boot */
986  }
987 
988  /* Check if this was a setup boot */
989  SetupBoot = (Flag == CM_BOOT_FLAG_SETUP ? TRUE : FALSE);
990 
991  /* Make sure we're only called once */
992  if (!CmFirstTime) return STATUS_ACCESS_DENIED;
993  CmFirstTime = FALSE;
994 
995  /* Acquire registry lock */
996  //CmpLockRegistryExclusive();
997 
998  /* Initialize the hives and lazy flusher */
999  CmpCmdInit(SetupBoot);
1000 
1001  /* Save version data */
1003 
1004  /* Release the registry lock */
1005  //CmpUnlockRegistry();
1006  return STATUS_SUCCESS;
1007 }
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
return STATUS_SUCCESS
Definition: btrfs.c:2664
#define CM_BOOT_FLAG_ACCEPTED
Definition: cmtypes.h:126
#define KeGetPreviousMode()
Definition: ketypes.h:1081
BOOLEAN CmpHoldLazyFlush
Definition: cmlazy.c:24
#define FALSE
Definition: types.h:117
#define HalEndOfBoot
Definition: haltypes.h:296
FORCEINLINE VOID Ki386PerfEnd(VOID)
Definition: ke.h:874
unsigned char BOOLEAN
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define PAGED_CODE()
Definition: video.h:57
#define CM_BOOT_FLAG_MAX
Definition: cmtypes.h:127
BOOLEAN CmFirstTime
Definition: ntapi.c:17
NTSYSAPI NTSTATUS NTAPI ZwInitializeRegistry(_In_ USHORT Flag)
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
BOOLEAN CmBootAcceptFirstTime
Definition: ntapi.c:16
VOID NTAPI CmpLazyFlush(VOID)
Definition: cmlazy.c:158
VOID NTAPI CmpSetVersionData(VOID)
Definition: cmsysini.c:2139
#define CM_BOOT_FLAG_SETUP
Definition: cmtypes.h:125
VOID NTAPI CmpCmdInit(IN BOOLEAN SetupBoot)
Definition: cmlazy.c:234
NTSTATUS NTAPI NtLoadKey ( IN POBJECT_ATTRIBUTES  KeyObjectAttributes,
IN POBJECT_ATTRIBUTES  FileObjectAttributes 
)

Definition at line 848 of file ntapi.c.

Referenced by ConnectRegistry(), RegLoadKeyW(), and test8().

850 {
851  /* Call the newer API */
852  return NtLoadKeyEx(KeyObjectAttributes, FileObjectAttributes, 0, NULL);
853 }
NTSTATUS NTAPI NtLoadKeyEx(IN POBJECT_ATTRIBUTES TargetKey, IN POBJECT_ATTRIBUTES SourceFile, IN ULONG Flags, IN HANDLE TrustClassKey)
Definition: ntapi.c:867
smooth NULL
Definition: ftsmooth.c:557
NTSTATUS NTAPI NtLoadKey2 ( IN POBJECT_ATTRIBUTES  KeyObjectAttributes,
IN POBJECT_ATTRIBUTES  FileObjectAttributes,
IN ULONG  Flags 
)

Definition at line 857 of file ntapi.c.

860 {
861  /* Call the newer API */
862  return NtLoadKeyEx(KeyObjectAttributes, FileObjectAttributes, Flags, NULL);
863 }
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI NtLoadKeyEx(IN POBJECT_ATTRIBUTES TargetKey, IN POBJECT_ATTRIBUTES SourceFile, IN ULONG Flags, IN HANDLE TrustClassKey)
Definition: ntapi.c:867
smooth NULL
Definition: ftsmooth.c:557
NTSTATUS NTAPI NtLoadKeyEx ( IN POBJECT_ATTRIBUTES  TargetKey,
IN POBJECT_ATTRIBUTES  SourceFile,
IN ULONG  Flags,
IN HANDLE  TrustClassKey 
)

Definition at line 867 of file ntapi.c.

Referenced by NtLoadKey(), and NtLoadKey2().

871 {
874  PCM_KEY_BODY KeyBody = NULL;
875  PAGED_CODE();
876 
877  /* Validate flags */
879 
880  /* Validate privilege */
881  if (!SeSinglePrivilegeCheck(SeRestorePrivilege, PreviousMode))
882  {
883  /* Fail */
884  DPRINT1("Restore Privilege missing!\n");
886  }
887 
888  /* Block APCs */
890 
891  /* Check if we have a trust class */
892  if (TrustClassKey)
893  {
894  /* Reference it */
895  Status = ObReferenceObjectByHandle(TrustClassKey,
896  0,
898  PreviousMode,
899  (PVOID *)&KeyBody,
900  NULL);
901  }
902 
903  /* Call the internal API */
904  Status = CmLoadKey(TargetKey, SourceFile, Flags, KeyBody);
905 
906  /* Dereference the trust key, if any */
907  if (KeyBody) ObDereferenceObject(KeyBody);
908 
909  /* Bring back APCs */
911 
912  /* Return status */
913  return Status;
914 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
NTSTATUS NTAPI CmLoadKey(IN POBJECT_ATTRIBUTES TargetKey, IN POBJECT_ATTRIBUTES SourceFile, IN ULONG Flags, IN PCM_KEY_BODY KeyBody)
Definition: cmapi.c:1998
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
smooth NULL
Definition: ftsmooth.c:557
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
const LUID SeRestorePrivilege
Definition: priv.c:39
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define REG_NO_LAZY_FLUSH
Definition: nt_native.h:1093
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define DPRINT1
Definition: precomp.h:8
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS NTAPI NtLockProductActivationKeys ( IN PULONG  pPrivateVer,
IN PULONG  pSafeMode 
)

Definition at line 1031 of file ntapi.c.

1033 {
1035 
1036  PreviousMode = ExGetPreviousMode();
1037  _SEH2_TRY
1038  {
1039  /* Check if the caller asked for the version */
1040  if (pPrivateVer != NULL)
1041  {
1042  /* For user mode, probe it */
1043  if (PreviousMode != KernelMode)
1044  {
1045  ProbeForRead(pPrivateVer, sizeof(ULONG), sizeof(ULONG));
1046  }
1047 
1048  /* Return the expected version */
1049  *pPrivateVer = PRODUCT_ACTIVATION_VERSION;
1050  }
1051 
1052  /* Check if the caller asked for safe mode mode state */
1053  if (pSafeMode != NULL)
1054  {
1055  /* For user mode, probe it */
1056  if (PreviousMode != KernelMode)
1057  {
1058  ProbeForRead(pSafeMode, sizeof(ULONG), sizeof(ULONG));
1059  }
1060 
1061  /* Return the safe boot mode state */
1062  *pSafeMode = InitSafeBootMode;
1063  }
1064  }
1066  {
1068  }
1069  _SEH2_END;
1070 
1071  return STATUS_SUCCESS;
1072 }
#define PRODUCT_ACTIVATION_VERSION
Definition: ntapi.c:1027
return STATUS_SUCCESS
Definition: btrfs.c:2664
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define _SEH2_TRY
Definition: pseh2_64.h:5
ULONG InitSafeBootMode
Definition: init.c:68
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NTSTATUS NTAPI NtLockRegistryKey ( IN HANDLE  KeyHandle)

Definition at line 1076 of file ntapi.c.

1077 {
1078  UNIMPLEMENTED;
1079  return STATUS_NOT_IMPLEMENTED;
1080 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtNotifyChangeKey ( IN HANDLE  KeyHandle,
IN HANDLE  Event,
IN PIO_APC_ROUTINE ApcRoutine  OPTIONAL,
IN PVOID ApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN ULONG  CompletionFilter,
IN BOOLEAN  WatchTree,
OUT PVOID  Buffer,
IN ULONG  Length,
IN BOOLEAN  Asynchronous 
)

Definition at line 918 of file ntapi.c.

Referenced by InitFunctionPtrs(), and RegNotifyChangeKeyValue().

928 {
929  /* Call the newer API */
931  0,
932  NULL,
933  Event,
934  ApcRoutine,
935  ApcContext,
938  WatchTree,
939  Buffer,
940  Length,
941  Asynchronous);
942 }
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN WatchTree
Definition: fltkernel.h:2239
NTSTATUS NTAPI NtNotifyChangeMultipleKeys(IN HANDLE MasterKeyHandle, IN ULONG Count, IN POBJECT_ATTRIBUTES SlaveObjects, IN HANDLE Event, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG CompletionFilter, IN BOOLEAN WatchTree, OUT PVOID Buffer, IN ULONG Length, IN BOOLEAN Asynchronous)
Definition: ntapi.c:1084
_In_ SYSTEM_POWER_STATE _In_ ULONG _In_ BOOLEAN Asynchronous
Definition: ntpoapi.h:296
smooth NULL
Definition: ftsmooth.c:557
Definition: bufpool.h:45
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:719
VOID UINTN Length
Definition: acefiex.h:744
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN _In_ BOOLEAN _In_ ULONG CompletionFilter
Definition: fltkernel.h:2239
NTSTATUS NTAPI NtNotifyChangeMultipleKeys ( IN HANDLE  MasterKeyHandle,
IN ULONG  Count,
IN POBJECT_ATTRIBUTES  SlaveObjects,
IN HANDLE  Event,
IN PIO_APC_ROUTINE ApcRoutine  OPTIONAL,
IN PVOID ApcContext  OPTIONAL,
OUT PIO_STATUS_BLOCK  IoStatusBlock,
IN ULONG  CompletionFilter,
IN BOOLEAN  WatchTree,
OUT PVOID  Buffer,
IN ULONG  Length,
IN BOOLEAN  Asynchronous 
)

Definition at line 1084 of file ntapi.c.

Referenced by NtNotifyChangeKey().

1096 {
1097  UNIMPLEMENTED;
1098  return STATUS_NOT_IMPLEMENTED;
1099 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtOpenKey ( OUT PHANDLE  KeyHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes 
)

Definition at line 120 of file ntapi.c.

Referenced by AddCodepageToRegistry(), AddFontsSettingsToRegistry(), BaseComputeProcessDllPath(), BasepIsProcessAllowed(), BaseSrvIsVdmAllowed(), CmGetSystemDriverList(), CmpCreateControlSet(), CmpInitializeMachineDependentConfiguration(), CmpSetSystemValues(), CreateBaseAcls(), DeleteKeyTest(), DeleteValueTest(), do_enumeratekey(), DumpRegistryData(), EnumerateKeyTest(), EnumerateValueTest(), EventThread(), GetComputerIdentifier(), GetComputerNameFromRegistry(), GetCPFileNameFromRegistry(), GetDisplayIdentifier(), GetDllList(), GetDosDevicesProtection(), GetTimeouts(), InitFunctionPtrs(), InitializeFmIfsOnce(), InstallDevice(), IsAcpiComputer(), IsShimInfrastructureDisabled(), LsapCreateDbObject(), LsapGetObjectAttribute(), LsapOpenDbObject(), LsapRegDeleteSubKey(), LsapRegOpenKey(), NLS_RegOpenKey(), NtOpenObject(), open_classes_key(), OpenClassesRootKey(), OpenCurrentConfigKey(), OpenLocalMachineKey(), OpenRegistryKeyHandle(), OpenUsersKey(), ProcessLocaleRegistry(), RegCopyTreeW(), RegDeleteKeyExW(), RegDeleteKeyValueW(), registry_callback(), RegOpenKeyExW(), RegOpenUserClassesRoot(), RegpCopyTree(), RegReplaceKeyW(), RegSetKeyValueA(), RegSetKeyValueW(), SampRegDeleteKey(), SampRegOpenKey(), SdbpOpenKey(), SetComputerNameToRegistry(), SetDefaultPagefile(), SetGeoID(), SetInstallPathValue(), SetMountedDeviceValue(), SetRosSpecificInfo(), SmLookupSubsystem(), SmpCreateDynamicEnvironmentVariables(), SmpLoadDataFromRegistry(), SmpQueryRegistrySosOption(), SmpTranslateSystemPartitionInformation(), START_TEST(), test1(), test2(), test3(), test5(), test8(), test9(), Test_KeyFullInformation(), Test_KeyNameInformation(), TestCreateOpen_(), and UnhandledExceptionFilter().

123 {
124  CM_PARSE_CONTEXT ParseContext = {0};
125  HANDLE Handle;
128  PAGED_CODE();
129  DPRINT("NtOpenKey(Path: %wZ, Root %x, Access: %x)\n",
130  ObjectAttributes->ObjectName, ObjectAttributes->RootDirectory, DesiredAccess);
131 
132  /* Ignore the WOW64 flag, it's not valid in the kernel */
134 
135  /* Check for user-mode caller */
136  if (PreviousMode != KernelMode)
137  {
138  /* Prepare to probe parameters */
139  _SEH2_TRY
140  {
141  /* Probe the key handle */
143  *KeyHandle = NULL;
144 
145  /* Probe object attributes */
147  sizeof(OBJECT_ATTRIBUTES),
148  sizeof(ULONG));
149  }
151  {
152  /* Return the exception code */
154  }
155  _SEH2_END;
156  }
157 
158  /* Just let the object manager handle this */
162  NULL,
164  &ParseContext,
165  &Handle);
166 
167  /* Only do this if we succeeded */
168  if (NT_SUCCESS(Status))
169  {
170  _SEH2_TRY
171  {
172  /* Return the handle to caller */
173  *KeyHandle = Handle;
174  }
176  {
177  /* Get the status */
178  Status = _SEH2_GetExceptionCode();
179  }
180  _SEH2_END;
181  }
182 
183  DPRINT("Returning handle %x, Status %x.\n", Handle, Status);
184 
185  /* Return status */
186  return Status;
187 }
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2522
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define KEY_WOW64_RES
Definition: cmtypes.h:47
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK DesiredAccess
Definition: creport.c:28
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE Handle
Definition: extypes.h:390
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:52
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
unsigned int ULONG
Definition: retypes.h:1
#define CmpKeyObjectType
Definition: ObTypes.c:132
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NTSTATUS NTAPI NtQueryKey ( IN HANDLE  KeyHandle,
IN KEY_INFORMATION_CLASS  KeyInformationClass,
OUT PVOID  KeyInformation,
IN ULONG  Length,
OUT PULONG  ResultLength 
)

Definition at line 411 of file ntapi.c.

Referenced by EnumerateKeyTest(), GetComputerIdentifier(), GetKeyName(), InitFunctionPtrs(), LsapRegQueryKeyInfo(), RegQueryInfoKeyW(), SampRegQueryKeyInfo(), test1(), test9(), Test_KeyFullInformation(), and Test_KeyNameInformation().

416 {
419  PCM_KEY_BODY KeyObject;
420  REG_QUERY_KEY_INFORMATION QueryKeyInfo;
421  REG_POST_OPERATION_INFORMATION PostOperationInfo;
422  OBJECT_HANDLE_INFORMATION HandleInfo;
423  PAGED_CODE();
424  DPRINT("NtQueryKey() KH 0x%p, KIC %d, Length %lu\n",
426 
427  /* Reject invalid classes */
434  {
435  /* Fail */
437  }
438 
439  /* Check if just the name is required */
441  {
442  /* Ignore access level */
444  0,
447  (PVOID*)&KeyObject,
448  &HandleInfo);
449  if (NT_SUCCESS(Status))
450  {
451  /* At least a single bit of access is required */
452  if (!HandleInfo.GrantedAccess)
453  {
454  /* No such luck */
455  ObDereferenceObject(KeyObject);
456  Status = STATUS_ACCESS_DENIED;
457  }
458  }
459  }
460  else
461  {
462  /* Get a reference */
467  (PVOID*)&KeyObject,
468  NULL);
469  }
470 
471  /* Quit on failure */
472  if (!NT_SUCCESS(Status)) return Status;
473 
474  if (PreviousMode != KernelMode)
475  {
476  _SEH2_TRY
477  {
479  ProbeForWrite(KeyInformation,
480  Length,
481  sizeof(ULONG));
482  }
484  {
485  /* Dereference and return status */
486  ObDereferenceObject(KeyObject);
488  }
489  _SEH2_END;
490  }
491 
492  /* Setup the callback */
493  PostOperationInfo.Object = (PVOID)KeyObject;
494  QueryKeyInfo.Object = (PVOID)KeyObject;
496  QueryKeyInfo.KeyInformation = KeyInformation;
497  QueryKeyInfo.Length = Length;
498  QueryKeyInfo.ResultLength = ResultLength;
499 
500  /* Do the callback */
501  Status = CmiCallRegisteredCallbacks(RegNtPreQueryKey, &QueryKeyInfo);
502  if (NT_SUCCESS(Status))
503  {
504  /* Call the internal API */
505  Status = CmQueryKey(KeyObject->KeyControlBlock,
507  KeyInformation,
508  Length,
509  ResultLength);
510 
511  /* Do the post callback */
512  PostOperationInfo.Status = Status;
513  CmiCallRegisteredCallbacks(RegNtPostQueryKey, &PostOperationInfo);
514  }
515 
516  /* Dereference and return status */
517  ObDereferenceObject(KeyObject);
518  return Status;
519 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
DWORD *typedef PVOID
Definition: winlogon.h:52
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
KEY_INFORMATION_CLASS KeyInformationClass
Definition: cmtypes.h:765
Definition: cmtypes.h:856
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
_In_ ULONG _In_ KEY_INFORMATION_CLASS KeyInformationClass
Definition: zwfuncs.h:166
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
ACCESS_MASK GrantedAccess
Definition: iotypes.h:158
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS Status
Definition: cmtypes.h:858
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS NTAPI CmQueryKey(_In_ PCM_KEY_CONTROL_BLOCK Kcb, _In_ KEY_INFORMATION_CLASS KeyInformationClass, _Out_opt_ PVOID KeyInformation, _In_ ULONG Length, _Out_ PULONG ResultLength)
Definition: cmapi.c:1615
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define _SEH2_TRY
Definition: pseh2_64.h:5
unsigned int ULONG
Definition: retypes.h:1
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
PVOID Object
Definition: cmtypes.h:857
NTSTATUS NTAPI NtQueryMultipleValueKey ( IN HANDLE  KeyHandle,
IN OUT PKEY_VALUE_ENTRY  ValueList,
IN ULONG  NumberOfValues,
OUT PVOID  Buffer,
IN OUT PULONG  Length,
OUT PULONG  ReturnLength 
)

Definition at line 1103 of file ntapi.c.

1109 {
1110  UNIMPLEMENTED;
1111  return STATUS_NOT_IMPLEMENTED;
1112 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtQueryOpenSubKeys ( IN POBJECT_ATTRIBUTES  TargetKey,
OUT PULONG  HandleCount 
)

Definition at line 1116 of file ntapi.c.

1118 {
1120  PCM_KEY_BODY KeyBody = NULL;
1121  HANDLE KeyHandle;
1122  NTSTATUS Status;
1123 
1124  DPRINT("NtQueryOpenSubKeys()\n");
1125 
1126  PAGED_CODE();
1127 
1128  /* Get the processor mode */
1129  PreviousMode = KeGetPreviousMode();
1130 
1131  if (PreviousMode != KernelMode)
1132  {
1133  /* Prepare to probe parameters */
1134  _SEH2_TRY
1135  {
1136  /* Probe target key */
1137  ProbeForRead(TargetKey,
1138  sizeof(OBJECT_ATTRIBUTES),
1139  sizeof(ULONG));
1140 
1141  /* Probe handle count */
1142  ProbeForWriteUlong(HandleCount);
1143  }
1145  {
1146  /* Return the exception code */
1148  }
1149  _SEH2_END;
1150  }
1151 
1152  /* Open a handle to the key */
1153  Status = ObOpenObjectByName(TargetKey,
1155  PreviousMode,
1156  NULL,
1157  KEY_READ,
1158  NULL,
1159  &KeyHandle);
1160  if (NT_SUCCESS(Status))
1161  {
1162  /* Reference the key object */
1163  Status = ObReferenceObjectByHandle(KeyHandle,
1164  KEY_READ,
1166  PreviousMode,
1167  (PVOID *)&KeyBody,
1168  NULL);
1169 
1170  /* Close the handle */
1171  NtClose(KeyHandle);
1172  }
1173 
1174  /* Fail, if the key object could not be referenced */
1175  if (!NT_SUCCESS(Status))
1176  return Status;
1177 
1178  /* Lock the registry exclusively */
1180 
1181  /* Fail, if we did not open a hive root key */
1182  if (KeyBody->KeyControlBlock->KeyCell !=
1183  KeyBody->KeyControlBlock->KeyHive->BaseBlock->RootCell)
1184  {
1185  DPRINT("Error: Key is not a hive root key!\n");
1187  ObDereferenceObject(KeyBody);
1188  return STATUS_INVALID_PARAMETER;
1189  }
1190 
1191  /* Call the internal API */
1192  *HandleCount = CmCountOpenSubKeys(KeyBody->KeyControlBlock,
1193  FALSE);
1194 
1195  /* Unlock the registry */
1197 
1198  /* Dereference the key object */
1199  ObDereferenceObject(KeyBody);
1200 
1201  DPRINT("Done.\n");
1202 
1203  return Status;
1204 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
DWORD *typedef PVOID
Definition: winlogon.h:52
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2522
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
#define KEY_READ
Definition: nt_native.h:1023
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define KeGetPreviousMode()
Definition: ketypes.h:1081
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
#define FALSE
Definition: types.h:117
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI CmpLockRegistryExclusive(VOID)
Definition: cmsysini.c:1917
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID NTAPI CmpUnlockRegistry(VOID)
Definition: cmsysini.c:2016
ULONG NTAPI CmCountOpenSubKeys(IN PCM_KEY_CONTROL_BLOCK RootKcb, IN BOOLEAN RemoveEmptyCacheEntries)
Definition: cmapi.c:2299
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3392
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:52
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
unsigned int ULONG
Definition: retypes.h:1
#define CmpKeyObjectType
Definition: ObTypes.c:132
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NTSTATUS NTAPI NtQueryOpenSubKeysEx ( IN POBJECT_ATTRIBUTES  TargetKey,
IN ULONG  BufferLength,
IN PVOID  Buffer,
IN PULONG  RequiredSize 
)

Definition at line 1208 of file ntapi.c.

1212 {
1213  UNIMPLEMENTED;
1214  return STATUS_NOT_IMPLEMENTED;
1215 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtQueryValueKey ( IN HANDLE  KeyHandle,
IN PUNICODE_STRING  ValueName,
IN KEY_VALUE_INFORMATION_CLASS  KeyValueInformationClass,
OUT PVOID  KeyValueInformation,
IN ULONG  Length,
OUT PULONG  ResultLength 
)

Definition at line 523 of file ntapi.c.

529 {
532  PCM_KEY_BODY KeyObject;
533  REG_QUERY_VALUE_KEY_INFORMATION QueryValueKeyInfo;
534  REG_POST_OPERATION_INFORMATION PostOperationInfo;
535  UNICODE_STRING ValueNameCopy = *ValueName;
536  PAGED_CODE();
537  DPRINT("NtQueryValueKey() KH 0x%p, VN '%wZ', KVIC %d, Length %lu\n",
539 
540  /* Verify that the handle is valid and is a registry key */
545  (PVOID*)&KeyObject,
546  NULL);
547  if (!NT_SUCCESS(Status)) return Status;
548 
549  if (PreviousMode != KernelMode)
550  {
551  _SEH2_TRY
552  {
554  ProbeForWrite(KeyValueInformation,
555  Length,
556  sizeof(ULONG));
557  }
559  {
560  /* Dereference and return status */
561  ObDereferenceObject(KeyObject);
563  }
564  _SEH2_END;
565  }
566 
567  /* Make sure the name is aligned properly */
568  if ((ValueNameCopy.Length & (sizeof(WCHAR) - 1)))
569  {
570  /* It isn't, so we'll fail */
571  ObDereferenceObject(KeyObject);
573  }
574  else
575  {
576  /* Ignore any null characters at the end */
577  while ((ValueNameCopy.Length) &&
578  !(ValueNameCopy.Buffer[ValueNameCopy.Length / sizeof(WCHAR) - 1]))
579  {
580  /* Skip it */
581  ValueNameCopy.Length -= sizeof(WCHAR);
582  }
583  }
584 
585  /* Setup the callback */
586  PostOperationInfo.Object = (PVOID)KeyObject;
587  QueryValueKeyInfo.Object = (PVOID)KeyObject;
588  QueryValueKeyInfo.ValueName = &ValueNameCopy;
590  QueryValueKeyInfo.Length = Length;
591  QueryValueKeyInfo.ResultLength = ResultLength;
592 
593  /* Do the callback */
594  Status = CmiCallRegisteredCallbacks(RegNtPreQueryValueKey, &QueryValueKeyInfo);
595  if (NT_SUCCESS(Status))
596  {
597  /* Call the internal API */
598  Status = CmQueryValueKey(KeyObject->KeyControlBlock,
599  ValueNameCopy,
601  KeyValueInformation,
602  Length,
603  ResultLength);
604 
605  /* Do the post callback */
606  PostOperationInfo.Status = Status;
608  }
609 
610  /* Dereference and return status */
611  ObDereferenceObject(KeyObject);
612  return Status;
613 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
DWORD *typedef PVOID
Definition: winlogon.h:52
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
Definition: cmtypes.h:856
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define WCHAR
Definition: msvc.h:43
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmtypes.h:777
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS Status
Definition: cmtypes.h:858
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI CmQueryValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN UNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
Definition: cmapi.c:1075
LONG NTSTATUS
Definition: DriverTester.h:11
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define _SEH2_TRY
Definition: pseh2_64.h:5
unsigned int ULONG
Definition: retypes.h:1
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
PVOID Object
Definition: cmtypes.h:857
_In_ ULONG _In_ KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmfuncs.h:93
NTSTATUS NTAPI NtRenameKey ( IN HANDLE  KeyHandle,
IN PUNICODE_STRING  ReplacementName 
)

Definition at line 1219 of file ntapi.c.

1221 {
1222  UNIMPLEMENTED;
1223  return STATUS_NOT_IMPLEMENTED;
1224 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtReplaceKey ( IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN HANDLE  Key,
IN POBJECT_ATTRIBUTES  ReplacedObjectAttributes 
)

Definition at line 1228 of file ntapi.c.

Referenced by RegReplaceKeyW().

1231 {
1232  UNIMPLEMENTED;
1233  return STATUS_NOT_IMPLEMENTED;
1234 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtRestoreKey ( IN HANDLE  KeyHandle,
IN HANDLE  FileHandle,
IN ULONG  RestoreFlags 
)

Definition at line 1238 of file ntapi.c.

Referenced by RegRestoreKeyW().

1241 {
1242  UNIMPLEMENTED;
1243  return STATUS_NOT_IMPLEMENTED;
1244 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtSaveKey ( IN HANDLE  KeyHandle,
IN HANDLE  FileHandle 
)

Definition at line 1248 of file ntapi.c.

Referenced by RegSaveKeyW(), and START_TEST().

1250 {
1251  /* Call the extended API */
1253 }
#define REG_STANDARD_FORMAT
Definition: cmtypes.h:97
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
static HANDLE FileHandle
Definition: cabinet.c:47
NTSTATUS NTAPI NtSaveKeyEx(IN HANDLE KeyHandle, IN HANDLE FileHandle, IN ULONG Flags)
Definition: ntapi.c:1257
NTSTATUS NTAPI NtSaveKeyEx ( IN HANDLE  KeyHandle,
IN HANDLE  FileHandle,
IN ULONG  Flags 
)

Definition at line 1257 of file ntapi.c.

Referenced by CreateRegistryFile(), and NtSaveKey().

1260 {
1261  NTSTATUS Status;
1262  PCM_KEY_BODY KeyObject;
1264 
1265  PAGED_CODE();
1266 
1267  DPRINT("NtSaveKeyEx(0x%p, 0x%p, %lu)\n", KeyHandle, FileHandle, Flags);
1268 
1269  /* Verify the flags */
1270  if ((Flags != REG_STANDARD_FORMAT)
1271  && (Flags != REG_LATEST_FORMAT)
1272  && (Flags != REG_NO_COMPRESSION))
1273  {
1274  /* Only one of these values can be specified */
1275  return STATUS_INVALID_PARAMETER;
1276  }
1277 
1278  /* Check for the SeBackupPrivilege */
1279  if (!SeSinglePrivilegeCheck(SeBackupPrivilege, PreviousMode))
1280  {
1282  }
1283 
1284  /* Verify that the handle is valid and is a registry key */
1286  KEY_READ,
1288  PreviousMode,
1289  (PVOID*)&KeyObject,
1290  NULL);
1291  if (!NT_SUCCESS(Status)) return Status;
1292 
1293  /* Call the internal API */
1294  Status = CmSaveKey(KeyObject->KeyControlBlock, FileHandle, Flags);
1295 
1296  ObDereferenceObject(KeyObject);
1297  return Status;
1298 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define REG_STANDARD_FORMAT
Definition: cmtypes.h:97
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
const LUID SeBackupPrivilege
Definition: priv.c:38
#define KEY_READ
Definition: nt_native.h:1023
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI CmSaveKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN HANDLE FileHandle, IN ULONG Flags)
Definition: cmapi.c:2572
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define REG_NO_COMPRESSION
Definition: cmtypes.h:99
#define REG_LATEST_FORMAT
Definition: cmtypes.h:98
Status
Definition: gdiplustypes.h:24
static HANDLE FileHandle
Definition: cabinet.c:47
LONG NTSTATUS
Definition: DriverTester.h:11
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS NTAPI NtSaveMergedKeys ( IN HANDLE  HighPrecedenceKeyHandle,
IN HANDLE  LowPrecedenceKeyHandle,
IN HANDLE  FileHandle 
)

Definition at line 1302 of file ntapi.c.

1305 {
1307  PCM_KEY_BODY HighPrecedenceKeyObject = NULL;
1308  PCM_KEY_BODY LowPrecedenceKeyObject = NULL;
1309  NTSTATUS Status;
1310 
1311  PAGED_CODE();
1312 
1313  DPRINT("NtSaveMergedKeys(0x%p, 0x%p, 0x%p)\n",
1314  HighPrecedenceKeyHandle, LowPrecedenceKeyHandle, FileHandle);
1315 
1316  PreviousMode = ExGetPreviousMode();
1317 
1318  /* Check for the SeBackupPrivilege */
1319  if (!SeSinglePrivilegeCheck(SeBackupPrivilege, PreviousMode))
1320  {
1322  }
1323 
1324  /* Verify that the handles are valid and are registry keys */
1325  Status = ObReferenceObjectByHandle(HighPrecedenceKeyHandle,
1326  KEY_READ,
1328  PreviousMode,
1329  (PVOID*)&HighPrecedenceKeyObject,
1330  NULL);
1331  if (!NT_SUCCESS(Status))
1332  goto done;
1333 
1334  Status = ObReferenceObjectByHandle(LowPrecedenceKeyHandle,
1335  KEY_READ,
1337  PreviousMode,
1338  (PVOID*)&LowPrecedenceKeyObject,
1339  NULL);
1340  if (!NT_SUCCESS(Status))
1341  goto done;
1342 
1343  /* Call the internal API */
1344  Status = CmSaveMergedKeys(HighPrecedenceKeyObject->KeyControlBlock,
1345  LowPrecedenceKeyObject->KeyControlBlock,
1346  FileHandle);
1347 
1348 done:
1349  if (LowPrecedenceKeyObject)
1350  ObDereferenceObject(LowPrecedenceKeyObject);
1351 
1352  if (HighPrecedenceKeyObject)
1353  ObDereferenceObject(HighPrecedenceKeyObject);
1354 
1355  return Status;
1356 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
const LUID SeBackupPrivilege
Definition: priv.c:38
#define KEY_READ
Definition: nt_native.h:1023
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI CmSaveMergedKeys(IN PCM_KEY_CONTROL_BLOCK HighKcb, IN PCM_KEY_CONTROL_BLOCK LowKcb, IN HANDLE FileHandle)
Definition: cmapi.c:2641
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Status
Definition: gdiplustypes.h:24
static HANDLE FileHandle
Definition: cabinet.c:47
LONG NTSTATUS
Definition: DriverTester.h:11
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS NTAPI NtSetInformationKey ( IN HANDLE  KeyHandle,
IN KEY_SET_INFORMATION_CLASS  KeyInformationClass,
IN PVOID  KeyInformation,
IN ULONG  KeyInformationLength 
)

Definition at line 1360 of file ntapi.c.

1364 {
1365  UNIMPLEMENTED;
1366  return STATUS_NOT_IMPLEMENTED;
1367 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114
NTSTATUS NTAPI NtSetValueKey ( IN HANDLE  KeyHandle,
IN PUNICODE_STRING  ValueName,
IN ULONG TitleIndex  ,
IN ULONG  Type,
IN PVOID  Data,
IN ULONG  DataSize 
)

Definition at line 617 of file ntapi.c.

Referenced by AddCodepageToRegistry(), AddFontsSettingsToRegistry(), AddHotkeySettings(), AddKbLayoutsToRegistry(), BasepMoveFileDelayed(), CmpCreateControlSet(), CmpInitializeMachineDependentConfiguration(), CmpInitializeRegistryNode(), CmpSetSystemValues(), CmpSetVersionData(), do_reg_operation(), InitFunctionPtrs(), InstallDriver(), Phase1InitializationDiscard(), ProcessLocaleRegistry(), RegpCopyTree(), RegSetValueExW(), SdbSetPermLayerKeys(), SetComputerNameToRegistry(), SetDefaultPagefile(), SetGeoID(), SetInstallPathValue(), SetLocaleInfoW(), SetMountedDeviceValue(), SetUserGeoID(), SetValueTest1(), SetValueTest2(), SmpCreateDynamicEnvironmentVariables(), SmpTranslateSystemPartitionInformation(), START_TEST(), test2(), test3(), and test6().

623 {
625  PCM_KEY_BODY KeyObject = NULL;
626  REG_SET_VALUE_KEY_INFORMATION SetValueKeyInfo;
627  REG_POST_OPERATION_INFORMATION PostOperationInfo;
628  UNICODE_STRING ValueNameCopy;
630 
631  PAGED_CODE();
632 
633  PreviousMode = ExGetPreviousMode();
634 
635  if (!DataSize)
636  Data = NULL;
637 
638  /* Probe and copy the data */
639  if ((PreviousMode != KernelMode) && (DataSize != 0))
640  {
642  if (!DataCopy)
644  _SEH2_TRY
645  {
647  RtlCopyMemory(DataCopy, Data, DataSize);
648  }
650  {
651  Status = _SEH2_GetExceptionCode();
652  }
653  _SEH2_END;
654 
655  if (!NT_SUCCESS(Status))
656  {
657  ExFreePoolWithTag(DataCopy, TAG_CM);
658  return Status;
659  }
660  Data = DataCopy;
661  }
662 
663  /* Capture the string */
664  Status = ProbeAndCaptureUnicodeString(&ValueNameCopy, PreviousMode, ValueName);
665  if (!NT_SUCCESS(Status))
666  goto end;
667 
668  DPRINT("NtSetValueKey() KH 0x%p, VN '%wZ', TI %x, T %lu, DS %lu\n",
669  KeyHandle, &ValueNameCopy, TitleIndex, Type, DataSize);
670 
671  /* Verify that the handle is valid and is a registry key */
676  (PVOID*)&KeyObject,
677  NULL);
678  if (!NT_SUCCESS(Status))
679  goto end;
680 
681  /* Make sure the name is aligned, not too long, and the data under 4GB */
682  if ( (ValueNameCopy.Length > 32767) ||
683  ((ValueNameCopy.Length & (sizeof(WCHAR) - 1))) ||
684  (DataSize > 0x80000000))
685  {
686  /* Fail */
687  Status = STATUS_INVALID_PARAMETER;
688  goto end;
689  }
690 
691  /* Ignore any null characters at the end */
692  while ((ValueNameCopy.Length) &&
693  !(ValueNameCopy.Buffer[ValueNameCopy.Length / sizeof(WCHAR) - 1]))
694  {
695  /* Skip it */
696  ValueNameCopy.Length -= sizeof(WCHAR);
697  }
698 
699  /* Don't touch read-only keys */
700  if (KeyObject->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY)
701  {
702  /* Fail */
703  Status = STATUS_ACCESS_DENIED;
704  goto end;
705  }
706 
707  /* Setup callback */
708  PostOperationInfo.Object = (PVOID)KeyObject;
709  SetValueKeyInfo.Object = (PVOID)KeyObject;
710  SetValueKeyInfo.ValueName = &ValueNameCopy;
711  SetValueKeyInfo.TitleIndex = TitleIndex;
712  SetValueKeyInfo.Type = Type;
713  SetValueKeyInfo.Data = Data;
714  SetValueKeyInfo.DataSize = DataSize;
715 
716  /* Do the callback */
717  Status = CmiCallRegisteredCallbacks(RegNtPreSetValueKey, &SetValueKeyInfo);
718  if (NT_SUCCESS(Status))
719  {
720  /* Call the internal API */
721  Status = CmSetValueKey(KeyObject->KeyControlBlock,
722  &ValueNameCopy,
723  Type,
724  Data,
725  DataSize);
726  }
727 
728  /* Do the post-callback */
729  PostOperationInfo.Status = Status;
731 
732 end:
733  /* Dereference and return status */
734  if (KeyObject)
735  ObDereferenceObject(KeyObject);
736  ReleaseCapturedUnicodeString(&ValueNameCopy, PreviousMode);
737  if ((PreviousMode != KernelMode) && Data)
739  return Status;
740 }
static __inline NTSTATUS ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, IN KPROCESSOR_MODE CurrentMode, IN const UNICODE_STRING *UnsafeSrc)
Definition: probe.h:142
DWORD *typedef PVOID
Definition: winlogon.h:52
Definition: cmtypes.h:856
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static ACCESS_MASK const OBJECT_ATTRIBUTES ULONG TitleIndex
Definition: reg.c:130
Type
Definition: Type.h:6
#define KEY_SET_VALUE
Definition: nt_native.h:1017
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4692
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2664
PVOID ULONG ULONG PULONG Data
Definition: oprghdlr.h:14
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
GLuint GLuint end
Definition: gl.h:1545
#define CM_KCB_READ_ONLY_KEY
Definition: cm.h:61
#define WCHAR
Definition: msvc.h:43
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI CmSetValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN PUNICODE_STRING ValueName, IN ULONG Type, IN PVOID Data, IN ULONG DataLength)
Definition: cmapi.c:644
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
Definition: probe.h:228
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS Status
Definition: cmtypes.h:858
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define TAG_CM
Definition: cmlib.h:203
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
UINT64 UINTN DataSize
Definition: acefiex.h:499
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
PUNICODE_STRING ValueName
Definition: cmtypes.h:711
#define CmpKeyObjectType
Definition: ObTypes.c:132
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1097
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
PVOID Object
Definition: cmtypes.h:857
NTSTATUS NTAPI NtUnloadKey ( IN POBJECT_ATTRIBUTES  KeyObjectAttributes)

Definition at line 1371 of file ntapi.c.

Referenced by RegUnLoadKeyW().

1372 {
1373  return NtUnloadKey2(KeyObjectAttributes, 0);
1374 }
NTSTATUS NTAPI NtUnloadKey2(IN POBJECT_ATTRIBUTES TargetKey, IN ULONG Flags)
Definition: ntapi.c:1378
NTSTATUS NTAPI NtUnloadKey2 ( IN POBJECT_ATTRIBUTES  TargetKey,
IN ULONG  Flags 
)

Definition at line 1378 of file ntapi.c.

Referenced by DisconnectRegistry(), and NtUnloadKey().

1380 {
1381  NTSTATUS Status;
1384  CM_PARSE_CONTEXT ParseContext = {0};
1386  PCM_KEY_BODY KeyBody = NULL;
1387  ULONG ParentConv = 0, ChildConv = 0;
1388  HANDLE Handle;
1389 
1390  PAGED_CODE();
1391 
1392  /* Validate privilege */
1393  if (!SeSinglePrivilegeCheck(SeRestorePrivilege, PreviousMode))
1394  {
1395  /* Fail */
1396  DPRINT1("Restore Privilege missing!\n");
1398  }
1399 
1400  /* Check for user-mode caller */
1401  if (PreviousMode != KernelMode)
1402  {
1403  /* Prepare to probe parameters */
1404  _SEH2_TRY
1405  {
1406  /* Probe object attributes */
1407  ProbeForRead(TargetKey,
1408  sizeof(OBJECT_ATTRIBUTES),
1409  sizeof(ULONG));
1410 
1411  ObjectAttributes = *TargetKey;
1412 
1413  /* Probe the string */
1414  ProbeForReadUnicodeString(&TargetKey->ObjectName);
1415 
1416  ObjectName = *TargetKey->ObjectName;
1417 
1418  ProbeForRead(ObjectName.Buffer,
1419  ObjectName.Length,
1420  sizeof(WCHAR));
1421 
1422  ObjectAttributes.ObjectName = &ObjectName;
1423  }
1425  {
1426  /* Return the exception code */
1428  }
1429  _SEH2_END;
1430  }
1431  else
1432  {
1433  /* Save the target attributes directly */
1434  ObjectAttributes = *TargetKey;
1435  }
1436 
1437  /* Setup the parse context */
1438  ParseContext.CreateOperation = TRUE;
1440 
1441  /* Do the create */
1442  Status = ObOpenObjectByName(&ObjectAttributes,
1444  KernelMode,
1445  NULL,
1446  KEY_WRITE,
1447  &ParseContext,
1448  &Handle);
1449 
1450  /* Return if failure encountered */
1451  if (!NT_SUCCESS(Status)) return Status;
1452 
1453  /* Reference it */
1454  Status = ObReferenceObjectByHandle(Handle,
1455  KEY_WRITE,
1457  KernelMode,
1458  (PVOID *)&KeyBody,
1459  NULL);
1460 
1461  /* Close the handle */
1462  ZwClose(Handle);
1463 
1464  /* Return if failure encountered */
1465  if (!NT_SUCCESS(Status)) return Status;
1466 
1467  /* Acquire the lock depending on flags */
1468  if (Flags == REG_FORCE_UNLOAD)
1469  {
1470  /* Lock registry exclusively */
1472  }
1473  else
1474  {
1475  /* Lock registry */
1476  CmpLockRegistry();
1477 
1478  /* Acquire the hive loading lock */
1480 
1481  /* Lock parent and child */
1482  if (KeyBody->KeyControlBlock->ParentKcb)
1483  ParentConv = KeyBody->KeyControlBlock->ParentKcb->ConvKey;
1484  else
1485  ParentConv = KeyBody->KeyControlBlock->ConvKey;
1486 
1487  ChildConv = KeyBody->KeyControlBlock->ConvKey;
1488 
1489  CmpAcquireTwoKcbLocksExclusiveByKey(ChildConv, ParentConv);
1490  }
1491 
1492  /* Check if it's being deleted already */
1493  if (KeyBody->KeyControlBlock->Delete)
1494  {
1495  /* Return appropriate status */
1496  Status = STATUS_KEY_DELETED;
1497  goto Quickie;
1498  }
1499 
1500  /* Check if it's a readonly key */
1501  if (KeyBody->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY)
1502  {
1503  /* Return appropriate status */
1504  Status = STATUS_ACCESS_DENIED;
1505  goto Quickie;
1506  }
1507 
1508  /* Call the internal API */
1509  Status = CmUnloadKey(KeyBody->KeyControlBlock,
1510  Flags);
1511 
1512  /* Check if we failed, but really need to succeed */
1513  if ((Status == STATUS_CANNOT_DELETE) && (Flags == REG_FORCE_UNLOAD))
1514  {
1515  /* TODO: We should perform another attempt here */
1516  ASSERT(FALSE);
1517  }
1518 
1519  /* If CmUnloadKey failed we need to unlock registry ourselves */
1520  if (!NT_SUCCESS(Status))
1521  {
1522  if (Flags != REG_FORCE_UNLOAD)
1523  {
1524  /* Release the KCB locks */
1525  CmpReleaseTwoKcbLockByKey(ChildConv, ParentConv);
1526 
1527  /* Release the hive loading lock */
1529  }
1530 
1531  /* Unlock the registry */
1533  }
1534 
1535 Quickie:
1536  /* Dereference the key */
1537  ObDereferenceObject(KeyBody);
1538 
1539  /* Return status */
1540  return Status;
1541 }
DWORD *typedef PVOID
Definition: winlogon.h:52
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2522
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:966
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:2740
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:62
#define CM_KCB_READ_ONLY_KEY
Definition: cm.h:61
ULONG CreateOptions
Definition: cm.h:484
VOID NTAPI CmpReleaseTwoKcbLockByKey(IN ULONG ConvKey1, IN ULONG ConvKey2)
Definition: cmsysini.c:2073
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:388
#define FALSE
Definition: types.h:117
#define _SEH2_END
Definition: pseh2_64.h:7
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1182
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
VOID NTAPI CmpLockRegistryExclusive(VOID)
Definition: cmsysini.c:1917
#define STATUS_KEY_DELETED
Definition: ntstatus.h:599
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:229
#define KEY_WRITE
Definition: nt_native.h:1031
_In_ HANDLE Handle
Definition: extypes.h:390
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
const LUID SeRestorePrivilege
Definition: priv.c:39
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID NTAPI CmpUnlockRegistry(VOID)
Definition: cmsysini.c:2016
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define REG_OPTION_BACKUP_RESTORE
Definition: nt_native.h:1066
#define PAGED_CODE()
Definition: video.h:57
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define STATUS_CANNOT_DELETE
Definition: shellext.h:52
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
EX_PUSH_LOCK CmpLoadHiveLock
Definition: cmdata.c:39
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI CmUnloadKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN ULONG Flags)
Definition: cmapi.c:2188
#define REG_FORCE_UNLOAD
DWORD *typedef HANDLE
Definition: winlogon.h:52
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
#define DPRINT1
Definition: precomp.h:8
PUNICODE_STRING ObjectName
Definition: umtypes.h:173
unsigned int ULONG
Definition: retypes.h:1
#define CmpKeyObjectType
Definition: ObTypes.c:132
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
VOID NTAPI CmpLockRegistry(VOID)
Definition: cmsysini.c:1930
BOOLEAN CreateOperation
Definition: cm.h:489
VOID NTAPI CmpAcquireTwoKcbLocksExclusiveByKey(IN ULONG ConvKey1, IN ULONG ConvKey2)
Definition: cmsysini.c:2044
NTSTATUS NTAPI NtUnloadKeyEx ( IN POBJECT_ATTRIBUTES  TargetKey,
IN HANDLE  Event 
)

Definition at line 1545 of file ntapi.c.

1547 {
1548  UNIMPLEMENTED;
1549  return STATUS_NOT_IMPLEMENTED;
1550 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Variable Documentation

BOOLEAN CmBootAcceptFirstTime = TRUE

Definition at line 16 of file ntapi.c.

Referenced by NtInitializeRegistry().

BOOLEAN CmFirstTime = TRUE

Definition at line 17 of file ntapi.c.

Referenced by CmShutdownSystem(), and NtInitializeRegistry().

ULONG InitSafeBootMode

Definition at line 68 of file init.c.

Referenced by NtLockProductActivationKeys().