[MKHIVE] Minor improvements.
[reactos.git] / sdk / tools / mkhive / registry.c
index cd238dc..a3cc712 100644 (file)
  *   - Implement RegDeleteKeyW() and RegDeleteValueW()
  */
 
  *   - Implement RegDeleteKeyW() and RegDeleteValueW()
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
 #define NDEBUG
 #include "mkhive.h"
 
 #define NDEBUG
 #include "mkhive.h"
 
@@ -463,11 +459,18 @@ RegpCreateOrOpenKey(
                                   Volatile,
                                   &BlockOffset);
         }
                                   Volatile,
                                   &BlockOffset);
         }
+        else // if (BlockOffset == HCELL_NIL)
+        {
+            Status = STATUS_OBJECT_NAME_NOT_FOUND; // ERROR_PATH_NOT_FOUND;
+        }
 
         HvReleaseCell(&ParentRegistryHive->Hive, ParentCellOffset);
 
         if (!NT_SUCCESS(Status))
 
         HvReleaseCell(&ParentRegistryHive->Hive, ParentCellOffset);
 
         if (!NT_SUCCESS(Status))
+        {
+            DPRINT("RegpCreateOrOpenKey('%S'): Could not create or open subkey '%wZ'\n", KeyName, &KeyString);
             return ERROR_UNSUCCESSFUL;
             return ERROR_UNSUCCESSFUL;
+        }
 
         ParentCellOffset = BlockOffset;
         if (End)
 
         ParentCellOffset = BlockOffset;
         if (End)
@@ -557,6 +560,7 @@ RegSetValueExW(
     PHHIVE Hive;
     PCM_KEY_NODE KeyNode; // ParentNode
     PCM_KEY_VALUE ValueCell;
     PHHIVE Hive;
     PCM_KEY_NODE KeyNode; // ParentNode
     PCM_KEY_VALUE ValueCell;
+    ULONG ChildIndex;
     HCELL_INDEX CellIndex;
     UNICODE_STRING ValueNameString;
 
     HCELL_INDEX CellIndex;
     UNICODE_STRING ValueNameString;
 
@@ -600,12 +604,24 @@ RegSetValueExW(
 
     /* Initialize value name string */
     RtlInitUnicodeString(&ValueNameString, lpValueName);
 
     /* Initialize value name string */
     RtlInitUnicodeString(&ValueNameString, lpValueName);
-    CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString);
+    if (!CmpFindNameInList(Hive,
+                           &KeyNode->ValueList,
+                           &ValueNameString,
+                           &ChildIndex,
+                           &CellIndex))
+    {
+        /* Sanity check */
+        ASSERT(CellIndex == HCELL_NIL);
+        /* Fail */
+        // Status = STATUS_INSUFFICIENT_RESOURCES;
+        return ERROR_UNSUCCESSFUL;
+    }
     if (CellIndex == HCELL_NIL)
     {
         /* The value doesn't exist, create a new one */
         Status = CmiAddValueKey(Key->RegistryHive,
                                 KeyNode,
     if (CellIndex == HCELL_NIL)
     {
         /* The value doesn't exist, create a new one */
         Status = CmiAddValueKey(Key->RegistryHive,
                                 KeyNode,
+                                ChildIndex,
                                 &ValueNameString,
                                 &ValueCell,
                                 &CellIndex);
                                 &ValueNameString,
                                 &ValueCell,
                                 &CellIndex);
@@ -698,7 +714,7 @@ RegSetValueExW(
 }
 
 
 }
 
 
-// Synced with freeldr/windows/registry.c
+// Synced with freeldr/ntldr/registry.c
 static
 VOID
 RepGetValueData(
 static
 VOID
 RepGetValueData(
@@ -737,7 +753,7 @@ RepGetValueData(
     }
 }
 
     }
 }
 
-// Similar to RegQueryValue in freeldr/windows/registry.c
+// Similar to RegQueryValue in freeldr/ntldr/registry.c
 LONG WINAPI
 RegQueryValueExW(
     IN HKEY hKey,
 LONG WINAPI
 RegQueryValueExW(
     IN HKEY hKey,
@@ -865,6 +881,7 @@ CreateSymLink(
     // IN PCWSTR TargetKeyPath OPTIONAL,
     IN HKEY TargetKeyHandle)
 {
     // IN PCWSTR TargetKeyPath OPTIONAL,
     IN HKEY TargetKeyHandle)
 {
+    LONG rc;
     PMEMKEY LinkKey, TargetKey;
     PREPARSE_POINT ReparsePoint;
 
     PMEMKEY LinkKey, TargetKey;
     PREPARSE_POINT ReparsePoint;
 
@@ -875,15 +892,20 @@ CreateSymLink(
     if (LinkKeyPath && !(LinkKeyHandle && *LinkKeyHandle))
     {
         /* Create the link key */
     if (LinkKeyPath && !(LinkKeyHandle && *LinkKeyHandle))
     {
         /* Create the link key */
-        RegCreateKeyExW(NULL,
-                        LinkKeyPath,
-                        0,
-                        NULL,
-                        REG_OPTION_VOLATILE,
-                        0,
-                        NULL,
-                        (HKEY*)&LinkKey,
-                        NULL);
+        rc = RegCreateKeyExW(NULL,
+                             LinkKeyPath,
+                             0,
+                             NULL,
+                             REG_OPTION_VOLATILE,
+                             0,
+                             NULL,
+                             (PHKEY)&LinkKey,
+                             NULL);
+        if (rc != ERROR_SUCCESS)
+        {
+            free(ReparsePoint);
+            return FALSE;
+        }
     }
     else if (LinkKeyHandle)
     {
     }
     else if (LinkKeyHandle)
     {