[NTOS:IO]
authorThomas Faber <thomas.faber@reactos.org>
Thu, 15 Jun 2017 18:32:14 +0000 (18:32 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Thu, 15 Jun 2017 18:32:14 +0000 (18:32 +0000)
- Pass the class key handle as a parameter to IopAttachFilterDrivers, since we already opened it in PipCallDriverAddDevice.
CORE-13336 #resolve

svn path=/trunk/; revision=75051

reactos/ntoskrnl/include/internal/io.h
reactos/ntoskrnl/io/iomgr/driver.c
reactos/ntoskrnl/io/pnpmgr/pnpinit.c

index ef7b4c6..54a4690 100644 (file)
@@ -1115,6 +1115,7 @@ FASTCALL
 IopAttachFilterDrivers(
     IN PDEVICE_NODE DeviceNode,
     IN HANDLE EnumSubKey,
 IopAttachFilterDrivers(
     IN PDEVICE_NODE DeviceNode,
     IN HANDLE EnumSubKey,
+    IN HANDLE ClassKey,
     IN BOOLEAN Lower
 );
 
     IN BOOLEAN Lower
 );
 
index 545fa97..4f4df52 100644 (file)
@@ -641,13 +641,10 @@ FASTCALL
 IopAttachFilterDrivers(
     PDEVICE_NODE DeviceNode,
     HANDLE EnumSubKey,
 IopAttachFilterDrivers(
     PDEVICE_NODE DeviceNode,
     HANDLE EnumSubKey,
+    HANDLE ClassKey,
     BOOLEAN Lower)
 {
     RTL_QUERY_REGISTRY_TABLE QueryTable[2] = { { NULL, 0, NULL, NULL, 0, NULL, 0 }, };
     BOOLEAN Lower)
 {
     RTL_QUERY_REGISTRY_TABLE QueryTable[2] = { { NULL, 0, NULL, NULL, 0, NULL, 0 }, };
-    UNICODE_STRING Class;
-    WCHAR ClassBuffer[40];
-    UNICODE_STRING ControlClass = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class");
-    HANDLE ControlKey, ClassKey;
     NTSTATUS Status;
 
     /*
     NTSTATUS Status;
 
     /*
@@ -673,57 +670,6 @@ IopAttachFilterDrivers(
         return Status;
     }
 
         return Status;
     }
 
-    /*
-     * Now get the class GUID
-     */
-    Class.Length = 0;
-    Class.MaximumLength = 40 * sizeof(WCHAR);
-    Class.Buffer = ClassBuffer;
-    QueryTable[0].QueryRoutine = NULL;
-    QueryTable[0].Name = L"ClassGUID";
-    QueryTable[0].EntryContext = &Class;
-    QueryTable[0].Flags = RTL_QUERY_REGISTRY_REQUIRED | RTL_QUERY_REGISTRY_DIRECT;
-
-    Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
-                                    (PWSTR)EnumSubKey,
-                                    QueryTable,
-                                    DeviceNode,
-                                    NULL);
-
-    /* If there is no class GUID, we're done */
-    if (!NT_SUCCESS(Status))
-    {
-        return STATUS_SUCCESS;
-    }
-
-    /*
-     * Load the class filter driver
-     */
-    Status = IopOpenRegistryKeyEx(&ControlKey,
-                                  NULL,
-                                  &ControlClass,
-                                  KEY_READ);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
-                &ControlClass, Status);
-        return STATUS_SUCCESS;
-    }
-
-    /* Open subkey */
-    Status = IopOpenRegistryKeyEx(&ClassKey,
-                                  ControlKey,
-                                  &Class,
-                                  KEY_READ);
-    if (!NT_SUCCESS(Status))
-    {
-        /* It's okay if there's no class key */
-        DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
-                &Class, Status);
-        ZwClose(ControlKey);
-        return STATUS_SUCCESS;
-    }
-
     QueryTable[0].QueryRoutine = IopAttachFilterDriversCallback;
     if (Lower)
         QueryTable[0].Name = L"LowerFilters";
     QueryTable[0].QueryRoutine = IopAttachFilterDriversCallback;
     if (Lower)
         QueryTable[0].Name = L"LowerFilters";
@@ -733,16 +679,17 @@ IopAttachFilterDrivers(
     QueryTable[0].Flags = 0;
     QueryTable[0].DefaultType = REG_NONE;
 
     QueryTable[0].Flags = 0;
     QueryTable[0].DefaultType = REG_NONE;
 
+    if (ClassKey == NULL)
+    {
+        return STATUS_SUCCESS;
+    }
+
     Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
                                     (PWSTR)ClassKey,
                                     QueryTable,
                                     DeviceNode,
                                     NULL);
 
     Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE,
                                     (PWSTR)ClassKey,
                                     QueryTable,
                                     DeviceNode,
                                     NULL);
 
-    /* Clean up */
-    ZwClose(ClassKey);
-    ZwClose(ControlKey);
-
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to load class %s filters: %08X\n",
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to load class %s filters: %08X\n",
index 733a68e..7153cd2 100644 (file)
@@ -253,7 +253,8 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode,
                        IN PDRIVER_OBJECT DriverObject)
 {
     NTSTATUS Status;
                        IN PDRIVER_OBJECT DriverObject)
 {
     NTSTATUS Status;
-    HANDLE EnumRootKey, SubKey, ControlKey, ClassKey, PropertiesKey;
+    HANDLE EnumRootKey, SubKey;
+    HANDLE ControlKey, ClassKey = NULL, PropertiesKey;
     UNICODE_STRING ClassGuid, Properties;
     UNICODE_STRING EnumRoot = RTL_CONSTANT_STRING(ENUM_ROOT);
     UNICODE_STRING ControlClass =
     UNICODE_STRING ClassGuid, Properties;
     UNICODE_STRING EnumRoot = RTL_CONSTANT_STRING(ENUM_ROOT);
     UNICODE_STRING ControlClass =
@@ -308,7 +309,6 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode,
             /* No class key */
             DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
                     &ControlClass, Status);
             /* No class key */
             DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
                     &ControlClass, Status);
-            ClassKey = NULL;
         }
         else
         {
         }
         else
         {
@@ -323,7 +323,6 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode,
                 /* No class key */
                 DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
                         &ClassGuid, Status);
                 /* No class key */
                 DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
                         &ClassGuid, Status);
-                ClassKey = NULL;
             }
         }
 
             }
         }
 
@@ -336,7 +335,6 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode,
                                           ClassKey,
                                           &Properties,
                                           KEY_READ);
                                           ClassKey,
                                           &Properties,
                                           KEY_READ);
-            ZwClose(ClassKey);
             if (!NT_SUCCESS(Status))
             {
                 /* No properties */
             if (!NT_SUCCESS(Status))
             {
                 /* No properties */
@@ -355,7 +353,7 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode,
     }
 
     /* Do ReactOS-style setup */
     }
 
     /* Do ReactOS-style setup */
-    Status = IopAttachFilterDrivers(DeviceNode, SubKey, TRUE);
+    Status = IopAttachFilterDrivers(DeviceNode, SubKey, ClassKey, TRUE);
     if (!NT_SUCCESS(Status))
     {
         IopRemoveDevice(DeviceNode);
     if (!NT_SUCCESS(Status))
     {
         IopRemoveDevice(DeviceNode);
@@ -368,7 +366,7 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode,
         goto Exit;
     }
 
         goto Exit;
     }
 
-    Status = IopAttachFilterDrivers(DeviceNode, SubKey, FALSE);
+    Status = IopAttachFilterDrivers(DeviceNode, SubKey, ClassKey, FALSE);
     if (!NT_SUCCESS(Status))
     {
         IopRemoveDevice(DeviceNode);
     if (!NT_SUCCESS(Status))
     {
         IopRemoveDevice(DeviceNode);
@@ -378,8 +376,12 @@ PipCallDriverAddDevice(IN PDEVICE_NODE DeviceNode,
     Status = IopStartDevice(DeviceNode);
 
 Exit:
     Status = IopStartDevice(DeviceNode);
 
 Exit:
-    /* Close key and return status */
+    /* Close keys and return status */
     ZwClose(SubKey);
     ZwClose(SubKey);
+    if (ClassKey != NULL)
+    {
+        ZwClose(ClassKey);
+    }
     return Status;
 }
 
     return Status;
 }