Removed calls to RtlpGetRegistryHandle().

svn path=/trunk/; revision=6336
This commit is contained in:
Eric Kohl 2003-10-16 12:50:30 +00:00
parent 382a403ea1
commit e4e84cbc31
2 changed files with 41 additions and 96 deletions

View file

@ -1,4 +1,4 @@
/* $Id: driver.c,v 1.24 2003/10/15 17:04:39 navaraf Exp $ /* $Id: driver.c,v 1.25 2003/10/16 12:50:30 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -18,8 +18,8 @@
#include <internal/po.h> #include <internal/po.h>
#include <internal/ldr.h> #include <internal/ldr.h>
#include <internal/id.h> #include <internal/id.h>
#include <internal/pool.h>
#include <internal/registry.h> #include <internal/registry.h>
#include <internal/pool.h>
#include <internal/se.h> #include <internal/se.h>
#include <internal/mm.h> #include <internal/mm.h>
#include <internal/ke.h> #include <internal/ke.h>
@ -664,29 +664,32 @@ IopInitializeSystemDrivers(VOID)
} }
/* /*
* IopGetDriverNameFromKeyNode * IopGetDriverNameFromServiceKey
* *
* Returns a module path from service registry key node. * Returns a module path from service registry key.
* *
* Parameters * Parameters
* RelativeTo
* Relative path identifier.
* PathName
* Relative key path name.
* ImagePath * ImagePath
* The result path. * The result path.
* KeyHandle
* Registry handle for service registry key node
* (\Registry\Machine\System\CurrentControlSet\Services\...)
* *
* Return Value * Return Value
* Status * Status
*/ */
NTSTATUS STDCALL NTSTATUS STDCALL
IopGetDriverNameFromKeyNode(PUNICODE_STRING ImagePath, HANDLE KeyHandle) IopGetDriverNameFromServiceKey(
ULONG RelativeTo,
PWSTR PathName,
PUNICODE_STRING ImagePath)
{ {
RTL_QUERY_REGISTRY_TABLE QueryTable[2]; RTL_QUERY_REGISTRY_TABLE QueryTable[2];
UNICODE_STRING RegistryImagePath; UNICODE_STRING RegistryImagePath;
NTSTATUS Status; NTSTATUS Status;
PKEY_NODE_INFORMATION NodeInformation; PWSTR ServiceName;
ULONG ResultLength;
RtlZeroMemory(&QueryTable, sizeof(QueryTable)); RtlZeroMemory(&QueryTable, sizeof(QueryTable));
RtlInitUnicodeString(&RegistryImagePath, NULL); RtlInitUnicodeString(&RegistryImagePath, NULL);
@ -695,8 +698,8 @@ IopGetDriverNameFromKeyNode(PUNICODE_STRING ImagePath, HANDLE KeyHandle)
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[0].EntryContext = &RegistryImagePath; QueryTable[0].EntryContext = &RegistryImagePath;
Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE, Status = RtlQueryRegistryValues(RelativeTo,
(PWSTR)KeyHandle, QueryTable, NULL, NULL); PathName, QueryTable, NULL, NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("RtlQueryRegistryValues() failed (Status %lx)\n", Status); DPRINT("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
@ -706,30 +709,25 @@ IopGetDriverNameFromKeyNode(PUNICODE_STRING ImagePath, HANDLE KeyHandle)
if (RegistryImagePath.Length == 0) if (RegistryImagePath.Length == 0)
{ {
RtlFreeUnicodeString(&RegistryImagePath); ServiceName = wcsrchr(PathName, L'\\');
ZwQueryKey(KeyHandle, KeyNodeInformation, 0, 0, &ResultLength); if (ServiceName == NULL)
NodeInformation = ExAllocatePool(NonPagedPool, ResultLength);
if (NodeInformation == NULL)
{ {
return STATUS_UNSUCCESSFUL; ServiceName = PathName;
} }
Status = ZwQueryKey(KeyHandle, KeyNodeInformation, NodeInformation, else
ResultLength, &ResultLength);
if (!NT_SUCCESS(Status))
{ {
ExFreePool(NodeInformation); ServiceName++;
return STATUS_UNSUCCESSFUL;
} }
ImagePath->Length = sizeof(UNICODE_NULL) + ImagePath->Length = sizeof(UNICODE_NULL) +
((33 + NodeInformation->NameLength) * sizeof(WCHAR)); ((33 + wcslen(ServiceName)) * sizeof(WCHAR));
ImagePath->Buffer = ExAllocatePool(NonPagedPool, ImagePath->Length); ImagePath->Buffer = ExAllocatePool(NonPagedPool, ImagePath->Length);
if (ImagePath->Buffer == NULL) if (ImagePath->Buffer == NULL)
{ {
ExFreePool(NodeInformation);
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
wcscpy(ImagePath->Buffer, L"\\SystemRoot\\system32\\drivers\\"); wcscpy(ImagePath->Buffer, L"\\SystemRoot\\system32\\drivers\\");
wcscat(ImagePath->Buffer, NodeInformation->Name); wcscat(ImagePath->Buffer, ServiceName);
wcscat(ImagePath->Buffer, L".sys"); wcscat(ImagePath->Buffer, L".sys");
} else } else
if (RegistryImagePath.Buffer[0] != L'\\') if (RegistryImagePath.Buffer[0] != L'\\')
@ -772,7 +770,6 @@ IopGetDriverNameFromKeyNode(PUNICODE_STRING ImagePath, HANDLE KeyHandle)
NTSTATUS NTSTATUS
IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode, BOOLEAN BootDriverOnly) IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode, BOOLEAN BootDriverOnly)
{ {
HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
if (DeviceNode->ServiceName.Buffer == NULL) if (DeviceNode->ServiceName.Buffer == NULL)
@ -780,14 +777,6 @@ IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode, BOOLEAN BootDriverOnly)
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
Status = RtlpGetRegistryHandle(RTL_REGISTRY_SERVICES,
DeviceNode->ServiceName.Buffer, FALSE, &KeyHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("RtlpGetRegistryHandle() failed (Status %x)\n", Status);
return Status;
}
if (BootDriverOnly) if (BootDriverOnly)
{ {
ULONG ServiceStart; ULONG ServiceStart;
@ -801,9 +790,8 @@ IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode, BOOLEAN BootDriverOnly)
QueryTable[0].Name = L"Start"; QueryTable[0].Name = L"Start";
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[0].EntryContext = &ServiceStart; QueryTable[0].EntryContext = &ServiceStart;
Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE, Status = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES,
(PWCHAR)KeyHandle, QueryTable, NULL, NULL); DeviceNode->ServiceName.Buffer, QueryTable, NULL, NULL);
NtClose(KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("RtlQueryRegistryValues() failed (Status %x)\n", Status); DPRINT("RtlQueryRegistryValues() failed (Status %x)\n", Status);
@ -847,8 +835,8 @@ IopInitializeDeviceNodeService(PDEVICE_NODE DeviceNode, BOOLEAN BootDriverOnly)
/* /*
* Get service path * Get service path
*/ */
Status = IopGetDriverNameFromKeyNode(&ImagePath, KeyHandle); Status = IopGetDriverNameFromServiceKey(RTL_REGISTRY_SERVICES,
NtClose(KeyHandle); DeviceNode->ServiceName.Buffer, &ImagePath);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("IopGetDriverNameFromKeyNode() failed (Status %x)\n", Status); DPRINT("IopGetDriverNameFromKeyNode() failed (Status %x)\n", Status);
@ -901,7 +889,6 @@ IopUnloadDriver(PUNICODE_STRING DriverServiceName, BOOLEAN UnloadPnpDrivers)
UNICODE_STRING ObjectName; UNICODE_STRING ObjectName;
PDRIVER_OBJECT DriverObject; PDRIVER_OBJECT DriverObject;
PMODULE_OBJECT ModuleObject; PMODULE_OBJECT ModuleObject;
HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
LPWSTR Start; LPWSTR Start;
@ -944,21 +931,13 @@ IopUnloadDriver(PUNICODE_STRING DriverServiceName, BOOLEAN UnloadPnpDrivers)
/* /*
* Get path of service... * Get path of service...
*/ */
Status = RtlpGetRegistryHandle(RTL_REGISTRY_ABSOLUTE, Status = IopGetDriverNameFromServiceKey(RTL_REGISTRY_ABSOLUTE,
DriverServiceName->Buffer, FALSE, &KeyHandle); DriverServiceName->Buffer, &ImagePath);
if (!NT_SUCCESS(Status))
{
DPRINT("RtlpGetRegistryHandle() failed (Status %x)\n", Status);
return Status;
}
Status = IopGetDriverNameFromKeyNode(&ImagePath, KeyHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("IopGetDriverNameFromKeyNode() failed (Status %x)\n", Status); DPRINT("IopGetDriverNameFromKeyNode() failed (Status %x)\n", Status);
NtClose(KeyHandle);
return Status; return Status;
} }
NtClose(KeyHandle);
/* /*
* ... and check if it's loaded * ... and check if it's loaded
@ -1006,7 +985,6 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
{ {
RTL_QUERY_REGISTRY_TABLE QueryTable[2]; RTL_QUERY_REGISTRY_TABLE QueryTable[2];
UNICODE_STRING ImagePath; UNICODE_STRING ImagePath;
HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
ULONG Type; ULONG Type;
PDEVICE_NODE DeviceNode; PDEVICE_NODE DeviceNode;
@ -1025,17 +1003,6 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
RtlInitUnicodeString(&ImagePath, NULL); RtlInitUnicodeString(&ImagePath, NULL);
/*
* Open service registry key
*/
Status = RtlpGetRegistryHandle(RTL_REGISTRY_ABSOLUTE,
DriverServiceName->Buffer, FALSE, &KeyHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("RtlpGetRegistryHandle() failed (Status %x)\n", Status);
return Status;
}
/* /*
* Get service type * Get service type
*/ */
@ -1043,32 +1010,26 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
QueryTable[0].Name = L"Type"; QueryTable[0].Name = L"Type";
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
QueryTable[0].EntryContext = &Type; QueryTable[0].EntryContext = &Type;
Status = RtlQueryRegistryValues(RTL_REGISTRY_HANDLE, (PWSTR)KeyHandle, Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
QueryTable, NULL, NULL); DriverServiceName->Buffer, QueryTable, NULL, NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("RtlQueryRegistryValues() failed (Status %lx)\n", Status); DPRINT("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
RtlFreeUnicodeString(&ImagePath); RtlFreeUnicodeString(&ImagePath);
NtClose(KeyHandle);
return Status; return Status;
} }
/* /*
* Get module path * Get module path
*/ */
Status = IopGetDriverNameFromKeyNode(&ImagePath, KeyHandle); Status = IopGetDriverNameFromServiceKey(RTL_REGISTRY_ABSOLUTE,
DriverServiceName->Buffer, &ImagePath);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("IopGetDriverNameFromKeyNode() failed (Status %x)\n", Status); DPRINT("IopGetDriverNameFromKeyNode() failed (Status %x)\n", Status);
NtClose(KeyHandle);
return Status; return Status;
} }
/*
* Close service registry key
*/
NtClose(KeyHandle);
DPRINT("FullImagePath: '%S'\n", ImagePath.Buffer); DPRINT("FullImagePath: '%S'\n", ImagePath.Buffer);
DPRINT("Type: %lx\n", Type); DPRINT("Type: %lx\n", Type);

