1 /* $Id: registry.c,v 1.112 2003/10/13 20:53:42 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 ObpCreateTypeObject (CmiKeyType
);
284 /* Initialize the hive list */
285 InitializeListHead(&CmiHiveListHead
);
286 ExInitializeResourceLite(&CmiHiveListLock
);
288 /* Build volatile registry store */
289 Status
= CmiCreateVolatileHive (&CmiVolatileHive
);
290 assert(NT_SUCCESS(Status
));
292 /* Create '\Registry' key. */
293 RtlInitUnicodeString(&KeyName
, REG_ROOT_KEY_NAME
);
294 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, 0, NULL
, NULL
);
295 Status
= ObCreateObject(KernelMode
,
304 assert(NT_SUCCESS(Status
));
305 Status
= ObInsertObject(RootKey
,
307 STANDARD_RIGHTS_REQUIRED
,
311 assert(NT_SUCCESS(Status
));
312 RootKey
->RegistryHive
= CmiVolatileHive
;
313 RootKey
->KeyCellOffset
= CmiVolatileHive
->HiveHeader
->RootKeyOffset
;
314 RootKey
->KeyCell
= CmiGetCell (CmiVolatileHive
, RootKey
->KeyCellOffset
, NULL
);
315 RootKey
->ParentKey
= RootKey
;
317 RootKey
->NumberOfSubKeys
= 0;
318 RootKey
->SubKeys
= NULL
;
319 RootKey
->SizeOfSubKeys
= 0;
320 Status
= RtlCreateUnicodeString(&RootKey
->Name
, L
"Registry");
321 assert(NT_SUCCESS(Status
));
323 KeInitializeSpinLock(&CmiKeyListLock
);
325 /* Create '\Registry\Machine' key. */
326 RtlInitUnicodeString(&KeyName
,
328 InitializeObjectAttributes(&ObjectAttributes
,
333 Status
= NtCreateKey(&KeyHandle
,
334 STANDARD_RIGHTS_REQUIRED
,
340 assert(NT_SUCCESS(Status
));
342 /* Create '\Registry\User' key. */
343 RtlInitUnicodeString(&KeyName
,
345 InitializeObjectAttributes(&ObjectAttributes
,
350 Status
= NtCreateKey(&KeyHandle
,
351 STANDARD_RIGHTS_REQUIRED
,
357 assert(NT_SUCCESS(Status
));
362 CmInit2(PCHAR CommandLine
)
368 /* FIXME: Store system start options */
372 /* Create the 'CurrentControlSet' link. */
373 Status
= CmiCreateCurrentControlSetLink();
374 if (!NT_SUCCESS(Status
))
376 KEBUGCHECK(CONFIG_INITIALIZATION_FAILED
);
379 /* Set PICE 'Start' value to 1, if PICE debugging is enabled */
381 p1
= (PCHAR
)CommandLine
;
382 while (p1
&& (p2
= strchr(p1
, '/')))
385 if (_strnicmp(p2
, "DEBUGPORT", 9) == 0)
391 if (_strnicmp(p2
, "PICE", 4) == 0)
401 Status
= RtlWriteRegistryValue(RTL_REGISTRY_SERVICES
,
407 if (!NT_SUCCESS(Status
))
409 KEBUGCHECK(CONFIG_INITIALIZATION_FAILED
);
415 CmiCreateCurrentControlSetLink(VOID
)
417 RTL_QUERY_REGISTRY_TABLE QueryTable
[5];
418 WCHAR TargetNameBuffer
[80];
419 ULONG TargetNameLength
;
420 UNICODE_STRING LinkName
;
421 UNICODE_STRING LinkValue
;
427 OBJECT_ATTRIBUTES ObjectAttributes
;
430 DPRINT("CmiCreateCurrentControlSetLink() called\n");
432 RtlZeroMemory(&QueryTable
, sizeof(QueryTable
));
434 QueryTable
[0].Name
= L
"Current";
435 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
436 QueryTable
[0].EntryContext
= &CurrentSet
;
438 QueryTable
[1].Name
= L
"Default";
439 QueryTable
[1].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
440 QueryTable
[1].EntryContext
= &DefaultSet
;
442 QueryTable
[2].Name
= L
"Failed";
443 QueryTable
[2].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
444 QueryTable
[2].EntryContext
= &Failed
;
446 QueryTable
[3].Name
= L
"LastKnownGood";
447 QueryTable
[3].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
448 QueryTable
[3].EntryContext
= &LastKnownGood
;
450 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
451 L
"\\Registry\\Machine\\SYSTEM\\Select",
455 if (!NT_SUCCESS(Status
))
460 DPRINT("Current %ld Default %ld\n", CurrentSet
, DefaultSet
);
462 swprintf(TargetNameBuffer
,
463 L
"\\Registry\\Machine\\SYSTEM\\ControlSet%03lu",
465 TargetNameLength
= wcslen(TargetNameBuffer
) * sizeof(WCHAR
);
467 DPRINT("Link target '%S'\n", TargetNameBuffer
);
469 RtlInitUnicodeStringFromLiteral(&LinkName
,
470 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet");
471 InitializeObjectAttributes(&ObjectAttributes
,
473 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
| OBJ_OPENLINK
,
476 Status
= NtCreateKey(&KeyHandle
,
477 KEY_ALL_ACCESS
| KEY_CREATE_LINK
,
481 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
483 if (!NT_SUCCESS(Status
))
485 DPRINT1("NtCreateKey() failed (Status %lx)\n", Status
);
489 RtlInitUnicodeStringFromLiteral(&LinkValue
,
490 L
"SymbolicLinkValue");
491 Status
= NtSetValueKey(KeyHandle
,
495 (PVOID
)TargetNameBuffer
,
497 if (!NT_SUCCESS(Status
))
499 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status
);
509 CmiConnectHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes
,
510 IN PREGISTRY_HIVE RegistryHive
)
512 UNICODE_STRING RemainingPath
;
513 PKEY_OBJECT ParentKey
;
518 DPRINT("CmiConnectHive(%p, %p) called.\n",
519 KeyObjectAttributes
, RegistryHive
);
521 Status
= ObFindObject(KeyObjectAttributes
,
525 if (!NT_SUCCESS(Status
))
530 DPRINT ("RemainingPath %wZ\n", &RemainingPath
);
532 if ((RemainingPath
.Buffer
== NULL
) || (RemainingPath
.Buffer
[0] == 0))
534 ObDereferenceObject (ParentKey
);
535 return STATUS_OBJECT_NAME_COLLISION
;
538 /* If RemainingPath contains \ we must return error
539 because CmiConnectHive() can not create trees */
540 SubName
= RemainingPath
.Buffer
;
541 if (*SubName
== L
'\\')
544 if (wcschr (SubName
, L
'\\') != NULL
)
546 ObDereferenceObject (ParentKey
);
547 return STATUS_OBJECT_NAME_NOT_FOUND
;
550 DPRINT("RemainingPath %wZ ParentKey %p\n",
551 &RemainingPath
, ParentKey
);
553 Status
= ObCreateObject(KernelMode
,
562 if (!NT_SUCCESS(Status
))
564 DPRINT1 ("ObCreateObject() failed (Status %lx)\n", Status
);
565 ObDereferenceObject (ParentKey
);
569 NewKey
->RegistryHive
= RegistryHive
;
570 NewKey
->KeyCellOffset
= RegistryHive
->HiveHeader
->RootKeyOffset
;
571 NewKey
->KeyCell
= CmiGetCell (RegistryHive
, NewKey
->KeyCellOffset
, NULL
);
573 NewKey
->NumberOfSubKeys
= 0;
574 NewKey
->SubKeys
= ExAllocatePool(PagedPool
,
575 NewKey
->KeyCell
->NumberOfSubKeys
* sizeof(ULONG
));
577 if ((NewKey
->SubKeys
== NULL
) && (NewKey
->KeyCell
->NumberOfSubKeys
!= 0))
579 DPRINT("NumberOfSubKeys %d\n", NewKey
->KeyCell
->NumberOfSubKeys
);
580 ObDereferenceObject (NewKey
);
581 ObDereferenceObject (ParentKey
);
582 return STATUS_INSUFFICIENT_RESOURCES
;
585 Status
= RtlCreateUnicodeString(&NewKey
->Name
,
587 if (!NT_SUCCESS(Status
))
589 DPRINT1("RtlCreateUnicodeString() failed (Status %lx)\n", Status
);
590 if (NewKey
->SubKeys
!= NULL
)
592 ExFreePool (NewKey
->SubKeys
);
594 ObDereferenceObject (NewKey
);
595 ObDereferenceObject (ParentKey
);
596 return STATUS_INSUFFICIENT_RESOURCES
;
599 CmiAddKeyToList (ParentKey
, NewKey
);
600 ObDereferenceObject (ParentKey
);
602 VERIFY_KEY_OBJECT(NewKey
);
604 /* Note: Do not dereference NewKey here! */
606 return STATUS_SUCCESS
;
611 CmiDisconnectHive (IN POBJECT_ATTRIBUTES KeyObjectAttributes
,
612 OUT PREGISTRY_HIVE
*RegistryHive
)
614 PKEY_OBJECT KeyObject
;
619 DPRINT("CmiDisconnectHive() called\n");
621 *RegistryHive
= NULL
;
623 Status
= ObOpenObjectByName (KeyObjectAttributes
,
627 STANDARD_RIGHTS_REQUIRED
,
630 if (!NT_SUCCESS(Status
))
632 DPRINT1 ("ObOpenObjectByName() failed (Status %lx)\n", Status
);
636 Status
= ObReferenceObjectByHandle (KeyHandle
,
637 STANDARD_RIGHTS_REQUIRED
,
643 if (!NT_SUCCESS(Status
))
645 DPRINT1 ("ObReferenceObjectByName() failed (Status %lx)\n", Status
);
648 DPRINT ("KeyObject %p Hive %p\n", KeyObject
, KeyObject
->RegistryHive
);
650 if (!(KeyObject
->KeyCell
->Flags
& REG_KEY_ROOT_CELL
))
652 DPRINT1 ("Key is not the Hive-Root-Key\n");
653 ObDereferenceObject (KeyObject
);
654 return STATUS_INVALID_PARAMETER
;
657 if (ObGetObjectHandleCount (KeyObject
) != 0 ||
658 ObGetObjectPointerCount (KeyObject
) != 2)
660 DPRINT1 ("Hive is still in use\n");
661 ObDereferenceObject (KeyObject
);
662 return STATUS_UNSUCCESSFUL
;
665 Hive
= KeyObject
->RegistryHive
;
666 CmiRemoveKeyFromList (KeyObject
);
668 /* Dereference KeyObject twice to delete it */
669 ObDereferenceObject (KeyObject
);
670 ObDereferenceObject (KeyObject
);
672 *RegistryHive
= Hive
;
674 DPRINT ("CmiDisconnectHive() done\n");
676 return STATUS_SUCCESS
;
681 CmiInitControlSetLink (VOID
)
683 OBJECT_ATTRIBUTES ObjectAttributes
;
684 UNICODE_STRING ControlSetKeyName
;
685 UNICODE_STRING ControlSetLinkName
;
686 UNICODE_STRING ControlSetValueName
;
690 /* Create 'ControlSet001' key */
691 RtlInitUnicodeStringFromLiteral (&ControlSetKeyName
,
692 L
"\\Registry\\Machine\\SYSTEM\\ControlSet001");
693 InitializeObjectAttributes (&ObjectAttributes
,
695 OBJ_CASE_INSENSITIVE
,
698 Status
= NtCreateKey (&KeyHandle
,
703 REG_OPTION_NON_VOLATILE
,
705 if (!NT_SUCCESS(Status
))
707 DPRINT1 ("NtCreateKey() failed (Status %lx)\n", Status
);
712 /* Link 'CurrentControlSet' to 'ControlSet001' key */
713 RtlInitUnicodeStringFromLiteral (&ControlSetLinkName
,
714 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet");
715 InitializeObjectAttributes (&ObjectAttributes
,
717 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
| OBJ_OPENLINK
,
720 Status
= NtCreateKey (&KeyHandle
,
721 KEY_ALL_ACCESS
| KEY_CREATE_LINK
,
725 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
727 if (!NT_SUCCESS(Status
))
729 DPRINT1 ("NtCreateKey() failed (Status %lx)\n", Status
);
733 RtlInitUnicodeStringFromLiteral (&ControlSetValueName
,
734 L
"SymbolicLinkValue");
735 Status
= NtSetValueKey (KeyHandle
,
736 &ControlSetValueName
,
739 (PVOID
)ControlSetKeyName
.Buffer
,
740 ControlSetKeyName
.Length
);
741 if (!NT_SUCCESS(Status
))
743 DPRINT1 ("NtSetValueKey() failed (Status %lx)\n", Status
);
747 return STATUS_SUCCESS
;
752 CmiInitHives(BOOLEAN SetupBoot
)
754 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo
;
755 OBJECT_ATTRIBUTES ObjectAttributes
;
756 UNICODE_STRING FileName
;
757 UNICODE_STRING KeyName
;
758 UNICODE_STRING ValueName
;
763 WCHAR ConfigPath
[MAX_PATH
];
770 DPRINT("CmiInitHives() called\n");
772 if (SetupBoot
== TRUE
)
774 RtlInitUnicodeStringFromLiteral(&KeyName
,
775 L
"\\Registry\\Machine\\HARDWARE");
776 InitializeObjectAttributes(&ObjectAttributes
,
778 OBJ_CASE_INSENSITIVE
,
781 Status
= NtOpenKey(&KeyHandle
,
784 if (!NT_SUCCESS(Status
))
786 DPRINT1("NtOpenKey() failed (Status %lx)\n", Status
);
790 RtlInitUnicodeStringFromLiteral(&ValueName
,
793 BufferSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + 4096;
794 ValueInfo
= ExAllocatePool(PagedPool
,
796 if (ValueInfo
== NULL
)
799 return(STATUS_INSUFFICIENT_RESOURCES
);
802 Status
= NtQueryValueKey(KeyHandle
,
804 KeyValuePartialInformation
,
809 if (!NT_SUCCESS(Status
))
811 ExFreePool(ValueInfo
);
815 RtlCopyMemory(ConfigPath
,
817 ValueInfo
->DataLength
);
818 ConfigPath
[ValueInfo
->DataLength
/ sizeof(WCHAR
)] = (WCHAR
)0;
819 ExFreePool(ValueInfo
);
823 wcscpy(ConfigPath
, L
"\\SystemRoot");
825 wcscat(ConfigPath
, L
"\\system32\\config");
827 DPRINT("ConfigPath: %S\n", ConfigPath
);
829 EndPtr
= ConfigPath
+ wcslen(ConfigPath
);
833 /* FIXME: Save boot log */
835 /* Connect the SYSTEM hive only if it has been created */
836 if (SetupBoot
== TRUE
)
838 wcscpy(EndPtr
, REG_SYSTEM_FILE_NAME
);
839 DPRINT ("ConfigPath: %S\n", ConfigPath
);
841 RtlInitUnicodeString (&KeyName
,
842 REG_SYSTEM_KEY_NAME
);
843 InitializeObjectAttributes(&ObjectAttributes
,
845 OBJ_CASE_INSENSITIVE
,
849 RtlInitUnicodeString (&FileName
,
851 Status
= CmiLoadHive (&ObjectAttributes
,
854 if (!NT_SUCCESS(Status
))
856 DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status
);
860 Status
= CmiInitControlSetLink ();
861 if (!NT_SUCCESS(Status
))
863 DPRINT1("CmiInitControlSetLink() failed (Status %lx)\n", Status
);
868 /* Connect the SOFTWARE hive */
869 wcscpy(EndPtr
, REG_SOFTWARE_FILE_NAME
);
870 RtlInitUnicodeString (&FileName
,
872 DPRINT ("ConfigPath: %S\n", ConfigPath
);
874 RtlInitUnicodeString (&KeyName
,
875 REG_SOFTWARE_KEY_NAME
);
876 InitializeObjectAttributes(&ObjectAttributes
,
878 OBJ_CASE_INSENSITIVE
,
882 Status
= CmiLoadHive (&ObjectAttributes
,
885 if (!NT_SUCCESS(Status
))
887 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
891 /* Connect the SAM hive */
892 wcscpy(EndPtr
, REG_SAM_FILE_NAME
);
893 RtlInitUnicodeString (&FileName
,
895 DPRINT ("ConfigPath: %S\n", ConfigPath
);
897 RtlInitUnicodeString (&KeyName
,
899 InitializeObjectAttributes(&ObjectAttributes
,
901 OBJ_CASE_INSENSITIVE
,
904 Status
= CmiLoadHive (&ObjectAttributes
,
907 if (!NT_SUCCESS(Status
))
909 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
913 /* Connect the SECURITY hive */
914 wcscpy(EndPtr
, REG_SEC_FILE_NAME
);
915 RtlInitUnicodeString (&FileName
,
917 DPRINT ("ConfigPath: %S\n", ConfigPath
);
919 RtlInitUnicodeString (&KeyName
,
921 InitializeObjectAttributes(&ObjectAttributes
,
923 OBJ_CASE_INSENSITIVE
,
926 Status
= CmiLoadHive (&ObjectAttributes
,
929 if (!NT_SUCCESS(Status
))
931 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
935 /* Connect the DEFAULT hive */
936 wcscpy(EndPtr
, REG_DEFAULT_USER_FILE_NAME
);
937 RtlInitUnicodeString (&FileName
,
939 DPRINT ("ConfigPath: %S\n", ConfigPath
);
941 RtlInitUnicodeString (&KeyName
,
942 REG_DEFAULT_USER_KEY_NAME
);
943 InitializeObjectAttributes(&ObjectAttributes
,
945 OBJ_CASE_INSENSITIVE
,
948 Status
= CmiLoadHive (&ObjectAttributes
,
951 if (!NT_SUCCESS(Status
))
953 DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status
);
957 // CmiCheckRegistry(TRUE);
959 /* Start automatic hive synchronization */
960 KeInitializeDpc(&CmiHiveSyncDpc
,
961 CmiHiveSyncDpcRoutine
,
963 KeInitializeTimer(&CmiHiveSyncTimer
);
964 CmiHiveSyncEnabled
= TRUE
;
966 DPRINT("CmiInitHives() done\n");
968 return(STATUS_SUCCESS
);
973 CmShutdownRegistry(VOID
)
978 DPRINT1("CmShutdownRegistry() called\n");
980 /* Stop automatic hive synchronization */
981 CmiHiveSyncEnabled
= FALSE
;
983 /* Cancel pending hive synchronization */
984 if (CmiHiveSyncPending
== TRUE
)
986 KeCancelTimer(&CmiHiveSyncTimer
);
987 CmiHiveSyncPending
= FALSE
;
990 /* Acquire hive list lock exclusively */
991 ExAcquireResourceExclusiveLite(&CmiHiveListLock
, TRUE
);
993 Entry
= CmiHiveListHead
.Flink
;
994 while (Entry
!= &CmiHiveListHead
)
996 Hive
= CONTAINING_RECORD(Entry
, REGISTRY_HIVE
, HiveList
);
998 if (!(IsNoFileHive(Hive
) || IsNoSynchHive(Hive
)))
1000 /* Acquire hive resource exclusively */
1001 ExAcquireResourceExclusiveLite(&Hive
->HiveResource
,
1004 /* Flush non-volatile hive */
1005 CmiFlushRegistryHive(Hive
);
1007 /* Release hive resource */
1008 ExReleaseResourceLite(&Hive
->HiveResource
);
1011 Entry
= Entry
->Flink
;
1014 /* Release hive list lock */
1015 ExReleaseResourceLite(&CmiHiveListLock
);
1017 DPRINT1("CmShutdownRegistry() done\n");
1022 CmiHiveSyncRoutine(PVOID DeferredContext
)
1024 PREGISTRY_HIVE Hive
;
1027 DPRINT("CmiHiveSyncRoutine() called\n");
1029 CmiHiveSyncPending
= FALSE
;
1031 /* Acquire hive list lock exclusively */
1032 ExAcquireResourceExclusiveLite(&CmiHiveListLock
, TRUE
);
1034 Entry
= CmiHiveListHead
.Flink
;
1035 while (Entry
!= &CmiHiveListHead
)
1037 Hive
= CONTAINING_RECORD(Entry
, REGISTRY_HIVE
, HiveList
);
1039 if (!(IsNoFileHive(Hive
) || IsNoSynchHive(Hive
)))
1041 /* Acquire hive resource exclusively */
1042 ExAcquireResourceExclusiveLite(&Hive
->HiveResource
,
1045 /* Flush non-volatile hive */
1046 CmiFlushRegistryHive(Hive
);
1048 /* Release hive resource */
1049 ExReleaseResourceLite(&Hive
->HiveResource
);
1052 Entry
= Entry
->Flink
;
1055 /* Release hive list lock */
1056 ExReleaseResourceLite(&CmiHiveListLock
);
1058 DPRINT("DeferredContext %x\n", DeferredContext
);
1059 ExFreePool(DeferredContext
);
1061 DPRINT("CmiHiveSyncRoutine() done\n");
1066 CmiHiveSyncDpcRoutine(PKDPC Dpc
,
1067 PVOID DeferredContext
,
1068 PVOID SystemArgument1
,
1069 PVOID SystemArgument2
)
1071 PWORK_QUEUE_ITEM WorkQueueItem
;
1073 WorkQueueItem
= ExAllocatePool(NonPagedPool
,
1074 sizeof(WORK_QUEUE_ITEM
));
1075 if (WorkQueueItem
== NULL
)
1077 DbgPrint("Failed to allocate work item\n");
1081 ExInitializeWorkItem(WorkQueueItem
,
1085 DPRINT("DeferredContext %x\n", WorkQueueItem
);
1086 ExQueueWorkItem(WorkQueueItem
,
1094 LARGE_INTEGER Timeout
;
1096 DPRINT("CmiSyncHives() called\n");
1098 if (CmiHiveSyncEnabled
== FALSE
||
1099 CmiHiveSyncPending
== TRUE
)
1102 CmiHiveSyncPending
= TRUE
;
1105 Timeout
.QuadPart
= -50000000LL;
1106 KeSetTimer(&CmiHiveSyncTimer
,