Implemented value enumeration in RtlQueryRegistryValues().

svn path=/trunk/; revision=2603
This commit is contained in:
Eric Kohl 2002-02-05 15:42:41 +00:00
parent 5d67a14618
commit 916157c159
2 changed files with 779 additions and 569 deletions

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.8 2001/09/16 13:19:31 chorns Exp $
/* $Id: registry.c,v 1.9 2002/02/05 15:42:41 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -15,7 +15,7 @@
* - finish RtlFormatCurrentUserKeyPath()
*/
/* INCLUDES *****************************************************************/
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <ntdll/registry.h>
@ -39,11 +39,11 @@ RtlCheckRegistryKey(IN ULONG RelativeTo,
FALSE,
&KeyHandle);
if (!NT_SUCCESS(Status))
return Status;
return(Status);
NtClose(KeyHandle);
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
@ -59,11 +59,11 @@ RtlCreateRegistryKey(IN ULONG RelativeTo,
TRUE,
&KeyHandle);
if (!NT_SUCCESS(Status))
return Status;
return(Status);
NtClose(KeyHandle);
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
@ -81,17 +81,17 @@ RtlDeleteRegistryValue(IN ULONG RelativeTo,
FALSE,
&KeyHandle);
if (!NT_SUCCESS(Status))
return Status;
return(Status);
RtlInitUnicodeString(&Name,
ValueName);
NtDeleteValueKey(KeyHandle,
Status = NtDeleteValueKey(KeyHandle,
&Name);
NtClose(KeyHandle);
return STATUS_SUCCESS;
return(Status);
}
@ -101,7 +101,7 @@ RtlFormatCurrentUserKeyPath(PUNICODE_STRING KeyPath)
/* FIXME: !!! */
RtlCreateUnicodeString(KeyPath,
L"\\Registry\\User\\.Default");
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
@ -126,7 +126,7 @@ RtlOpenCurrentUser(IN ACCESS_MASK DesiredAccess,
&ObjectAttributes);
RtlFreeUnicodeString(&KeyPath);
if (NT_SUCCESS(Status))
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
RtlInitUnicodeString(&KeyPath,
@ -158,8 +158,10 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
PKEY_VALUE_FULL_INFORMATION FullValueInfo;
ULONG BufferSize;
ULONG ResultSize;
ULONG Index;
DPRINT("RtlQueryRegistryValues() called\n");
@ -168,7 +170,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
FALSE,
&BaseKeyHandle);
if (!NT_SUCCESS(Status))
return Status;
return(Status);
CurrentKeyHandle = BaseKeyHandle;
QueryEntry = QueryTable;
@ -241,10 +243,12 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
if (ValueInfo->Type == REG_SZ)
{
PUNICODE_STRING ValueString;
ValueString = (PUNICODE_STRING)QueryEntry->EntryContext;
if (ValueString->Buffer == 0)
{
RtlInitUnicodeString(ValueString, NULL);
RtlInitUnicodeString(ValueString,
NULL);
ValueString->MaximumLength = 256 * sizeof(WCHAR);
ValueString->Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0,
@ -268,17 +272,124 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
}
}
RtlFreeHeap (RtlGetProcessHeap(), 0, ValueInfo);
RtlFreeHeap(RtlGetProcessHeap(),
0,
ValueInfo);
}
else
{
DPRINT("Query value via query routine: %S\n", QueryEntry->Name);
if (QueryEntry->Name != NULL)
{
RtlInitUnicodeString(&KeyName,
QueryEntry->Name);
BufferSize = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + 4096;
ValueInfo = RtlAllocateHeap(RtlGetProcessHeap(),
0,
BufferSize);
if (ValueInfo == NULL)
{
Status = STATUS_NO_MEMORY;
break;
}
Status = NtQueryValueKey(CurrentKeyHandle,
&KeyName,
KeyValuePartialInformation,
ValueInfo,
BufferSize,
&ResultSize);
if (!NT_SUCCESS(Status))
{
Status = QueryEntry->QueryRoutine(QueryEntry->Name,
QueryEntry->DefaultType,
QueryEntry->DefaultData,
QueryEntry->DefaultLength,
Context,
QueryEntry->EntryContext);
}
else
{
Status = QueryEntry->QueryRoutine(QueryEntry->Name,
ValueInfo->Type,
ValueInfo->Data,
ValueInfo->DataLength,
Context,
QueryEntry->EntryContext);
}
RtlFreeHeap(RtlGetProcessHeap(),
0,
ValueInfo);
if (!NT_SUCCESS(Status))
break;
}
else if (QueryEntry->Flags & RTL_QUERY_REGISTRY_NOVALUE)
{
DPRINT("Simple callback\n");
Status = QueryEntry->QueryRoutine(NULL,
REG_NONE,
NULL,
0,
Context,
QueryEntry->EntryContext);
if (!NT_SUCCESS(Status))
break;
}
else
{
DPRINT("Enumerate values\n");
BufferSize = sizeof(KEY_VALUE_FULL_INFORMATION) + 4096;
FullValueInfo = RtlAllocateHeap(RtlGetProcessHeap(),
0,
BufferSize);
if (ValueInfo == NULL)
{
Status = STATUS_NO_MEMORY;
break;
}
Index = 0;
while (TRUE)
{
Status = NtEnumerateValueKey(CurrentKeyHandle,
Index,
KeyValueFullInformation,
FullValueInfo,
BufferSize,
&ResultSize);
if (!NT_SUCCESS(Status))
{
if (Status == STATUS_NO_MORE_ENTRIES)
Status = STATUS_SUCCESS;
break;
}
Status = QueryEntry->QueryRoutine(FullValueInfo->Name,
FullValueInfo->Type,
(PVOID)FullValueInfo + FullValueInfo->DataOffset,
FullValueInfo->DataLength,
Context,
QueryEntry->EntryContext);
if (!NT_SUCCESS(Status))
break;
Index++;
}
RtlFreeHeap(RtlGetProcessHeap(),
0,
ValueInfo);
if (!NT_SUCCESS(Status))
break;
}
}
if (QueryEntry->Flags & RTL_QUERY_REGISTRY_DELETE)
{
DPRINT("Delete value: %S\n", QueryEntry->Name);
DPRINT1("FIXME: Delete value: %S\n", QueryEntry->Name);
}
@ -290,7 +401,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
NtClose(BaseKeyHandle);
return Status;
return(Status);
}
@ -311,21 +422,21 @@ RtlWriteRegistryValue(IN ULONG RelativeTo,
TRUE,
&KeyHandle);
if (!NT_SUCCESS(Status))
return Status;
return(Status);
RtlInitUnicodeString(&Name,
ValueName);
NtSetValueKey(KeyHandle,
Status = NtSetValueKey(KeyHandle,
&Name,
0,
ValueType,
ValueData,
ValueLength);
if (NT_SUCCESS(Status))
NtClose(KeyHandle);
return STATUS_SUCCESS;
return(Status);
}
@ -338,8 +449,7 @@ RtlpNtCreateKey(OUT HANDLE KeyHandle,
IN ULONG Unused2)
{
if (ObjectAttributes != NULL)
ObjectAttributes->Attributes &=
~(OBJ_PERMANENT | OBJ_EXCLUSIVE);
ObjectAttributes->Attributes &= ~(OBJ_PERMANENT | OBJ_EXCLUSIVE);
return(NtCreateKey(KeyHandle,
DesiredAccess,
@ -419,8 +529,7 @@ RtlpNtOpenKey(OUT HANDLE KeyHandle,
IN ULONG Unused)
{
if (ObjectAttributes != NULL)
ObjectAttributes->Attributes &=
~(OBJ_PERMANENT | OBJ_EXCLUSIVE);
ObjectAttributes->Attributes &= ~(OBJ_PERMANENT | OBJ_EXCLUSIVE);
return(NtOpenKey(KeyHandle,
DesiredAccess,
@ -502,6 +611,7 @@ RtlpNtSetValueKey(IN HANDLE KeyHandle,
DataLength));
}
/* INTERNAL FUNCTIONS ******************************************************/
NTSTATUS
@ -519,15 +629,14 @@ RtlpGetRegistryHandle(ULONG RelativeTo,
if (RelativeTo & RTL_REGISTRY_HANDLE)
{
Status = NtDuplicateObject(
NtCurrentProcess(),
Status = NtDuplicateObject(NtCurrentProcess(),
(HANDLE)Path,
NtCurrentProcess(),
KeyHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
return Status;
return(Status);
}
if (RelativeTo & RTL_REGISTRY_OPTIONAL)
@ -579,20 +688,14 @@ RtlpGetRegistryHandle(ULONG RelativeTo,
RtlAppendUnicodeToString(&KeyName,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
break;
}
if ((RelativeTo == RTL_REGISTRY_ABSOLUTE) || (Path[0] != L'\\'))
{
RtlAppendUnicodeToString(&KeyName,
Path);
}
else
if (Path[0] == L'\\')
{
Path++;
}
RtlAppendUnicodeToString(&KeyName,
Path);
}
DPRINT("KeyName %wZ\n", &KeyName);
@ -619,8 +722,7 @@ RtlpGetRegistryHandle(ULONG RelativeTo,
&ObjectAttributes);
}
return Status;
return(Status);
}
/* EOF */

View file

@ -140,8 +140,10 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
PKEY_VALUE_FULL_INFORMATION FullValueInfo;
ULONG BufferSize;
ULONG ResultSize;
ULONG Index;
DPRINT("RtlQueryRegistryValues() called\n");
@ -152,7 +154,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
if (!NT_SUCCESS(Status))
{
DPRINT("RtlpGetRegistryHandle() failed with status %x\n", Status);
return Status;
return(Status);
}
CurrentKeyHandle = BaseKeyHandle;
@ -230,12 +232,15 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
if (ValueInfo->Type == REG_SZ)
{
PUNICODE_STRING ValueString;
ValueString = (PUNICODE_STRING)QueryEntry->EntryContext;
if (ValueString->Buffer == 0)
{
RtlInitUnicodeString(ValueString, NULL);
RtlInitUnicodeString(ValueString,
NULL);
ValueString->MaximumLength = 256 * sizeof(WCHAR);
ValueString->Buffer = ExAllocatePool(PagedPool, ValueString->MaximumLength);
ValueString->Buffer = ExAllocatePool(PagedPool,
ValueString->MaximumLength);
if (!ValueString->Buffer)
break;
ValueString->Buffer[0] = 0;
@ -261,11 +266,113 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
{
DPRINT("Query value via query routine: %S\n", QueryEntry->Name);
if (QueryEntry->Name != NULL)
{
RtlInitUnicodeString(&KeyName,
QueryEntry->Name);
BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 4096;
ValueInfo = ExAllocatePool(PagedPool,
BufferSize);
if (ValueInfo == NULL)
{
Status = STATUS_NO_MEMORY;
break;
}
Status = NtQueryValueKey(CurrentKeyHandle,
&KeyName,
KeyValuePartialInformation,
ValueInfo,
BufferSize,
&ResultSize);
if (!NT_SUCCESS(Status))
{
Status = QueryEntry->QueryRoutine(QueryEntry->Name,
QueryEntry->DefaultType,
QueryEntry->DefaultData,
QueryEntry->DefaultLength,
Context,
QueryEntry->EntryContext);
}
else
{
Status = QueryEntry->QueryRoutine(QueryEntry->Name,
ValueInfo->Type,
ValueInfo->Data,
ValueInfo->DataLength,
Context,
QueryEntry->EntryContext);
}
ExFreePool(ValueInfo);
if (!NT_SUCCESS(Status))
break;
}
else if (QueryEntry->Flags & RTL_QUERY_REGISTRY_NOVALUE)
{
DPRINT("Simple callback\n");
Status = QueryEntry->QueryRoutine(NULL,
REG_NONE,
NULL,
0,
Context,
QueryEntry->EntryContext);
if (!NT_SUCCESS(Status))
break;
}
else
{
DPRINT("Enumerate values\n");
BufferSize = sizeof(KEY_VALUE_FULL_INFORMATION) + 4096;
FullValueInfo = ExAllocatePool(PagedPool,
BufferSize);
if (ValueInfo == NULL)
{
Status = STATUS_NO_MEMORY;
break;
}
Index = 0;
while (TRUE)
{
Status = NtEnumerateValueKey(CurrentKeyHandle,
Index,
KeyValueFullInformation,
FullValueInfo,
BufferSize,
&ResultSize);
if (!NT_SUCCESS(Status))
{
if (Status == STATUS_NO_MORE_ENTRIES)
Status = STATUS_SUCCESS;
break;
}
Status = QueryEntry->QueryRoutine(FullValueInfo->Name,
FullValueInfo->Type,
(PVOID)FullValueInfo + FullValueInfo->DataOffset,
FullValueInfo->DataLength,
Context,
QueryEntry->EntryContext);
if (!NT_SUCCESS(Status))
break;
Index++;
}
ExFreePool(ValueInfo);
if (!NT_SUCCESS(Status))
break;
}
}
if (QueryEntry->Flags & RTL_QUERY_REGISTRY_DELETE)
{
DPRINT("Delete value: %S\n", QueryEntry->Name);
DPRINT1("FIXME: Delete value: %S\n", QueryEntry->Name);
}
@ -277,7 +384,7 @@ RtlQueryRegistryValues(IN ULONG RelativeTo,
NtClose(BaseKeyHandle);
return Status;
return(Status);
}
@ -298,7 +405,7 @@ RtlWriteRegistryValue(IN ULONG RelativeTo,
TRUE,
&KeyHandle);
if (!NT_SUCCESS(Status))
return Status;
return(Status);
RtlInitUnicodeString(&Name,
ValueName);
@ -312,9 +419,10 @@ RtlWriteRegistryValue(IN ULONG RelativeTo,
NtClose(KeyHandle);
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL
RtlFormatCurrentUserKeyPath(IN OUT PUNICODE_STRING KeyPath)
{
@ -322,7 +430,7 @@ RtlFormatCurrentUserKeyPath(IN OUT PUNICODE_STRING KeyPath)
RtlCreateUnicodeString(KeyPath,
L"\\Registry\\User\\.Default");
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
/* ------------------------------------------ Private Implementation */