ReactOS 0.4.17-dev-1190-g4c812f4
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

VOID ReleaseCapturedObjectAttributes (_In_ POBJECT_ATTRIBUTES CapturedObjectAttributes, _In_ KPROCESSOR_MODE AccessMode)
 
NTSTATUS ProbeAndCaptureObjectAttributes (_Out_ POBJECT_ATTRIBUTES CapturedObjectAttributes, _Out_ PUNICODE_STRING ObjectName, _In_ KPROCESSOR_MODE AccessMode, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ BOOLEAN CaptureSecurity)
 
static NTSTATUS CmpConvertHandleToKernelHandle (_In_ HANDLE SourceHandle, _In_opt_ POBJECT_TYPE ObjectType, _In_ ACCESS_MASK DesiredAccess, _In_ KPROCESSOR_MODE AccessMode, _Out_ PHANDLE KernelHandle)
 
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
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file ntapi.c.

◆ PRODUCT_ACTIVATION_VERSION

#define PRODUCT_ACTIVATION_VERSION   7749

Definition at line 1399 of file ntapi.c.

Function Documentation

◆ CmpConvertHandleToKernelHandle()

static NTSTATUS CmpConvertHandleToKernelHandle ( _In_ HANDLE  SourceHandle,
_In_opt_ POBJECT_TYPE  ObjectType,
_In_ ACCESS_MASK  DesiredAccess,
_In_ KPROCESSOR_MODE  AccessMode,
_Out_ PHANDLE  KernelHandle 
)
static

Definition at line 194 of file ntapi.c.

200{
203
205
206 /* NULL handle is valid */
207 if (SourceHandle == NULL)
208 return STATUS_SUCCESS;
209
210 /* Get the object pointer */
215 &Object,
216 NULL);
217 if (!NT_SUCCESS(Status))
218 return Status;
219
220 /* Create a kernel handle from the pointer */
223 NULL,
228
229 /* Dereference the object */
231 return Status;
232}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
HANDLE KernelHandle
Definition: legacy.c:24
Status
Definition: gdiplustypes.h:24
ObjectType
Definition: metafile.c:88
#define KernelMode
Definition: asm.h:38
_In_ HANDLE SourceHandle
Definition: obfuncs.h:447
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2769
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:493
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by NtLoadKeyEx(), NtSaveKeyEx(), NtSaveMergedKeys(), and NtUnloadKey2().

◆ NtCompactKeys()

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

Definition at line 1383 of file ntapi.c.

1385{
1388}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42

◆ NtCompressKey()

NTSTATUS NTAPI NtCompressKey ( IN HANDLE  Key)

Definition at line 1392 of file ntapi.c.

1393{
1396}

◆ NtCreateKey()

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 239 of file ntapi.c.

246{
249 CM_PARSE_CONTEXT ParseContext = {0};
251 PAGED_CODE();
252
253 DPRINT("NtCreateKey(Path: %wZ, Root %x, Access: %x, CreateOptions %x)\n",
254 ObjectAttributes->ObjectName, ObjectAttributes->RootDirectory,
256
257 /* Ignore the WOW64 flag, it's not valid in the kernel */
258 DesiredAccess &= ~KEY_WOW64_RES;
259
260 /* Check for user-mode caller */
262 {
263 /* Prepare to probe parameters */
265 {
266 /* Check if we have a class */
267 if (Class)
268 {
269 /* Probe it */
270 ParseContext.Class = ProbeForReadUnicodeString(Class);
271 ProbeForRead(ParseContext.Class.Buffer,
272 ParseContext.Class.Length,
273 sizeof(WCHAR));
274 }
275
276 /* Probe the key handle */
278 *KeyHandle = NULL;
279
280 /* Probe object attributes */
282 sizeof(OBJECT_ATTRIBUTES),
283 sizeof(ULONG));
284
285 if (Disposition)
287 }
289 {
290 /* Return the exception code */
292 }
293 _SEH2_END;
294 }
295 else
296 {
297 /* Save the class directly */
298 if (Class) ParseContext.Class = *Class;
299 }
300
301 /* Setup the parse context */
302 ParseContext.CreateOperation = TRUE;
303 ParseContext.CreateOptions = CreateOptions;
304
305 /* Do the create */
309 NULL,
311 &ParseContext,
312 &Handle);
313
315 {
316 /* Return data to user */
318 if (Disposition) *Disposition = ParseContext.Disposition;
319 }
321 {
322 /* Get the status */
324 }
325 _SEH2_END;
326
327 DPRINT("Returning handle %x, Status %x.\n", Handle, Status);
328
329 /* Return status */
330 return Status;
331}
#define PAGED_CODE()
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG _In_ KPROCESSOR_MODE PreviousMode
#define CmpKeyObjectType
Definition: ObTypes.cpp:179
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define TRUE
Definition: types.h:120
#define ExGetPreviousMode
Definition: ex.h:143
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
ULONG Handle
Definition: gdb_input.c:15
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
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:2559
short WCHAR
Definition: pedump.c:58
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
#define DPRINT
Definition: sndvol32.h:73
ULONG Disposition
Definition: cm.h:440
UNICODE_STRING Class
Definition: cm.h:438
BOOLEAN CreateOperation
Definition: cm.h:444
ULONG CreateOptions
Definition: cm.h:439
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7

Referenced by add_boot_rename_entry(), AddHotkeySettings(), AddKbLayoutsToRegistry(), BasepMoveFileDelayed(), CmInitSystem1(), CmpCreateControlSet(), CmpCreateHardwareProfile(), CmpInitializeHardwareConfiguration(), CmpInitializeMachineDependentConfiguration(), CmpInitializeRegistryNode(), CmpSetVersionData(), create_key(), create_registry_key(), CreateKeyTest(), CreateNestedKey(), CreateRegistryKeyHandle(), CreateRegKey(), CreateSymLinkKey(), DeleteSymLinkKey(), InitFunctionPtrs(), InitializeUserModePnpManager(), InstallDriver(), LOCALE_InitRegistry(), LsapCreateDatabaseKeys(), LsapCreateDbObject(), LsapSetObjectAttribute(), RegInitializeRegistry(), RegpCopyTree(), SdbRegisterDatabaseEx(), SdbUnregisterDatabase(), SetActiveComputerNameToRegistry(), SetMountedDeviceValue(), SetUserGeoID(), SetValueTest1(), SetValueTest2(), START_TEST(), test2(), test3(), test6(), test7(), Test_KeyFullInformation(), test_perflib_key(), and TestCreateOpen_().

◆ NtDeleteKey()

NTSTATUS NTAPI NtDeleteKey ( IN HANDLE  KeyHandle)

Definition at line 407 of file ntapi.c.

408{
409 PCM_KEY_BODY KeyObject;
411 REG_DELETE_KEY_INFORMATION DeleteKeyInfo;
412 REG_POST_OPERATION_INFORMATION PostOperationInfo;
413 PAGED_CODE();
414 DPRINT("NtDeleteKey(KH 0x%p)\n", KeyHandle);
415
416 /* Verify that the handle is valid and is a registry key */
418 DELETE,
421 (PVOID*)&KeyObject,
422 NULL);
423 if (!NT_SUCCESS(Status)) return Status;
424
425 /* Setup the callback */
426 PostOperationInfo.Object = (PVOID)KeyObject;
427 DeleteKeyInfo.Object = (PVOID)KeyObject;
429 if (NT_SUCCESS(Status))
430 {
431 /* Check if we are read-only */
432 if ((KeyObject->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY) ||
433 (KeyObject->KeyControlBlock->ParentKcb->ExtFlags & CM_KCB_READ_ONLY_KEY))
434 {
435 /* Fail */
437 }
438 else
439 {
440 /* Call the internal API */
441 Status = CmDeleteKey(KeyObject);
442 }
443
444 /* Do post callback */
445 PostOperationInfo.Status = Status;
447 }
448
449 /* Dereference and return status */
450 ObDereferenceObject(KeyObject);
451 return Status;
452}
#define CM_KCB_READ_ONLY_KEY
Definition: cm.h:59
NTSTATUS NTAPI CmDeleteKey(IN PCM_KEY_BODY KeyBody)
Definition: cmapi.c:1823
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
#define DELETE
Definition: nt_native.h:57
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:237
Definition: cmtypes.h:859
PVOID Object
Definition: cmtypes.h:860
NTSTATUS Status
Definition: cmtypes.h:861
void * PVOID
Definition: typedefs.h:50
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
@ RegNtPostDeleteKey
Definition: cmtypes.h:657
@ RegNtPreDeleteKey
Definition: cmtypes.h:632

