From a0da7760d42980da904f38b759fdeaf8183d09dd Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Sun, 9 Dec 2007 19:36:04 +0000 Subject: [PATCH] - Our NtCreateKey currently allows building trees (which is incorrect) if the parent key is a symbolic link (which does exist), but if the target doesn't exist (Since the check 'does parent exist' is done Before the symlink is converted to its target. One side-effect is that although we create the CurrentControlSet symlink to ControlSet001, we never create ControlSet001. We end up creating it later during the boot by creating a sub-key, by exposing the bug in NtCreateKey. Since the new NtCreateKey uses the new parse routine code and doesn't exhibit this bug, we have to create ControlSet001 manually to avoid a failure. Other bugs of this nature may exist. Bug found and fixed by Alex. - Implement the last bit of the new parse routine (creating children) and write a new version of NtCreateKey which uses the parse routine. Disable it for now until other latent bugs are fixed. svn path=/trunk/; revision=31112 --- reactos/ntoskrnl/config/cm.h | 9 -------- reactos/ntoskrnl/config/cmparse.c | 14 ++++++++---- reactos/ntoskrnl/config/cmsysini.c | 21 ++++++++++++++++- reactos/ntoskrnl/config/ntapi.c | 36 ++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/reactos/ntoskrnl/config/cm.h b/reactos/ntoskrnl/config/cm.h index e36e089dd2f..84fc9bfe80b 100644 --- a/reactos/ntoskrnl/config/cm.h +++ b/reactos/ntoskrnl/config/cm.h @@ -495,15 +495,6 @@ typedef struct _KEY_INFORMATION // // BUGBUG Old Hive Stuff for Temporary Support // -NTSTATUS -NTAPI -CmFindObject(POBJECT_CREATE_INFORMATION ObjectCreateInfo, - PUNICODE_STRING ObjectName, - PVOID* ReturnedObject, - PUNICODE_STRING RemainingPath, - POBJECT_TYPE ObjectType, - IN PACCESS_STATE AccessState, - IN PVOID ParseContext); NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2); /////////////////////////////////////////////////////////////////////////////// diff --git a/reactos/ntoskrnl/config/cmparse.c b/reactos/ntoskrnl/config/cmparse.c index 72a568fe689..29f1866122b 100644 --- a/reactos/ntoskrnl/config/cmparse.c +++ b/reactos/ntoskrnl/config/cmparse.c @@ -1077,7 +1077,7 @@ CmpParseKey2(IN PVOID ParseObject, while (TRUE) { /* Get the next component */ - Result = CmpGetNextName(&Current, &NextName, &Last); + Result = CmpGetNextName(&Current, &NextName, &Last); if ((Result) && (NextName.Length)) { /* See if this is a sym link */ @@ -1184,9 +1184,15 @@ CmpParseKey2(IN PVOID ParseObject, } else { - /* Create: should not see this (yet) */ - DPRINT1("Unexpected: Creating new child\n"); - while (TRUE); + /* Do the create */ + Status = CmpDoCreate(Hive, + Cell, + AccessState, + &NextName, + AccessMode, + ParseContext, + ParentKcb, + Object); } /* Check for reparse (in this case, someone beat us) */ diff --git a/reactos/ntoskrnl/config/cmsysini.c b/reactos/ntoskrnl/config/cmsysini.c index 53d90ad3933..a7d924d2902 100644 --- a/reactos/ntoskrnl/config/cmsysini.c +++ b/reactos/ntoskrnl/config/cmsysini.c @@ -363,6 +363,26 @@ CmpCreateControlSet(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* ReactOS Hack: Hard-code current to 001 for SetupLdr */ if (!LoaderBlock->RegistryBase) { + /* Build the ControlSet001 key */ + RtlInitUnicodeString(&KeyName, + L"\\Registry\\Machine\\System\\ControlSet001"); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = NtCreateKey(&KeyHandle, + KEY_ALL_ACCESS, + &ObjectAttributes, + 0, + NULL, + 0, + &Disposition); + if (!NT_SUCCESS(Status)) return Status; + + /* Don't need the handle */ + ZwClose(KeyHandle); + /* Use hard-coded setting */ ControlSet = 1; goto UseSet; @@ -396,7 +416,6 @@ UseSet: OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = NtCreateKey(&KeyHandle, KEY_CREATE_LINK, &ObjectAttributes, diff --git a/reactos/ntoskrnl/config/ntapi.c b/reactos/ntoskrnl/config/ntapi.c index ec1537249d2..6a6affc1f6f 100644 --- a/reactos/ntoskrnl/config/ntapi.c +++ b/reactos/ntoskrnl/config/ntapi.c @@ -18,6 +18,42 @@ BOOLEAN CmFirstTime = TRUE; /* FUNCTIONS *****************************************************************/ +#if 0 +NTSTATUS +NTAPI +NtCreateKey(OUT PHANDLE KeyHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN ULONG TitleIndex, + IN PUNICODE_STRING Class, + IN ULONG CreateOptions, + OUT PULONG Disposition) +{ + NTSTATUS Status; + KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); + CM_PARSE_CONTEXT ParseContext = {0}; + PAGED_CODE(); + + /* Setup the parse context */ + ParseContext.CreateOperation = TRUE; + ParseContext.CreateOptions = CreateOptions; + if (Class) ParseContext.Class = *Class; + + /* Do the create */ + Status = ObOpenObjectByName(ObjectAttributes, + CmpKeyObjectType, + PreviousMode, + NULL, + DesiredAccess, + &ParseContext, + KeyHandle); + + /* Return data to user */ + if (Disposition) *Disposition = ParseContext.Disposition; + return Status; +} +#endif + NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle,