IopAttachFilterDrivers(
PDEVICE_NODE DeviceNode,
HANDLE EnumSubKey,
+ HANDLE ClassKey,
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;
/*
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].Flags = 0;
QueryTable[0].DefaultType = REG_NONE;
+ if (ClassKey == NULL)
+ {
+ return STATUS_SUCCESS;
+ }
+
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",
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 =
/* No class key */
DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
&ControlClass, Status);
- ClassKey = NULL;
}
else
{
/* No class key */
DPRINT1("IopOpenRegistryKeyEx() failed for '%wZ' with status 0x%lx\n",
&ClassGuid, Status);
- ClassKey = NULL;
}
}
ClassKey,
&Properties,
KEY_READ);
- ZwClose(ClassKey);
if (!NT_SUCCESS(Status))
{
/* No properties */
}
/* Do ReactOS-style setup */
- Status = IopAttachFilterDrivers(DeviceNode, SubKey, TRUE);
+ Status = IopAttachFilterDrivers(DeviceNode, SubKey, ClassKey, TRUE);
if (!NT_SUCCESS(Status))
{
IopRemoveDevice(DeviceNode);
goto Exit;
}
- Status = IopAttachFilterDrivers(DeviceNode, SubKey, FALSE);
+ Status = IopAttachFilterDrivers(DeviceNode, SubKey, ClassKey, FALSE);
if (!NT_SUCCESS(Status))
{
IopRemoveDevice(DeviceNode);
Status = IopStartDevice(DeviceNode);
Exit:
- /* Close key and return status */
+ /* Close keys and return status */
ZwClose(SubKey);
+ if (ClassKey != NULL)
+ {
+ ZwClose(ClassKey);
+ }
return Status;
}