Referenced by DeleteKeyTest(), DeleteSymLinkKey(), DestroyProtoHive(), do_reg_operation(), InitFunctionPtrs(), LsapRegDeleteKey(), LsapRegDeleteSubKey(), RegCleanupRegistry(), RegDeleteKeyExA(), RegDeleteKeyExW(), RegInitializeRegistry(), SampRegDeleteKey(), SdbUnregisterDatabase(), START_TEST(), test2(), test3(), test7(), Test_KeyFullInformation(), and test_perflib_key().

◆ NtDeleteValueKey()

NTSTATUS NTAPI NtDeleteValueKey ( IN HANDLE  KeyHandle,
IN PUNICODE_STRING  ValueName 
)

Definition at line 1013 of file ntapi.c.

1015{
1017 PCM_KEY_BODY KeyObject;
1018 REG_DELETE_VALUE_KEY_INFORMATION DeleteValueKeyInfo;
1019 REG_POST_OPERATION_INFORMATION PostOperationInfo;
1021 UNICODE_STRING ValueNameCopy;
1022
1023 PAGED_CODE();
1024
1025 /* Verify that the handle is valid and is a registry key */
1030 (PVOID*)&KeyObject,
1031 NULL);
1032 if (!NT_SUCCESS(Status))
1033 return Status;
1034
1035 /* Capture the string */
1037 if (!NT_SUCCESS(Status))
1038 goto Quit;
1039
1040 /* Make sure the name is aligned properly */
1041 if (ValueNameCopy.Length & (sizeof(WCHAR) - 1))
1042 {
1043 /* It isn't, so we'll fail */
1045 goto Quit;
1046 }
1047
1048 /* Don't touch read-only keys */
1049 if (KeyObject->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY)
1050 {
1051 /* Fail */
1053 goto Quit;
1054 }
1055
1056 /* Do the callback */
1057 DeleteValueKeyInfo.Object = (PVOID)KeyObject;
1058 DeleteValueKeyInfo.ValueName = ValueName;
1060 &DeleteValueKeyInfo);
1061 if (NT_SUCCESS(Status))
1062 {
1063 /* Call the internal API */
1064 Status = CmDeleteValueKey(KeyObject->KeyControlBlock, ValueNameCopy);
1065
1066 /* Do the post callback */
1067 PostOperationInfo.Object = (PVOID)KeyObject;
1068 PostOperationInfo.Status = Status;
1070 &PostOperationInfo);
1071 }
1072
1073Quit:
1074 if (ValueNameCopy.Buffer)
1076
1077 /* Dereference and return status */
1078 ObDereferenceObject(KeyObject);
1079 return Status;
1080}
NTSTATUS NTAPI CmDeleteValueKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN UNICODE_STRING ValueName)
Definition: cmapi.c:915
#define KEY_SET_VALUE
Definition: nt_native.h:1020
static __inline NTSTATUS ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, IN KPROCESSOR_MODE CurrentMode, IN const UNICODE_STRING *UnsafeSrc)
Definition: probe.h:142
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
Definition: probe.h:239
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
@ RegNtPreDeleteValueKey
Definition: cmtypes.h:636
@ RegNtPostDeleteValueKey
Definition: cmtypes.h:659

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

◆ NtEnumerateKey()

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 456 of file ntapi.c.

462{
465 PCM_KEY_BODY KeyObject;
466 REG_ENUMERATE_KEY_INFORMATION EnumerateKeyInfo;
467 REG_POST_OPERATION_INFORMATION PostOperationInfo;
468 PAGED_CODE();
469 DPRINT("NtEnumerateKey() KH 0x%p, Index 0x%x, KIC %d, Length %lu\n",
471
472 /* Reject classes we don't know about */
476 {
477 /* Fail */
479 }
480
481 /* Verify that the handle is valid and is a registry key */
486 (PVOID*)&KeyObject,
487 NULL);
488 if (!NT_SUCCESS(Status)) return Status;
489
491 {
493 {
495 ProbeForWrite(KeyInformation,
496 Length,
497 sizeof(ULONG));
498 }
500 {
501 /* Dereference and return status */
502 ObDereferenceObject(KeyObject);
504 }
505 _SEH2_END;
506 }
507
508 /* Setup the callback */
509 PostOperationInfo.Object = (PVOID)KeyObject;
510 EnumerateKeyInfo.Object = (PVOID)KeyObject;
511 EnumerateKeyInfo.Index = Index;
512 EnumerateKeyInfo.KeyInformationClass = KeyInformationClass;
513 EnumerateKeyInfo.Length = Length;
514 EnumerateKeyInfo.ResultLength = ResultLength;
515
516 /* Do the callback */
518 if (NT_SUCCESS(Status))
519 {
520 /* Call the internal API */
522 Index,
524 KeyInformation,
525 Length,
527
528 /* Do the post callback */
529 PostOperationInfo.Status = Status;
531 }
532
533 /* Dereference and return status */
534 ObDereferenceObject(KeyObject);
535 DPRINT("Returning status %x.\n", Status);
536 return Status;
537}
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:1734
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
@ KeyBasicInformation
Definition: nt_native.h:1134
@ KeyNodeInformation
Definition: nt_native.h:1135
@ KeyFullInformation
Definition: nt_native.h:1136
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1022
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
KEY_INFORMATION_CLASS KeyInformationClass
Definition: cmtypes.h:745
_In_ PGUID _In_ ULONG _Out_ PULONG ResultLength
Definition: ucxcontroller.h:83
_In_ WDFCOLLECTION _In_ ULONG Index
@ RegNtPreEnumerateKey
Definition: cmtypes.h:642
@ RegNtPostEnumerateKey
Definition: cmtypes.h:662
_In_ ULONG _In_ KEY_INFORMATION_CLASS KeyInformationClass
Definition: zwfuncs.h:167

◆ NtEnumerateValueKey()

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 541 of file ntapi.c.

547{
550 PCM_KEY_BODY KeyObject;
551 REG_ENUMERATE_VALUE_KEY_INFORMATION EnumerateValueKeyInfo;
552 REG_POST_OPERATION_INFORMATION PostOperationInfo;
553
554 PAGED_CODE();
555
556 DPRINT("NtEnumerateValueKey() KH 0x%p, Index 0x%x, KVIC %d, Length %lu\n",
558
559 /* Reject classes we don't know about */
565 {
566 /* Fail */
568 }
569
570 /* Verify that the handle is valid and is a registry key */
575 (PVOID*)&KeyObject,
576 NULL);
577 if (!NT_SUCCESS(Status)) return Status;
578
580 {
582 {
584 ProbeForWrite(KeyValueInformation,
585 Length,
586 sizeof(ULONG));
587 }
589 {
590 /* Dereference and return status */
591 ObDereferenceObject(KeyObject);
593 }
594 _SEH2_END;
595 }
596
597 /* Setup the callback */
598 PostOperationInfo.Object = (PVOID)KeyObject;
599 EnumerateValueKeyInfo.Object = (PVOID)KeyObject;
600 EnumerateValueKeyInfo.Index = Index;
602 EnumerateValueKeyInfo.KeyValueInformation = KeyValueInformation;
603 EnumerateValueKeyInfo.Length = Length;
604 EnumerateValueKeyInfo.ResultLength = ResultLength;
605
606 /* Do the callback */
608 &EnumerateValueKeyInfo);
609 if (NT_SUCCESS(Status))
610 {
611 /* Call the internal API */
613 Index,
615 KeyValueInformation,
616 Length,
618
619 /* Do the post callback */
620 PostOperationInfo.Status = Status;
622 }
623
624 /* Dereference and return status */
625 ObDereferenceObject(KeyObject);
626 return Status;
627}
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:1191
@ KeyValuePartialInformationAlign64
Definition: reg.c:112
@ KeyValueFullInformationAlign64
Definition: reg.c:111
_In_ ULONG _In_ KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmfuncs.h:94
@ KeyValueBasicInformation
Definition: nt_native.h:1183
@ KeyValuePartialInformation
Definition: nt_native.h:1185
@ KeyValueFullInformation
Definition: nt_native.h:1184
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmtypes.h:757
@ RegNtPostEnumerateValueKey
Definition: cmtypes.h:663
@ RegNtPreEnumerateValueKey
Definition: cmtypes.h:644

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

