RtlQueryRegistryValues():

* Fixed a bug which returned malformed Unicode strings.
* Removed an unnecessary limitation.

svn path=/trunk/; revision=5570
This commit is contained in:
Eric Kohl 2003-08-14 14:52:13 +00:00
parent 2b3c1f4b49
commit d535f217c0
2 changed files with 51 additions and 119 deletions

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.22 2003/07/11 23:58:45 ekohl Exp $ /* $Id: registry.c,v 1.23 2003/08/14 14:52:13 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -206,15 +206,6 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
while ((QueryEntry->QueryRoutine != NULL) || while ((QueryEntry->QueryRoutine != NULL) ||
(QueryEntry->Name != NULL)) (QueryEntry->Name != NULL))
{ {
if ((QueryEntry->QueryRoutine == NULL) &&
((QueryEntry->Flags & RTL_QUERY_REGISTRY_SUBKEY) != 0))
{
Status = STATUS_INVALID_PARAMETER;
break;
}
DPRINT("Name: %S\n", QueryEntry->Name);
if (((QueryEntry->Flags & (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY)) != 0) && if (((QueryEntry->Flags & (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY)) != 0) &&
(BaseKeyHandle != CurrentKeyHandle)) (BaseKeyHandle != CurrentKeyHandle))
{ {
@ -278,7 +269,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
SourceString = (PUNICODE_STRING)QueryEntry->DefaultData; SourceString = (PUNICODE_STRING)QueryEntry->DefaultData;
ValueString = (PUNICODE_STRING)QueryEntry->EntryContext; ValueString = (PUNICODE_STRING)QueryEntry->EntryContext;
if (ValueString->Buffer == 0) if (ValueString->Buffer == NULL)
{ {
ValueString->Length = SourceString->Length; ValueString->Length = SourceString->Length;
ValueString->MaximumLength = SourceString->MaximumLength; ValueString->MaximumLength = SourceString->MaximumLength;
@ -321,7 +312,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
ValueString = (PUNICODE_STRING)QueryEntry->EntryContext; ValueString = (PUNICODE_STRING)QueryEntry->EntryContext;
if (ValueString->Buffer == NULL) if (ValueString->Buffer == NULL)
{ {
ValueString->MaximumLength = ValueInfo->DataLength + sizeof(WCHAR); ValueString->MaximumLength = ValueInfo->DataLength;
ValueString->Buffer = RtlAllocateHeap(RtlGetProcessHeap(), ValueString->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0, 0,
ValueString->MaximumLength); ValueString->MaximumLength);
@ -333,7 +324,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
ValueString->Buffer[0] = 0; ValueString->Buffer[0] = 0;
} }
ValueString->Length = min(ValueInfo->DataLength, ValueString->Length = min(ValueInfo->DataLength,
ValueString->MaximumLength - sizeof(WCHAR)); ValueString->MaximumLength) - sizeof(WCHAR);
memcpy(ValueString->Buffer, memcpy(ValueString->Buffer,
ValueInfo->Data, ValueInfo->Data,
ValueString->Length); ValueString->Length);

View file

@ -8,9 +8,6 @@
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#ifdef WIN32_REGDBG
#include "cm_win32.h"
#else
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <roscfg.h> #include <roscfg.h>
#include <internal/ob.h> #include <internal/ob.h>
@ -23,7 +20,6 @@
#include <internal/debug.h> #include <internal/debug.h>
#include "cm.h" #include "cm.h"
#endif
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
@ -166,10 +162,6 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
PWSTR StringPtr; PWSTR StringPtr;
DPRINT("RtlQueryRegistryValues() called\n"); DPRINT("RtlQueryRegistryValues() called\n");
#ifdef WIN32_REGDBG
BaseKeyHandle = NULL;
CurrentKeyHandle = NULL;
#endif
Status = RtlpGetRegistryHandle(RelativeTo, Status = RtlpGetRegistryHandle(RelativeTo,
(PWSTR) Path, (PWSTR) Path,
@ -186,48 +178,6 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
while ((QueryEntry->QueryRoutine != NULL) || while ((QueryEntry->QueryRoutine != NULL) ||
(QueryEntry->Name != NULL)) (QueryEntry->Name != NULL))
{ {
/* TODO: (from RobD)
packet.sys has this code which calls this (and fails here) with:
RtlZeroMemory(ParamTable, sizeof(ParamTable));
//
// change to the linkage key
//
ParamTable[0].QueryRoutine = NULL; // NOTE: QueryRoutine is set to NULL
ParamTable[0].Flags = RTL_QUERY_REGISTRY_SUBKEY;
ParamTable[0].Name = L"Linkage";
//
// Get the name of the mac driver we should bind to
//
ParamTable[1].QueryRoutine = PacketQueryRegistryRoutine;
ParamTable[1].Flags = RTL_QUERY_REGISTRY_REQUIRED | RTL_QUERY_REGISTRY_NOEXPAND;
ParamTable[1].Name = L"Bind";
ParamTable[1].EntryContext = (PVOID)MacDriverName;
ParamTable[1].DefaultType = REG_MULTI_SZ;
Status = RtlQueryRegistryValues(
IN ULONG RelativeTo = RTL_REGISTRY_ABSOLUTE,
IN PWSTR Path = Path,
IN PRTL_QUERY_REGISTRY_TABLE QueryTable = ParamTable,
IN PVOID Context = NULL,
IN PVOID Environment = NULL);
*/
//CSH: Was:
//if ((QueryEntry->QueryRoutine == NULL) &&
// ((QueryEntry->Flags & (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_DIRECT)) != 0))
// Which is more correct?
if ((QueryEntry->QueryRoutine == NULL) &&
((QueryEntry->Flags & RTL_QUERY_REGISTRY_SUBKEY) != 0))
{
DPRINT("Bad parameters\n");
Status = STATUS_INVALID_PARAMETER;
break;
}
DPRINT("Name: %S\n", QueryEntry->Name);
if (((QueryEntry->Flags & (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY)) != 0) && if (((QueryEntry->Flags & (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY)) != 0) &&
(BaseKeyHandle != CurrentKeyHandle)) (BaseKeyHandle != CurrentKeyHandle))
{ {
@ -266,9 +216,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
Status = STATUS_NO_MEMORY; Status = STATUS_NO_MEMORY;
break; break;
} }
#ifdef WIN32_REGDBG
memset(ValueInfo, 0, BufferSize);
#endif
Status = ZwQueryValueKey(CurrentKeyHandle, Status = ZwQueryValueKey(CurrentKeyHandle,
&KeyName, &KeyName,
KeyValuePartialInformation, KeyValuePartialInformation,
@ -335,7 +283,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
{ {
RtlInitUnicodeString(ValueString, RtlInitUnicodeString(ValueString,
NULL); NULL);
ValueString->MaximumLength = ValueInfo->DataLength + sizeof(WCHAR); //256 * sizeof(WCHAR); ValueString->MaximumLength = ValueInfo->DataLength;
ValueString->Buffer = ExAllocatePool(PagedPool, ValueString->Buffer = ExAllocatePool(PagedPool,
ValueString->MaximumLength); ValueString->MaximumLength);
if (!ValueString->Buffer) if (!ValueString->Buffer)
@ -343,7 +291,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
ValueString->Buffer[0] = 0; ValueString->Buffer[0] = 0;
} }
ValueString->Length = RtlMin(ValueInfo->DataLength, ValueString->Length = RtlMin(ValueInfo->DataLength,
ValueString->MaximumLength - sizeof(WCHAR)); ValueString->MaximumLength) - sizeof(WCHAR);
memcpy(ValueString->Buffer, memcpy(ValueString->Buffer,
ValueInfo->Data, ValueInfo->Data,
ValueString->Length); ValueString->Length);
@ -493,11 +441,8 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
!(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND)) !(QueryEntry->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
{ {
DPRINT("Expand REG_MULTI_SZ type\n"); DPRINT("Expand REG_MULTI_SZ type\n");
#ifdef WIN32_REGDBG
StringPtr = (PWSTR)(FullValueInfo + FullValueInfo->DataOffset);
#else
StringPtr = (PWSTR)((PVOID)FullValueInfo + FullValueInfo->DataOffset); StringPtr = (PWSTR)((PVOID)FullValueInfo + FullValueInfo->DataOffset);
#endif
while (*StringPtr != 0) while (*StringPtr != 0)
{ {
StringLen = (wcslen(StringPtr) + 1) * sizeof(WCHAR); StringLen = (wcslen(StringPtr) + 1) * sizeof(WCHAR);
@ -516,11 +461,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
{ {
Status = QueryEntry->QueryRoutine(FullValueInfo->Name, Status = QueryEntry->QueryRoutine(FullValueInfo->Name,
FullValueInfo->Type, FullValueInfo->Type,
#ifdef WIN32_REGDBG
FullValueInfo + FullValueInfo->DataOffset,
#else
(PVOID)FullValueInfo + FullValueInfo->DataOffset, (PVOID)FullValueInfo + FullValueInfo->DataOffset,
#endif
FullValueInfo->DataLength, FullValueInfo->DataLength,
Context, Context,
QueryEntry->EntryContext); QueryEntry->EntryContext);
@ -551,7 +492,7 @@ ByeBye:
NtClose(BaseKeyHandle); NtClose(BaseKeyHandle);
return(Status); return Status;
} }
@ -727,60 +668,60 @@ RtlpCreateRegistryKeyPath(PWSTR Path)
if (_wcsnicmp(Path, L"\\Registry\\", 10) != 0) if (_wcsnicmp(Path, L"\\Registry\\", 10) != 0)
{ {
return(STATUS_INVALID_PARAMETER); return STATUS_INVALID_PARAMETER;
} }
wcsncpy(KeyBuffer, Path, MAX_PATH-1); wcsncpy (KeyBuffer, Path, MAX_PATH-1);
RtlInitUnicodeString(&KeyName, KeyBuffer); RtlInitUnicodeString (&KeyName, KeyBuffer);
/* Skip \\Registry\\ */ /* Skip \\Registry\\ */
Current = KeyName.Buffer; Current = KeyName.Buffer;
Current = wcschr(Current, '\\') + 1; Current = wcschr (Current, '\\') + 1;
Current = wcschr(Current, '\\') + 1; Current = wcschr (Current, '\\') + 1;
do { do
Next = wcschr(Current, '\\'); {
if (Next == NULL) Next = wcschr (Current, '\\');
{ if (Next == NULL)
/* The end */ {
} /* The end */
else }
{ else
*Next = 0; {
} *Next = 0;
}
InitializeObjectAttributes( InitializeObjectAttributes (&ObjectAttributes,
&ObjectAttributes, &KeyName,
&KeyName, OBJ_CASE_INSENSITIVE,
OBJ_CASE_INSENSITIVE, NULL,
NULL, NULL);
NULL);
DPRINT("Create '%S'\n", KeyName.Buffer); DPRINT("Create '%S'\n", KeyName.Buffer);
Status = NtCreateKey( Status = NtCreateKey (&KeyHandle,
&KeyHandle, KEY_ALL_ACCESS,
KEY_ALL_ACCESS, &ObjectAttributes,
&ObjectAttributes, 0,
0, NULL,
NULL, 0,
0, NULL);
NULL); if (!NT_SUCCESS (Status))
if (!NT_SUCCESS(Status)) {
{ DPRINT ("NtCreateKey() failed with status %x\n", Status);
DPRINT("NtCreateKey() failed with status %x\n", Status); return Status;
return Status; }
}
NtClose(KeyHandle); NtClose (KeyHandle);
if (Next != NULL) if (Next != NULL)
{ {
*Next = L'\\'; *Next = L'\\';
} }
Current = Next + 1; Current = Next + 1;
} while (Next != NULL); }
while (Next != NULL);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }