RegQueryValueExW: Now returns the space needed for the query to succeed

with a return of ERROR_MORE_DATA, as required by documentation.

svn path=/trunk/; revision=7280
This commit is contained in:
Art Yerkes 2003-12-28 08:47:28 +00:00
parent bb4da13c9c
commit a7a6d33f53

View file

@ -1,4 +1,4 @@
/* $Id: reg.c,v 1.38 2003/12/24 21:51:38 gvg Exp $ /* $Id: reg.c,v 1.39 2003/12/28 08:47:28 arty Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -191,12 +191,14 @@ OpenClassesRootKey (PHANDLE KeyHandle)
&Attributes); &Attributes);
} }
#undef NDEBUG
static NTSTATUS static NTSTATUS
OpenLocalMachineKey (PHANDLE KeyHandle) OpenLocalMachineKey (PHANDLE KeyHandle)
{ {
OBJECT_ATTRIBUTES Attributes; OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry\\Machine"); UNICODE_STRING KeyName = ROS_STRING_INITIALIZER(L"\\Registry\\Machine");
NTSTATUS Status;
DPRINT("OpenLocalMachineKey()\n"); DPRINT("OpenLocalMachineKey()\n");
@ -205,11 +207,15 @@ OpenLocalMachineKey (PHANDLE KeyHandle)
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
return NtOpenKey (KeyHandle, Status = NtOpenKey (KeyHandle,
MAXIMUM_ALLOWED, MAXIMUM_ALLOWED,
&Attributes); &Attributes);
DPRINT("NtOpenKey(%wZ) => %08x\n", &KeyName, Status);
return Status;
} }
#define NDEBUG
static NTSTATUS static NTSTATUS
OpenUsersKey (PHANDLE KeyHandle) OpenUsersKey (PHANDLE KeyHandle)
@ -2100,6 +2106,7 @@ RegQueryValueExW (HKEY hKey,
ULONG BufferSize; ULONG BufferSize;
ULONG ResultSize; ULONG ResultSize;
HKEY KeyHandle; HKEY KeyHandle;
ULONG MaxCopy = lpcbData ? *lpcbData : 0;
DPRINT("hKey 0x%X lpValueName %S lpData 0x%X lpcbData %d\n", DPRINT("hKey 0x%X lpValueName %S lpData 0x%X lpcbData %d\n",
hKey, lpValueName, lpData, lpcbData ? *lpcbData : 0); hKey, lpValueName, lpData, lpcbData ? *lpcbData : 0);
@ -2121,7 +2128,7 @@ RegQueryValueExW (HKEY hKey,
RtlInitUnicodeString (&ValueName, RtlInitUnicodeString (&ValueName,
lpValueName); lpValueName);
BufferSize = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + *lpcbData; BufferSize = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + MaxCopy;
ValueInfo = RtlAllocateHeap (ProcessHeap, ValueInfo = RtlAllocateHeap (ProcessHeap,
0, 0,
BufferSize); BufferSize);
@ -2141,37 +2148,46 @@ RegQueryValueExW (HKEY hKey,
if (Status == STATUS_BUFFER_TOO_SMALL) if (Status == STATUS_BUFFER_TOO_SMALL)
{ {
/* Return ERROR_SUCCESS and the buffer space needed for a successful call */ /* Return ERROR_SUCCESS and the buffer space needed for a successful call */
ErrorCode = ERROR_SUCCESS; MaxCopy = 0;
ValueInfo->DataLength = 0; ErrorCode = ERROR_MORE_DATA;
} }
else if (!NT_SUCCESS(Status)) else if (!NT_SUCCESS(Status))
{ {
ErrorCode = RtlNtStatusToDosError (Status); ErrorCode = RtlNtStatusToDosError (Status);
SetLastError (ErrorCode); SetLastError (ErrorCode);
ValueInfo->DataLength = 0; MaxCopy = 0;
}
if (lpType != NULL)
{
*lpType = ValueInfo->Type;
}
if (NT_SUCCESS(Status))
RtlMoveMemory (lpData,
ValueInfo->Data,
min(ValueInfo->DataLength,MaxCopy));
if ((ValueInfo->Type == REG_SZ) ||
(ValueInfo->Type == REG_MULTI_SZ) ||
(ValueInfo->Type == REG_EXPAND_SZ))
{
if (MaxCopy > ValueInfo->DataLength / sizeof(WCHAR))
((PWSTR)lpData)[ValueInfo->DataLength / sizeof(WCHAR)] = 0;
if (lpcbData) {
*lpcbData = (ResultSize - sizeof(*ValueInfo)) / sizeof(WCHAR);
DPRINT("(string) Returning Size: %d\n", *lpcbData);
}
} }
else else
{ if (lpcbData) {
if (lpType != NULL) *lpcbData = ResultSize - sizeof(*ValueInfo);
{ DPRINT("(other) Returning Size: %d\n", *lpcbData);
*lpType = ValueInfo->Type;
}
RtlMoveMemory (lpData,
ValueInfo->Data,
ValueInfo->DataLength);
if ((ValueInfo->Type == REG_SZ) ||
(ValueInfo->Type == REG_MULTI_SZ) ||
(ValueInfo->Type == REG_EXPAND_SZ))
{
((PWSTR)lpData)[ValueInfo->DataLength / sizeof(WCHAR)] = 0;
}
} }
DPRINT("Type %d Size %d\n", ValueInfo->Type, ValueInfo->DataLength); DPRINT("Type %d Size %d\n", ValueInfo->Type, ValueInfo->DataLength);
if (NULL != lpcbData)
{
*lpcbData = (DWORD)ValueInfo->DataLength;
}
RtlFreeHeap (ProcessHeap, RtlFreeHeap (ProcessHeap,
0, 0,
ValueInfo); ValueInfo);