[CMLIB]
[reactos.git] / reactos / ntoskrnl / config / cmsysini.c
index dc03e96..45242d2 100644 (file)
@@ -36,6 +36,71 @@ extern BOOLEAN CmFirstTime;
 
 /* FUNCTIONS ******************************************************************/
 
+BOOLEAN
+NTAPI
+CmpLinkKeyToHive(
+    _In_z_ PWSTR LinkKeyName,
+    _In_z_ PWSTR TargetKeyName)
+{
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    UNICODE_STRING LinkKeyName_U;
+    HANDLE TargetKeyHandle;
+    ULONG Disposition;
+    NTSTATUS Status;
+    PAGED_CODE();
+
+    /* Initialize the object attributes */
+    RtlInitUnicodeString(&LinkKeyName_U, LinkKeyName);
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &LinkKeyName_U,
+                               OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
+                               NULL,
+                               NULL);
+
+    /* Create the link key */
+    Status = ZwCreateKey(&TargetKeyHandle,
+                         KEY_CREATE_LINK,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK,
+                         &Disposition);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("CM: CmpLinkKeyToHive: couldn't create %S Status = 0x%lx\n",
+                LinkKeyName, Status);
+        return FALSE;
+    }
+
+    /* Check if the new key was actually created */
+    if (Disposition != REG_CREATED_NEW_KEY)
+    {
+        DPRINT1("CM: CmpLinkKeyToHive: %S already exists!\n", LinkKeyName);
+        ZwClose(TargetKeyHandle);
+        return FALSE;
+    }
+
+    /* Set the target key name as link target */
+    Status = ZwSetValueKey(TargetKeyHandle,
+                           &CmSymbolicLinkValueName,
+                           0,
+                           REG_LINK,
+                           TargetKeyName,
+                           wcslen(TargetKeyName) * sizeof(WCHAR));
+
+    /* Close the link key handle */
+    ObCloseHandle(TargetKeyHandle, KernelMode);
+
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("CM: CmpLinkKeyToHive: couldn't create symbolic link for %S\n",
+                TargetKeyName);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 VOID
 NTAPI
 CmpDeleteKeyObject(PVOID DeletedObject)
@@ -164,7 +229,7 @@ CmpQueryKeyName(IN PVOID ObjectBody,
         ((Length < (*ReturnLength)) && (BytesToCopy < sizeof(WCHAR))))
     {
         /* Free the buffer allocated by CmpConstructName */
-        ExFreePool(KeyName);
+        ExFreePoolWithTag(KeyName, TAG_CM);
 
         /* Return buffer length failure without writing anything there because nothing fits */
         return STATUS_INFO_LENGTH_MISMATCH;
@@ -207,7 +272,7 @@ CmpQueryKeyName(IN PVOID ObjectBody,
     _SEH2_END;
 
     /* Free the buffer allocated by CmpConstructName */
-    ExFreePool(KeyName);
+    ExFreePoolWithTag(KeyName, TAG_CM);
 
     /* Return status */
     return Status;
@@ -584,7 +649,7 @@ UseSet:
     LoaderExtension = LoaderBlock->Extension;
     if (LoaderExtension)
     {
-        ASSERTMSG("ReactOS doesn't support NTLDR Profiles yet!\n", FALSE);
+        DPRINT("ReactOS doesn't support NTLDR Profiles yet!\n");
     }
 
     /* Create the current hardware profile key */
@@ -751,7 +816,6 @@ CmpInitializeSystemHive(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     if (HiveBase)
     {
         /* Import it */
-        ((PHBASE_BLOCK)HiveBase)->Length = LoaderBlock->RegistryLength;
         Status = CmpInitializeHive((PCMHIVE*)&SystemHive,
                                    HINIT_MEMORY,
                                    HIVE_NOLAZYFLUSH,
@@ -1389,9 +1453,13 @@ CmpInitializeHiveList(IN USHORT Flag)
     /* Get rid of the SD */
     ExFreePoolWithTag(SecurityDescriptor, TAG_CM);
 
-    /* FIXME: Link SECURITY to SAM */
+    /* Link SECURITY to SAM */
+    CmpLinkKeyToHive(L"\\Registry\\Machine\\Security\\SAM",
+                     L"\\Registry\\Machine\\SAM\\SAM");
 
-    /* FIXME: Link S-1-5-18 to .Default */
+    /* Link S-1-5-18 to .Default */
+    CmpLinkKeyToHive(L"\\Registry\\User\\S-1-5-18",
+                     L"\\Registry\\User\\.Default");
 }
 
 BOOLEAN
@@ -1881,6 +1949,11 @@ CmpUnlockRegistry(VOID)
         CmpDoFlushAll(TRUE);
         CmpFlushOnLockRelease = FALSE;
     }
+    else
+    {
+        /* Lazy flush the registry */
+        CmpLazyFlush();
+    }
 
     /* Release the lock and leave the critical region */
     ExReleaseResourceLite(&CmpRegistryLock);