[NTOSKRNL]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 11 Jun 2011 11:58:46 +0000 (11:58 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 11 Jun 2011 11:58:46 +0000 (11:58 +0000)
- Do not create/open the CurrentVersion key in a single call to NtCreateKey  because its parent key might not exist yet.
See issue #6302 for more details.

svn path=/trunk/; revision=52184

reactos/ntoskrnl/config/cmsysini.c

index f6b3142..8159383 100644 (file)
@@ -1946,13 +1946,16 @@ CmpSetVersionData(VOID)
     UNICODE_STRING KeyName;
     UNICODE_STRING ValueName;
     UNICODE_STRING ValueData;
     UNICODE_STRING KeyName;
     UNICODE_STRING ValueName;
     UNICODE_STRING ValueData;
-    HANDLE KeyHandle;
+    HANDLE SoftwareKeyHandle = NULL;
+    HANDLE MicrosoftKeyHandle = NULL;
+    HANDLE WindowsNtKeyHandle = NULL;
+    HANDLE CurrentVersionKeyHandle = NULL;
     WCHAR Buffer[128];
     NTSTATUS Status;
 
     /* Open the 'CurrentVersion' key */
     RtlInitUnicodeString(&KeyName,
     WCHAR Buffer[128];
     NTSTATUS Status;
 
     /* Open the 'CurrentVersion' key */
     RtlInitUnicodeString(&KeyName,
-                         L"\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
+                         L"\\REGISTRY\\MACHINE\\SOFTWARE");
 
     InitializeObjectAttributes(&ObjectAttributes,
                                &KeyName,
 
     InitializeObjectAttributes(&ObjectAttributes,
                                &KeyName,
@@ -1960,7 +1963,7 @@ CmpSetVersionData(VOID)
                                NULL,
                                NULL);
 
                                NULL,
                                NULL);
 
-    Status = NtCreateKey(&KeyHandle,
+    Status = NtCreateKey(&SoftwareKeyHandle,
                          KEY_CREATE_SUB_KEY,
                          &ObjectAttributes,
                          0,
                          KEY_CREATE_SUB_KEY,
                          &ObjectAttributes,
                          0,
@@ -1973,6 +1976,75 @@ CmpSetVersionData(VOID)
         return;
     }
 
         return;
     }
 
+    /* Open the 'CurrentVersion' key */
+    RtlInitUnicodeString(&KeyName,
+                         L"Microsoft");
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &KeyName,
+                               OBJ_CASE_INSENSITIVE,
+                               SoftwareKeyHandle,
+                               NULL);
+
+    Status = NtCreateKey(&MicrosoftKeyHandle,
+                         KEY_CREATE_SUB_KEY,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         0,
+                         NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status);
+        goto done;
+    }
+
+    /* Open the 'CurrentVersion' key */
+    RtlInitUnicodeString(&KeyName,
+                         L"Windows NT");
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &KeyName,
+                               OBJ_CASE_INSENSITIVE,
+                               MicrosoftKeyHandle,
+                               NULL);
+
+    Status = NtCreateKey(&WindowsNtKeyHandle,
+                         KEY_CREATE_SUB_KEY,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         0,
+                         NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status);
+        goto done;
+    }
+
+    /* Open the 'CurrentVersion' key */
+    RtlInitUnicodeString(&KeyName,
+                         L"CurrentVersion");
+
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &KeyName,
+                               OBJ_CASE_INSENSITIVE,
+                               WindowsNtKeyHandle,
+                               NULL);
+
+    Status = NtCreateKey(&CurrentVersionKeyHandle,
+                         KEY_CREATE_SUB_KEY | KEY_SET_VALUE,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         0,
+                         NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status);
+        goto done;
+    }
+
     /* Set the 'CurrentType' value */
     RtlInitUnicodeString(&ValueName,
                          L"CurrentType");
     /* Set the 'CurrentType' value */
     RtlInitUnicodeString(&ValueName,
                          L"CurrentType");
@@ -1994,15 +2066,26 @@ CmpSetVersionData(VOID)
     RtlInitUnicodeString(&ValueData,
                          Buffer);
 
     RtlInitUnicodeString(&ValueData,
                          Buffer);
 
-    NtSetValueKey(KeyHandle,
+    NtSetValueKey(CurrentVersionKeyHandle,
                   &ValueName,
                   0,
                   REG_SZ,
                   ValueData.Buffer,
                   ValueData.Length + sizeof(WCHAR));
 
                   &ValueName,
                   0,
                   REG_SZ,
                   ValueData.Buffer,
                   ValueData.Length + sizeof(WCHAR));
 
-    /* Close the key */
-    NtClose(KeyHandle);
+done:;
+    /* Close the keys */
+    if (CurrentVersionKeyHandle != NULL)
+        NtClose(CurrentVersionKeyHandle);
+
+    if (WindowsNtKeyHandle != NULL)
+        NtClose(WindowsNtKeyHandle);
+
+    if (MicrosoftKeyHandle != NULL)
+        NtClose(MicrosoftKeyHandle);
+
+    if (SoftwareKeyHandle != NULL)
+        NtClose(SoftwareKeyHandle);
 }
 
 /* EOF */
 }
 
 /* EOF */