- 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
#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 *****************************************************************/
{
Big:
/* This was some sort of special key */
- ReturnIndex = 0x80000000;
+ ReturnIndex = INVALID_INDEX;
goto ReturnFailure;
}
/* Check if we found it */
if (!Result)
{
- /* We got lucky...return it */
+ /* We got lucky... return it */
*SubKey = LeafCell;
ReturnIndex = Low;
goto Return;
{
/* Fail with special value */
*SubKey = HCELL_NIL;
- return 0x80000000;
+ return INVALID_INDEX;
}
/* Check if we got lucky and found it */
{
/* Fail with special value */
*SubKey = HCELL_NIL;
- return 0x80000000;
+ return INVALID_INDEX;
}
/* Check if we got lucky and found it */
{
/* Fail with special value */
*SubKey = HCELL_NIL;
- return 0x80000000;
+ return INVALID_INDEX;
}
/* Return the high */
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 */
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;
HvReleaseCell(Hive, CellToRelease);
/* Make sure we found a valid index */
- if (Found & 0x80000000) break;
+ if (Found & INVALID_INDEX) break;
}
else
{
{
/* 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 */
/* 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 */
/* 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 */
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)
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;
{
/* 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 */
/* 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 */
#include "cmlib.h"
#define NDEBUG
-#include "debug.h"
+#include <debug.h>
/* GLOBALS *******************************************************************/
IN PWCHAR CompressedName,
IN ULONG NameLength)
{
- WCHAR *p;
- UCHAR *pp;
+ WCHAR* p;
+ UCHAR* pp;
WCHAR chr1, chr2;
USHORT SearchLength;
LONG Result;
p = SearchName->Buffer;
pp = (PUCHAR)CompressedName;
SearchLength = (SearchName->Length / sizeof(WCHAR));
- while ((SearchLength) && (NameLength))
+ while (SearchLength > 0 && NameLength > 0)
{
/* Get the characters */
chr1 = *p++;
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;
/* 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;
/* 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];
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;
NULL,
&CellIndex))
{
- /* Santy check */
+ /* Sanity check */
ASSERT(CellIndex == HCELL_NIL);
}
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)
return TRUE;
}
- /* Unsupported */
+ /* Unsupported at the moment */
ASSERT_VALUE_BIG(Hive, *Length);
/* Get the data from the cell */
return TRUE;
}
+/*
+ * NOTE: This function doesn't support big values, contrary to CmpGetValueData.
+ */
PCELL_DATA
NTAPI
CmpValueToData(IN PHHIVE Hive,
IN PHHIVE DestinationHive,
IN OUT PCHILD_LIST DestValueList,
IN HSTORAGE_TYPE StorageType)
-
{
NTSTATUS Status = STATUS_SUCCESS;
HCELL_INDEX CellIndex = HCELL_NIL;
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;
RegistryHive->BaseBlock->Type = HFILE_TYPE_PRIMARY;
RegistryHive->BaseBlock->Sequence1++;
RegistryHive->BaseBlock->CheckSum =
- HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
+ HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
/* Write hive block */
FileOffset = 0;
PCM_KEY_NODE KeyNode;
PCELL_DATA CellData;
ULONG StorageType;
- LARGE_INTEGER SystemTime;
PCM_KEY_CONTROL_BLOCK Kcb;
PSECURITY_DESCRIPTOR NewDescriptor;
/* 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;
&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))
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 */
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 */
{
UNICODE_STRING KeyName;
PCM_KEY_NODE KeyCell;
- LARGE_INTEGER SystemTime;
PAGED_CODE();
/* Initialize the node name and allocate it */
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;
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);
}
/* 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 */
}
/* 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();
* 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
* 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
+++ /dev/null
-/*
- * 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
-);
* 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
* 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
-/* 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
#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);