Author: tkreuzer
Date: Sat Nov 16 18:27:26 2013
New Revision: 61011

URL: http://svn.reactos.org/svn/reactos?rev=61011&view=rev
Log:
[RTL]
Fix RtlWriteRegistryValue, it closed the handle passed to it instead of 
checking for RTL_REGISTRY_HANDLE flag.

[NTOSKRNL]
Fix PnpRootCreateDevice, which was relying on the broken RtlWriteRegistryValue 
by aborting, when it *succeeded* to create a registry key, instead of when it 
failed.
Also use kernel handles and ObCloseHandle.

Modified:
    trunk/reactos/lib/rtl/registry.c
    trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c

Modified: trunk/reactos/lib/rtl/registry.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/registry.c?rev=61011&r1=61010&r2=61011&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/registry.c    [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/registry.c    [iso-8859-1] Sat Nov 16 18:27:26 2013
@@ -661,8 +661,13 @@
                            ValueData,
                            ValueLength);
 
-    /* All went well, close the handle and return status */
-    ZwClose(KeyHandle);
+    /* Did the caller pass a key handle? */
+    if (!(RelativeTo & RTL_REGISTRY_HANDLE))
+    {
+        /* We opened the key in RtlpGetRegistryHandle, so close it now */
+        ZwClose(KeyHandle);
+    }
+
     return Status;
 }
 

Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c?rev=61011&r1=61010&r2=61011&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c  [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c  [iso-8859-1] Sat Nov 16 
18:27:26 2013
@@ -227,9 +227,13 @@
     Status = IopOpenRegistryKeyEx(&EnumHandle, NULL, &EnumKeyName, KEY_READ);
     if (NT_SUCCESS(Status))
     {
-        InitializeObjectAttributes(&ObjectAttributes, &Device->DeviceID, 
OBJ_CASE_INSENSITIVE, EnumHandle, NULL);
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &Device->DeviceID,
+                                   OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
+                                   EnumHandle,
+                                   NULL);
         Status = ZwCreateKey(&DeviceKeyHandle, KEY_SET_VALUE, 
&ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL);
-        ZwClose(EnumHandle);
+        ObCloseHandle(EnumHandle, KernelMode);
     }
 
     if (!NT_SUCCESS(Status))
@@ -298,16 +302,20 @@
     }
 
     /* Finish creating the instance path in the registry */
-    InitializeObjectAttributes(&ObjectAttributes, &Device->InstanceID, 
OBJ_CASE_INSENSITIVE, DeviceKeyHandle, NULL);
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &Device->InstanceID,
+                               OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
+                               DeviceKeyHandle,
+                               NULL);
     Status = ZwCreateKey(&InstanceKeyHandle, KEY_QUERY_VALUE, 
&ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL);
-    if (NT_SUCCESS(Status))
+    if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to create instance path (0x%x)\n", Status);
         goto cleanup;
     }
 
     /* Just close the handle */
-    ZwClose(InstanceKeyHandle);
+    ObCloseHandle(InstanceKeyHandle, KernelMode);
 
     if (FullInstancePath)
     {
@@ -370,7 +378,7 @@
         ExFreePoolWithTag(Device, TAG_PNP_ROOT);
     }
     if (DeviceKeyHandle != INVALID_HANDLE_VALUE)
-        ZwClose(DeviceKeyHandle);
+        ObCloseHandle(DeviceKeyHandle, KernelMode);
     return Status;
 }
 


Reply via email to