◆ NtFlushKey()

NTSTATUS NTAPI NtFlushKey ( IN HANDLE  KeyHandle)

Definition at line 1084 of file ntapi.c.

1085{
1087 PCM_KEY_BODY KeyObject;
1088 PAGED_CODE();
1089
1090 /* Get the key object */
1092 0,
1095 (PVOID*)&KeyObject,
1096 NULL);
1097 if (!NT_SUCCESS(Status)) return Status;
1098
1099 /* Lock the registry */
1101
1102 /* Lock the KCB */
1104
1105 /* Make sure KCB isn't deleted */
1106 if (KeyObject->KeyControlBlock->Delete)
1107 {
1108 /* Fail */
1110 }
1111 else
1112 {
1113 /* Call the internal API */
1114 Status = CmFlushKey(KeyObject->KeyControlBlock, FALSE);
1115 }
1116
1117 /* Release the locks */
1120
1121 /* Dereference the object and return status */
1122 ObDereferenceObject(KeyObject);
1123 return Status;
1124}
#define CmpAcquireKcbLockShared(k)
Definition: cm_x.h:162
FORCEINLINE VOID CmpReleaseKcbLock(PCM_KEY_CONTROL_BLOCK Kcb)
Definition: cm_x.h:202
NTSTATUS NTAPI CmFlushKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN BOOLEAN ExclusiveLock)
Definition: cmapi.c:1937
VOID NTAPI CmpUnlockRegistry(VOID)
Definition: cmsysini.c:2081
VOID NTAPI CmpLockRegistry(VOID)
Definition: cmsysini.c:1995
#define FALSE
Definition: types.h:117
#define STATUS_KEY_DELETED
Definition: ntstatus.h:707

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

◆ NtInitializeRegistry()

NTSTATUS NTAPI NtInitializeRegistry ( IN USHORT  Flag)

Definition at line 1317 of file ntapi.c.

1318{
1319 BOOLEAN SetupBoot;
1321 PAGED_CODE();
1322
1323 /* Always do this as kernel mode */
1324 if (KeGetPreviousMode() == UserMode)
1325 return ZwInitializeRegistry(Flag);
1326
1327 /* Enough of the system has booted by now */
1328 Ki386PerfEnd();
1329
1330 /* Validate flag */
1332
1333 /* Check if boot was accepted */
1335 {
1336 /* Only allow once */
1339
1340 /* Get the control set accepted */
1342 if (Flag)
1343 {
1344 /* Save the last known good boot */
1346
1347 /* Notify HAL */
1348 HalEndOfBoot();
1349
1350 /* Enable lazy flush */
1352 CmpLazyFlush();
1353 return Status;
1354 }
1355
1356 /* Otherwise, invalid boot */
1358 }
1359
1360 /* Check if this was a setup boot */
1361 SetupBoot = (Flag == CM_BOOT_FLAG_SETUP ? TRUE : FALSE);
1362
1363 /* Make sure we're only called once */
1364 if (!CmFirstTime) return STATUS_ACCESS_DENIED;
1366
1367 /* Lock the registry exclusively */
1369
1370 /* Initialize the hives and lazy flusher */
1371 CmpCmdInit(SetupBoot);
1372
1373 /* Save version data */
1375
1376 /* Release the registry lock */
1378 return STATUS_SUCCESS;
1379}
unsigned char BOOLEAN
Definition: actypes.h:127
NTSTATUS NTAPI CmpSaveBootControlSet(IN USHORT ControlSet)
Definition: cmcontrl.c:267
VOID NTAPI CmpLazyFlush(VOID)
Definition: cmlazy.c:157
VOID NTAPI CmpCmdInit(IN BOOLEAN SetupBoot)
Definition: cmlazy.c:233
BOOLEAN CmpHoldLazyFlush
Definition: cmlazy.c:23
VOID NTAPI CmpSetVersionData(VOID)
Definition: cmsysini.c:2207
VOID NTAPI CmpLockRegistryExclusive(VOID)
Definition: cmsysini.c:1982
#define KeGetPreviousMode()
Definition: ketypes.h:1115
NTSYSAPI NTSTATUS NTAPI ZwInitializeRegistry(_In_ USHORT Flag)
#define CM_BOOT_FLAG_ACCEPTED
Definition: cmtypes.h:174
#define CM_BOOT_FLAG_MAX
Definition: cmtypes.h:175
#define CM_BOOT_FLAG_SETUP
Definition: cmtypes.h:173
#define UserMode
Definition: asm.h:39
BOOLEAN CmBootAcceptFirstTime
Definition: ntapi.c:16
BOOLEAN CmFirstTime
Definition: ntapi.c:17
#define Ki386PerfEnd()
Definition: ke.h:174
Definition: xml2sdb.h:103
#define HalEndOfBoot
Definition: haltypes.h:317

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

◆ NtLoadKey()

NTSTATUS NTAPI NtLoadKey ( IN POBJECT_ATTRIBUTES  KeyObjectAttributes,
IN POBJECT_ATTRIBUTES  FileObjectAttributes 
)

Definition at line 1128 of file ntapi.c.

1130{
1131 /* Call the newer API */
1132 return NtLoadKeyEx(KeyObjectAttributes, FileObjectAttributes, 0, NULL);
1133}
NTSTATUS NTAPI NtLoadKeyEx(IN POBJECT_ATTRIBUTES TargetKey, IN POBJECT_ATTRIBUTES SourceFile, IN ULONG Flags, IN HANDLE TrustClassKey)
Definition: ntapi.c:1147
_In_ PWDFDEVICE_INIT _In_ PWDF_FILEOBJECT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES FileObjectAttributes
Definition: wdfdevice.h:3406

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

◆ NtLoadKey2()

NTSTATUS NTAPI NtLoadKey2 ( IN POBJECT_ATTRIBUTES  KeyObjectAttributes,
IN POBJECT_ATTRIBUTES  FileObjectAttributes,
IN ULONG  Flags 
)

Definition at line 1137 of file ntapi.c.

1140{
1141 /* Call the newer API */
1142 return NtLoadKeyEx(KeyObjectAttributes, FileObjectAttributes, Flags, NULL);
1143}
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245

◆ NtLoadKeyEx()

NTSTATUS NTAPI NtLoadKeyEx ( IN POBJECT_ATTRIBUTES  TargetKey,
IN POBJECT_ATTRIBUTES  SourceFile,
IN ULONG  Flags,
IN HANDLE  TrustClassKey 
)

Definition at line 1147 of file ntapi.c.

