NTSTATUS Status;
/* don't close null handle or a pseudo handle */
- if ((!hKey) || (((ULONG_PTR)hKey & 0xF0000000) == 0x80000000))
+ if (!hKey)
{
return ERROR_INVALID_HANDLE;
}
+ if (((ULONG_PTR)hKey & 0xF0000000) == 0x80000000)
+ {
+ return ERROR_SUCCESS;
+ }
+
Status = NtClose(hKey);
if (!NT_SUCCESS(Status))
{
}
if (IsHKCRKey(ParentKey))
- return DeleteHKCRKey(ParentKey, lpSubKey, samDesired, Reserved);
+ {
+ LONG ErrorCode = DeleteHKCRKey(ParentKey, lpSubKey, samDesired, Reserved);
+ ClosePredefKey(ParentKey);
+ return ErrorCode;
+ }
if (samDesired & KEY_WOW64_32KEY)
ERR("Wow64 not yet supported!\n");
* NOTES
* - Unless RRF_NOEXPAND is specified, REG_EXPAND_SZ values are automatically
* expanded and pdwType is set to REG_SZ instead.
- * - Restrictions are applied after expanding, using RRF_RT_REG_EXPAND_SZ
+ * - Restrictions are applied after expanding, using RRF_RT_REG_EXPAND_SZ
* without RRF_NOEXPAND is thus not allowed.
* An exception is the case where RRF_RT_ANY is specified, because then
* RRF_NOEXPAND is allowed.
*
* @implemented
*/
-LONG WINAPI
-RegEnumKeyExA(HKEY hKey,
- DWORD dwIndex,
- LPSTR lpName,
- LPDWORD lpcbName,
- LPDWORD lpReserved,
- LPSTR lpClass,
- LPDWORD lpcbClass,
- PFILETIME lpftLastWriteTime)
+LONG
+WINAPI
+RegEnumKeyExA(
+ _In_ HKEY hKey,
+ _In_ DWORD dwIndex,
+ _Out_ LPSTR lpName,
+ _Inout_ LPDWORD lpcbName,
+ _Reserved_ LPDWORD lpReserved,
+ _Out_opt_ LPSTR lpClass,
+ _Inout_opt_ LPDWORD lpcbClass,
+ _Out_opt_ PFILETIME lpftLastWriteTime)
{
- union
- {
- KEY_NODE_INFORMATION Node;
- KEY_BASIC_INFORMATION Basic;
- } *KeyInfo;
-
- UNICODE_STRING StringU;
- ANSI_STRING StringA;
- LONG ErrorCode = ERROR_SUCCESS;
- DWORD NameLength;
- DWORD ClassLength = 0;
- DWORD BufferSize;
- ULONG ResultSize;
- HANDLE KeyHandle;
- NTSTATUS Status;
-
- TRACE("RegEnumKeyExA(hKey 0x%x, dwIndex %d, lpName 0x%x, *lpcbName %d, lpClass 0x%x, lpcbClass %d)\n",
- hKey, dwIndex, lpName, *lpcbName, lpClass, lpcbClass ? *lpcbClass : 0);
-
- if ((lpClass) && (!lpcbClass))
- {
- return ERROR_INVALID_PARAMETER;
- }
-
- Status = MapDefaultKey(&KeyHandle, hKey);
- if (!NT_SUCCESS(Status))
- {
- return RtlNtStatusToDosError(Status);
- }
+ WCHAR* NameBuffer = NULL;
+ WCHAR* ClassBuffer = NULL;
+ DWORD NameLength, ClassLength;
+ LONG ErrorCode;
+ /* Allocate our buffers */
if (*lpcbName > 0)
{
- NameLength = min (*lpcbName - 1 , REG_MAX_NAME_SIZE) * sizeof (WCHAR);
- }
- else
- {
- NameLength = 0;
- }
-
- if (lpClass)
- {
- if (*lpcbClass > 0)
+ NameLength = *lpcbName;
+ NameBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *lpcbName * sizeof(WCHAR));
+ if (NameBuffer == NULL)
{
- ClassLength = min (*lpcbClass -1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
- }
- else
- {
- ClassLength = 0;
+ ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
+ goto Exit;
}
-
- /* The class name should start at a dword boundary */
- BufferSize = ((sizeof(KEY_NODE_INFORMATION) + NameLength + 3) & ~3) + ClassLength;
- }
- else
- {
- BufferSize = sizeof(KEY_BASIC_INFORMATION) + NameLength;
}
- KeyInfo = RtlAllocateHeap (ProcessHeap, 0, BufferSize);
- if (KeyInfo == NULL)
- {
- ErrorCode = ERROR_OUTOFMEMORY;
- goto Cleanup;
- }
-
- Status = NtEnumerateKey(KeyHandle,
- (ULONG)dwIndex,
- lpClass == NULL ? KeyBasicInformation : KeyNodeInformation,
- KeyInfo,
- BufferSize,
- &ResultSize);
- TRACE("NtEnumerateKey() returned status 0x%X\n", Status);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError (Status);
- }
- else
+ if (lpClass)
{
- if (lpClass == NULL)
- {
- if (KeyInfo->Basic.NameLength > NameLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- StringU.Buffer = KeyInfo->Basic.Name;
- StringU.Length = KeyInfo->Basic.NameLength;
- StringU.MaximumLength = KeyInfo->Basic.NameLength;
- }
- }
- else
- {
- if (KeyInfo->Node.NameLength > NameLength ||
- KeyInfo->Node.ClassLength > ClassLength)
- {
- ErrorCode = ERROR_BUFFER_OVERFLOW;
- }
- else
- {
- StringA.Buffer = lpClass;
- StringA.Length = 0;
- StringA.MaximumLength = *lpcbClass;
- StringU.Buffer = (PWCHAR)((ULONG_PTR)KeyInfo->Node.Name + KeyInfo->Node.ClassOffset);
- StringU.Length = KeyInfo->Node.ClassLength;
- StringU.MaximumLength = KeyInfo->Node.ClassLength;
- RtlUnicodeStringToAnsiString (&StringA, &StringU, FALSE);
- lpClass[StringA.Length] = 0;
- *lpcbClass = StringA.Length;
- StringU.Buffer = KeyInfo->Node.Name;
- StringU.Length = KeyInfo->Node.NameLength;
- StringU.MaximumLength = KeyInfo->Node.NameLength;
- }
- }
-
- if (ErrorCode == ERROR_SUCCESS)
+ if (*lpcbClass > 0)
{
- StringA.Buffer = lpName;
- StringA.Length = 0;
- StringA.MaximumLength = *lpcbName;
- RtlUnicodeStringToAnsiString (&StringA, &StringU, FALSE);
- lpName[StringA.Length] = 0;
- *lpcbName = StringA.Length;
- if (lpftLastWriteTime != NULL)
+ ClassLength = *lpcbClass;
+ ClassBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *lpcbClass * sizeof(WCHAR));
+ if (ClassBuffer == NULL)
{
- if (lpClass == NULL)
- {
- lpftLastWriteTime->dwLowDateTime = KeyInfo->Basic.LastWriteTime.u.LowPart;
- lpftLastWriteTime->dwHighDateTime = KeyInfo->Basic.LastWriteTime.u.HighPart;
- }
- else
- {
- lpftLastWriteTime->dwLowDateTime = KeyInfo->Node.LastWriteTime.u.LowPart;
- lpftLastWriteTime->dwHighDateTime = KeyInfo->Node.LastWriteTime.u.HighPart;
- }
+ ErrorCode = ERROR_NOT_ENOUGH_MEMORY;
+ goto Exit;
}
}
}
- /*TRACE("Key Namea0 Length %d\n", StringU.Length);*/ /* BUGBUG could be uninitialized */
- TRACE("Key Name1 Length %d\n", NameLength);
- TRACE("Key Name Length %d\n", *lpcbName);
- TRACE("Key Name %s\n", lpName);
+ /* Do the actual call */
+ ErrorCode = RegEnumKeyExW(
+ hKey,
+ dwIndex,
+ NameBuffer,
+ lpcbName,
+ lpReserved,
+ ClassBuffer,
+ lpcbClass,
+ lpftLastWriteTime);
- RtlFreeHeap(ProcessHeap,
- 0,
- KeyInfo);
+ if (ErrorCode != ERROR_SUCCESS)
+ goto Exit;
-Cleanup:
- ClosePredefKey(KeyHandle);
+ /* Convert the strings */
+ RtlUnicodeToMultiByteN(lpName, *lpcbName, 0, NameBuffer, *lpcbName * sizeof(WCHAR));
+ /* NULL terminate if we can */
+ if (NameLength > *lpcbName)
+ lpName[*lpcbName] = '\0';
+
+ if (lpClass)
+ {
+ RtlUnicodeToMultiByteN(lpClass, *lpcbClass, 0, NameBuffer, *lpcbClass * sizeof(WCHAR));
+ if (ClassLength > *lpcbClass)
+ lpClass[*lpcbClass] = '\0';
+ }
+
+Exit:
+ if (NameBuffer)
+ RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
+ if (ClassBuffer)
+ RtlFreeHeap(RtlGetProcessHeap(), 0, ClassBuffer);
return ErrorCode;
}
*
* @implemented
*/
-LONG WINAPI
-RegEnumKeyExW(HKEY hKey,
- DWORD dwIndex,
- LPWSTR lpName,
- LPDWORD lpcbName,
- LPDWORD lpReserved,
- LPWSTR lpClass,
- LPDWORD lpcbClass,
- PFILETIME lpftLastWriteTime)
+LONG
+WINAPI
+RegEnumKeyExW(
+ _In_ HKEY hKey,
+ _In_ DWORD dwIndex,
+ _Out_ LPWSTR lpName,
+ _Inout_ LPDWORD lpcbName,
+ _Reserved_ LPDWORD lpReserved,
+ _Out_opt_ LPWSTR lpClass,
+ _Inout_opt_ LPDWORD lpcbClass,
+ _Out_opt_ PFILETIME lpftLastWriteTime)
{
union
{
return RtlNtStatusToDosError(Status);
}
+ if (IsHKCRKey(KeyHandle))
+ {
+ ErrorCode = EnumHKCRKey(
+ KeyHandle,
+ dwIndex,
+ lpName,
+ lpcbName,
+ lpReserved,
+ lpClass,
+ lpcbClass,
+ lpftLastWriteTime);
+ ClosePredefKey(KeyHandle);
+ return ErrorCode;
+ }
+
if (*lpcbName > 0)
{
NameLength = min (*lpcbName - 1, REG_MAX_NAME_SIZE) * sizeof (WCHAR);
{
if (KeyInfo->Basic.NameLength > NameLength)
{
- ErrorCode = ERROR_BUFFER_OVERFLOW;
+ ErrorCode = ERROR_MORE_DATA;
}
else
{
if (KeyInfo->Node.NameLength > NameLength ||
KeyInfo->Node.ClassLength > ClassLength)
{
- ErrorCode = ERROR_BUFFER_OVERFLOW;
+ ErrorCode = ERROR_MORE_DATA;
}
else
{
* @implemented
*/
LONG WINAPI
-RegEnumValueA(HKEY hKey,
- DWORD index,
- LPSTR value,
- LPDWORD val_count,
- LPDWORD reserved,
- LPDWORD type,
- LPBYTE data,
- LPDWORD count)
+RegEnumValueA(
+ _In_ HKEY hKey,
+ _In_ DWORD dwIndex,
+ _Out_ LPSTR lpName,
+ _Inout_ LPDWORD lpcbName,
+ _Reserved_ LPDWORD lpdwReserved,
+ _Out_opt_ LPDWORD lpdwType,
+ _Out_opt_ LPBYTE lpData,
+ _Inout_opt_ LPDWORD lpcbData)
{
- HANDLE KeyHandle;
- NTSTATUS status;
- ULONG total_size;
- char buffer[256], *buf_ptr = buffer;
- KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
- static const int info_size = FIELD_OFFSET( KEY_VALUE_FULL_INFORMATION, Name );
+ WCHAR* NameBuffer;
+ DWORD NameBufferSize, NameLength;
+ LONG ErrorCode;
+ DWORD LocalType = REG_NONE;
+ BOOL NameOverflow = FALSE;
- //TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
- // hkey, index, value, val_count, reserved, type, data, count );
+ /* Do parameter checks now, once and for all. */
+ if (!lpName || !lpcbName)
+ return ERROR_INVALID_PARAMETER;
- /* NT only checks count, not val_count */
- if ((data && !count) || reserved)
+ if ((lpData && !lpcbData) || lpdwReserved)
return ERROR_INVALID_PARAMETER;
- status = MapDefaultKey(&KeyHandle, hKey);
- if (!NT_SUCCESS(status))
+ /* Get the size of the buffer we must use for the first call to RegEnumValueW */
+ ErrorCode = RegQueryInfoKeyW(
+ hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &NameBufferSize, NULL, NULL, NULL);
+ if (ErrorCode != ERROR_SUCCESS)
+ return ErrorCode;
+
+ /* Add space for the null terminator */
+ NameBufferSize++;
+
+ /* Allocate the buffer for the unicode name */
+ NameBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, NameBufferSize * sizeof(WCHAR));
+ if (NameBuffer == NULL)
{
- return RtlNtStatusToDosError(status);
+ return ERROR_NOT_ENOUGH_MEMORY;
}
- total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
- if (data) total_size += *count;
- total_size = min( sizeof(buffer), total_size );
-
- status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
- buffer, total_size, &total_size );
- if (status && (status != STATUS_BUFFER_OVERFLOW) && (status != STATUS_BUFFER_TOO_SMALL)) goto done;
+ /*
+ * This code calls RegEnumValueW twice, because we need to know the type of the enumerated value.
+ * So for the first call, we check if we overflow on the name, as we have no way of knowing if this
+ * is an overflow on the data or on the name during the the second call. So the first time, we make the
+ * call with the supplied value. This is merdique, but this is how it is.
+ */
+ NameLength = *lpcbName;
+ ErrorCode = RegEnumValueW(
+ hKey,
+ dwIndex,
+ NameBuffer,
+ &NameLength,
+ NULL,
+ &LocalType,
+ NULL,
+ NULL);
+ if (ErrorCode != ERROR_SUCCESS)
+ {
+ if (ErrorCode == ERROR_MORE_DATA)
+ NameOverflow = TRUE;
+ else
+ goto Exit;
+ }
- /* we need to fetch the contents for a string type even if not requested,
- * because we need to compute the length of the ASCII string. */
- if (value || data || is_string(info->Type))
+ if (is_string(LocalType) && lpcbData)
{
- /* retry with a dynamically allocated buffer */
- while ((status == STATUS_BUFFER_OVERFLOW) || (status == STATUS_BUFFER_TOO_SMALL))
- {
- if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
- if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
- {
- status = STATUS_INSUFFICIENT_RESOURCES;
- goto done;
- }
- info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
- status = NtEnumerateValueKey( KeyHandle, index, KeyValueFullInformation,
- buf_ptr, total_size, &total_size );
- }
+ /* We must allocate a buffer to get the unicode data */
+ DWORD DataBufferSize = *lpcbData * sizeof(WCHAR);
+ WCHAR* DataBuffer = NULL;
+ DWORD DataLength = *lpcbData;
+ LPSTR DataStr = (LPSTR)lpData;
- if (status) goto done;
+ if (lpData)
+ DataBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *lpcbData * sizeof(WCHAR));
- if (is_string(info->Type))
+ /* Do the real call */
+ ErrorCode = RegEnumValueW(
+ hKey,
+ dwIndex,
+ NameBuffer,
+ &NameBufferSize,
+ lpdwReserved,
+ lpdwType,
+ (LPBYTE)DataBuffer,
+ &DataBufferSize);
+
+ *lpcbData = DataBufferSize / sizeof(WCHAR);
+
+ if (ErrorCode != ERROR_SUCCESS)
{
- ULONG len;
- RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
- info->DataLength );
- if (data && len)
- {
- if (len > *count) status = STATUS_BUFFER_OVERFLOW;
- else
- {
- RtlUnicodeToMultiByteN( (PCHAR)data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
- info->DataLength );
- /* if the type is REG_SZ and data is not 0-terminated
- * and there is enough space in the buffer NT appends a \0 */
- if (len < *count && data[len-1]) data[len] = 0;
- }
- }
- info->DataLength = len;
+ RtlFreeHeap(RtlGetProcessHeap(), 0, DataBuffer);
+ goto Exit;
}
- else if (data)
+
+ /* Copy the data whatever the error code is */
+ if (lpData)
{
- if (info->DataLength > *count) status = STATUS_BUFFER_OVERFLOW;
- else memcpy( data, buf_ptr + info->DataOffset, info->DataLength );
+ /* Do the data conversion */
+ RtlUnicodeToMultiByteN(DataStr, DataLength, 0, DataBuffer, DataBufferSize);
+ /* NULL-terminate if there is enough room */
+ if ((DataLength > *lpcbData) && (DataStr[*lpcbData - 1] != '\0'))
+ DataStr[*lpcbData] = '\0';
}
- if (value && !status)
- {
- ULONG len;
+ RtlFreeHeap(RtlGetProcessHeap(), 0, DataBuffer);
+ }
+ else
+ {
+ /* No data conversion needed. Do the call with provided buffers */
+ ErrorCode = RegEnumValueW(
+ hKey,
+ dwIndex,
+ NameBuffer,
+ &NameBufferSize,
+ lpdwReserved,
+ lpdwType,
+ lpData,
+ lpcbData);
- RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
- if (len >= *val_count)
- {
- status = STATUS_BUFFER_OVERFLOW;
- if (*val_count)
- {
- len = *val_count - 1;
- RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
- value[len] = 0;
- }
- }
- else
- {
- RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
- value[len] = 0;
- *val_count = len;
- }
+ if (ErrorCode != ERROR_SUCCESS)
+ {
+ goto Exit;
}
}
- else status = STATUS_SUCCESS;
- if (type) *type = info->Type;
- if (count) *count = info->DataLength;
+ if (NameOverflow)
+ {
+ ErrorCode = ERROR_MORE_DATA;
+ goto Exit;
+ }
- done:
- if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
- ClosePredefKey(KeyHandle);
- return RtlNtStatusToDosError(status);
+ /* Convert the name string */
+ RtlUnicodeToMultiByteN(lpName, *lpcbName, lpcbName, NameBuffer, NameBufferSize * sizeof(WCHAR));
+ ((PSTR)lpName)[*lpcbName] = '\0';
+
+Exit:
+ if (NameBuffer)
+ RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
+
+ return ErrorCode;
}
* Success: ERROR_SUCCESS
* Failure: nonzero error code from Winerror.h
*/
-LONG WINAPI
-RegEnumValueW(HKEY hKey,
- DWORD index,
- LPWSTR value,
- PDWORD val_count,
- PDWORD reserved,
- PDWORD type,
- LPBYTE data,
- PDWORD count)
+LONG
+WINAPI
+RegEnumValueW(
+ _In_ HKEY hKey,
+ _In_ DWORD index,
+ _Out_ LPWSTR value,
+ _Inout_ PDWORD val_count,
+ _Reserved_ PDWORD reserved,
+ _Out_opt_ PDWORD type,
+ _Out_opt_ LPBYTE data,
+ _Inout_opt_ PDWORD count)
{
HANDLE KeyHandle;
NTSTATUS status;
KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
static const int info_size = FIELD_OFFSET( KEY_VALUE_FULL_INFORMATION, Name );
- //TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
- // hkey, index, value, val_count, reserved, type, data, count );
+ TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
+ hKey, index, value, val_count, reserved, type, data, count );
- /* NT only checks count, not val_count */
- if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
+ if (!value || !val_count)
+ return ERROR_INVALID_PARAMETER;
+
+ if ((data && !count) || reserved)
+ return ERROR_INVALID_PARAMETER;
status = MapDefaultKey(&KeyHandle, hKey);
if (!NT_SUCCESS(status))
return RtlNtStatusToDosError(status);
}
+ if (IsHKCRKey(KeyHandle))
+ {
+ LONG ErrorCode = EnumHKCRValue(
+ KeyHandle,
+ index,
+ value,
+ val_count,
+ reserved,
+ type,
+ data,
+ count);
+ ClosePredefKey(KeyHandle);
+ return ErrorCode;
+ }
+
total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
if (data) total_size += *count;
total_size = min( sizeof(buffer), total_size );
}
if (IsHKCRKey(KeyHandle))
- return OpenHKCRKey(KeyHandle, lpSubKey, ulOptions, samDesired, phkResult);
+ {
+ ErrorCode = OpenHKCRKey(KeyHandle, lpSubKey, ulOptions, samDesired, phkResult);
+ ClosePredefKey(KeyHandle);
+ return ErrorCode;
+ }
if (ulOptions & REG_OPTION_OPEN_LINK)
Attributes |= OBJ_OPENLINK;
LONG WINAPI
RegQueryInfoKeyA(HKEY hKey,
LPSTR lpClass,
- LPDWORD lpcbClass,
+ LPDWORD lpcClass,
LPDWORD lpReserved,
LPDWORD lpcSubKeys,
- LPDWORD lpcbMaxSubKeyLen,
- LPDWORD lpcbMaxClassLen,
+ LPDWORD lpcMaxSubKeyLen,
+ LPDWORD lpcMaxClassLen,
LPDWORD lpcValues,
- LPDWORD lpcbMaxValueNameLen,
- LPDWORD lpcbMaxValueLen,
+ LPDWORD lpcMaxValueNameLen,
+ LPDWORD lpcMaxValueLen,
LPDWORD lpcbSecurityDescriptor,
PFILETIME lpftLastWriteTime)
{
UNICODE_STRING UnicodeString;
ANSI_STRING AnsiString;
LONG ErrorCode;
+ NTSTATUS Status;
+ DWORD cClass = 0;
+
+ if ((lpClass) && (!lpcClass))
+ {
+ return ERROR_INVALID_PARAMETER;
+ }
RtlInitUnicodeString(&UnicodeString,
NULL);
if (lpClass != NULL)
{
- UnicodeString.Buffer = &ClassName[0];
- UnicodeString.MaximumLength = sizeof(ClassName);
- AnsiString.MaximumLength = *lpcbClass;
+ RtlInitEmptyUnicodeString(&UnicodeString,
+ ClassName,
+ sizeof(ClassName));
+ cClass = sizeof(ClassName) / sizeof(WCHAR);
}
ErrorCode = RegQueryInfoKeyW(hKey,
UnicodeString.Buffer,
- lpcbClass,
+ &cClass,
lpReserved,
lpcSubKeys,
- lpcbMaxSubKeyLen,
- lpcbMaxClassLen,
+ lpcMaxSubKeyLen,
+ lpcMaxClassLen,
lpcValues,
- lpcbMaxValueNameLen,
- lpcbMaxValueLen,
+ lpcMaxValueNameLen,
+ lpcMaxValueLen,
lpcbSecurityDescriptor,
lpftLastWriteTime);
if ((ErrorCode == ERROR_SUCCESS) && (lpClass != NULL))
{
- AnsiString.Buffer = lpClass;
- AnsiString.Length = 0;
- UnicodeString.Length = *lpcbClass * sizeof(WCHAR);
- RtlUnicodeStringToAnsiString(&AnsiString,
- &UnicodeString,
- FALSE);
- *lpcbClass = AnsiString.Length;
- lpClass[AnsiString.Length] = 0;
+ if (*lpcClass == 0)
+ {
+ return ErrorCode;
+ }
+
+ RtlInitEmptyAnsiString(&AnsiString, lpClass, *lpcClass);
+ UnicodeString.Length = cClass * sizeof(WCHAR);
+ Status = RtlUnicodeStringToAnsiString(&AnsiString,
+ &UnicodeString,
+ FALSE);
+ ErrorCode = RtlNtStatusToDosError(Status);
+ cClass = AnsiString.Length;
+ lpClass[cClass] = ANSI_NULL;
+ }
+
+ if (lpcClass != NULL)
+ {
+ *lpcClass = cClass;
}
return ErrorCode;
LONG WINAPI
RegQueryInfoKeyW(HKEY hKey,
LPWSTR lpClass,
- LPDWORD lpcbClass,
+ LPDWORD lpcClass,
LPDWORD lpReserved,
LPDWORD lpcSubKeys,
- LPDWORD lpcbMaxSubKeyLen,
- LPDWORD lpcbMaxClassLen,
+ LPDWORD lpcMaxSubKeyLen,
+ LPDWORD lpcMaxClassLen,
LPDWORD lpcValues,
- LPDWORD lpcbMaxValueNameLen,
- LPDWORD lpcbMaxValueLen,
+ LPDWORD lpcMaxValueNameLen,
+ LPDWORD lpcMaxValueLen,
LPDWORD lpcbSecurityDescriptor,
PFILETIME lpftLastWriteTime)
{
ULONG Length;
LONG ErrorCode = ERROR_SUCCESS;
- if ((lpClass) && (!lpcbClass))
+ if ((lpClass) && (!lpcClass))
{
return ERROR_INVALID_PARAMETER;
}
if (lpClass != NULL)
{
- if (*lpcbClass > 0)
+ if (*lpcClass > 0)
{
- ClassLength = min(*lpcbClass - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
+ ClassLength = min(*lpcClass - 1, REG_MAX_NAME_SIZE) * sizeof(WCHAR);
}
else
{
ErrorCode = ERROR_OUTOFMEMORY;
goto Cleanup;
}
-
- FullInfo->ClassLength = ClassLength;
}
else
{
FullInfoSize = sizeof(KEY_FULL_INFORMATION);
FullInfo = &FullInfoBuffer;
- FullInfo->ClassLength = 0;
}
- FullInfo->ClassOffset = FIELD_OFFSET(KEY_FULL_INFORMATION, Class);
Status = NtQueryKey(KeyHandle,
KeyFullInformation,
FullInfoSize,
&Length);
TRACE("NtQueryKey() returned status 0x%X\n", Status);
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW)
{
- if (lpClass != NULL)
- {
- RtlFreeHeap(ProcessHeap,
- 0,
- FullInfo);
- }
-
ErrorCode = RtlNtStatusToDosError(Status);
goto Cleanup;
}
}
TRACE("MaxNameLen %lu\n", FullInfo->MaxNameLen);
- if (lpcbMaxSubKeyLen != NULL)
+ if (lpcMaxSubKeyLen != NULL)
{
- *lpcbMaxSubKeyLen = FullInfo->MaxNameLen / sizeof(WCHAR) + 1;
+ *lpcMaxSubKeyLen = FullInfo->MaxNameLen / sizeof(WCHAR);
}
TRACE("MaxClassLen %lu\n", FullInfo->MaxClassLen);
- if (lpcbMaxClassLen != NULL)
+ if (lpcMaxClassLen != NULL)
{
- *lpcbMaxClassLen = FullInfo->MaxClassLen / sizeof(WCHAR) + 1;
+ *lpcMaxClassLen = FullInfo->MaxClassLen / sizeof(WCHAR);
}
TRACE("Values %lu\n", FullInfo->Values);
}
TRACE("MaxValueNameLen %lu\n", FullInfo->MaxValueNameLen);
- if (lpcbMaxValueNameLen != NULL)
+ if (lpcMaxValueNameLen != NULL)
{
- *lpcbMaxValueNameLen = FullInfo->MaxValueNameLen / sizeof(WCHAR) + 1;
+ *lpcMaxValueNameLen = FullInfo->MaxValueNameLen / sizeof(WCHAR);
}
TRACE("MaxValueDataLen %lu\n", FullInfo->MaxValueDataLen);
- if (lpcbMaxValueLen != NULL)
+ if (lpcMaxValueLen != NULL)
{
- *lpcbMaxValueLen = FullInfo->MaxValueDataLen;
+ *lpcMaxValueLen = FullInfo->MaxValueDataLen;
}
if (lpcbSecurityDescriptor != NULL)
NULL,
0,
lpcbSecurityDescriptor);
- if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
+ if (Status != STATUS_BUFFER_TOO_SMALL)
{
- if (lpClass != NULL)
- {
- RtlFreeHeap(ProcessHeap,
- 0,
- FullInfo);
- }
-
- ErrorCode = RtlNtStatusToDosError(Status);
- goto Cleanup;
+ *lpcbSecurityDescriptor = 0;
}
}
if (lpClass != NULL)
{
+ if (*lpcClass == 0)
+ {
+ goto Cleanup;
+ }
+
if (FullInfo->ClassLength > ClassLength)
{
- ErrorCode = ERROR_BUFFER_OVERFLOW;
+ ErrorCode = ERROR_INSUFFICIENT_BUFFER;
}
else
{
RtlCopyMemory(lpClass,
FullInfo->Class,
FullInfo->ClassLength);
- *lpcbClass = FullInfo->ClassLength / sizeof(WCHAR);
- lpClass[*lpcbClass] = 0;
+ lpClass[FullInfo->ClassLength / sizeof(WCHAR)] = UNICODE_NULL;
}
+ }
+
+ if (lpcClass != NULL)
+ {
+ *lpcClass = FullInfo->ClassLength / sizeof(WCHAR);
+ }
+Cleanup:
+ if (lpClass != NULL)
+ {
RtlFreeHeap(ProcessHeap,
0,
FullInfo);
}
-Cleanup:
ClosePredefKey(KeyHandle);
return ErrorCode;
LONG ErrorCode;
if (maxBytes >= (1024*1024))
- return ERROR_TRANSFER_TOO_LONG;
+ return ERROR_MORE_DATA;
*ldwTotsize = 0;
LONG ErrorCode;
if (maxBytes >= (1024*1024))
- return ERROR_TRANSFER_TOO_LONG;
+ return ERROR_MORE_DATA;
*ldwTotsize = 0;
* Failure: ERROR_INVALID_HANDLE, if hkey is invalid.
* ERROR_INVALID_PARAMETER, if any other parameter is invalid.
* ERROR_MORE_DATA, if on input *count is too small to hold the contents.
- *
+ *
* NOTES
- * MSDN states that if data is too small it is partially filled. In reality
+ * MSDN states that if data is too small it is partially filled. In reality
* it remains untouched.
*/
LONG
ErrorCode = RegQueryValueExW(hkeyorg, nameW.Buffer, NULL, &LocalType, NULL, &BufferSize);
if (ErrorCode != ERROR_SUCCESS)
{
- if (!data)
+ if ((!data) && count)
*count = 0;
RtlFreeUnicodeString(&nameW);
return ErrorCode;
if (name && name[0])
{
ret = RegOpenKeyW( hkey, name, &subkey);
- if (ret != ERROR_SUCCESS)
+ if (ret != ERROR_SUCCESS)
{
return ret;
}
}
ret = RegQueryValueExW( subkey, NULL, NULL, NULL, (LPBYTE)data, (LPDWORD)count );
-
- if (subkey != hkey)
+
+ if (subkey != hkey)
{
RegCloseKey( subkey );
}
if (ret == ERROR_FILE_NOT_FOUND)
{
/* return empty string if default value not found */
- if (data)
+ if (data)
*data = 0;
- if (count)
+ if (count)
*count = sizeof(WCHAR);
ret = ERROR_SUCCESS;
}