Author: ion
Date: Fri May 11 23:34:11 2007
New Revision: 26703
URL:
http://svn.reactos.org/svn/reactos?rev=26703&view=rev
Log:
- Move CmpCreateRootNode and CmpCreateRegistryRoot to cmsysini.c as well, and add some
fixes to CmpCreateRegistryRoot to make it compatible with the Cm Rewrite when it's
done.
- Initialize some stuff that wasn't being initialized in CmpCreateRootNode.
- Use CmpHiveRootSecurityDescriptor in CmpCreateRegistryRoot to protect the key.
- Save the root handle globally so we can close it during shutdown.
- Add cmkcbncb.c with an empty stub for CmpCreateKeyControlBlock. Will copy from Cm
rewrite branch later.
- Properly name fields of CM_KEY_NODE in the headers of the /config tree.
Added:
trunk/reactos/ntoskrnl/config/cmkcbncb.c
Modified:
trunk/reactos/ntoskrnl/cm/cm.h
trunk/reactos/ntoskrnl/cm/registry.c
trunk/reactos/ntoskrnl/config/cm.h
trunk/reactos/ntoskrnl/config/cmsysini.c
trunk/reactos/ntoskrnl/ntoskrnl.rbuild
Modified: trunk/reactos/ntoskrnl/cm/cm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cm/cm.h?rev=26703…
==============================================================================
--- trunk/reactos/ntoskrnl/cm/cm.h (original)
+++ trunk/reactos/ntoskrnl/cm/cm.h Fri May 11 23:34:11 2007
@@ -486,6 +486,16 @@
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)
{
Modified: trunk/reactos/ntoskrnl/cm/registry.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cm/registry.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/cm/registry.c (original)
+++ trunk/reactos/ntoskrnl/cm/registry.c Fri May 11 23:34:11 2007
@@ -159,6 +159,15 @@
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,
@@ -181,142 +190,6 @@
/* Connect the hive */
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
Modified: trunk/reactos/ntoskrnl/config/cm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cm.h?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cm.h (original)
+++ trunk/reactos/ntoskrnl/config/cm.h Fri May 11 23:34:11 2007
@@ -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 _CM_KEY_NODE
{
- USHORT Id;
+ USHORT Signature;
USHORT Flags;
LARGE_INTEGER LastWriteTime;
ULONG Spare;
@@ -476,15 +476,15 @@
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 @@
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 @@
//
PCM_KEY_CONTROL_BLOCK
NTAPI
-CmpCreateKcb(
+CmpCreateKeyControlBlock(
IN PHHIVE Hive,
IN HCELL_INDEX Index,
IN PCM_KEY_NODE Node,
@@ -841,6 +879,17 @@
CmpDereferenceKcbWithLock(
IN PCM_KEY_CONTROL_BLOCK Kcb,
IN BOOLEAN LockHeldExclusively
+);
+
+VOID
+NTAPI
+EnlistKeyBodyWithKCB(
+#if 0
+ IN PCM_KEY_BODY KeyObject,
+#else
+ IN PKEY_OBJECT KeyObject,
+#endif
+ IN ULONG Flags
);
//
@@ -983,24 +1032,6 @@
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
//
#include "cm_x.h"
Added: trunk/reactos/ntoskrnl/config/cmkcbncb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmkcbncb.c…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmkcbncb.c (added)
+++ trunk/reactos/ntoskrnl/config/cmkcbncb.c Fri May 11 23:34:11 2007
@@ -1,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(a)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;
+}
Modified: trunk/reactos/ntoskrnl/config/cmsysini.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmsysini.c…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmsysini.c (original)
+++ trunk/reactos/ntoskrnl/config/cmsysini.c Fri May 11 23:34:11 2007
@@ -27,6 +27,8 @@
BOOLEAN CmSelfHeal = TRUE;
BOOLEAN CmpSelfHeal = TRUE;
ULONG CmpBootType;
+
+HANDLE CmpRegistryRootHandle;
extern BOOLEAN ExpInTextModeSetup;
@@ -480,3 +482,164 @@
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;
+}
Modified: trunk/reactos/ntoskrnl/ntoskrnl.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl.rbuild?r…
==============================================================================
--- trunk/reactos/ntoskrnl/ntoskrnl.rbuild (original)
+++ trunk/reactos/ntoskrnl/ntoskrnl.rbuild Fri May 11 23:34:11 2007
@@ -95,6 +95,7 @@
<file>cmdata.c</file>
<file>cmindex.c</file>
<file>cmhook.c</file>
+ <file>cmkcbncb.c</file>
<file>cmmapvw.c</file>
<file>cmname.c</file>
<file>cmparse.c</file>