1151{
1154 OBJECT_ATTRIBUTES CapturedTargetKey;
1155 OBJECT_ATTRIBUTES CapturedSourceFile;
1156 UNICODE_STRING TargetKeyName, SourceFileName;
1157 HANDLE KmTargetKeyRootDir = NULL, KmSourceFileRootDir = NULL;
1158 PCM_KEY_BODY KeyBody = NULL;
1159
1160 PAGED_CODE();
1161
1162 /* Validate flags */
1163 if (Flags & ~REG_NO_LAZY_FLUSH)
1165
1166 /* Validate privilege */
1168 {
1169 DPRINT1("Restore Privilege missing!\n");
1171 }
1172
1173 /* Block APCs */
1175
1176 /* Check for user-mode caller */
1177 if (PreviousMode != KernelMode)
1178 {
1179 /* Prepare to probe parameters */
1180 _SEH2_TRY
1181 {
1182 /* Probe target key */
1183 ProbeForRead(TargetKey,
1184 sizeof(OBJECT_ATTRIBUTES),
1185 sizeof(ULONG));
1186
1187 /* Probe source file */
1188 ProbeForRead(SourceFile,
1189 sizeof(OBJECT_ATTRIBUTES),
1190 sizeof(ULONG));
1191 }
1193 {
1194 /* Return the exception code */
1196 _SEH2_YIELD(goto Quit);
1197 }
1198 _SEH2_END;
1199 }
1200
1201 /* Probe and capture the target key attributes, including the security */
1202 Status = ProbeAndCaptureObjectAttributes(&CapturedTargetKey,
1203 &TargetKeyName,
1205 TargetKey,
1206 TRUE);
1207 if (!NT_SUCCESS(Status))
1208 goto Quit;
1209
1210 /*
1211 * Probe and capture the source file attributes, but not the security.
1212 * A proper security context is built by CmLoadKey().
1213 */
1214 Status = ProbeAndCaptureObjectAttributes(&CapturedSourceFile,
1215 &SourceFileName,
1217 SourceFile,
1218 FALSE);
1219 if (!NT_SUCCESS(Status))
1220 {
1221 ReleaseCapturedObjectAttributes(&CapturedTargetKey, PreviousMode);
1222 goto Quit;
1223 }
1224
1225 /* Make sure the target key root directory handle is a kernel handle */
1228 KEY_READ,
1230 &KmTargetKeyRootDir);
1231 if (!NT_SUCCESS(Status))
1232 goto Cleanup;
1233 CapturedTargetKey.RootDirectory = KmTargetKeyRootDir;
1234 CapturedTargetKey.Attributes |= OBJ_KERNEL_HANDLE;
1235
1236 /* Make sure the source file root directory handle is a kernel handle */
1241 &KmSourceFileRootDir);
1242 if (!NT_SUCCESS(Status))
1243 goto Cleanup;
1244 CapturedSourceFile.RootDirectory = KmSourceFileRootDir;
1245 CapturedSourceFile.Attributes |= OBJ_KERNEL_HANDLE;
1246
1247 /* Check if we have a trust class */
1248 if (TrustClassKey)
1249 {
1250 /* Reference it */
1251 Status = ObReferenceObjectByHandle(TrustClassKey,
1252 0,
1255 (PVOID*)&KeyBody,
1256 NULL);
1257 }
1258
1259 /* Call the internal API */
1260 Status = CmLoadKey(&CapturedTargetKey,
1261 &CapturedSourceFile,
1262 Flags,
1263 KeyBody);
1264
1265 /* Dereference the trust key, if any */
1266 if (KeyBody) ObDereferenceObject(KeyBody);
1267
1268Cleanup:
1269 /* Close the local kernel handles */
1270 if (KmSourceFileRootDir)
1271 ObCloseHandle(KmSourceFileRootDir, KernelMode);
1272 if (KmTargetKeyRootDir)
1273 ObCloseHandle(KmTargetKeyRootDir, KernelMode);
1274
1275 /* Release the captured object attributes */
1276 ReleaseCapturedObjectAttributes(&CapturedSourceFile, PreviousMode);
1277 ReleaseCapturedObjectAttributes(&CapturedTargetKey, PreviousMode);
1278
1279Quit:
1280 /* Bring back APCs */
1282
1283 /* Return status */
1284 return Status;
1285}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI CmLoadKey(IN POBJECT_ATTRIBUTES TargetKey, IN POBJECT_ATTRIBUTES SourceFile, IN ULONG Flags, IN PCM_KEY_BODY KeyBody)
Definition: cmapi.c:2012
static const WCHAR Cleanup[]
Definition: register.c:80
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define REG_NO_LAZY_FLUSH
Definition: nt_native.h:1096
#define KEY_READ
Definition: nt_native.h:1026
#define FILE_TRAVERSE
Definition: nt_native.h:643
static NTSTATUS CmpConvertHandleToKernelHandle(_In_ HANDLE SourceHandle, _In_opt_ POBJECT_TYPE ObjectType, _In_ ACCESS_MASK DesiredAccess, _In_ KPROCESSOR_MODE AccessMode, _Out_ PHANDLE KernelHandle)
Definition: ntapi.c:194
NTSTATUS ProbeAndCaptureObjectAttributes(_Out_ POBJECT_ATTRIBUTES CapturedObjectAttributes, _Out_ PUNICODE_STRING ObjectName, _In_ KPROCESSOR_MODE AccessMode, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ BOOLEAN CaptureSecurity)
Definition: ntapi.c:52
VOID ReleaseCapturedObjectAttributes(_In_ POBJECT_ATTRIBUTES CapturedObjectAttributes, _In_ KPROCESSOR_MODE AccessMode)
Definition: ntapi.c:26
const LUID SeRestorePrivilege
Definition: priv.c:37
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3411
HANDLE RootDirectory
Definition: umtypes.h:186

Referenced by InitFunctionPtrs(), NtLoadKey(), and NtLoadKey2().

◆ NtLockProductActivationKeys()

NTSTATUS NTAPI NtLockProductActivationKeys ( IN PULONG  pPrivateVer,
IN PULONG  pSafeMode 
)

Definition at line 1403 of file ntapi.c.

1405{
1407
1409 _SEH2_TRY
1410 {
1411 /* Check if the caller asked for the version */
1412 if (pPrivateVer != NULL)
1413 {
1414 /* For user mode, probe it */
1415 if (PreviousMode != KernelMode)
1416 {
1417 ProbeForWriteUlong(pPrivateVer);
1418 }
1419
1420 /* Return the expected version */
1421 *pPrivateVer = PRODUCT_ACTIVATION_VERSION;
1422 }
1423
1424 /* Check if the caller asked for safe mode mode state */
1425 if (pSafeMode != NULL)
1426 {
1427 /* For user mode, probe it */
1428 if (PreviousMode != KernelMode)
1429 {
1430 ProbeForWriteUlong(pSafeMode);
1431 }
1432
1433 /* Return the safe boot mode state */
1434 *pSafeMode = InitSafeBootMode;
1435 }
1436 }
1438 {
1440 }
1441 _SEH2_END;
1442
1443 return STATUS_SUCCESS;
1444}
PULONG InitSafeBootMode
Definition: init.c:75
#define PRODUCT_ACTIVATION_VERSION
Definition: ntapi.c:1399

◆ NtLockRegistryKey()

NTSTATUS NTAPI NtLockRegistryKey ( IN HANDLE  KeyHandle)

Definition at line 1448 of file ntapi.c.

1449{
1452}

◆ NtNotifyChangeKey()

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 1289 of file ntapi.c.

1299{
1300 /* Call the newer API */
1302 0,
1303 NULL,
1304 Event,
1305 ApcRoutine,
1306 ApcContext,
1309 WatchTree,
1310 Buffer,
1311 Length,
1312 Asynchronous);
1313}
Definition: bufpool.h:45
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG Event
Definition: dispmprt.h:1287
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN _In_ BOOLEAN _In_ ULONG CompletionFilter
Definition: fltkernel.h:2243
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN WatchTree
Definition: fltkernel.h:2241
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:727
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:726
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:1456
_In_ SYSTEM_POWER_STATE _In_ ULONG _In_ BOOLEAN Asynchronous
Definition: ntpoapi.h:305

Referenced by InitFunctionPtrs(), and RegNotifyChangeKeyValue().

◆ NtNotifyChangeMultipleKeys()

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 1456 of file ntapi.c.

1468{
1471}
#define UNIMPLEMENTED_ONCE
Definition: typedefs.h:30

Referenced by NtNotifyChangeKey(), NtNotifyChangeMultipleKeys_WatchThread(), and START_TEST().

◆ NtOpenKey()

NTSTATUS NTAPI NtOpenKey ( OUT PHANDLE  KeyHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES  ObjectAttributes 
)

Definition at line 335 of file ntapi.c.

338{
339 CM_PARSE_CONTEXT ParseContext = {0};
343 PAGED_CODE();
344 DPRINT("NtOpenKey(Path: %wZ, Root %x, Access: %x)\n",
345 ObjectAttributes->ObjectName, ObjectAttributes->RootDirectory, DesiredAccess);
346
347 /* Ignore the WOW64 flag, it's not valid in the kernel */
348 DesiredAccess &= ~KEY_WOW64_RES;
349
350 /* Check for user-mode caller */
352 {
353 /* Prepare to probe parameters */
355 {
356 /* Probe the key handle */
358 *KeyHandle = NULL;
359
360 /* Probe object attributes */
362 sizeof(OBJECT_ATTRIBUTES),
363 sizeof(ULONG));
364 }
366 {
367 /* Return the exception code */
369 }
370 _SEH2_END;
371 }
372
373 /* Just let the object manager handle this */
377 NULL,
379 &ParseContext,
380 &Handle);
381
382 /* Only do this if we succeeded */
383 if (NT_SUCCESS(Status))
384 {
386 {
387 /* Return the handle to caller */
388 *KeyHandle = Handle;
389 }
391 {
392 /* Get the status */
394 }
395 _SEH2_END;
396 }
397
398 DPRINT("Returning handle %x, Status %x.\n", Handle, Status);
399
400 /* Return status */
401 return Status;
402}

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

◆ NtQueryKey()

NTSTATUS NTAPI NtQueryKey ( IN HANDLE  KeyHandle,
IN KEY_INFORMATION_CLASS  KeyInformationClass,
OUT PVOID  KeyInformation,
IN ULONG  Length,
OUT PULONG  ResultLength 
)

Definition at line 631 of file ntapi.c.

636{
639 PCM_KEY_BODY KeyObject;
640 REG_QUERY_KEY_INFORMATION QueryKeyInfo;
641 REG_POST_OPERATION_INFORMATION PostOperationInfo;
642 OBJECT_HANDLE_INFORMATION HandleInfo;
643 PAGED_CODE();
644 DPRINT("NtQueryKey() KH 0x%p, KIC %d, Length %lu\n",
646
647 /* Reject invalid classes */
654 {
655 /* Fail */
657 }
658
659 /* Check if just the name is required */
661 {
662 /* Ignore access level */
664 0,
667 (PVOID*)&KeyObject,
668 &HandleInfo);
669 if (NT_SUCCESS(Status))
670 {
671 /* At least a single bit of access is required */
672 if (!HandleInfo.GrantedAccess)
673 {
674 /* No such luck */
675 ObDereferenceObject(KeyObject);
677 }
678 }
679 }
680 else
681 {
682 /* Get a reference */
687 (PVOID*)&KeyObject,
688 NULL);
689 }
690
691 /* Quit on failure */
692 if (!NT_SUCCESS(Status)) return Status;
693
695 {
697 {
699 ProbeForWrite(KeyInformation,
700 Length,
701 sizeof(ULONG));
702 }
704 {
705 /* Dereference and return status */
706 ObDereferenceObject(KeyObject);
708 }
709 _SEH2_END;
710 }
711
712 /* Setup the callback */
713 PostOperationInfo.Object = (PVOID)KeyObject;
714 QueryKeyInfo.Object = (PVOID)KeyObject;
716 QueryKeyInfo.KeyInformation = KeyInformation;
717 QueryKeyInfo.Length = Length;
718 QueryKeyInfo.ResultLength = ResultLength;
719
720 /* Do the callback */
722 if (NT_SUCCESS(Status))
723 {
724 /* Call the internal API */
725 Status = CmQueryKey(KeyObject->KeyControlBlock,
727 KeyInformation,
728 Length,
730
731 /* Do the post callback */
732 PostOperationInfo.Status = Status;
734 }
735
736 /* Dereference and return status */
737 ObDereferenceObject(KeyObject);
738 return Status;
739}
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:1614
ACCESS_MASK GrantedAccess
Definition: iotypes.h:181
KEY_INFORMATION_CLASS KeyInformationClass
Definition: cmtypes.h:768
@ KeyFlagsInformation
Definition: winternl.h:1854
@ KeyCachedInformation
Definition: winternl.h:1853
@ KeyNameInformation
Definition: winternl.h:1852
@ RegNtPostQueryKey
Definition: cmtypes.h:664
@ RegNtPreQueryKey
Definition: cmtypes.h:646

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

◆ NtQueryMultipleValueKey()

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 1475 of file ntapi.c.

1481{
1484}

◆ NtQueryOpenSubKeys()

NTSTATUS NTAPI NtQueryOpenSubKeys ( IN POBJECT_ATTRIBUTES  TargetKey,
OUT PULONG  HandleCount 
)

Definition at line 1488 of file ntapi.c.

1490{
1492 PCM_KEY_BODY KeyBody = NULL;
1495 ULONG SubKeys;
1496
1497 DPRINT("NtQueryOpenSubKeys()\n");
1498
1499 PAGED_CODE();
1500
1501 /* Get the processor mode */
1503
1504 /* Check for user-mode caller */
1505 if (PreviousMode != KernelMode)
1506 {
1507 /* Prepare to probe parameters */
1508 _SEH2_TRY
1509 {
1510 /* Probe target key */
1511 ProbeForRead(TargetKey,
1512 sizeof(OBJECT_ATTRIBUTES),
1513 sizeof(ULONG));
1514
1515 /* Probe handle count */
1517 }
1519 {
1520 /* Return the exception code */
1522 }
1523 _SEH2_END;
1524 }
1525
1526 /* Open a handle to the key */
1527 Status = ObOpenObjectByName(TargetKey,
1530 NULL,
1531 KEY_READ,
1532 NULL,
1533 &KeyHandle);
1534 if (NT_SUCCESS(Status))
1535 {
1536 /* Reference the key object */
1538 KEY_READ,
1541 (PVOID*)&KeyBody,
1542 NULL);
1543
1544 /* Close the handle */
1546 }
1547
1548 /* Fail, if the key object could not be referenced */
1549 if (!NT_SUCCESS(Status))
1550 return Status;
1551
1552 /* Lock the registry exclusively */
1554
1555 /* Fail, if we did not open a hive root key */
1556 if (KeyBody->KeyControlBlock->KeyCell !=
1557 KeyBody->KeyControlBlock->KeyHive->BaseBlock->RootCell)
1558 {
1559 DPRINT("Error: Key is not a hive root key!\n");
1561 ObDereferenceObject(KeyBody);
1563 }
1564
1565 /* Call the internal API */
1566 SubKeys = CmpEnumerateOpenSubKeys(KeyBody->KeyControlBlock,
1567 FALSE, FALSE);
1568
1569 /* Unlock the registry */
1571
1572 /* Dereference the key object */
1573 ObDereferenceObject(KeyBody);
1574
1575 /* Write back the result */
1576 _SEH2_TRY
1577 {
1578 *HandleCount = SubKeys;
1579 }
1581 {
1583 }
1584 _SEH2_END;
1585
1586 DPRINT("Done.\n");
1587
1588 return Status;
1589}
ULONG NTAPI CmpEnumerateOpenSubKeys(_In_ PCM_KEY_CONTROL_BLOCK RootKcb, _In_ BOOLEAN RemoveEmptyCacheEntries, _In_ BOOLEAN DereferenceOpenedEntries)
Definition: cmapi.c:2339
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3434
static ULONG HandleCount
Definition: uefidisk.c:67

Referenced by START_TEST().

◆ NtQueryOpenSubKeysEx()

NTSTATUS NTAPI NtQueryOpenSubKeysEx ( IN POBJECT_ATTRIBUTES  TargetKey,
IN ULONG  BufferLength,
IN PVOID  Buffer,
IN PULONG  RequiredSize 
)

Definition at line 1593 of file ntapi.c.

1597{
1600}

◆ NtQueryValueKey()

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 743 of file ntapi.c.

749{
752 PCM_KEY_BODY KeyObject;
753 REG_QUERY_VALUE_KEY_INFORMATION QueryValueKeyInfo;
754 REG_POST_OPERATION_INFORMATION PostOperationInfo;
755 UNICODE_STRING ValueNameCopy;
756
757 PAGED_CODE();
758
759 DPRINT("NtQueryValueKey() KH 0x%p, VN '%wZ', KVIC %d, Length %lu\n",
761
762 /* Reject classes we don't know about */
768 {
769 /* Fail */
771 }
772
773 /* Verify that the handle is valid and is a registry key */
778 (PVOID*)&KeyObject,
779 NULL);
780 if (!NT_SUCCESS(Status))
781 return Status;
782
784 {
786 {
788 ProbeForWrite(KeyValueInformation,
789 Length,
790 sizeof(ULONG));
791 }
793 {
794 /* Dereference and return status */
795 ObDereferenceObject(KeyObject);
797 }
798 _SEH2_END;
799 }
800
801 /* Capture the string */
803 if (!NT_SUCCESS(Status))
804 goto Quit;
805
806 /* Make sure the name is aligned properly */
807 if (ValueNameCopy.Length & (sizeof(WCHAR) - 1))
808 {
809 /* It isn't, so we'll fail */
811 goto Quit;
812 }
813
814 /* Ignore any null characters at the end */
815 while (ValueNameCopy.Length &&
816 !(ValueNameCopy.Buffer[ValueNameCopy.Length / sizeof(WCHAR) - 1]))
817 {
818 /* Skip it */
819 ValueNameCopy.Length -= sizeof(WCHAR);
820 }
821
822 /* Setup the callback */
823 PostOperationInfo.Object = (PVOID)KeyObject;
824 QueryValueKeyInfo.Object = (PVOID)KeyObject;
825 QueryValueKeyInfo.ValueName = &ValueNameCopy;
827 QueryValueKeyInfo.Length = Length;
828 QueryValueKeyInfo.ResultLength = ResultLength;
829
830 /* Do the callback */
832 if (NT_SUCCESS(Status))
833 {
834 /* Call the internal API */
836 ValueNameCopy,
838 KeyValueInformation,
839 Length,
841
842 /* Do the post callback */
843 PostOperationInfo.Status = Status;
845 }
846
847Quit:
848 if (ValueNameCopy.Buffer)
850
851 /* Dereference and return status */
852 ObDereferenceObject(KeyObject);
853 return Status;
854}
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:1074
KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmtypes.h:780
@ RegNtPostQueryValueKey
Definition: cmtypes.h:665
@ RegNtPreQueryValueKey
Definition: cmtypes.h:648

