1 /* $Id: registry.c,v 1.105 2003/06/16 13:56:30 ekohl Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/cm/registry.c
6 * PURPOSE: Registry functions
7 * PROGRAMMERS: Rex Jolliff
14 #define NTOS_MODE_KERNEL
19 #include <internal/ob.h>
20 #include <internal/registry.h>
21 #include <reactos/bugcodes.h>
24 #include <internal/debug.h>
28 /* GLOBALS ******************************************************************/
30 POBJECT_TYPE CmiKeyType
= NULL
;
31 PREGISTRY_HIVE CmiVolatileHive
= NULL
;
32 KSPIN_LOCK CmiKeyListLock
;
34 LIST_ENTRY CmiHiveListHead
;
35 ERESOURCE CmiHiveListLock
;
37 volatile BOOLEAN CmiHiveSyncEnabled
= FALSE
;
38 volatile BOOLEAN CmiHiveSyncPending
= FALSE
;
40 KTIMER CmiHiveSyncTimer
;
42 static GENERIC_MAPPING CmiKeyMapping
=
43 {KEY_READ
, KEY_WRITE
, KEY_EXECUTE
, KEY_ALL_ACCESS
};
48 CmiCheckKey(BOOLEAN Verbose
,
52 CmiCreateCurrentControlSetLink(VOID
);
55 CmiHiveSyncDpcRoutine(PKDPC Dpc
,
56 PVOID DeferredContext
,
57 PVOID SystemArgument1
,
58 PVOID SystemArgument2
);
60 /* FUNCTIONS ****************************************************************/
63 CmiCheckSubKeys(BOOLEAN Verbose
,
66 OBJECT_ATTRIBUTES ObjectAttributes
;
67 PKEY_NODE_INFORMATION KeyInfo
;
68 WCHAR KeyBuffer
[MAX_PATH
];
69 UNICODE_STRING KeyPath
;
80 BufferSize
= sizeof(KEY_NODE_INFORMATION
) + 4096;
81 KeyInfo
= ExAllocatePool(PagedPool
, BufferSize
);
83 Status
= NtEnumerateKey(Key
,
89 if (!NT_SUCCESS(Status
))
92 if (Status
== STATUS_NO_MORE_ENTRIES
)
93 Status
= STATUS_SUCCESS
;
99 KeyInfo
->NameLength
/ sizeof(WCHAR
));
103 DbgPrint("Key: %S\n", Name
);
106 /* FIXME: Check info. */
110 wcscpy(KeyBuffer
, L
"\\Registry\\");
111 wcscat(KeyBuffer
, Name
);
113 RtlInitUnicodeString(&KeyPath
, KeyBuffer
);
115 InitializeObjectAttributes(&ObjectAttributes
,
117 OBJ_CASE_INSENSITIVE
,
121 Status
= NtOpenKey(&SubKey
,
125 assert(NT_SUCCESS(Status
));
127 CmiCheckKey(Verbose
, SubKey
);
134 assert(NT_SUCCESS(Status
));
139 CmiCheckValues(BOOLEAN Verbose
,
142 PKEY_NODE_INFORMATION ValueInfo
;
143 WCHAR Name
[MAX_PATH
];
152 BufferSize
= sizeof(KEY_NODE_INFORMATION
) + 4096;
153 ValueInfo
= ExAllocatePool(PagedPool
, BufferSize
);
155 Status
= NtEnumerateValueKey(Key
,
161 if (!NT_SUCCESS(Status
))
163 ExFreePool(ValueInfo
);
164 if (Status
== STATUS_NO_MORE_ENTRIES
)
165 Status
= STATUS_SUCCESS
;
171 ValueInfo
->NameLength
/ sizeof(WCHAR
));
175 DbgPrint("Value: %S\n", Name
);
178 /* FIXME: Check info. */
180 ExFreePool(ValueInfo
);
185 assert(NT_SUCCESS(Status
));
190 CmiCheckKey(BOOLEAN Verbose
,
193 CmiCheckValues(Verbose
, Key
);
194 CmiCheckSubKeys(Verbose
, Key
);
199 CmiCheckByName(BOOLEAN Verbose
,
202 OBJECT_ATTRIBUTES ObjectAttributes
;
203 WCHAR KeyPathBuffer
[MAX_PATH
];
204 UNICODE_STRING KeyPath
;
208 wcscpy(KeyPathBuffer
, L
"\\Registry\\");
209 wcscat(KeyPathBuffer
, KeyName
);
211 RtlInitUnicodeString(&KeyPath
, KeyPathBuffer
);
213 InitializeObjectAttributes(&ObjectAttributes
,
215 OBJ_CASE_INSENSITIVE
,
219 Status
= NtOpenKey(&Key
,
225 if (!NT_SUCCESS(Status
))
227 DbgPrint("KeyPath %wZ Status: %.08x", KeyPath
, Status
);
228 DbgPrint("KeyPath %S Status: %.08x", KeyPath
.Buffer
, Status
);
229 assert(NT_SUCCESS(Status
));
233 CmiCheckKey(Verbose
, Key
);
240 CmiCheckRegistry(BOOLEAN Verbose
)
243 DbgPrint("Checking registry internals\n");
245 CmiCheckByName(Verbose
, L
"Machine");
246 CmiCheckByName(Verbose
, L
"User");
251 CmInitializeRegistry(VOID
)
253 OBJECT_ATTRIBUTES ObjectAttributes
;
254 UNICODE_STRING KeyName
;
256 HANDLE RootKeyHandle
;
260 /* Initialize the Key object type */
261 CmiKeyType
= ExAllocatePool(NonPagedPool
, sizeof(OBJECT_TYPE
));
263 CmiKeyType
->TotalObjects
= 0;
264 CmiKeyType
->TotalHandles
= 0;
265 CmiKeyType
->MaxObjects
= LONG_MAX
;
266 CmiKeyType
->MaxHandles
= LONG_MAX
;
267 CmiKeyType
->PagedPoolCharge
= 0;
268 CmiKeyType
->NonpagedPoolCharge
= sizeof(KEY_OBJECT
);
269 CmiKeyType
->Mapping
= &CmiKeyMapping
;
270 CmiKeyType
->Dump
= NULL
;
271 CmiKeyType
->Open
= NULL
;
272 CmiKeyType
->Close
= NULL
;
273 CmiKeyType
->Delete
= CmiObjectDelete
;
274 CmiKeyType
->Parse
= CmiObjectParse
;
275 CmiKeyType
->Security
= CmiObjectSecurity
;
276 CmiKeyType
->QueryName
= CmiObjectQueryName
;
277 CmiKeyType
->OkayToClose
= NULL
;
278 CmiKeyType
->Create
= CmiObjectCreate
;
279 CmiKeyType
->DuplicationNotify
= NULL
;
280 RtlInitUnicodeString(&CmiKeyType
->TypeName
, L
"Key");
282 /* Initialize the hive list */
283 InitializeListHead(&CmiHiveListHead
);
284 ExInitializeResourceLite(&CmiHiveListLock
);
286 /* Build volatile registry store */
287 Status
= CmiCreateVolatileHive (&CmiVolatileHive
);
288 assert(NT_SUCCESS(Status
));
290 /* Create '\Registry' key. */
291 RtlInitUnicodeString(&KeyName
, REG_ROOT_KEY_NAME
);
292 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, 0, NULL
, NULL
);
293 Status
= ObRosCreateObject(&RootKeyHandle
,
294 STANDARD_RIGHTS_REQUIRED
,
298 assert(NT_SUCCESS(Status
));
299 Status
= ObReferenceObjectByHandle(RootKeyHandle
,
300 STANDARD_RIGHTS_REQUIRED
,
305 assert(NT_SUCCESS(Status
));
306 RootKey
->RegistryHive
= CmiVolatileHive
;
307 RootKey
->BlockOffset
= CmiVolatileHive
->HiveHeader
->RootKeyCell
;
308 RootKey
->KeyCell
= CmiGetBlock(CmiVolatileHive
, RootKey
->BlockOffset
, NULL
);
309 RootKey
->ParentKey
= RootKey
;
311 RootKey
->NumberOfSubKeys
= 0;
312 RootKey
->SubKeys
= NULL
;
313 RootKey
->SizeOfSubKeys
= 0;
314 Status
= RtlCreateUnicodeString(&RootKey
->Name
, L
"Registry");
315 assert(NT_SUCCESS(Status
));
317 KeInitializeSpinLock(&CmiKeyListLock
);
319 /* Create '\Registry\Machine' key. */
320 RtlInitUnicodeString(&KeyName
,
322 InitializeObjectAttributes(&ObjectAttributes
,
327 Status
= NtCreateKey(&KeyHandle
,
328 STANDARD_RIGHTS_REQUIRED
,
334 assert(NT_SUCCESS(Status
));
336 /* Create '\Registry\User' key. */
337 RtlInitUnicodeString(&KeyName
,
339 InitializeObjectAttributes(&ObjectAttributes
,
344 Status
= NtCreateKey(&KeyHandle
,
345 STANDARD_RIGHTS_REQUIRED
,
351 assert(NT_SUCCESS(Status
));
356 CmInit2(PCHAR CommandLine
)
362 /* FIXME: Store system start options */
366 /* Create the 'CurrentControlSet' link. */
367 Status
= CmiCreateCurrentControlSetLink();
368 if (!NT_SUCCESS(Status
))
370 KeBugCheck(CONFIG_INITIALIZATION_FAILED
);
373 /* Set PICE 'Start' value to 1, if PICE debugging is enabled */
375 p1
= (PCHAR
)CommandLine
;
376 while (p1
&& (p2
= strchr(p1
, '/')))
379 if (_strnicmp(p2
, "DEBUGPORT", 9) == 0)
385 if (_strnicmp(p2
, "PICE", 4) == 0)
395 Status
= RtlWriteRegistryValue(RTL_REGISTRY_SERVICES
,
401 if (!NT_SUCCESS(Status
))
403 KeBugCheck(CONFIG_INITIALIZATION_FAILED
);
409 CmiCreateCurrentControlSetLink(VOID
)
411 RTL_QUERY_REGISTRY_TABLE QueryTable
[5];
412 WCHAR TargetNameBuffer
[80];
413 ULONG TargetNameLength
;
414 UNICODE_STRING LinkName
;
415 UNICODE_STRING LinkValue
;
421 OBJECT_ATTRIBUTES ObjectAttributes
;
424 DPRINT("CmiCreateCurrentControlSetLink() called\n");
426 RtlZeroMemory(&QueryTable
, sizeof(QueryTable
));
428 QueryTable
[0].Name
= L
"Current";
429 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
430 QueryTable
[0].EntryContext
= &CurrentSet
;
432 QueryTable
[1].Name
= L
"Default";
433 QueryTable
[1].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
434 QueryTable
[1].EntryContext
= &DefaultSet
;
436 QueryTable
[2].Name
= L
"Failed";
437 QueryTable
[2].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
438 QueryTable
[2].EntryContext
= &Failed
;
440 QueryTable
[3].Name
= L
"LastKnownGood";
441 QueryTable
[3].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
442 QueryTable
[3].EntryContext
= &LastKnownGood
;
444 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
445 L
"\\Registry\\Machine\\SYSTEM\\Select",
449 if (!NT_SUCCESS(Status
))
454 DPRINT("Current %ld Default %ld\n", CurrentSet
, DefaultSet
);
456 swprintf(TargetNameBuffer
,
457 L
"\\Registry\\Machine\\SYSTEM\\ControlSet%03lu",
459 TargetNameLength
= wcslen(TargetNameBuffer
) * sizeof(WCHAR
);
461 DPRINT("Link target '%S'\n", TargetNameBuffer
);
463 RtlInitUnicodeStringFromLiteral(&LinkName
,
464 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet");
465 InitializeObjectAttributes(&ObjectAttributes
,
467 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
| OBJ_OPENLINK
,
470 Status
= NtCreateKey(&KeyHandle
,
471 KEY_ALL_ACCESS
| KEY_CREATE_LINK
,
475 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
477 if (!NT_SUCCESS(Status
))
479 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
483 RtlInitUnicodeStringFromLiteral(&LinkValue
,
484 L
"SymbolicLinkValue");
485 Status
= NtSetValueKey(KeyHandle
,
489 (PVOID
)TargetNameBuffer
,
491 if (!NT_SUCCESS(Status
))
493 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
503 CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes
,
504 IN PREGISTRY_HIVE RegistryHive
)
506 UNICODE_STRING RemainingPath
;
507 PKEY_OBJECT ParentKey
;
512 DPRINT("CmiConnectHive(%p, %p) called.\n",
513 KeyObjectAttributes
, RegistryHive
);
515 Status
= ObFindObject(KeyObjectAttributes
,
519 if (!NT_SUCCESS(Status
))
524 DPRINT ("RemainingPath %wZ\n", &RemainingPath
);
526 if ((RemainingPath
.Buffer
== NULL
) || (RemainingPath
.Buffer
[0] == 0))
528 ObDereferenceObject (ParentKey
);
529 return STATUS_OBJECT_NAME_COLLISION
;
532 /* If RemainingPath contains \ we must return error
533 because CmiConnectHive() can not create trees */
534 SubName
= RemainingPath
.Buffer
;
535 if (*SubName
== L
'\\')
538 if (wcschr (SubName
, L
'\\') != NULL
)
540 ObDereferenceObject (ParentKey
);
541 return STATUS_OBJECT_NAME_NOT_FOUND
;
544 DPRINT("RemainingPath %S ParentObject %x\n",
545 RemainingPath
.Buffer
, Object
);
547 Status
= ObRosCreateObject(NULL
,
548 STANDARD_RIGHTS_REQUIRED
,
552 if (!NT_SUCCESS(Status
))
557 if (!NT_SUCCESS(Status
))
559 DPRINT1 ("ObRosCreateObject() failed (Status %lx)\n", Status
);
560 ObDereferenceObject (ParentKey
);
564 NewKey
->RegistryHive
= RegistryHive
;
565 NewKey
->BlockOffset
= RegistryHive
->HiveHeader
->RootKeyCell
;
566 NewKey
->KeyCell
= CmiGetBlock(RegistryHive
, NewKey
->BlockOffset
, NULL
);
568 NewKey
->NumberOfSubKeys
= 0;
569 NewKey
->SubKeys
= ExAllocatePool(PagedPool
,
570 NewKey
->KeyCell
->NumberOfSubKeys
* sizeof(ULONG
));
572 if ((NewKey
->SubKeys
== NULL
) && (NewKey
->KeyCell
->NumberOfSubKeys
!= 0))
574 DPRINT("NumberOfSubKeys %d\n", NewKey
->KeyCell
->NumberOfSubKeys
);
575 ObDereferenceObject (NewKey
);
576 ObDereferenceObject (ParentKey
);
577 return STATUS_INSUFFICIENT_RESOURCES
;
580 Status
= RtlCreateUnicodeString(&NewKey
->Name
,
582 if (!NT_SUCCESS(Status
))
584 DPRINT1("RtlCreateUnicodeString() failed (Status %lx)\n", Status
);
585 if (NewKey
->SubKeys
!= NULL
)
587 ExFreePool (NewKey
->SubKeys
);
589 ObDereferenceObject (NewKey
);
590 ObDereferenceObject (ParentKey
);
591 return STATUS_INSUFFICIENT_RESOURCES
;
594 CmiAddKeyToList (ParentKey
, NewKey
);
595 ObDereferenceObject (ParentKey
);
597 VERIFY_KEY_OBJECT(NewKey
);
599 /* Note: Do not dereference NewKey here! */
601 return STATUS_SUCCESS
;
606 CmiDisconnectHive (IN POBJECT_ATTRIBUTES KeyObjectAttributes
,
607 OUT PREGISTRY_HIVE
*RegistryHive
)
609 PKEY_OBJECT KeyObject
;
614 DPRINT("CmiDisconnectHive() called\n");
616 *RegistryHive
= NULL
;
618 Status
= ObOpenObjectByName (KeyObjectAttributes
,
622 STANDARD_RIGHTS_REQUIRED
,
625 if (!NT_SUCCESS(Status
))
627 DPRINT1 ("ObOpenObjectByName() failed (Status %lx)\n", Status
);
631 Status
= ObReferenceObjectByHandle (KeyHandle
,
632 STANDARD_RIGHTS_REQUIRED
,
638 if (!NT_SUCCESS(Status
))
640 DPRINT1 ("ObReferenceObjectByName() failed (Status %lx)\n", Status
);
643 DPRINT ("KeyObject %p Hive %p\n", KeyObject
, KeyObject
->RegistryHive
);
645 if (!(KeyObject
->KeyCell
->Flags
& REG_KEY_ROOT_CELL
))
647 DPRINT1 ("Key is not the Hive-Root-Key\n");
648 ObDereferenceObject (KeyObject
);
649 return STATUS_INVALID_PARAMETER
;
652 if (ObGetObjectHandleCount (KeyObject
) != 0 ||
653 ObGetObjectPointerCount (KeyObject
) != 2)
655 DPRINT1 ("Hive is still in use\n");
656 ObDereferenceObject (KeyObject
);
657 return STATUS_UNSUCCESSFUL
;
660 Hive
= KeyObject
->RegistryHive
;
661 CmiRemoveKeyFromList (KeyObject
);
663 /* Dereference KeyObject twice to delete it */
664 ObDereferenceObject (KeyObject
);
665 ObDereferenceObject (KeyObject
);
667 *RegistryHive
= Hive
;
669 DPRINT ("CmiDisconnectHive() done\n");
671 return STATUS_SUCCESS
;
676 CmiInitControlSetLink (VOID
)
678 OBJECT_ATTRIBUTES ObjectAttributes
;
679 UNICODE_STRING ControlSetKeyName
;
680 UNICODE_STRING ControlSetLinkName
;
681 UNICODE_STRING ControlSetValueName
;
685 /* Create 'ControlSet001' key */
686 RtlInitUnicodeStringFromLiteral (&ControlSetKeyName
,
687 L
"\\Registry\\Machine\\SYSTEM\\ControlSet001");
688 InitializeObjectAttributes (&ObjectAttributes
,
690 OBJ_CASE_INSENSITIVE
,
693 Status
= NtCreateKey (&KeyHandle
,
698 REG_OPTION_NON_VOLATILE
,
700 if (!NT_SUCCESS(Status
))
702 DPRINT1 ("NtCreateKey() failed (Status %lx)\n", Status
);
707 /* Link 'CurrentControlSet' to 'ControlSet001' key */
708 RtlInitUnicodeStringFromLiteral (&ControlSetLinkName
,
709 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet");
710 InitializeObjectAttributes (&ObjectAttributes
,
712 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
| OBJ_OPENLINK
,
715 Status
= NtCreateKey (&KeyHandle
,
716 KEY_ALL_ACCESS
| KEY_CREATE_LINK
,
720 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
722 if (!NT_SUCCESS(Status
))
724 DPRINT1 ("NtCreateKey() failed (Status %lx)\n", Status
);
728 RtlInitUnicodeStringFromLiteral (&ControlSetValueName
,
729 L
"SymbolicLinkValue");
730 Status
= NtSetValueKey (KeyHandle
,
731 &ControlSetValueName
,
734 (PVOID
)ControlSetKeyName
.Buffer
,
735 ControlSetKeyName
.Length
);
736 if (!NT_SUCCESS(Status
))
738 DPRINT1 ("NtSetValueKey() failed (Status %lx)\n", Status
);
742 return STATUS_SUCCESS
;
747 CmiInitHives(BOOLEAN SetupBoot
)
749 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo
;
750 OBJECT_ATTRIBUTES ObjectAttributes
;
751 UNICODE_STRING FileName
;
752 UNICODE_STRING KeyName
;
753 UNICODE_STRING ValueName
;
758 WCHAR ConfigPath
[MAX_PATH
];
765 DPRINT("CmiInitHives() called\n");
767 if (SetupBoot
== TRUE
)
769 RtlInitUnicodeStringFromLiteral(&KeyName
,
770 L
"\\Registry\\Machine\\HARDWARE");
771 InitializeObjectAttributes(&ObjectAttributes
,
773 OBJ_CASE_INSENSITIVE
,
776 Status
= NtOpenKey(&KeyHandle
,
779 if (!NT_SUCCESS(Status
))
781 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
785 RtlInitUnicodeStringFromLiteral(&ValueName
,
788 BufferSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + 4096;
789 ValueInfo
= ExAllocatePool(PagedPool
,
791 if (ValueInfo
== NULL
)
794 return(STATUS_INSUFFICIENT_RESOURCES
);
797 Status
= NtQueryValueKey(KeyHandle
,
799 KeyValuePartialInformation
,
804 if (!NT_SUCCESS(Status
))
806 ExFreePool(ValueInfo
);
810 RtlCopyMemory(ConfigPath
,
812 ValueInfo
->DataLength
);
813 ConfigPath
[ValueInfo
->DataLength
/ sizeof(WCHAR
)] = (WCHAR
)0;
814 ExFreePool(ValueInfo
);
818 wcscpy(ConfigPath
, L
"\\SystemRoot");
820 wcscat(ConfigPath
, L
"\\system32\\config");
822 DPRINT("ConfigPath: %S\n", ConfigPath
);
824 EndPtr
= ConfigPath
+ wcslen(ConfigPath
);
828 /* FIXME: Save boot log */
830 /* Connect the SYSTEM hive only if it has been created */
831 if (SetupBoot
== TRUE
)
833 wcscpy(EndPtr
, REG_SYSTEM_FILE_NAME
);
834 DPRINT ("ConfigPath: %S\n", ConfigPath
);
836 RtlInitUnicodeString (&KeyName
,
837 REG_SYSTEM_KEY_NAME
);
838 InitializeObjectAttributes(&ObjectAttributes
,
840 OBJ_CASE_INSENSITIVE
,
844 RtlInitUnicodeString (&FileName
,
846 Status
= CmiLoadHive (&ObjectAttributes
,
849 if (!NT_SUCCESS(Status
))
851 DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status
);
855 Status
= CmiInitControlSetLink ();
856 if (!NT_SUCCESS(Status
))
858 DPRINT1("CmiInitControlSetLink() failed (Status %lx)\n", Status
);
863 /* Connect the SOFTWARE hive */
864 wcscpy(EndPtr
, REG_SOFTWARE_FILE_NAME
);
865 RtlInitUnicodeString (&FileName
,
867 DPRINT ("ConfigPath: %S\n", ConfigPath
);
869 RtlInitUnicodeString (&KeyName
,
870 REG_SOFTWARE_KEY_NAME
);
871 InitializeObjectAttributes(&ObjectAttributes
,
873 OBJ_CASE_INSENSITIVE
,
877 Status
= CmiLoadHive (&ObjectAttributes
,
880 if (!NT_SUCCESS(Status
))
882 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
886 /* Connect the SAM hive */
887 wcscpy(EndPtr
, REG_SAM_FILE_NAME
);
888 RtlInitUnicodeString (&FileName
,
890 DPRINT ("ConfigPath: %S\n", ConfigPath
);
892 RtlInitUnicodeString (&KeyName
,
894 InitializeObjectAttributes(&ObjectAttributes
,
896 OBJ_CASE_INSENSITIVE
,
899 Status
= CmiLoadHive (&ObjectAttributes
,
902 if (!NT_SUCCESS(Status
))
904 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
908 /* Connect the SECURITY hive */
909 wcscpy(EndPtr
, REG_SEC_FILE_NAME
);
910 RtlInitUnicodeString (&FileName
,
912 DPRINT ("ConfigPath: %S\n", ConfigPath
);
914 RtlInitUnicodeString (&KeyName
,
916 InitializeObjectAttributes(&ObjectAttributes
,
918 OBJ_CASE_INSENSITIVE
,
921 Status
= CmiLoadHive (&ObjectAttributes
,
924 if (!NT_SUCCESS(Status
))
926 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
930 /* Connect the DEFAULT hive */
931 wcscpy(EndPtr
, REG_DEFAULT_USER_FILE_NAME
);
932 RtlInitUnicodeString (&FileName
,
934 DPRINT ("ConfigPath: %S\n", ConfigPath
);
936 RtlInitUnicodeString (&KeyName
,
937 REG_DEFAULT_USER_KEY_NAME
);
938 InitializeObjectAttributes(&ObjectAttributes
,
940 OBJ_CASE_INSENSITIVE
,
943 Status
= CmiLoadHive (&ObjectAttributes
,
946 if (!NT_SUCCESS(Status
))
948 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
952 // CmiCheckRegistry(TRUE);
954 /* Start automatic hive synchronization */
955 KeInitializeDpc(&CmiHiveSyncDpc
,
956 CmiHiveSyncDpcRoutine
,
958 KeInitializeTimer(&CmiHiveSyncTimer
);
959 CmiHiveSyncEnabled
= TRUE
;
961 DPRINT("CmiInitHives() done\n");
963 return(STATUS_SUCCESS
);
968 CmShutdownRegistry(VOID
)
973 DPRINT1("CmShutdownRegistry() called\n");
975 /* Stop automatic hive synchronization */
976 CmiHiveSyncEnabled
= FALSE
;
978 /* Acquire hive list lock exclusively */
979 ExAcquireResourceExclusiveLite(&CmiHiveListLock
, TRUE
);
981 Entry
= CmiHiveListHead
.Flink
;
982 while (Entry
!= &CmiHiveListHead
)
984 Hive
= CONTAINING_RECORD(Entry
, REGISTRY_HIVE
, HiveList
);
986 if (!(IsNoFileHive(Hive
) || IsNoSynchHive(Hive
)))
988 /* Acquire hive resource exclusively */
989 ExAcquireResourceExclusiveLite(&Hive
->HiveResource
,
992 /* Flush non-volatile hive */
993 CmiFlushRegistryHive(Hive
);
995 /* Release hive resource */
996 ExReleaseResourceLite(&Hive
->HiveResource
);
999 Entry
= Entry
->Flink
;
1002 /* Release hive list lock */
1003 ExReleaseResourceLite(&CmiHiveListLock
);
1005 DPRINT1("CmShutdownRegistry() done\n");
1010 CmiHiveSyncRoutine(PVOID DeferredContext
)
1012 PREGISTRY_HIVE Hive
;
1015 DPRINT("CmiHiveSyncRoutine() called\n");
1017 CmiHiveSyncPending
= FALSE
;
1019 /* Acquire hive list lock exclusively */
1020 ExAcquireResourceExclusiveLite(&CmiHiveListLock
, TRUE
);
1022 Entry
= CmiHiveListHead
.Flink
;
1023 while (Entry
!= &CmiHiveListHead
)
1025 Hive
= CONTAINING_RECORD(Entry
, REGISTRY_HIVE
, HiveList
);
1027 if (!(IsNoFileHive(Hive
) || IsNoSynchHive(Hive
)))
1029 /* Acquire hive resource exclusively */
1030 ExAcquireResourceExclusiveLite(&Hive
->HiveResource
,
1033 /* Flush non-volatile hive */
1034 CmiFlushRegistryHive(Hive
);
1036 /* Release hive resource */
1037 ExReleaseResourceLite(&Hive
->HiveResource
);
1040 Entry
= Entry
->Flink
;
1043 /* Release hive list lock */
1044 ExReleaseResourceLite(&CmiHiveListLock
);
1046 DPRINT("DeferredContext %x\n", DeferredContext
);
1047 ExFreePool(DeferredContext
);
1049 DPRINT("CmiHiveSyncRoutine() done\n");
1054 CmiHiveSyncDpcRoutine(PKDPC Dpc
,
1055 PVOID DeferredContext
,
1056 PVOID SystemArgument1
,
1057 PVOID SystemArgument2
)
1059 PWORK_QUEUE_ITEM WorkQueueItem
;
1061 WorkQueueItem
= ExAllocatePool(NonPagedPool
,
1062 sizeof(WORK_QUEUE_ITEM
));
1063 if (WorkQueueItem
== NULL
)
1065 DbgPrint("Failed to allocate work item\n");
1069 ExInitializeWorkItem(WorkQueueItem
,
1073 DPRINT("DeferredContext %x\n", WorkQueueItem
);
1074 ExQueueWorkItem(WorkQueueItem
,
1082 LARGE_INTEGER Timeout
;
1084 DPRINT("CmiSyncHives() called\n");
1086 if (CmiHiveSyncEnabled
== FALSE
||
1087 CmiHiveSyncPending
== TRUE
)
1090 CmiHiveSyncPending
= TRUE
;
1093 Timeout
.QuadPart
= -50000000LL;
1094 KeSetTimer(&CmiHiveSyncTimer
,