diff --git a/reactos/ntoskrnl/cm/cm.h b/reactos/ntoskrnl/cm/cm.h index e0cfd32d01f..3789b0d7462 100644 --- a/reactos/ntoskrnl/cm/cm.h +++ b/reactos/ntoskrnl/cm/cm.h @@ -486,6 +486,16 @@ NTSTATUS NTAPI CmpCreateObjectTypes(VOID); +BOOLEAN +NTAPI +CmpCreateRootNode(IN PHHIVE Hive, + IN PCWSTR Name, + OUT PHCELL_INDEX Index); + +BOOLEAN +NTAPI +CmpCreateRegistryRoot(VOID); + #if 0 static __inline PVOID xHvGetCell(char *file, int line, PHHIVE Hive, HCELL_INDEX Cell) { diff --git a/reactos/ntoskrnl/cm/registry.c b/reactos/ntoskrnl/cm/registry.c index dfc9e06952d..5cd8cfcf94c 100644 --- a/reactos/ntoskrnl/cm/registry.c +++ b/reactos/ntoskrnl/cm/registry.c @@ -159,6 +159,15 @@ CmpRosGetHardwareHive(OUT PULONG Length) return (PVOID)(MdBlock->BasePage << PAGE_SHIFT); } +VOID +NTAPI +EnlistKeyBodyWithKCB(IN PKEY_OBJECT KeyObject, + IN ULONG Flags) +{ + /* Insert it into the global list (we don't have KCBs here) */ + InsertTailList(&CmiKeyObjectListHead, &KeyObject->ListEntry); +} + NTSTATUS NTAPI CmpLinkHiveToMaster(IN PUNICODE_STRING LinkName, @@ -183,142 +192,6 @@ CmpLinkHiveToMaster(IN PUNICODE_STRING LinkName, return CmiConnectHive(&ObjectAttributes, RegistryHive); } -BOOLEAN -NTAPI -CmpCreateRootNode(IN PHHIVE Hive, - IN PCWSTR Name, - OUT PHCELL_INDEX Index) -{ - UNICODE_STRING KeyName; - PCM_KEY_NODE KeyCell; - LARGE_INTEGER SystemTime; - PAGED_CODE(); - - /* Initialize the node name and allocate it */ - RtlInitUnicodeString(&KeyName, Name); - *Index = HvAllocateCell(Hive, - FIELD_OFFSET(CM_KEY_NODE, Name) + - CmpNameSize(Hive, &KeyName), - HvStable); // FIXME: , HCELL_NIL); - if (*Index == HCELL_NIL) return FALSE; - - /* Set the cell index and get the data */ - Hive->HiveHeader->RootCell = *Index; - KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, *Index); - if (!KeyCell) return FALSE; - - /* Setup the cell */ - KeyCell->Id = (USHORT)CM_KEY_NODE_SIGNATURE;; - KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE; - KeQuerySystemTime(&SystemTime); - KeyCell->LastWriteTime = SystemTime; - KeyCell->Parent = HCELL_NIL; - KeyCell->SubKeyCounts[HvStable] = 0; - KeyCell->SubKeyCounts[HvVolatile] = 0; - KeyCell->SubKeyLists[HvStable] = HCELL_NIL; - KeyCell->SubKeyLists[HvVolatile] = HCELL_NIL; - KeyCell->ValueList.Count = 0; - KeyCell->ValueList.List = HCELL_NIL; - KeyCell->SecurityKeyOffset = HCELL_NIL; - KeyCell->ClassNameOffset = HCELL_NIL; - KeyCell->ClassSize = 0; - - /* Copy the name (this will also set the length) */ - KeyCell->NameSize = CmpCopyName(Hive, (PWCHAR)KeyCell->Name, &KeyName); - - /* Check if the name was compressed */ - if (KeyCell->NameSize < KeyName.Length) - { - /* Set the flag */ - KeyCell->Flags |= KEY_COMP_NAME; - } - - /* Return success */ - HvReleaseCell(Hive, *Index); - return TRUE; -} - -BOOLEAN -NTAPI -CmpCreateRegistryRoot(VOID) -{ - UNICODE_STRING KeyName; - OBJECT_ATTRIBUTES ObjectAttributes; - PKEY_OBJECT RootKey; - HANDLE RootKeyHandle; - HCELL_INDEX RootIndex; - NTSTATUS Status; - PCM_KEY_NODE KeyCell; - PAGED_CODE(); - - /* Setup the root node */ - if (!CmpCreateRootNode(&CmiVolatileHive->Hive, L"REGISTRY", &RootIndex)) - { - /* We failed */ - return FALSE; - } - - /* Create '\Registry' key. */ - RtlInitUnicodeString(&KeyName, REG_ROOT_KEY_NAME); - InitializeObjectAttributes(&ObjectAttributes, - &KeyName, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - Status = ObCreateObject(KernelMode, - CmpKeyObjectType, - &ObjectAttributes, - KernelMode, - NULL, - sizeof(KEY_OBJECT), - 0, - 0, - (PVOID*)&RootKey); - if (!NT_SUCCESS(Status)) return FALSE; - - /* Sanity check, and get the key cell */ - ASSERT((&CmiVolatileHive->Hive)->ReleaseCellRoutine == NULL); - KeyCell = (PCM_KEY_NODE)HvGetCell(&CmiVolatileHive->Hive, RootIndex); - if (!KeyCell) return FALSE; - - /* Setup the root key */ - RootKey->RegistryHive = CmiVolatileHive; - RootKey->KeyCellOffset = RootIndex; - RootKey->KeyCell = KeyCell; - RootKey->ParentKey = RootKey; - RootKey->Flags = 0; - RootKey->SubKeyCounts = 0; - RootKey->SubKeys = NULL; - RootKey->SizeOfSubKeys = 0; - - /* Insert it into the object list head */ - InsertTailList(&CmiKeyObjectListHead, &RootKey->ListEntry); - - /* Setup the name */ - RtlpCreateUnicodeString(&RootKey->Name, L"Registry", NonPagedPool); - - /* Insert the key into the namespace */ - Status = ObInsertObject(RootKey, - NULL, - KEY_ALL_ACCESS, - 0, - NULL, - &RootKeyHandle); - if (!NT_SUCCESS(Status)) return FALSE; - - /* Reference the key again so that we never lose it */ - Status = ObReferenceObjectByHandle(RootKeyHandle, - KEY_READ, - NULL, - KernelMode, - (PVOID*)&RootKey, - NULL); - if (!NT_SUCCESS(Status)) return FALSE; - - /* Completely sucessful */ - return TRUE; -} - BOOLEAN INIT_FUNCTION NTAPI diff --git a/reactos/ntoskrnl/config/cm.h b/reactos/ntoskrnl/config/cm.h index 79145309e0c..72fe036b8f9 100644 --- a/reactos/ntoskrnl/config/cm.h +++ b/reactos/ntoskrnl/config/cm.h @@ -145,7 +145,7 @@ #define CMP_HASH_PRIME 1000000007 // -// CmpCreateKcb Flags +// CmpCreateKeyControlBlock Flags // #define CMP_CREATE_FAKE_KCB 0x1 #define CMP_LOCK_HASHES_FOR_KCB 0x2 @@ -468,7 +468,7 @@ typedef struct _CHILD_LIST typedef struct _CM_KEY_NODE { - USHORT Id; + USHORT Signature; USHORT Flags; LARGE_INTEGER LastWriteTime; ULONG Spare; @@ -476,15 +476,15 @@ typedef struct _CM_KEY_NODE ULONG SubKeyCounts[HvMaxStorageType]; HCELL_INDEX SubKeyLists[HvMaxStorageType]; CHILD_LIST ValueList; - HCELL_INDEX SecurityKeyOffset; - HCELL_INDEX ClassNameOffset; + HCELL_INDEX Security; + HCELL_INDEX Class; ULONG MaxNameLen; ULONG MaxClassLen; ULONG MaxValueNameLen; ULONG MaxValueDataLen; ULONG WorkVar; USHORT NameLength; - USHORT ClassSize; + USHORT ClassLength; WCHAR Name[0]; } CM_KEY_NODE, *PCM_KEY_NODE; @@ -637,6 +637,44 @@ typedef struct _CM_SYSTEM_CONTROL_VECTOR PULONG Type; } CM_SYSTEM_CONTROL_VECTOR, *PCM_SYSTEM_CONTROL_VECTOR; +/////////////////////////////////////////////////////////////////////////////// +// +// BUGBUG Old Hive Stuff for Temporary Support +// +#define SYSTEM_REG_FILE L"\\SystemRoot\\System32\\Config\\SYSTEM" +#define SYSTEM_LOG_FILE L"\\SystemRoot\\System32\\Config\\SYSTEM.log" +#define REG_SYSTEM_KEY_NAME L"\\Registry\\Machine\\SYSTEM" +typedef struct _EREGISTRY_HIVE +{ + HHIVE Hive; + LIST_ENTRY HiveList; + UNICODE_STRING HiveFileName; + UNICODE_STRING LogFileName; + PCM_KEY_SECURITY RootSecurityCell; + ULONG Flags; + HANDLE HiveHandle; + HANDLE LogHandle; +} EREGISTRY_HIVE, *PEREGISTRY_HIVE; +typedef struct _KEY_OBJECT +{ + CSHORT Type; + CSHORT Size; + ULONG Flags; + UNICODE_STRING Name; + PEREGISTRY_HIVE RegistryHive; + HCELL_INDEX KeyCellOffset; + PCM_KEY_NODE KeyCell; + struct _KEY_OBJECT *ParentKey; + LIST_ENTRY ListEntry; + ULONG SubKeyCounts; + ULONG SizeOfSubKeys; + struct _KEY_OBJECT **SubKeys; + ULONG TimeStamp; + LIST_ENTRY HiveList; +} KEY_OBJECT, *PKEY_OBJECT; +extern PEREGISTRY_HIVE CmiVolatileHive; +/////////////////////////////////////////////////////////////////////////////// + // // Mapped View Hive Functions // @@ -827,7 +865,7 @@ CmpFreeDelayItem( // PCM_KEY_CONTROL_BLOCK NTAPI -CmpCreateKcb( +CmpCreateKeyControlBlock( IN PHHIVE Hive, IN HCELL_INDEX Index, IN PCM_KEY_NODE Node, @@ -843,6 +881,17 @@ CmpDereferenceKcbWithLock( IN BOOLEAN LockHeldExclusively ); +VOID +NTAPI +EnlistKeyBodyWithKCB( +#if 0 + IN PCM_KEY_BODY KeyObject, +#else + IN PKEY_OBJECT KeyObject, +#endif + IN ULONG Flags +); + // // Name Functions // @@ -982,24 +1031,6 @@ extern PCM_FULL_RESOURCE_DESCRIPTOR CmpConfigurationData; extern UNICODE_STRING CmTypeName[]; extern BOOLEAN ExpInTextModeSetup; -// -// BUGBUG Old Hive Stuff for Temporary Support -// -#define SYSTEM_REG_FILE L"\\SystemRoot\\System32\\Config\\SYSTEM" -#define SYSTEM_LOG_FILE L"\\SystemRoot\\System32\\Config\\SYSTEM.log" -#define REG_SYSTEM_KEY_NAME L"\\Registry\\Machine\\SYSTEM" -typedef struct _EREGISTRY_HIVE -{ - HHIVE Hive; - LIST_ENTRY HiveList; - UNICODE_STRING HiveFileName; - UNICODE_STRING LogFileName; - PCM_KEY_SECURITY RootSecurityCell; - ULONG Flags; - HANDLE HiveHandle; - HANDLE LogHandle; -} EREGISTRY_HIVE, *PEREGISTRY_HIVE; - // // Inlined functions // diff --git a/reactos/ntoskrnl/config/cmkcbncb.c b/reactos/ntoskrnl/config/cmkcbncb.c new file mode 100644 index 00000000000..7298f218c10 --- /dev/null +++ b/reactos/ntoskrnl/config/cmkcbncb.c @@ -0,0 +1,31 @@ +/* + * PROJECT: ReactOS Kernel + * LICENSE: GPL - See COPYING in the top level directory + * FILE: ntoskrnl/config/cmkcbncb.c + * PURPOSE: Configuration Manager - Key Control and Name Control Blocks + * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) + */ + +/* INCLUDES ******************************************************************/ + +#include "ntoskrnl.h" +#include "cm.h" +#define NDEBUG +#include "debug.h" + +/* GLOBALS *******************************************************************/ + +/* FUNCTIONS *****************************************************************/ + +PCM_KEY_CONTROL_BLOCK +NTAPI +CmpCreateKeyControlBlock(IN PHHIVE Hive, + IN HCELL_INDEX Index, + IN PCM_KEY_NODE Node, + IN PCM_KEY_CONTROL_BLOCK Parent, + IN ULONG Flags, + IN PUNICODE_STRING KeyName) +{ + /* Temporary hack */ + return (PVOID)1; +} diff --git a/reactos/ntoskrnl/config/cmsysini.c b/reactos/ntoskrnl/config/cmsysini.c index 4c580131b0d..c20602043e4 100644 --- a/reactos/ntoskrnl/config/cmsysini.c +++ b/reactos/ntoskrnl/config/cmsysini.c @@ -28,6 +28,8 @@ BOOLEAN CmSelfHeal = TRUE; BOOLEAN CmpSelfHeal = TRUE; ULONG CmpBootType; +HANDLE CmpRegistryRootHandle; + extern BOOLEAN ExpInTextModeSetup; /* FUNCTIONS *****************************************************************/ @@ -480,3 +482,164 @@ CmpCreateObjectTypes(VOID) return ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &CmpKeyObjectType); } +BOOLEAN +NTAPI +CmpCreateRootNode(IN PHHIVE Hive, + IN PCWSTR Name, + OUT PHCELL_INDEX Index) +{ + UNICODE_STRING KeyName; + PCM_KEY_NODE KeyCell; + LARGE_INTEGER SystemTime; + PAGED_CODE(); + + /* Initialize the node name and allocate it */ + RtlInitUnicodeString(&KeyName, Name); + *Index = HvAllocateCell(Hive, + FIELD_OFFSET(CM_KEY_NODE, Name) + + CmpNameSize(Hive, &KeyName), + HvStable); // FIXME: , HCELL_NIL); + if (*Index == HCELL_NIL) return FALSE; + + /* Set the cell index and get the data */ + Hive->HiveHeader->RootCell = *Index; + KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, *Index); + if (!KeyCell) return FALSE; + + /* Setup the cell */ + KeyCell->Signature = (USHORT)CM_KEY_NODE_SIGNATURE;; + KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE; + KeQuerySystemTime(&SystemTime); + KeyCell->LastWriteTime = SystemTime; + KeyCell->Parent = HCELL_NIL; + KeyCell->SubKeyCounts[HvStable] = 0; + KeyCell->SubKeyCounts[HvVolatile] = 0; + KeyCell->SubKeyLists[HvStable] = HCELL_NIL; + KeyCell->SubKeyLists[HvVolatile] = HCELL_NIL; + KeyCell->ValueList.Count = 0; + KeyCell->ValueList.List = HCELL_NIL; + KeyCell->Security = HCELL_NIL; + KeyCell->Class = HCELL_NIL; + KeyCell->ClassLength = 0; + KeyCell->MaxNameLen = 0; + KeyCell->MaxClassLen = 0; + KeyCell->MaxValueNameLen = 0; + KeyCell->MaxValueDataLen = 0; + + /* Copy the name (this will also set the length) */ + KeyCell->NameLength = CmpCopyName(Hive, (PWCHAR)KeyCell->Name, &KeyName); + + /* Check if the name was compressed */ + if (KeyCell->NameLength < KeyName.Length) + { + /* Set the flag */ + KeyCell->Flags |= KEY_COMP_NAME; + } + + /* Return success */ + HvReleaseCell(Hive, *Index); + return TRUE; +} + +BOOLEAN +NTAPI +CmpCreateRegistryRoot(VOID) +{ + UNICODE_STRING KeyName; + OBJECT_ATTRIBUTES ObjectAttributes; +#if 0 + PCM_KEY_BODY RootKey; +#else + PKEY_OBJECT RootKey; +#endif + HCELL_INDEX RootIndex; + NTSTATUS Status; + PCM_KEY_NODE KeyCell; + PSECURITY_DESCRIPTOR SecurityDescriptor; + PCM_KEY_CONTROL_BLOCK Kcb; + PAGED_CODE(); + + /* Setup the root node */ + if (!CmpCreateRootNode(&CmiVolatileHive->Hive, L"REGISTRY", &RootIndex)) + { + /* We failed */ + return FALSE; + } + + /* Create '\Registry' key. */ + RtlInitUnicodeString(&KeyName, L"\\Registry"); + SecurityDescriptor = CmpHiveRootSecurityDescriptor(); + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = ObCreateObject(KernelMode, + CmpKeyObjectType, + &ObjectAttributes, + KernelMode, + NULL, + sizeof(KEY_OBJECT), + 0, + 0, + (PVOID*)&RootKey); + ExFreePool(SecurityDescriptor); + if (!NT_SUCCESS(Status)) return FALSE; + + /* Sanity check, and get the key cell */ + ASSERT((&CmiVolatileHive->Hive)->ReleaseCellRoutine == NULL); + KeyCell = (PCM_KEY_NODE)HvGetCell(&CmiVolatileHive->Hive, RootIndex); + if (!KeyCell) return FALSE; + + /* Create the KCB */ + RtlInitUnicodeString(&KeyName, L"Registry"); + Kcb = CmpCreateKeyControlBlock(&CmiVolatileHive->Hive, + RootIndex, + KeyCell, + NULL, + 0, + &KeyName); + if (!Kcb) return FALSE; + + /* Initialize the object */ +#if 0 + RootKey->Type = TAG('k', 'v', '0', '2'; + RootKey->KeyControlBlock = Kcb; + RootKey->NotifyBlock = NULL; + RootKey->ProcessID = PsGetCurrentProcessId(); +#else + RtlpCreateUnicodeString(&RootKey->Name, L"Registry", NonPagedPool); + RootKey->RegistryHive = CmiVolatileHive; + RootKey->KeyCellOffset = RootIndex; + RootKey->KeyCell = KeyCell; + RootKey->ParentKey = RootKey; + RootKey->Flags = 0; + RootKey->SubKeyCounts = 0; + RootKey->SubKeys = NULL; + RootKey->SizeOfSubKeys = 0; +#endif + + /* Insert it into the object list head */ + EnlistKeyBodyWithKCB(RootKey, 0); + + /* Insert the key into the namespace */ + Status = ObInsertObject(RootKey, + NULL, + KEY_ALL_ACCESS, + 0, + NULL, + &CmpRegistryRootHandle); + if (!NT_SUCCESS(Status)) return FALSE; + + /* Reference the key again so that we never lose it */ + Status = ObReferenceObjectByHandle(CmpRegistryRootHandle, + KEY_READ, + NULL, + KernelMode, + (PVOID*)&RootKey, + NULL); + if (!NT_SUCCESS(Status)) return FALSE; + + /* Completely sucessful */ + return TRUE; +} diff --git a/reactos/ntoskrnl/ntoskrnl.rbuild b/reactos/ntoskrnl/ntoskrnl.rbuild index 2cf63485ad6..563ed4aafff 100644 --- a/reactos/ntoskrnl/ntoskrnl.rbuild +++ b/reactos/ntoskrnl/ntoskrnl.rbuild @@ -95,6 +95,7 @@ cmdata.c cmindex.c cmhook.c + cmkcbncb.c cmmapvw.c cmname.c cmparse.c