◆ NtRenameKey()

NTSTATUS NTAPI NtRenameKey ( IN HANDLE  KeyHandle,
IN PUNICODE_STRING  ReplacementName 
)

Definition at line 1604 of file ntapi.c.

1606{
1609}

Referenced by test_NtRenameKey().

◆ NtReplaceKey()

NTSTATUS NTAPI NtReplaceKey ( IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN HANDLE  Key,
IN POBJECT_ATTRIBUTES  ReplacedObjectAttributes 
)

Definition at line 1613 of file ntapi.c.

1616{
1619}

Referenced by RegReplaceKeyW().

◆ NtRestoreKey()

NTSTATUS NTAPI NtRestoreKey ( IN HANDLE  KeyHandle,
IN HANDLE  FileHandle,
IN ULONG  RestoreFlags 
)

Definition at line 1623 of file ntapi.c.

1626{
1629}

Referenced by RegRestoreKeyW().

◆ NtSaveKey()

NTSTATUS NTAPI NtSaveKey ( IN HANDLE  KeyHandle,
IN HANDLE  FileHandle 
)

Definition at line 1633 of file ntapi.c.

1635{
1636 /* Call the extended API */
1638}
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
NTSTATUS NTAPI NtSaveKeyEx(IN HANDLE KeyHandle, IN HANDLE FileHandle, IN ULONG Flags)
Definition: ntapi.c:1642
#define REG_STANDARD_FORMAT
Definition: cmtypes.h:97

Referenced by RegSaveKeyExW(), RegSaveKeyW(), and START_TEST().

◆ NtSaveKeyEx()

NTSTATUS NTAPI NtSaveKeyEx ( IN HANDLE  KeyHandle,
IN HANDLE  FileHandle,
IN ULONG  Flags 
)

Definition at line 1642 of file ntapi.c.

1645{
1647 HANDLE KmFileHandle = NULL;
1648 PCM_KEY_BODY KeyObject;
1650
1651 PAGED_CODE();
1652
1653 DPRINT("NtSaveKeyEx(0x%p, 0x%p, %lu)\n", KeyHandle, FileHandle, Flags);
1654
1655 /* Verify the flags */
1656 if ((Flags != REG_STANDARD_FORMAT)
1657 && (Flags != REG_LATEST_FORMAT)
1658 && (Flags != REG_NO_COMPRESSION))
1659 {
1660 /* Only one of these values can be specified */
1662 }
1663
1664 /* Validate privilege */
1666 {
1668 }
1669
1670 /* Make sure the target file handle is a kernel handle */
1675 &KmFileHandle);
1676 if (!NT_SUCCESS(Status))
1677 goto Quit;
1678
1679 /* Verify that the handle is valid and is a registry key */
1681 KEY_READ,
1684 (PVOID*)&KeyObject,
1685 NULL);
1686 if (!NT_SUCCESS(Status))
1687 goto Quit;
1688
1689 /* Call the internal API */
1690 Status = CmSaveKey(KeyObject->KeyControlBlock, KmFileHandle, Flags);
1691
1692 /* Dereference the registry key */
1693 ObDereferenceObject(KeyObject);
1694
1695Quit:
1696 /* Close the local kernel handle */
1697 if (KmFileHandle)
1698 ObCloseHandle(KmFileHandle, KernelMode);
1699
1700 return Status;
1701}
NTSTATUS NTAPI CmSaveKey(IN PCM_KEY_CONTROL_BLOCK Kcb, IN HANDLE FileHandle, IN ULONG Flags)
Definition: cmapi.c:2649
#define FILE_WRITE_DATA
Definition: nt_native.h:631
const LUID SeBackupPrivilege
Definition: priv.c:36
#define REG_LATEST_FORMAT
Definition: cmtypes.h:98
#define REG_NO_COMPRESSION
Definition: cmtypes.h:99

Referenced by CreateRegistryFile(), and NtSaveKey().

◆ NtSaveMergedKeys()

NTSTATUS NTAPI NtSaveMergedKeys ( IN HANDLE  HighPrecedenceKeyHandle,
IN HANDLE  LowPrecedenceKeyHandle,
IN HANDLE  FileHandle 
)

Definition at line 1705 of file ntapi.c.

1708{
1711 HANDLE KmFileHandle = NULL;
1712 PCM_KEY_BODY HighPrecedenceKeyObject = NULL;
1713 PCM_KEY_BODY LowPrecedenceKeyObject = NULL;
1714
1715 PAGED_CODE();
1716
1717 DPRINT("NtSaveMergedKeys(0x%p, 0x%p, 0x%p)\n",
1718 HighPrecedenceKeyHandle, LowPrecedenceKeyHandle, FileHandle);
1719
1721
1722 /* Validate privilege */
1724 {
1726 }
1727
1728 /* Make sure the target file handle is a kernel handle */
1733 &KmFileHandle);
1734 if (!NT_SUCCESS(Status))
1735 goto Quit;
1736
1737 /* Verify that the handles are valid and are registry keys */
1738 Status = ObReferenceObjectByHandle(HighPrecedenceKeyHandle,
1739 KEY_READ,
1742 (PVOID*)&HighPrecedenceKeyObject,
1743 NULL);
1744 if (!NT_SUCCESS(Status))
1745 goto Quit;
1746
1747 Status = ObReferenceObjectByHandle(LowPrecedenceKeyHandle,
1748 KEY_READ,
1751 (PVOID*)&LowPrecedenceKeyObject,
1752 NULL);
1753 if (!NT_SUCCESS(Status))
1754 goto Quit;
1755
1756 /* Call the internal API */
1757 Status = CmSaveMergedKeys(HighPrecedenceKeyObject->KeyControlBlock,
1758 LowPrecedenceKeyObject->KeyControlBlock,
1759 KmFileHandle);
1760
1761Quit:
1762 /* Dereference the opened key objects */
1763 if (LowPrecedenceKeyObject)
1764 ObDereferenceObject(LowPrecedenceKeyObject);
1765 if (HighPrecedenceKeyObject)
1766 ObDereferenceObject(HighPrecedenceKeyObject);
1767
1768 /* Close the local kernel handle */
1769 if (KmFileHandle)
1770 ObCloseHandle(KmFileHandle, KernelMode);
1771
1772 return Status;
1773}
NTSTATUS NTAPI CmSaveMergedKeys(IN PCM_KEY_CONTROL_BLOCK HighKcb, IN PCM_KEY_CONTROL_BLOCK LowKcb, IN HANDLE FileHandle)
Definition: cmapi.c:2743

◆ NtSetInformationKey()

NTSTATUS NTAPI NtSetInformationKey ( IN HANDLE  KeyHandle,
IN KEY_SET_INFORMATION_CLASS  KeyInformationClass,
IN PVOID  KeyInformation,
IN ULONG  KeyInformationLength 
)

Definition at line 1777 of file ntapi.c.

1781{
1784}

◆ NtSetValueKey()

NTSTATUS NTAPI NtSetValueKey ( IN HANDLE  KeyHandle,
IN PUNICODE_STRING  ValueName,
IN ULONG TitleIndex  OPTIONAL,
IN ULONG  Type,
IN PVOID  Data,
IN ULONG  DataSize 
)

Definition at line 858 of file ntapi.c.