View file

@ -1,4 +1,4 @@
/* $Id: pnproot.c,v 1.16 2003/09/25 18:29:44 navaraf Exp $ /* $Id: pnproot.c,v 1.17 2003/10/16 12:50:30 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -14,7 +14,6 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <reactos/bugcodes.h> #include <reactos/bugcodes.h>
#include <internal/io.h> #include <internal/io.h>
#include <internal/registry.h>
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
@ -382,7 +381,6 @@ PnpRootFdoReadDeviceInfo(
RTL_QUERY_REGISTRY_TABLE QueryTable[2]; RTL_QUERY_REGISTRY_TABLE QueryTable[2];
PUNICODE_STRING DeviceDesc; PUNICODE_STRING DeviceDesc;
WCHAR KeyName[MAX_PATH]; WCHAR KeyName[MAX_PATH];
HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
DPRINT("Called\n"); DPRINT("Called\n");
@ -391,8 +389,7 @@ PnpRootFdoReadDeviceInfo(
DeviceDesc = &Device->DeviceDescription; DeviceDesc = &Device->DeviceDescription;
wcscpy(KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\"); wcscpy(KeyName, ENUM_NAME_ROOT);
wcscat(KeyName, ENUM_NAME_ROOT);
wcscat(KeyName, L"\\"); wcscat(KeyName, L"\\");
wcscat(KeyName, Device->ServiceName.Buffer); wcscat(KeyName, Device->ServiceName.Buffer);
wcscat(KeyName, L"\\"); wcscat(KeyName, L"\\");
@ -400,17 +397,6 @@ PnpRootFdoReadDeviceInfo(
DPRINT("KeyName %S\n", KeyName); DPRINT("KeyName %S\n", KeyName);
Status = RtlpGetRegistryHandle(
RTL_REGISTRY_ABSOLUTE,
KeyName,
FALSE,
&KeyHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("RtlpGetRegistryHandle() failed (Status %x)\n", Status);
return Status;
}
RtlZeroMemory(QueryTable, sizeof(QueryTable)); RtlZeroMemory(QueryTable, sizeof(QueryTable));
RtlInitUnicodeString(DeviceDesc, NULL); RtlInitUnicodeString(DeviceDesc, NULL);
@ -420,14 +406,12 @@ PnpRootFdoReadDeviceInfo(
QueryTable[0].EntryContext = DeviceDesc; QueryTable[0].EntryContext = DeviceDesc;
Status = RtlQueryRegistryValues( Status = RtlQueryRegistryValues(
RTL_REGISTRY_HANDLE, RTL_REGISTRY_ENUM,
(PWSTR)KeyHandle, KeyName,
QueryTable, QueryTable,
NULL, NULL,
NULL); NULL);
NtClose(KeyHandle);
DPRINT("RtlQueryRegistryValues() returned status %x\n", Status); DPRINT("RtlQueryRegistryValues() returned status %x\n", Status);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))