- One less hardcoded number.
- Minor code formatting.

[NTOS]
- Minor code formatting (cmvalche.c).
- The key-node timestamp can usually be retrieved without using another temporary value.
- The security descriptor copy allocated for the hive can be freed after it was assigned to it.

[MKHIVE]
- Minor formatting of the source headers.
- Update the list of registry value types; add another error code (to be used later on).
- Remove now unused "ntoskrnl.h" header.

CORE-10793

svn path=/trunk/; revision=70601
This commit is contained in:
Hermès Bélusca-Maïto
2016-01-16 23:54:45 +00:00
parent b45ce14687
commit 5a29ec2659
13 changed files with 90 additions and 96 deletions

View File

@@ -10,19 +10,19 @@
#include "cmlib.h"
#define NDEBUG
#include "debug.h"
#include <debug.h>
/* GLOBALS *******************************************************************/
ULONG CmpMaxFastIndexPerHblock =
(HBLOCK_SIZE - (sizeof(HBIN) +
sizeof(HCELL) +
FIELD_OFFSET(CM_KEY_FAST_INDEX, List))) / sizeof(CM_INDEX);
#define INVALID_INDEX 0x80000000
ULONG CmpMaxIndexPerHblock =
(HBLOCK_SIZE - (sizeof(HBIN) +
sizeof(HCELL) +
FIELD_OFFSET(CM_KEY_INDEX, List))) / sizeof(HCELL_INDEX) - 1;
#define CmpMaxFastIndexPerHblock \
((HBLOCK_SIZE - (sizeof(HBIN) + sizeof(HCELL) + \
FIELD_OFFSET(CM_KEY_FAST_INDEX, List))) / sizeof(CM_INDEX))
#define CmpMaxIndexPerHblock \
((HBLOCK_SIZE - (sizeof(HBIN) + sizeof(HCELL) + \
FIELD_OFFSET(CM_KEY_INDEX, List))) / sizeof(HCELL_INDEX) - 1)
/* FUNCTIONS *****************************************************************/
@@ -232,7 +232,7 @@ CmpFindSubKeyInRoot(IN PHHIVE Hive,
{
Big:
/* This was some sort of special key */
ReturnIndex = 0x80000000;
ReturnIndex = INVALID_INDEX;
goto ReturnFailure;
}
@@ -262,7 +262,7 @@ Big:
/* Check if we found it */
if (!Result)
{
/* We got lucky...return it */
/* We got lucky... return it */
*SubKey = LeafCell;
ReturnIndex = Low;
goto Return;
@@ -389,7 +389,7 @@ CmpFindSubKeyInLeaf(IN PHHIVE Hive,
{
/* Fail with special value */
*SubKey = HCELL_NIL;
return 0x80000000;
return INVALID_INDEX;
}
/* Check if we got lucky and found it */
@@ -425,7 +425,7 @@ CmpFindSubKeyInLeaf(IN PHHIVE Hive,
{
/* Fail with special value */
*SubKey = HCELL_NIL;
return 0x80000000;
return INVALID_INDEX;
}
/* Check if we got lucky and found it */
@@ -448,7 +448,7 @@ CmpFindSubKeyInLeaf(IN PHHIVE Hive,
{
/* Fail with special value */
*SubKey = HCELL_NIL;
return 0x80000000;
return INVALID_INDEX;
}
/* Return the high */
@@ -625,8 +625,7 @@ CmpFindSubKeyByNumber(IN PHHIVE Hive,
if (Number < Node->SubKeyCounts[Volatile])
{
/* Get the actual key index */
Index = (PCM_KEY_INDEX)HvGetCell(Hive,
Node->SubKeyLists[Volatile]);
Index = (PCM_KEY_INDEX)HvGetCell(Hive, Node->SubKeyLists[Volatile]);
if (!Index) return HCELL_NIL;
/* Do a search inside it */
@@ -717,7 +716,7 @@ CmpFindSubKeyByName(IN PHHIVE Hive,
HvReleaseCell(Hive, CellToRelease);
/* Make sure we found something valid */
if (Found & 0x80000000) break;
if (Found & INVALID_INDEX) break;
/* Get the new Index Root and set the new cell to be released */
if (SubKey == HCELL_NIL) continue;
@@ -744,7 +743,7 @@ CmpFindSubKeyByName(IN PHHIVE Hive,
HvReleaseCell(Hive, CellToRelease);
/* Make sure we found a valid index */
if (Found & 0x80000000) break;
if (Found & INVALID_INDEX) break;
}
else
{
@@ -856,7 +855,7 @@ CmpMarkIndexDirty(IN PHHIVE Hive,
{
/* Get the child inside the root */
Result = CmpFindSubKeyInRoot(Hive, Index, &SearchName, &Child);
if (Result & 0x80000000) goto Quickie;
if (Result & INVALID_INDEX) goto Quickie;
if (Child == HCELL_NIL) continue;
/* We found it, mark the cell dirty */
@@ -886,7 +885,7 @@ CmpMarkIndexDirty(IN PHHIVE Hive,
/* Find the child in the leaf */
Result = CmpFindSubKeyInLeaf(Hive, Index, &SearchName, &Child);
if (Result & 0x80000000) goto Quickie;
if (Result & INVALID_INDEX) goto Quickie;
if (Child != HCELL_NIL)
{
/* We found it, free the name now */
@@ -1004,7 +1003,7 @@ CmpAddToLeaf(IN PHHIVE Hive,
/* Find the insertion point for our entry */
i = CmpFindSubKeyInLeaf(Hive, Leaf, Name, &Child);
if (i & 0x80000000) return HCELL_NIL;
if (i & INVALID_INDEX) return HCELL_NIL;
ASSERT(Child == HCELL_NIL);
/* Check if we're not last */
@@ -1299,7 +1298,7 @@ CmpSelectLeaf(IN PHHIVE Hive,
SubKeyIndex = CmpFindSubKeyInRoot(Hive, IndexKey, Name, &LeafCell);
/* Make sure we found something valid */
if (SubKeyIndex & 0x80000000) return HCELL_NIL;
if (SubKeyIndex & INVALID_INDEX) return HCELL_NIL;
/* Try to fit it into the LeafCell, if it was found */
if (LeafCell != HCELL_NIL)
@@ -1705,7 +1704,7 @@ CmpRemoveSubKey(IN PHHIVE Hive,
HCELL_INDEX RootCell = HCELL_NIL, LeafCell, ChildCell;
PCM_KEY_INDEX Root = NULL, Leaf;
PCM_KEY_FAST_INDEX Child;
ULONG Storage, RootIndex = 0x80000000, LeafIndex;
ULONG Storage, RootIndex = INVALID_INDEX, LeafIndex;
BOOLEAN Result = FALSE;
HCELL_INDEX CellToRelease1 = HCELL_NIL, CellToRelease2 = HCELL_NIL;
@@ -1784,7 +1783,7 @@ CmpRemoveSubKey(IN PHHIVE Hive,
{
/* Find the child inside the root */
RootIndex = CmpFindSubKeyInRoot(Hive, Leaf, &SearchName, &ChildCell);
if (RootIndex & 0x80000000) goto Exit;
if (RootIndex & INVALID_INDEX) goto Exit;
ASSERT(ChildCell != FALSE);
/* The root cell is now this leaf */
@@ -1807,7 +1806,7 @@ CmpRemoveSubKey(IN PHHIVE Hive,
/* Now get the child in the leaf */
LeafIndex = CmpFindSubKeyInLeaf(Hive, Leaf, &SearchName, &ChildCell);
if (LeafIndex & 0x80000000) goto Exit;
if (LeafIndex & INVALID_INDEX) goto Exit;
ASSERT(ChildCell != HCELL_NIL);
/* Decrement key counts and check if this was the last leaf entry */

View File

@@ -10,7 +10,7 @@
#include "cmlib.h"
#define NDEBUG
#include "debug.h"
#include <debug.h>
/* GLOBALS *******************************************************************/
@@ -110,8 +110,8 @@ CmpCompareCompressedName(IN PCUNICODE_STRING SearchName,
IN PWCHAR CompressedName,
IN ULONG NameLength)
{
WCHAR *p;
UCHAR *pp;
WCHAR* p;
UCHAR* pp;
WCHAR chr1, chr2;
USHORT SearchLength;
LONG Result;
@@ -120,7 +120,7 @@ CmpCompareCompressedName(IN PCUNICODE_STRING SearchName,
p = SearchName->Buffer;
pp = (PUCHAR)CompressedName;
SearchLength = (SearchName->Length / sizeof(WCHAR));
while ((SearchLength) && (NameLength))
while (SearchLength > 0 && NameLength > 0)
{
/* Get the characters */
chr1 = *p++;
@@ -149,8 +149,8 @@ NTAPI
CmpFindNameInList(IN PHHIVE Hive,
IN PCHILD_LIST ChildList,
IN PUNICODE_STRING Name,
IN PULONG ChildIndex,
IN PHCELL_INDEX CellIndex)
OUT PULONG ChildIndex,
OUT PHCELL_INDEX CellIndex)
{
PCELL_DATA CellData;
HCELL_INDEX CellToRelease = HCELL_NIL;
@@ -199,14 +199,14 @@ CmpFindNameInList(IN PHHIVE Hive,
/* Check if it's a compressed value name */
if (KeyValue->Flags & VALUE_COMP_NAME)
{
/* Use the compressed name check */
/* Compare compressed names */
Result = CmpCompareCompressedName(Name,
KeyValue->Name,
KeyValue->NameLength);
}
else
{
/* Setup the Unicode string */
/* Compare the Unicode name directly */
SearchName.Length = KeyValue->NameLength;
SearchName.MaximumLength = SearchName.Length;
SearchName.Buffer = KeyValue->Name;
@@ -216,7 +216,7 @@ CmpFindNameInList(IN PHHIVE Hive,
/* Check if we found it */
if (!Result)
{
/* We did...return info to caller */
/* We did... return info to caller */
if (ChildIndex) *ChildIndex = i;
*CellIndex = CellData->u.KeyList[i];
@@ -235,7 +235,7 @@ CmpFindNameInList(IN PHHIVE Hive,
goto Return;
}
/* Nothing found...check if the caller wanted more info */
/* Nothing found... check if the caller wanted more info */
ASSERT(ChildList->Count == 0);
if (ChildIndex) *ChildIndex = 0;
*CellIndex = HCELL_NIL;

View File

@@ -109,7 +109,7 @@ CmpFindValueByName(IN PHHIVE Hive,
NULL,
&CellIndex))
{
/* Santy check */
/* Sanity check */
ASSERT(CellIndex == HCELL_NIL);
}
@@ -117,11 +117,14 @@ CmpFindValueByName(IN PHHIVE Hive,
return CellIndex;
}
/*
* NOTE: This function should support big values, contrary to CmpValueToData.
*/
BOOLEAN
NTAPI
CmpGetValueData(IN PHHIVE Hive,
IN PCM_KEY_VALUE Value,
IN PULONG Length,
OUT PULONG Length,
OUT PVOID *Buffer,
OUT PBOOLEAN BufferAllocated,
OUT PHCELL_INDEX CellToRelease)
@@ -144,7 +147,7 @@ CmpGetValueData(IN PHHIVE Hive,
return TRUE;
}
/* Unsupported */
/* Unsupported at the moment */
ASSERT_VALUE_BIG(Hive, *Length);
/* Get the data from the cell */
@@ -156,6 +159,9 @@ CmpGetValueData(IN PHHIVE Hive,
return TRUE;
}
/*
* NOTE: This function doesn't support big values, contrary to CmpGetValueData.
*/
PCELL_DATA
NTAPI
CmpValueToData(IN PHHIVE Hive,
@@ -409,7 +415,6 @@ CmpCopyKeyValueList(IN PHHIVE SourceHive,
IN PHHIVE DestinationHive,
IN OUT PCHILD_LIST DestValueList,
IN HSTORAGE_TYPE StorageType)
{
NTSTATUS Status = STATUS_SUCCESS;
HCELL_INDEX CellIndex = HCELL_NIL;

View File

@@ -118,10 +118,10 @@ HvpWriteLog(
DPRINT("FileFlush failed\n");
}
/* Update second update counter and CheckSum. */
/* Update second update counter and CheckSum */
RegistryHive->BaseBlock->Sequence2++;
RegistryHive->BaseBlock->CheckSum =
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
/* Write hive header again with updated sequence counter. */
FileOffset = 0;
@@ -170,7 +170,7 @@ HvpWriteHive(
RegistryHive->BaseBlock->Type = HFILE_TYPE_PRIMARY;
RegistryHive->BaseBlock->Sequence1++;
RegistryHive->BaseBlock->CheckSum =
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
/* Write hive block */
FileOffset = 0;

View File

@@ -219,7 +219,6 @@ CmpDoCreateChild(IN PHHIVE Hive,
PCM_KEY_NODE KeyNode;
PCELL_DATA CellData;
ULONG StorageType;
LARGE_INTEGER SystemTime;
PCM_KEY_CONTROL_BLOCK Kcb;
PSECURITY_DESCRIPTOR NewDescriptor;
@@ -312,8 +311,7 @@ CmpDoCreateChild(IN PHHIVE Hive,
/* Fill out the key node */
KeyNode->Signature = CM_KEY_NODE_SIGNATURE;
KeyNode->Flags = Flags;
KeQuerySystemTime(&SystemTime);
KeyNode->LastWriteTime = SystemTime;
KeQuerySystemTime(&KeyNode->LastWriteTime);
KeyNode->Spare = 0;
KeyNode->Parent = ParentCell;
KeyNode->SubKeyCounts[Stable] = 0;
@@ -378,6 +376,9 @@ CmpDoCreateChild(IN PHHIVE Hive,
&CmpKeyObjectType->TypeInfo.GenericMapping);
}
/* Now that the security descriptor is copied in the hive, we can free the original */
SeDeassignSecurity(&NewDescriptor);
Quickie:
/* Check if we got here because of failure */
if (!NT_SUCCESS(Status))
@@ -516,7 +517,7 @@ CmpDoCreate(IN PHHIVE Hive,
KeyBody->KeyControlBlock->ParentKcb->KcbMaxNameLen = Name->Length;
}
/* Check if we need toupdate class length maximum */
/* Check if we need to update class length maximum */
if (KeyNode->MaxClassLen < ParseContext->Class.Length)
{
/* Update it */
@@ -925,7 +926,7 @@ CmpCreateLinkNode(IN PHHIVE Hive,
KeyBody->KeyControlBlock->ParentKcb->KcbMaxNameLen = Name.Length;
}
/* Check if we need toupdate class length maximum */
/* Check if we need to update class length maximum */
if (KeyNode->MaxClassLen < Context->Class.Length)
{
/* Update it */

View File

@@ -1030,7 +1030,6 @@ CmpCreateRootNode(IN PHHIVE Hive,
{
UNICODE_STRING KeyName;
PCM_KEY_NODE KeyCell;
LARGE_INTEGER SystemTime;
PAGED_CODE();
/* Initialize the node name and allocate it */
@@ -1048,10 +1047,9 @@ CmpCreateRootNode(IN PHHIVE Hive,
if (!KeyCell) return FALSE;
/* Setup the cell */
KeyCell->Signature = (USHORT)CM_KEY_NODE_SIGNATURE;
KeyCell->Signature = CM_KEY_NODE_SIGNATURE;
KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE;
KeQuerySystemTime(&SystemTime);
KeyCell->LastWriteTime = SystemTime;
KeQuerySystemTime(&KeyCell->LastWriteTime);
KeyCell->Parent = HCELL_NIL;
KeyCell->SubKeyCounts[Stable] = 0;
KeyCell->SubKeyCounts[Volatile] = 0;
@@ -1068,14 +1066,11 @@ CmpCreateRootNode(IN PHHIVE Hive,
KeyCell->MaxValueDataLen = 0;
/* Copy the name (this will also set the length) */
KeyCell->NameLength = CmpCopyName(Hive, (PWCHAR)KeyCell->Name, &KeyName);
KeyCell->NameLength = CmpCopyName(Hive, KeyCell->Name, &KeyName);
/* Check if the name was compressed */
/* Check if the name was compressed and set the flag if so */
if (KeyCell->NameLength < KeyName.Length)
{
/* Set the flag */
KeyCell->Flags |= KEY_COMP_NAME;
}
/* Return success */
HvReleaseCell(Hive, *Index);

View File

@@ -249,14 +249,14 @@ CmpFindValueByNameFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
}
/* Get the key value for this index */
SearchResult = CmpGetValueKeyFromCache(Kcb,
CellData,
i,
CachedValue,
Value,
IndexIsCached,
ValueIsCached,
CellToRelease);
SearchResult = CmpGetValueKeyFromCache(Kcb,
CellData,
i,
CachedValue,
Value,
IndexIsCached,
ValueIsCached,
CellToRelease);
if (SearchResult != SearchSuccess)
{
/* We either failed or need the exclusive lock */
@@ -266,7 +266,7 @@ CmpFindValueByNameFromCache(IN PCM_KEY_CONTROL_BLOCK Kcb,
}
/* Check if the both the index and the value are cached */
if ((IndexIsCached) && (*ValueIsCached))
if (IndexIsCached && *ValueIsCached)
{
/* We don't expect this yet */
ASSERT_VALUE_CACHE();

View File

@@ -16,7 +16,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* COPYRIGHT: See COPYING in the top level directory
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS hive maker
* FILE: tools/mkhive/binhive.c
* PURPOSE: Binary hive export code

View File

@@ -16,7 +16,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* COPYRIGHT: See COPYING in the top level directory
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS hive maker
* FILE: tools/mkhive/binhive.h
* PURPOSE: Binary hive export code

View File

@@ -1,14 +0,0 @@
/*
* This header is used together with cmindex.c and cmname.c
*/
#define NDEBUG
#include "mkhive.h"
PVOID
NTAPI
CmpAllocate(
IN SIZE_T Size,
IN BOOLEAN Paged,
IN ULONG Tag
);

View File

@@ -16,7 +16,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* COPYRIGHT: See COPYING in the top level directory
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS hive maker
* FILE: tools/mkhive/reginf.c
* PURPOSE: Inf file import code

View File

@@ -16,7 +16,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* COPYRIGHT: See COPYING in the top level directory
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS hive maker
* FILE: tools/mkhive/reginf.h
* PURPOSE: Inf file import code

View File

@@ -1,4 +1,5 @@
/* COPYRIGHT: See COPYING in the top level directory
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS hive maker
* FILE: tools/mkhive/registry.h
* PURPOSE: Registry code
@@ -34,23 +35,26 @@ extern CMHIVE BcdHive; /* \Registry\Machine\BCD00000000 */
#define ERROR_SUCCESS 0L
#define ERROR_UNSUCCESSFUL 1L
#define ERROR_FILE_NOT_FOUND 2L
#define ERROR_OUTOFMEMORY 14L
#define ERROR_INVALID_PARAMETER 87L
#define ERROR_MORE_DATA 234L
#define ERROR_NO_MORE_ITEMS 259L
#define REG_NONE 0
#define REG_SZ 1
#define REG_EXPAND_SZ 2
#define REG_BINARY 3
#define REG_DWORD 4
#define REG_DWORD_BIG_ENDIAN 5
#define REG_DWORD_LITTLE_ENDIAN 4
#define REG_LINK 6
#define REG_MULTI_SZ 7
#define REG_RESOURCE_LIST 8
#define REG_FULL_RESOURCE_DESCRIPTOR 9
#define REG_RESOURCE_REQUIREMENTS_LIST 10
#define REG_NONE 0
#define REG_SZ 1
#define REG_EXPAND_SZ 2
#define REG_BINARY 3
#define REG_DWORD 4
#define REG_DWORD_LITTLE_ENDIAN 4
#define REG_DWORD_BIG_ENDIAN 5
#define REG_LINK 6
#define REG_MULTI_SZ 7
#define REG_RESOURCE_LIST 8
#define REG_FULL_RESOURCE_DESCRIPTOR 9
#define REG_RESOURCE_REQUIREMENTS_LIST 10
#define REG_QWORD 11
#define REG_QWORD_LITTLE_ENDIAN 11
VOID
RegInitializeRegistry(VOID);