864{
867 PCM_KEY_BODY KeyObject;
868 REG_SET_VALUE_KEY_INFORMATION SetValueKeyInfo;
869 REG_POST_OPERATION_INFORMATION PostOperationInfo;
870 UNICODE_STRING ValueNameCopy;
871
872 PAGED_CODE();
873
875
876 /* Verify that the handle is valid and is a registry key */
881 (PVOID*)&KeyObject,
882 NULL);
883 if (!NT_SUCCESS(Status))
884 return Status;
885
886 if (!DataSize)
887 Data = NULL;
888
889 /* Probe and copy the data */
890 if ((PreviousMode != KernelMode) && (DataSize != 0))
891 {
892 PVOID DataCopy = NULL;
893
895 {
897 }
899 {
901 }
902 _SEH2_END;
903
904 if (!NT_SUCCESS(Status))
905 {
906 /* Dereference and return status */
907 ObDereferenceObject(KeyObject);
908 return Status;
909 }
910
912 if (!DataCopy)
913 {
914 /* Dereference and return status */
915 ObDereferenceObject(KeyObject);
917 }
918
920 {
921 RtlCopyMemory(DataCopy, Data, DataSize);
922 }
924 {
926 }
927 _SEH2_END;
928
929 if (!NT_SUCCESS(Status))
930 {
931 /* Dereference and return status */
932 ExFreePoolWithTag(DataCopy, TAG_CM);
933 ObDereferenceObject(KeyObject);
934 return Status;
935 }
936
937 Data = DataCopy;
938 }
939
940 /* Capture the string */
942 if (!NT_SUCCESS(Status))
943 goto Quit;
944
945 DPRINT("NtSetValueKey() KH 0x%p, VN '%wZ', TI %x, T %lu, DS %lu\n",
946 KeyHandle, &ValueNameCopy, TitleIndex, Type, DataSize);
947
948 /* Make sure the name is aligned, not too long, and the data under 4GB */
949 if ((ValueNameCopy.Length > 32767) ||
950 (ValueNameCopy.Length & (sizeof(WCHAR) - 1)) ||
951 (DataSize > 0x80000000))
952 {
953 /* Fail */
955 goto Quit;
956 }
957
958 /* Ignore any null characters at the end */
959 while (ValueNameCopy.Length &&
960 !(ValueNameCopy.Buffer[ValueNameCopy.Length / sizeof(WCHAR) - 1]))
961 {
962 /* Skip it */
963 ValueNameCopy.Length -= sizeof(WCHAR);
964 }
965
966 /* Don't touch read-only keys */
967 if (KeyObject->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY)
968 {
969 /* Fail */
971 goto Quit;
972 }
973
974 /* Setup callback */
975 PostOperationInfo.Object = (PVOID)KeyObject;
976 SetValueKeyInfo.Object = (PVOID)KeyObject;
977 SetValueKeyInfo.ValueName = &ValueNameCopy;
978 SetValueKeyInfo.TitleIndex = TitleIndex;
979 SetValueKeyInfo.Type = Type;
980 SetValueKeyInfo.Data = Data;
981 SetValueKeyInfo.DataSize = DataSize;
982
983 /* Do the callback */
985 if (NT_SUCCESS(Status))
986 {
987 /* Call the internal API */
989 &ValueNameCopy,
990 Type,
991 Data,
992 DataSize);
993
994 /* Do the post-callback */
995 PostOperationInfo.Status = Status;
997 }
998
999Quit:
1000 if (ValueNameCopy.Buffer)
1002
1003 if ((PreviousMode != KernelMode) && Data)
1005
1006 /* Dereference and return status */
1007 ObDereferenceObject(KeyObject);
1008 return Status;
1009}
Type
Definition: Type.h:7
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:643
#define TAG_CM
Definition: cmlib.h:219
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static ACCESS_MASK const OBJECT_ATTRIBUTES ULONG TitleIndex
Definition: reg.c:142
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
PUNICODE_STRING ValueName
Definition: cmtypes.h:714
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
@ RegNtPreSetValueKey
Definition: cmtypes.h:634
@ RegNtPostSetValueKey
Definition: cmtypes.h:658

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

◆ NtUnloadKey()

NTSTATUS NTAPI NtUnloadKey ( IN POBJECT_ATTRIBUTES  KeyObjectAttributes)

Definition at line 1788 of file ntapi.c.

1789{
1790 return NtUnloadKey2(KeyObjectAttributes, 0);
1791}
NTSTATUS NTAPI NtUnloadKey2(IN POBJECT_ATTRIBUTES TargetKey, IN ULONG Flags)
Definition: ntapi.c:1795

Referenced by DisconnectRegistry(), and RegUnLoadKeyW().

◆ NtUnloadKey2()

NTSTATUS NTAPI NtUnloadKey2 ( IN POBJECT_ATTRIBUTES  TargetKey,
IN ULONG  Flags 
)

Definition at line 1795 of file ntapi.c.

1797{
1799 OBJECT_ATTRIBUTES CapturedTargetKey;
1801 HANDLE KmTargetKeyRootDir = NULL;
1802 CM_PARSE_CONTEXT ParseContext = {0};
1804 PCM_KEY_BODY KeyBody = NULL;
1805 HANDLE Handle;
1806
1807 PAGED_CODE();
1808
1809 /* Validate privilege */
1811 {
1812 DPRINT1("Restore Privilege missing!\n");
1814 }
1815
1816 /* Check for user-mode caller */
1817 if (PreviousMode != KernelMode)
1818 {
1819 /* Prepare to probe parameters */
1820 _SEH2_TRY
1821 {
1822 /* Probe object attributes */
1823 ProbeForRead(TargetKey,
1824 sizeof(OBJECT_ATTRIBUTES),
1825 sizeof(ULONG));
1826
1827 CapturedTargetKey = *TargetKey;
1828
1829 /* Probe the string */
1830 ObjectName = ProbeForReadUnicodeString(CapturedTargetKey.ObjectName);
1831 ProbeForRead(ObjectName.Buffer,
1832 ObjectName.Length,
1833 sizeof(WCHAR));
1834
1835 CapturedTargetKey.ObjectName = &ObjectName;
1836 }
1838 {
1839 /* Return the exception code */
1841 }
1842 _SEH2_END;
1843 }
1844 else
1845 {
1846 /* Save the target attributes directly */
1847 CapturedTargetKey = *TargetKey;
1848 }
1849
1850 /* Make sure the target key root directory handle is a kernel handle */
1853 KEY_WRITE,
1855 &KmTargetKeyRootDir);
1856 if (!NT_SUCCESS(Status))
1857 return Status;
1858 CapturedTargetKey.RootDirectory = KmTargetKeyRootDir;
1859 CapturedTargetKey.Attributes |= OBJ_KERNEL_HANDLE;
1860
1861 /* Setup the parse context */
1862 ParseContext.CreateOperation = TRUE;
1864
1865 /* Do the create */
1866 /* Open a local handle to the key */
1867 Status = ObOpenObjectByName(&CapturedTargetKey,
1869 KernelMode,
1870 NULL,
1871 KEY_WRITE,
1872 &ParseContext,
1873 &Handle);
1874 if (NT_SUCCESS(Status))
1875 {
1876 /* Reference the key object */
1878 KEY_WRITE,
1880 KernelMode,
1881 (PVOID*)&KeyBody,
1882 NULL);
1883
1884 /* Close the handle */
1886 }
1887
1888 /* Close the local kernel handle */
1889 if (KmTargetKeyRootDir)
1890 ObCloseHandle(KmTargetKeyRootDir, KernelMode);
1891
1892 /* Return if a failure was encountered */
1893 if (!NT_SUCCESS(Status))
1894 return Status;
1895
1896 /*
1897 * Lock down the entire registry when we unload a hive.
1898 *
1899 * NOTE: We might block other threads of other processes that do
1900 * operations with unrelated keys of other hives when we lock
1901 * the registry for exclusive use by the calling thread that does
1902 * the unloading. If this turns out to cause a major overhead we
1903 * have to rethink the locking mechanism here (prior commit - f1d2a44).
1904 */
1907
1908 /* Check if it's being deleted already */
1909 if (KeyBody->KeyControlBlock->Delete)
1910 {
1911 /* Return appropriate status */
1913 goto Quit;
1914 }
1915
1916 /* Check if it's a read-only key */
1917 if (KeyBody->KeyControlBlock->ExtFlags & CM_KCB_READ_ONLY_KEY)
1918 {
1919 /* Return appropriate status */
1921 goto Quit;
1922 }
1923
1924 /* Call the internal API. Note that CmUnloadKey() unlocks the registry only on success. */
1926
1927Quit:
1928 /* If CmUnloadKey() failed we need to unlock registry ourselves */
1929 if (!NT_SUCCESS(Status))
1930 {
1931 /* Unlock the hive loading and registry locks */
1934 }
1935
1936 /* Dereference the key */
1937 ObDereferenceObject(KeyBody);
1938
1939 /* Return status */
1940 return Status;
1941}
NTSTATUS NTAPI CmUnloadKey(_In_ PCM_KEY_CONTROL_BLOCK Kcb, _In_ ULONG Flags)
Definition: cmapi.c:2209
EX_PUSH_LOCK CmpLoadHiveLock
Definition: cmdata.c:39
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1039
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1255
#define REG_OPTION_BACKUP_RESTORE
Definition: nt_native.h:1069
#define KEY_WRITE
Definition: nt_native.h:1034
PUNICODE_STRING ObjectName
Definition: umtypes.h:187
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64

Referenced by DisconnectRegistry(), and NtUnloadKey().

◆ NtUnloadKeyEx()

NTSTATUS NTAPI NtUnloadKeyEx ( IN POBJECT_ATTRIBUTES  TargetKey,
IN HANDLE  Event 
)

Definition at line 1945 of file ntapi.c.

1947{
1950}

◆ ProbeAndCaptureObjectAttributes()

NTSTATUS ProbeAndCaptureObjectAttributes ( _Out_ POBJECT_ATTRIBUTES  CapturedObjectAttributes,
_Out_ PUNICODE_STRING  ObjectName,
_In_ KPROCESSOR_MODE  AccessMode,
_In_ POBJECT_ATTRIBUTES  ObjectAttributes,
_In_ BOOLEAN  CaptureSecurity 
)

Definition at line 52 of file ntapi.c.

58{
61 // PSECURITY_QUALITY_OF_SERVICE SecurityQos;
62 PUNICODE_STRING LocalObjectName = NULL;
63
64 /* Zero out the Capture Data */
65 RtlZeroMemory(CapturedObjectAttributes, sizeof(*CapturedObjectAttributes));
66
67 /* SEH everything here for protection */
69 {
70 /* Check if we got attributes */
72 {
73 /* Check if we're in user mode */
75 {
76 /* Probe the attributes */
78 sizeof(OBJECT_ATTRIBUTES),
79 sizeof(ULONG));
80 }
81
82 /* Validate the Size and Attributes */
83 if ((ObjectAttributes->Length != sizeof(OBJECT_ATTRIBUTES)) ||
84 (ObjectAttributes->Attributes & ~OBJ_VALID_KERNEL_ATTRIBUTES)) // Understood as all the possible valid attributes
85 {
86 /* Invalid combination, fail */
88 }
89
90 /* Set some Create Info and do not allow user-mode kernel handles */
91 CapturedObjectAttributes->Length = sizeof(OBJECT_ATTRIBUTES);
92 CapturedObjectAttributes->RootDirectory = ObjectAttributes->RootDirectory;
93 CapturedObjectAttributes->Attributes = ObpValidateAttributes(ObjectAttributes->Attributes, AccessMode);
94 LocalObjectName = ObjectAttributes->ObjectName;
95 SecurityDescriptor = ObjectAttributes->SecurityDescriptor;
96 // SecurityQos = ObjectAttributes->SecurityQualityOfService;
97
98 /* Check if we have a security descriptor */
99 if (CaptureSecurity && SecurityDescriptor)
100 {
101 /*
102 * Capture it.
103 * Note: This has an implicit memory barrier due
104 * to the function call, so cleanup is safe here.
105 */
109 TRUE,
110 &CapturedObjectAttributes->
112 if (!NT_SUCCESS(Status))
113 {
114 /* Capture failed, quit */
115 CapturedObjectAttributes->SecurityDescriptor = NULL;
116 _SEH2_YIELD(return Status);
117 }
118 }
119 else
120 {
121 CapturedObjectAttributes->SecurityDescriptor = NULL;
122 }
123
124#if 0
125// We don't use the QoS!
126
127 /* Check if we have QoS */
128 if (SecurityQos)
129 {
130 /* Check if we came from user mode */
131 if (AccessMode != KernelMode)
132 {
133 /* Validate the QoS */
134 ProbeForRead(SecurityQos,
136 sizeof(ULONG));
137 }
138
139 /* Save Info */
140 CapturedObjectAttributes->SecurityQualityOfService = *SecurityQos;
141 CapturedObjectAttributes->SecurityQos =
142 &CapturedObjectAttributes->SecurityQualityOfService;
143 }
144#else
145 CapturedObjectAttributes->SecurityQualityOfService = NULL;
146#endif
147 }
148 else
149 {
150 /* We don't have a name */
151 LocalObjectName = NULL;
152 }
153 }
155 {
156 /* Cleanup and return the exception code */
157 ReleaseCapturedObjectAttributes(CapturedObjectAttributes, AccessMode);
159 }
160 _SEH2_END;
161
162 /* Now check if the Object Attributes had an Object Name */
163 if (LocalObjectName)
164 {
166 }
167 else
168 {
169 /* Clear the string */
170 RtlInitEmptyUnicodeString(ObjectName, NULL, 0);
171
172 /* It cannot have specified a Root Directory */
173 if (CapturedObjectAttributes->RootDirectory)
174 {
176 }
177 }
178
179 /* Set the caputured object attributes name pointer to the one the user gave to us */
180 CapturedObjectAttributes->ObjectName = ObjectName;
181
182 /* Cleanup if we failed */
183 if (!NT_SUCCESS(Status))
184 {
185 ReleaseCapturedObjectAttributes(CapturedObjectAttributes, AccessMode);
186 }
187
188 /* Return status to caller */
189 return Status;
190}
#define NonPagedPool
Definition: env_spec_w32.h:307
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:349
#define OBJ_VALID_KERNEL_ATTRIBUTES
Definition: obtypes.h:78
NTSTATUS NTAPI SeCaptureSecurityDescriptor(_In_ PSECURITY_DESCRIPTOR _OriginalSecurityDescriptor, _In_ KPROCESSOR_MODE CurrentMode, _In_ POOL_TYPE PoolType, _In_ BOOLEAN CaptureIfKernel, _Out_ PSECURITY_DESCRIPTOR *CapturedSecurityDescriptor)
Captures a security descriptor.
Definition: sd.c:386
FORCEINLINE ULONG ObpValidateAttributes(IN ULONG Attributes, IN KPROCESSOR_MODE PreviousMode)
Definition: ob_x.h:22
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
struct _OBJECT_ATTRIBUTES OBJECT_ATTRIBUTES
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191

Referenced by NtLoadKeyEx().

◆ ReleaseCapturedObjectAttributes()

VOID ReleaseCapturedObjectAttributes ( _In_ POBJECT_ATTRIBUTES  CapturedObjectAttributes,
_In_ KPROCESSOR_MODE  AccessMode 
)

Definition at line 26 of file ntapi.c.

29{
30 /* Check if we have a security descriptor */
31 if (CapturedObjectAttributes->SecurityDescriptor)
32 {
33 /* Release it */
34 SeReleaseSecurityDescriptor(CapturedObjectAttributes->SecurityDescriptor,
36 TRUE);
37 CapturedObjectAttributes->SecurityDescriptor = NULL;
38 }
39
40 /* Check if we have an object name */
41 if (CapturedObjectAttributes->ObjectName)
42 {
43 /* Release it */
44 ReleaseCapturedUnicodeString(CapturedObjectAttributes->ObjectName, AccessMode);
45 }
46}
NTSTATUS NTAPI SeReleaseSecurityDescriptor(_In_ PSECURITY_DESCRIPTOR CapturedSecurityDescriptor, _In_ KPROCESSOR_MODE CurrentMode, _In_ BOOLEAN CaptureIfKernelMode)
Releases a captured security descriptor buffer.
Definition: sd.c:760

Referenced by NtLoadKeyEx(), and ProbeAndCaptureObjectAttributes().

Variable Documentation

◆ CmBootAcceptFirstTime

BOOLEAN CmBootAcceptFirstTime = TRUE

Definition at line 16 of file ntapi.c.

Referenced by NtInitializeRegistry().

◆ CmFirstTime

BOOLEAN CmFirstTime = TRUE

Definition at line 17 of file ntapi.c.

Referenced by CmShutdownSystem(), and NtInitializeRegistry().