Converted enum_key_value request to the new request mechanism.

This commit is contained in:
Alexandre Julliard 2000-12-15 20:57:00 +00:00
parent ebb3a68cbc
commit 0b6a79c961
8 changed files with 444 additions and 974 deletions

View File

@ -27,14 +27,6 @@
DEFAULT_DEBUG_CHANNEL(reg);
/* Unicode->Ansi conversion without string delimiters */
static LPSTR memcpyWtoA( LPSTR dst, LPCWSTR src, INT n )
{
LPSTR p = dst;
while (n-- > 0) *p++ = (CHAR)*src++;
return dst;
}
/* check if value type needs string conversion (Ansi<->Unicode) */
static inline int is_string( DWORD type )
{
@ -1000,8 +992,11 @@ DWORD WINAPI RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_count,
LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
{
DWORD ret, len;
struct enum_key_value_request *req = get_req_buffer();
NTSTATUS status;
DWORD total_size;
char buffer[256], *buf_ptr = buffer;
KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
static const int info_size = sizeof(*info) - sizeof(info->Name);
TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
hkey, index, value, val_count, reserved, type, data, count );
@ -1009,41 +1004,65 @@ DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_co
/* NT only checks count, not val_count */
if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
req->hkey = hkey;
req->index = index;
req->offset = 0;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
if (data) total_size += *count;
total_size = min( sizeof(buffer), total_size );
len = strlenW( req->name ) + 1;
if (len > *val_count) return ERROR_MORE_DATA;
memcpy( value, req->name, len * sizeof(WCHAR) );
*val_count = len - 1;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
buffer, total_size, &total_size );
if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
if (data)
if (value || data)
{
if (*count < req->len) ret = ERROR_MORE_DATA;
else
/* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW)
{
/* copy the data */
unsigned int max = server_remaining( req->data );
unsigned int pos = 0;
while (pos < req->len)
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
buf_ptr, total_size, &total_size );
}
if (status) goto done;
if (value)
{
if (info->NameLength/sizeof(WCHAR) >= *val_count)
{
unsigned int len = min( req->len - pos, max );
memcpy( data + pos, req->data, len );
if ((pos += len) >= req->len) break;
req->offset = pos;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
status = STATUS_BUFFER_OVERFLOW;
goto done;
}
memcpy( value, info->Name, info->NameLength );
*val_count = info->NameLength / sizeof(WCHAR);
value[*val_count] = 0;
}
if (data)
{
if (total_size - info->DataOffset > *count)
{
status = STATUS_BUFFER_OVERFLOW;
goto done;
}
memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
if (total_size - info->DataOffset <= *count-sizeof(WCHAR) && is_string(info->Type))
{
/* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \0 */
WCHAR *ptr = (WCHAR *)(data + total_size - info->DataOffset);
if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
}
}
/* 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 (req->len && is_string(req->type) &&
(req->len < *count) && ((WCHAR *)data)[req->len-1]) ((WCHAR *)data)[req->len] = 0;
}
if (type) *type = req->type;
if (count) *count = req->len;
return ret;
if (type) *type = info->Type;
if (count) *count = info->DataLength;
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError(status);
}
@ -1053,8 +1072,11 @@ DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_co
DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
{
DWORD ret, len, total_len;
struct enum_key_value_request *req = get_req_buffer();
NTSTATUS status;
DWORD total_size;
char buffer[256], *buf_ptr = buffer;
KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
static const int info_size = sizeof(*info) - sizeof(info->Name);
TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
hkey, index, value, val_count, reserved, type, data, count );
@ -1062,47 +1084,80 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
/* NT only checks count, not val_count */
if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
req->hkey = hkey;
req->index = index;
req->offset = 0;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
if (data) total_size += *count;
total_size = min( sizeof(buffer), total_size );
len = strlenW( req->name ) + 1;
if (len > *val_count) return ERROR_MORE_DATA;
memcpyWtoA( value, req->name, len );
*val_count = len - 1;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
buffer, total_size, &total_size );
if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
total_len = is_string( req->type ) ? req->len/sizeof(WCHAR) : req->len;
if (data)
/* 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 (*count < total_len) ret = ERROR_MORE_DATA;
else
/* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW)
{
/* copy the data */
unsigned int max = server_remaining( req->data );
unsigned int pos = 0;
while (pos < req->len)
{
unsigned int len = min( req->len - pos, max );
if (is_string( req->type ))
memcpyWtoA( data + pos/sizeof(WCHAR), (WCHAR *)req->data, len/sizeof(WCHAR) );
else
memcpy( data + pos, req->data, len );
if ((pos += len) >= req->len) break;
req->offset = pos;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
}
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
buf_ptr, total_size, &total_size );
}
if (status) goto done;
if (value)
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
NULL, 0, NULL, NULL );
if (len >= *val_count)
{
status = STATUS_BUFFER_OVERFLOW;
goto done;
}
WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
value, len, NULL, NULL );
value[len] = 0;
*val_count = len;
}
if (is_string(info->Type))
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
(total_size - info->DataOffset) / sizeof(WCHAR),
NULL, 0, NULL, NULL );
if (data && len)
{
if (len > *count)
{
status = STATUS_BUFFER_OVERFLOW;
goto done;
}
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
(total_size - info->DataOffset) / sizeof(WCHAR),
data, len, NULL, NULL );
/* 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;
}
else if (data)
{
if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
}
/* 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 (total_len && is_string(req->type) && (total_len < *count) && data[total_len-1])
data[total_len] = 0;
}
if (count) *count = total_len;
if (type) *type = req->type;
return ret;
if (type) *type = info->Type;
if (count) *count = info->DataLength;
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError(status);
}

View File

@ -311,148 +311,154 @@ NTSTATUS WINAPI NtQueryKey( HANDLE handle, KEY_INFORMATION_CLASS info_class,
return ret;
}
/* fill the key value info structure for a specific info class */
static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
DWORD length, int type, int name_len, int data_len )
{
switch(info_class)
{
case KeyValueBasicInformation:
{
KEY_VALUE_BASIC_INFORMATION keyinfo;
keyinfo.TitleIndex = 0;
keyinfo.Type = type;
keyinfo.NameLength = name_len;
length = min( length, sizeof(keyinfo) - sizeof(keyinfo.Name) );
memcpy( info, &keyinfo, length );
break;
}
case KeyValueFullInformation:
{
KEY_VALUE_FULL_INFORMATION keyinfo;
keyinfo.TitleIndex = 0;
keyinfo.Type = type;
keyinfo.DataOffset = sizeof(keyinfo) - sizeof(keyinfo.Name) + name_len;
keyinfo.DataLength = data_len;
keyinfo.NameLength = name_len;
length = min( length, sizeof(keyinfo) - sizeof(keyinfo.Name) );
memcpy( info, &keyinfo, length );
break;
}
case KeyValuePartialInformation:
{
KEY_VALUE_PARTIAL_INFORMATION keyinfo;
keyinfo.TitleIndex = 0;
keyinfo.Type = type;
keyinfo.DataLength = data_len;
length = min( length, sizeof(keyinfo) - sizeof(keyinfo.Data) );
memcpy( info, &keyinfo, length );
break;
}
default:
break;
}
}
/******************************************************************************
* NtEnumerateValueKey [NTDLL]
* ZwEnumerateValueKey
*/
NTSTATUS WINAPI NtEnumerateValueKey(
HANDLE KeyHandle,
ULONG Index,
KEY_VALUE_INFORMATION_CLASS KeyInformationClass,
PVOID KeyInformation,
ULONG Length,
PULONG ResultLength)
NTSTATUS WINAPI NtEnumerateValueKey( HANDLE handle, ULONG index,
KEY_VALUE_INFORMATION_CLASS info_class,
void *info, DWORD length, DWORD *result_len )
{
struct enum_key_value_request *req = get_req_buffer();
UINT NameLength;
NTSTATUS ret;
TRACE("(0x%08x,0x%08lx,0x%08x,%p,0x%08lx,%p)\n",
KeyHandle, Index, KeyInformationClass, KeyInformation, Length, ResultLength);
NTSTATUS ret;
char *data_ptr, *name_ptr;
int fixed_size = 0, name_len = 0, data_len = 0, offset = 0, type = 0, total_len = 0;
req->hkey = KeyHandle;
req->index = Index;
if ((ret = server_call_noerr(REQ_ENUM_KEY_VALUE)) != STATUS_SUCCESS) return ret;
TRACE( "(0x%x,%lu,%d,%p,%ld)\n", handle, index, info_class, info, length );
switch (KeyInformationClass)
{
case KeyBasicInformation:
{
PKEY_VALUE_BASIC_INFORMATION kbi = KeyInformation;
NameLength = strlenW(req->name) * sizeof(WCHAR);
*ResultLength = sizeof(KEY_VALUE_BASIC_INFORMATION) - sizeof(WCHAR) + NameLength;
if (*ResultLength > Length) return STATUS_BUFFER_TOO_SMALL;
/* compute the length we want to retrieve */
switch(info_class)
{
case KeyValueBasicInformation:
fixed_size = sizeof(KEY_VALUE_BASIC_INFORMATION) - sizeof(WCHAR);
name_ptr = (char *)info + fixed_size;
data_ptr = NULL;
break;
case KeyValueFullInformation:
fixed_size = sizeof(KEY_VALUE_FULL_INFORMATION) - sizeof(WCHAR);
name_ptr = data_ptr = (char *)info + fixed_size;
break;
case KeyValuePartialInformation:
fixed_size = sizeof(KEY_VALUE_PARTIAL_INFORMATION) - sizeof(UCHAR);
name_ptr = NULL;
data_ptr = (char *)info + fixed_size;
break;
default:
FIXME( "Information class %d not implemented\n", info_class );
return STATUS_INVALID_PARAMETER;
}
if (length > fixed_size) data_len = length - fixed_size;
kbi->TitleIndex = 0;
kbi->Type = req->type;
kbi->NameLength = NameLength;
memcpy(kbi->Name, req->name, kbi->NameLength);
}
break;
case KeyValueFullInformation:
{
PKEY_VALUE_FULL_INFORMATION kbi = KeyInformation;
UINT DataOffset;
do
{
size_t reqlen = data_len + sizeof(WCHAR);
if (name_ptr && !offset) reqlen += MAX_PATH*sizeof(WCHAR);
reqlen = min( reqlen, REQUEST_MAX_VAR_SIZE );
NameLength = strlenW(req->name) * sizeof(WCHAR);
DataOffset = sizeof(KEY_VALUE_FULL_INFORMATION) - sizeof(WCHAR) + NameLength;
*ResultLength = DataOffset + req->len;
SERVER_START_REQ
{
struct enum_key_value_request *req = server_alloc_req( sizeof(*req), reqlen );
if (*ResultLength > Length) return STATUS_BUFFER_TOO_SMALL;
req->hkey = handle;
req->index = index;
req->offset = offset;
kbi->TitleIndex = 0;
kbi->Type = req->type;
kbi->DataOffset = DataOffset;
kbi->DataLength = req->len;
kbi->NameLength = NameLength;
memcpy(kbi->Name, req->name, kbi->NameLength);
memcpy(((LPBYTE)kbi) + DataOffset, req->data, req->len);
}
break;
case KeyValuePartialInformation:
{
PKEY_VALUE_PARTIAL_INFORMATION kbi = KeyInformation;
*ResultLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) - sizeof(WCHAR) + req->len;
if (!(ret = server_call_noerr( REQ_ENUM_KEY_VALUE )))
{
size_t size = server_data_size(req) - sizeof(WCHAR);
WCHAR *name = server_data_ptr(req);
if (!offset) /* name is only present on the first request */
{
name_len = *name++;
size -= name_len;
if (name_ptr)
{
if (name_len > data_len) /* overflow */
{
memcpy( name_ptr, name, data_len );
data_len = 0;
ret = STATUS_BUFFER_OVERFLOW;
}
else
{
memcpy( name_ptr, name, name_len );
data_len -= name_len;
if (data_ptr) data_ptr += name_len;
}
}
name += name_len / sizeof(WCHAR);
}
else name++; /* skip 0 length */
if (*ResultLength > Length) return STATUS_BUFFER_TOO_SMALL;
if (data_ptr)
{
size = min( size, data_len );
memcpy( data_ptr + offset, name, size );
offset += size;
data_len -= size;
}
type = req->type;
total_len = req->len;
}
}
SERVER_END_REQ;
if (ret) return ret;
} while (data_len && data_ptr && offset < total_len);
*result_len = total_len + fixed_size + (name_ptr ? name_len : 0);
if (data_ptr && offset < total_len) ret = STATUS_BUFFER_OVERFLOW;
if (length < fixed_size) ret = STATUS_BUFFER_OVERFLOW;
copy_key_value_info( info_class, info, length, type, name_len, total_len );
return ret;
kbi->TitleIndex = 0;
kbi->Type = req->type;
kbi->DataLength = req->len;
memcpy(kbi->Data, req->data, req->len);
}
break;
default:
FIXME("not implemented\n");
}
return STATUS_SUCCESS;
}
/******************************************************************************
* NtFlushKey [NTDLL]
* ZwFlushKey
*/
NTSTATUS WINAPI NtFlushKey(HANDLE KeyHandle)
{
FIXME("(0x%08x) stub!\n",
KeyHandle);
return 1;
}
/******************************************************************************
* NtLoadKey [NTDLL]
* ZwLoadKey
*/
NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, const OBJECT_ATTRIBUTES *file )
{
FIXME("stub!\n");
dump_ObjectAttributes(attr);
dump_ObjectAttributes(file);
return STATUS_SUCCESS;
}
/******************************************************************************
* NtNotifyChangeKey [NTDLL]
* ZwNotifyChangeKey
*/
NTSTATUS WINAPI NtNotifyChangeKey(
IN HANDLE KeyHandle,
IN HANDLE Event,
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
IN PVOID ApcContext OPTIONAL,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN ULONG CompletionFilter,
IN BOOLEAN Asynchroneous,
OUT PVOID ChangeBuffer,
IN ULONG Length,
IN BOOLEAN WatchSubtree)
{
FIXME("(0x%08x,0x%08x,%p,%p,%p,0x%08lx, 0x%08x,%p,0x%08lx,0x%08x) stub!\n",
KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
Asynchroneous, ChangeBuffer, Length, WatchSubtree);
return STATUS_SUCCESS;
}
/******************************************************************************
* NtQueryMultipleValueKey [NTDLL]
* ZwQueryMultipleValueKey
*/
NTSTATUS WINAPI NtQueryMultipleValueKey(
HANDLE KeyHandle,
PVALENTW ListOfValuesToQuery,
ULONG NumberOfItems,
PVOID MultipleValueInformation,
ULONG Length,
PULONG ReturnLength)
{
FIXME("(0x%08x,%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
Length,ReturnLength);
return STATUS_SUCCESS;
}
/******************************************************************************
* NtQueryValueKey [NTDLL]
@ -531,43 +537,75 @@ NTSTATUS WINAPI NtQueryValueKey( HANDLE handle, const UNICODE_STRING *name,
if (offset < total_len) ret = STATUS_BUFFER_OVERFLOW;
if (length < fixed_size) ret = STATUS_BUFFER_OVERFLOW;
switch(info_class)
{
case KeyValueBasicInformation:
{
KEY_VALUE_BASIC_INFORMATION keyinfo;
keyinfo.TitleIndex = 0;
keyinfo.Type = type;
keyinfo.NameLength = 0;
memcpy( info, &keyinfo, min(fixed_size,length) );
break;
}
case KeyValueFullInformation:
{
KEY_VALUE_FULL_INFORMATION keyinfo;
keyinfo.TitleIndex = 0;
keyinfo.Type = type;
keyinfo.DataOffset = fixed_size;
keyinfo.DataLength = total_len;
keyinfo.NameLength = 0;
memcpy( info, &keyinfo, min(fixed_size,length) );
break;
}
case KeyValuePartialInformation:
{
KEY_VALUE_PARTIAL_INFORMATION keyinfo;
keyinfo.TitleIndex = 0;
keyinfo.Type = type;
keyinfo.DataLength = total_len;
memcpy( info, &keyinfo, min(fixed_size,length) );
break;
}
default:
break;
}
copy_key_value_info( info_class, info, length, type, 0, total_len );
return ret;
}
/******************************************************************************
* NtFlushKey [NTDLL]
* ZwFlushKey
*/
NTSTATUS WINAPI NtFlushKey(HANDLE KeyHandle)
{
FIXME("(0x%08x) stub!\n",
KeyHandle);
return 1;
}
/******************************************************************************
* NtLoadKey [NTDLL]
* ZwLoadKey
*/
NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, const OBJECT_ATTRIBUTES *file )
{
FIXME("stub!\n");
dump_ObjectAttributes(attr);
dump_ObjectAttributes(file);
return STATUS_SUCCESS;
}
/******************************************************************************
* NtNotifyChangeKey [NTDLL]
* ZwNotifyChangeKey
*/
NTSTATUS WINAPI NtNotifyChangeKey(
IN HANDLE KeyHandle,
IN HANDLE Event,
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
IN PVOID ApcContext OPTIONAL,
OUT PIO_STATUS_BLOCK IoStatusBlock,
IN ULONG CompletionFilter,
IN BOOLEAN Asynchroneous,
OUT PVOID ChangeBuffer,
IN ULONG Length,
IN BOOLEAN WatchSubtree)
{
FIXME("(0x%08x,0x%08x,%p,%p,%p,0x%08lx, 0x%08x,%p,0x%08lx,0x%08x) stub!\n",
KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
Asynchroneous, ChangeBuffer, Length, WatchSubtree);
return STATUS_SUCCESS;
}
/******************************************************************************
* NtQueryMultipleValueKey [NTDLL]
* ZwQueryMultipleValueKey
*/
NTSTATUS WINAPI NtQueryMultipleValueKey(
HANDLE KeyHandle,
PVALENTW ListOfValuesToQuery,
ULONG NumberOfItems,
PVOID MultipleValueInformation,
ULONG Length,
PULONG ReturnLength)
{
FIXME("(0x%08x,%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
Length,ReturnLength);
return STATUS_SUCCESS;
}
/******************************************************************************
* NtReplaceKey [NTDLL]
* ZwReplaceKey

View File

@ -44,9 +44,6 @@ struct request_max_size
/* max size of the variable part of a request */
#define REQUEST_MAX_VAR_SIZE 1024
/* a path name for server requests (Unicode) */
typedef WCHAR path_t[MAX_PATH+1];
/* definitions of the event data depending on the event code */
struct debug_event_exception
@ -1094,8 +1091,8 @@ struct enum_key_value_request
IN unsigned int offset; /* offset for getting data */
OUT int type; /* value type */
OUT int len; /* value data len */
OUT path_t name; /* value name */
OUT unsigned char data[1]; /* value data */
OUT VARARG(name,unicode_len_str); /* value name */
OUT VARARG(data,bytes); /* value data */
};
@ -1591,7 +1588,7 @@ union generic_request
struct async_result_request async_result;
};
#define SERVER_PROTOCOL_VERSION 28
#define SERVER_PROTOCOL_VERSION 29
/* ### make_requests end ### */
/* Everything above this line is generated automatically by tools/make_requests */

View File

@ -28,14 +28,6 @@
DEFAULT_DEBUG_CHANNEL(reg);
/* Unicode->Ansi conversion without string delimiters */
static LPSTR memcpyWtoA( LPSTR dst, LPCWSTR src, INT n )
{
LPSTR p = dst;
while (n-- > 0) *p++ = (CHAR)*src++;
return dst;
}
/* check if value type needs string conversion (Ansi<->Unicode) */
static inline int is_string( DWORD type )
{
@ -50,47 +42,6 @@ static inline int reg_server_call( enum request req )
return res;
}
/******************************************************************************
* RegCreateKeyExW [ADVAPI32.131]
*
* PARAMS
* hkey [I] Handle of an open key
* name [I] Address of subkey name
* reserved [I] Reserved - must be 0
* class [I] Address of class string
* options [I] Special options flag
* access [I] Desired security access
* sa [I] Address of key security structure
* retkey [O] Address of buffer for opened handle
* dispos [O] Receives REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
*
* NOTES
* in case of failing retkey remains untouched
*/
DWORD WINAPI RegCreateKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, LPWSTR class,
DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
LPHKEY retkey, LPDWORD dispos )
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW, classW;
if (reserved) return ERROR_INVALID_PARAMETER;
if (!(access & KEY_ALL_ACCESS) || (access & ~KEY_ALL_ACCESS)) return ERROR_ACCESS_DENIED;
attr.Length = sizeof(attr);
attr.RootDirectory = hkey;
attr.ObjectName = &nameW;
attr.Attributes = 0;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
RtlInitUnicodeString( &nameW, name );
RtlInitUnicodeString( &classW, class );
return RtlNtStatusToDosError( NtCreateKey( retkey, access, &attr, 0,
&classW, options, dispos ) );
}
/******************************************************************************
* RegCreateKeyExA [ADVAPI32.130]
*/
@ -129,18 +80,6 @@ DWORD WINAPI RegCreateKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, LPSTR clas
}
/******************************************************************************
* RegCreateKeyW [ADVAPI32.132]
*/
DWORD WINAPI RegCreateKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
{
/* FIXME: previous implementation converted ERROR_INVALID_HANDLE to ERROR_BADKEY, */
/* but at least my version of NT (4.0 SP5) doesn't do this. -- AJ */
return RegCreateKeyExW( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, retkey, NULL );
}
/******************************************************************************
* RegCreateKeyA [ADVAPI32.129]
*/
@ -152,43 +91,6 @@ DWORD WINAPI RegCreateKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
/******************************************************************************
* RegOpenKeyExW [ADVAPI32.150]
*
* Opens the specified key
*
* Unlike RegCreateKeyEx, this does not create the key if it does not exist.
*
* PARAMS
* hkey [I] Handle of open key
* name [I] Name of subkey to open
* reserved [I] Reserved - must be zero
* access [I] Security access mask
* retkey [O] Handle to open key
*
* RETURNS
* Success: ERROR_SUCCESS
* Failure: Error code
*
* NOTES
* in case of failing is retkey = 0
*/
DWORD WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
attr.Length = sizeof(attr);
attr.RootDirectory = hkey;
attr.ObjectName = &nameW;
attr.Attributes = 0;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
RtlInitUnicodeString( &nameW, name );
return RtlNtStatusToDosError( NtOpenKey( retkey, access, &attr ) );
}
/******************************************************************************
* RegOpenKeyExA [ADVAPI32.149]
*/
@ -217,27 +119,6 @@ DWORD WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, REGSAM acces
}
/******************************************************************************
* RegOpenKeyW [ADVAPI32.151]
*
* PARAMS
* hkey [I] Handle of open key
* name [I] Address of name of subkey to open
* retkey [O] Handle to open key
*
* RETURNS
* Success: ERROR_SUCCESS
* Failure: Error code
*
* NOTES
* in case of failing is retkey = 0
*/
DWORD WINAPI RegOpenKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
{
return RegOpenKeyExW( hkey, name, 0, KEY_ALL_ACCESS, retkey );
}
/******************************************************************************
* RegOpenKeyA [ADVAPI32.148]
*/
@ -247,91 +128,6 @@ DWORD WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
}
/******************************************************************************
* RegOpenCurrentUser [ADVAPI32]
* FIXME: This function is supposed to retrieve a handle to the
* HKEY_CURRENT_USER for the user the current thread is impersonating.
* Since Wine does not currently allow threads to impersonate other users,
* this stub should work fine.
*/
DWORD WINAPI RegOpenCurrentUser( REGSAM access, PHKEY retkey )
{
return RegOpenKeyExA( HKEY_CURRENT_USER, "", 0, access, retkey );
}
/******************************************************************************
* RegEnumKeyExW [ADVAPI32.139]
*
* PARAMS
* hkey [I] Handle to key to enumerate
* index [I] Index of subkey to enumerate
* name [O] Buffer for subkey name
* name_len [O] Size of subkey buffer
* reserved [I] Reserved
* class [O] Buffer for class string
* class_len [O] Size of class buffer
* ft [O] Time key last written to
*/
DWORD WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_len,
LPDWORD reserved, LPWSTR class, LPDWORD class_len, FILETIME *ft )
{
NTSTATUS status;
char buffer[256], *buf_ptr = buffer;
KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
DWORD total_size;
TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
name_len ? *name_len : -1, reserved, class, class_len, ft );
if (reserved) return ERROR_INVALID_PARAMETER;
status = NtEnumerateKey( hkey, index, KeyNodeInformation,
buffer, sizeof(buffer), &total_size );
while (status == STATUS_BUFFER_OVERFLOW)
{
/* retry with a dynamically allocated buffer */
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_NODE_INFORMATION *)buf_ptr;
status = NtEnumerateKey( hkey, index, KeyNodeInformation,
buf_ptr, total_size, &total_size );
}
if (!status)
{
DWORD len = info->NameLength / sizeof(WCHAR);
DWORD cls_len = info->ClassLength / sizeof(WCHAR);
if (ft) *ft = info->LastWriteTime;
if (len >= *name_len || (class_len && (cls_len >= *class_len)))
status = STATUS_BUFFER_OVERFLOW;
else
{
*name_len = len;
memcpy( name, info->Name, info->NameLength );
name[len] = 0;
if (class_len)
{
*class_len = cls_len;
if (class)
{
memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
class[cls_len] = 0;
}
}
}
}
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError( status );
}
/******************************************************************************
* RegEnumKeyExA [ADVAPI32.138]
*/
@ -399,15 +195,6 @@ DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len
}
/******************************************************************************
* RegEnumKeyW [ADVAPI32.140]
*/
DWORD WINAPI RegEnumKeyW( HKEY hkey, DWORD index, LPWSTR name, DWORD name_len )
{
return RegEnumKeyExW( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
}
/******************************************************************************
* RegEnumKeyA [ADVAPI32.137]
*/
@ -417,89 +204,6 @@ DWORD WINAPI RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
}
/******************************************************************************
* RegQueryInfoKeyW [ADVAPI32.153]
*
* PARAMS
* hkey [I] Handle to key to query
* class [O] Buffer for class string
* class_len [O] Size of class string buffer
* reserved [I] Reserved
* subkeys [O] Buffer for number of subkeys
* max_subkey [O] Buffer for longest subkey name length
* max_class [O] Buffer for longest class string length
* values [O] Buffer for number of value entries
* max_value [O] Buffer for longest value name length
* max_data [O] Buffer for longest value data length
* security [O] Buffer for security descriptor length
* modif [O] Modification time
*
* - win95 allows class to be valid and class_len to be NULL
* - winnt returns ERROR_INVALID_PARAMETER if class is valid and class_len is NULL
* - both allow class to be NULL and class_len to be NULL
* (it's hard to test validity, so test !NULL instead)
*/
DWORD WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPDWORD reserved,
LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
LPDWORD values, LPDWORD max_value, LPDWORD max_data,
LPDWORD security, FILETIME *modif )
{
NTSTATUS status;
char buffer[256], *buf_ptr = buffer;
KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
DWORD total_size;
TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
if (class && !class_len && !(GetVersion() & 0x80000000 /*NT*/))
return ERROR_INVALID_PARAMETER;
status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
if (class)
{
/* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW)
{
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_FULL_INFORMATION *)buf_ptr;
status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
}
if (!status)
{
if (class_len && (info->ClassLength/sizeof(WCHAR) + 1 > *class_len))
{
status = STATUS_BUFFER_OVERFLOW;
}
else
{
memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
class[info->ClassLength/sizeof(WCHAR)] = 0;
}
}
}
if (!status || status == STATUS_BUFFER_OVERFLOW)
{
if (class_len) *class_len = info->ClassLength / sizeof(WCHAR);
if (subkeys) *subkeys = info->SubKeys;
if (max_subkey) *max_subkey = info->MaxNameLen;
if (max_class) *max_class = info->MaxClassLen;
if (values) *values = info->Values;
if (max_value) *max_value = info->MaxValueNameLen;
if (max_data) *max_data = info->MaxValueDataLen;
if (modif) *modif = info->LastWriteTime;
}
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError( status );
}
/******************************************************************************
* RegQueryInfoKeyA [ADVAPI32.152]
*/
@ -590,32 +294,6 @@ DWORD WINAPI RegCloseKey( HKEY hkey )
}
/******************************************************************************
* RegDeleteKeyW [ADVAPI32.134]
*
* PARAMS
* hkey [I] Handle to open key
* name [I] Name of subkey to delete
*
* RETURNS
* Success: ERROR_SUCCESS
* Failure: Error code
*/
DWORD WINAPI RegDeleteKeyW( HKEY hkey, LPCWSTR name )
{
DWORD ret;
HKEY tmp;
if (!name || !*name) return NtDeleteKey( hkey );
if (!(ret = RegOpenKeyExW( hkey, name, 0, 0, &tmp )))
{
ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
RegCloseKey( tmp );
}
return ret;
}
/******************************************************************************
* RegDeleteKeyA [ADVAPI32.133]
*/
@ -635,45 +313,6 @@ DWORD WINAPI RegDeleteKeyA( HKEY hkey, LPCSTR name )
/******************************************************************************
* RegSetValueExW [ADVAPI32.170]
*
* Sets the data and type of a value under a register key
*
* PARAMS
* hkey [I] Handle of key to set value for
* name [I] Name of value to set
* reserved [I] Reserved - must be zero
* type [I] Flag for value type
* data [I] Address of value data
* count [I] Size of value data
*
* RETURNS
* Success: ERROR_SUCCESS
* Failure: Error code
*
* NOTES
* win95 does not care about count for REG_SZ and finds out the len by itself (js)
* NT does definitely care (aj)
*/
DWORD WINAPI RegSetValueExW( HKEY hkey, LPCWSTR name, DWORD reserved,
DWORD type, CONST BYTE *data, DWORD count )
{
UNICODE_STRING nameW;
if (count && is_string(type))
{
LPCWSTR str = (LPCWSTR)data;
/* if user forgot to count terminating null, add it (yes NT does this) */
if (str[count / sizeof(WCHAR) - 1] && !str[count / sizeof(WCHAR)])
count += sizeof(WCHAR);
}
RtlInitUnicodeString( &nameW, name );
return RtlNtStatusToDosError( NtSetValueKey( hkey, &nameW, 0, type, data, count ) );
}
/******************************************************************************
* RegSetValueExA [ADVAPI32.169]
*/
@ -713,30 +352,6 @@ DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
}
/******************************************************************************
* RegSetValueW [ADVAPI32.171]
*/
DWORD WINAPI RegSetValueW( HKEY hkey, LPCWSTR name, DWORD type, LPCWSTR data, DWORD count )
{
HKEY subkey = hkey;
DWORD ret;
TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_w(name), type, debugstr_w(data), count );
if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
if (name && name[0]) /* need to create the subkey */
{
if ((ret = RegCreateKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
}
ret = RegSetValueExW( subkey, NULL, 0, REG_SZ, (LPBYTE)data,
(strlenW( data ) + 1) * sizeof(WCHAR) );
if (subkey != hkey) RegCloseKey( subkey );
return ret;
}
/******************************************************************************
* RegSetValueA [ADVAPI32.168]
*/
@ -760,86 +375,6 @@ DWORD WINAPI RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWOR
/******************************************************************************
* RegQueryValueExW [ADVAPI32.158]
*
* Retrieves type and data for a specified name associated with an open key
*
* PARAMS
* hkey [I] Handle of key to query
* name [I] Name of value to query
* reserved [I] Reserved - must be NULL
* type [O] Address of buffer for value type. If NULL, the type
* is not required.
* data [O] Address of data buffer. If NULL, the actual data is
* not required.
* count [I/O] Address of data buffer size
*
* RETURNS
* ERROR_SUCCESS: Success
* ERROR_MORE_DATA: !!! if the specified buffer is not big enough to hold the data
* buffer is left untouched. The MS-documentation is wrong (js) !!!
*/
DWORD WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDWORD type,
LPBYTE data, LPDWORD count )
{
NTSTATUS status;
UNICODE_STRING name_str;
DWORD total_size;
char buffer[256], *buf_ptr = buffer;
KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
static const int info_size = sizeof(*info) - sizeof(info->Data);
TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
hkey, debugstr_w(name), reserved, type, data, count, count ? *count : 0 );
if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
RtlInitUnicodeString( &name_str, name );
if (data) total_size = min( sizeof(buffer), *count + info_size );
else total_size = info_size;
status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
buffer, total_size, &total_size );
if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
if (data)
{
/* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count)
{
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
buf_ptr, total_size, &total_size );
}
if (!status)
{
memcpy( data, buf_ptr + info_size, total_size - info_size );
/* 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 (total_size - info_size <= *count-sizeof(WCHAR) && is_string(info->Type))
{
WCHAR *ptr = (WCHAR *)(data + total_size - info_size);
if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
}
}
else if (status != STATUS_BUFFER_OVERFLOW) goto done;
}
if (type) *type = info->Type;
if (count) *count = total_size - info_size;
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError(status);
}
/******************************************************************************
* RegQueryValueExA [ADVAPI32.157]
*
@ -930,33 +465,6 @@ DWORD WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD
}
/******************************************************************************
* RegQueryValueW [ADVAPI32.159]
*/
DWORD WINAPI RegQueryValueW( HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count )
{
DWORD ret;
HKEY subkey = hkey;
TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_w(name), data, count ? *count : 0 );
if (name && name[0])
{
if ((ret = RegOpenKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
}
ret = RegQueryValueExW( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
if (subkey != hkey) RegCloseKey( subkey );
if (ret == ERROR_FILE_NOT_FOUND)
{
/* return empty string if default value not found */
if (data) *data = 0;
if (count) *count = 1;
ret = ERROR_SUCCESS;
}
return ret;
}
/******************************************************************************
* RegQueryValueA [ADVAPI32.156]
*/
@ -984,78 +492,17 @@ DWORD WINAPI RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
}
/******************************************************************************
* RegEnumValueW [ADVAPI32.142]
*
* PARAMS
* hkey [I] Handle to key to query
* index [I] Index of value to query
* value [O] Value string
* val_count [I/O] Size of value buffer (in wchars)
* reserved [I] Reserved
* type [O] Type code
* data [O] Value data
* count [I/O] Size of data buffer (in bytes)
*/
DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_count,
LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
{
DWORD ret, len;
struct enum_key_value_request *req = get_req_buffer();
TRACE("(%x,%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;
req->hkey = hkey;
req->index = index;
req->offset = 0;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
len = strlenW( req->name ) + 1;
if (len > *val_count) return ERROR_MORE_DATA;
memcpy( value, req->name, len * sizeof(WCHAR) );
*val_count = len - 1;
if (data)
{
if (*count < req->len) ret = ERROR_MORE_DATA;
else
{
/* copy the data */
unsigned int max = server_remaining( req->data );
unsigned int pos = 0;
while (pos < req->len)
{
unsigned int len = min( req->len - pos, max );
memcpy( data + pos, req->data, len );
if ((pos += len) >= req->len) break;
req->offset = pos;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
}
}
/* 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 (req->len && is_string(req->type) &&
(req->len < *count) && ((WCHAR *)data)[req->len-1]) ((WCHAR *)data)[req->len] = 0;
}
if (type) *type = req->type;
if (count) *count = req->len;
return ret;
}
/******************************************************************************
* RegEnumValueA [ADVAPI32.141]
*/
DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
{
DWORD ret, len, total_len;
struct enum_key_value_request *req = get_req_buffer();
NTSTATUS status;
DWORD total_size;
char buffer[256], *buf_ptr = buffer;
KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
static const int info_size = sizeof(*info) - sizeof(info->Name);
TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
hkey, index, value, val_count, reserved, type, data, count );
@ -1063,69 +510,84 @@ DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_cou
/* NT only checks count, not val_count */
if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
req->hkey = hkey;
req->index = index;
req->offset = 0;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
if (data) total_size += *count;
total_size = min( sizeof(buffer), total_size );
len = strlenW( req->name ) + 1;
if (len > *val_count) return ERROR_MORE_DATA;
memcpyWtoA( value, req->name, len );
*val_count = len - 1;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
buffer, total_size, &total_size );
if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
total_len = is_string( req->type ) ? req->len/sizeof(WCHAR) : req->len;
if (data)
/* 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 (*count < total_len) ret = ERROR_MORE_DATA;
else
/* retry with a dynamically allocated buffer */
while (status == STATUS_BUFFER_OVERFLOW)
{
/* copy the data */
unsigned int max = server_remaining( req->data );
unsigned int pos = 0;
while (pos < req->len)
{
unsigned int len = min( req->len - pos, max );
if (is_string( req->type ))
memcpyWtoA( data + pos/sizeof(WCHAR), (WCHAR *)req->data, len/sizeof(WCHAR) );
else
memcpy( data + pos, req->data, len );
if ((pos += len) >= req->len) break;
req->offset = pos;
if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
}
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
return ERROR_NOT_ENOUGH_MEMORY;
info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
buf_ptr, total_size, &total_size );
}
if (status) goto done;
if (value)
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
NULL, 0, NULL, NULL );
if (len >= *val_count)
{
status = STATUS_BUFFER_OVERFLOW;
goto done;
}
WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
value, len, NULL, NULL );
value[len] = 0;
*val_count = len;
}
if (is_string(info->Type))
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
(total_size - info->DataOffset) / sizeof(WCHAR),
NULL, 0, NULL, NULL );
if (data && len)
{
if (len > *count)
{
status = STATUS_BUFFER_OVERFLOW;
goto done;
}
WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
(total_size - info->DataOffset) / sizeof(WCHAR),
data, len, NULL, NULL );
/* 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;
}
else if (data)
{
if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
}
/* 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 (total_len && is_string(req->type) && (total_len < *count) && data[total_len-1])
data[total_len] = 0;
}
if (count) *count = total_len;
if (type) *type = req->type;
return ret;
if (type) *type = info->Type;
if (count) *count = info->DataLength;
done:
if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
return RtlNtStatusToDosError(status);
}
/******************************************************************************
* RegDeleteValueW [ADVAPI32.136]
*
* PARAMS
* hkey [I] handle to key
* name [I] name of value to delete
*
* RETURNS
* error status
*/
DWORD WINAPI RegDeleteValueW( HKEY hkey, LPCWSTR name )
{
UNICODE_STRING nameW;
RtlInitUnicodeString( &nameW, name );
return RtlNtStatusToDosError( NtDeleteValueKey( hkey, &nameW ) );
}
/******************************************************************************
* RegDeleteValueA [ADVAPI32.135]
*/
@ -1146,51 +608,6 @@ DWORD WINAPI RegDeleteValueA( HKEY hkey, LPCSTR name )
}
/******************************************************************************
* RegLoadKeyW [ADVAPI32.185]
*
* PARAMS
* hkey [I] Handle of open key
* subkey [I] Address of name of subkey
* filename [I] Address of filename for registry information
*/
LONG WINAPI RegLoadKeyW( HKEY hkey, LPCWSTR subkey, LPCWSTR filename )
{
HANDLE file;
DWORD ret, len, err = GetLastError();
TRACE( "(%x,%s,%s)\n", hkey, debugstr_w(subkey), debugstr_w(filename) );
if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
len = strlenW( subkey ) * sizeof(WCHAR);
if (len > MAX_PATH*sizeof(WCHAR)) return ERROR_INVALID_PARAMETER;
if ((file = CreateFileW( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, -1 )) == INVALID_HANDLE_VALUE)
{
ret = GetLastError();
goto done;
}
SERVER_START_REQ
{
struct load_registry_request *req = server_alloc_req( sizeof(*req), len );
req->hkey = hkey;
req->file = file;
memcpy( server_data_ptr(req), subkey, len );
ret = reg_server_call( REQ_LOAD_REGISTRY );
}
SERVER_END_REQ;
CloseHandle( file );
done:
SetLastError( err ); /* restore the last error code */
return ret;
}
/******************************************************************************
* RegLoadKeyA [ADVAPI32.184]
*/
@ -1291,15 +708,3 @@ done:
SetLastError( err ); /* restore last error code */
return ret;
}
/******************************************************************************
* RegSaveKeyW [ADVAPI32.166]
*/
LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa )
{
LPSTR fileA = HEAP_strdupWtoA( GetProcessHeap(), 0, file );
DWORD ret = RegSaveKeyA( hkey, fileA, sa );
if (fileA) HeapFree( GetProcessHeap(), 0, fileA );
return ret;
}

View File

@ -792,7 +792,7 @@ static void set_value( struct key *key, WCHAR *name, int type, unsigned int tota
}
/* get a key value */
static size_t get_value( struct key *key, WCHAR *name, unsigned int offset,
static size_t get_value( struct key *key, const WCHAR *name, unsigned int offset,
unsigned int maxlen, int *type, int *len, void *data )
{
struct key_value *value;
@ -820,25 +820,50 @@ static size_t get_value( struct key *key, WCHAR *name, unsigned int offset,
}
/* enumerate a key value */
static void enum_value( struct key *key, int i, WCHAR *name, unsigned int offset,
unsigned int maxlen, int *type, int *len, void *data )
static size_t enum_value( struct key *key, int i, unsigned int offset,
unsigned int maxlen, int *type, int *len, void *data )
{
struct key_value *value;
size_t ret = 0;
if (i < 0 || i > key->last_value) set_error( STATUS_NO_MORE_ENTRIES );
else
{
WCHAR *name_ptr = data;
value = &key->values[i];
strcpyW( name, value->name );
*type = value->type;
*len = value->len;
if (value->data && offset < value->len)
if (maxlen >= sizeof(WCHAR))
{
if (maxlen > value->len - offset) maxlen = value->len - offset;
memcpy( data, (char *)value->data + offset, maxlen );
size_t name_len = 0;
/* copy the name only the first time (offset==0),
* otherwise store an empty name in the buffer
*/
maxlen -= sizeof(WCHAR);
ret += sizeof(WCHAR);
if (!offset)
{
name_len = strlenW( value->name ) * sizeof(WCHAR);
if (name_len > maxlen) name_len = maxlen;
}
*name_ptr++ = name_len;
memcpy( name_ptr, value->name, name_len );
maxlen -= name_len;
ret += name_len;
data = (char *)name_ptr + name_len;
if (value->data && offset < value->len)
{
if (maxlen > value->len - offset) maxlen = value->len - offset;
memcpy( data, (char *)value->data + offset, maxlen );
ret += maxlen;
}
}
if (debug_level > 1) dump_operation( key, value, "Enum" );
}
return ret;
}
/* delete a value */
@ -1674,16 +1699,16 @@ DECL_HANDLER(get_key_value)
DECL_HANDLER(enum_key_value)
{
struct key *key;
unsigned int max = get_req_size( req, req->data, sizeof(req->data[0]) );
size_t len = 0;
req->len = 0;
req->name[0] = 0;
if ((key = get_hkey_obj( req->hkey, KEY_QUERY_VALUE )))
{
enum_value( key, req->index, req->name, req->offset, max,
&req->type, &req->len, req->data );
len = enum_value( key, req->index, req->offset, get_req_data_size(req),
&req->type, &req->len, get_req_data(req) );
release_object( key );
}
set_req_data_size( req, len );
}
/* delete a value of a registry key */

View File

@ -365,6 +365,9 @@ void open_master_socket(void)
struct sockaddr_un addr;
int fd, slen;
/* make sure no request is larger than the maximum size */
assert( sizeof(union generic_request) == sizeof(struct request_max_size) );
create_server_dir();
if ((fd = socket( AF_UNIX, SOCK_STREAM, 0 )) == -1) fatal_perror( "socket" );
addr.sun_family = AF_UNIX;

View File

@ -66,31 +66,6 @@ inline static void set_req_data_size( const void *req, size_t size )
((struct request_header *)req)->var_size = size;
}
#define REQUEST_END(req) ((char *)(req) + MAX_REQUEST_LENGTH - sizeof(struct server_buffer_info))
/* get the remaining size in the request buffer for object of a given size */
static inline int get_req_size( const void *req, const void *ptr, size_t typesize )
{
return (REQUEST_END(req) - (char *)ptr) / typesize;
}
/* get the length of a request string, without going past the end of the request */
static inline size_t get_req_strlen( const void *req, const char *str )
{
const char *p = str;
while (*p && (p < REQUEST_END(req) - 1)) p++;
return p - str;
}
/* same as above for Unicode */
static inline size_t get_req_strlenW( const void *req, const WCHAR *str )
{
const WCHAR *p = str;
while (*p && (p < (WCHAR *)REQUEST_END(req) - 1)) p++;
return p - str;
}
/* Everything below this line is generated automatically by tools/make_requests */
/* ### make_requests begin ### */

View File

@ -42,26 +42,6 @@ static void dump_uints( const int *ptr, int len )
fputc( '}', stderr );
}
static void dump_bytes( const unsigned char *ptr, int len )
{
fputc( '{', stderr );
while (len > 0)
{
fprintf( stderr, "%02x", *ptr++ );
if (--len) fputc( ',', stderr );
}
fputc( '}', stderr );
}
static void dump_path_t( const void *req, const path_t *path )
{
const WCHAR *str = *path;
size_t len = get_req_strlenW( req, str );
fprintf( stderr, "L\"" );
dump_strW( str, len, stderr, "\"\"" );
fputc( '\"', stderr );
}
static void dump_context( const CONTEXT *context )
{
#ifdef __i386__
@ -261,14 +241,6 @@ static size_t dump_varargs_input_records( const void *req )
return get_size(req);
}
/* dumping for functions for requests that have a variable part */
static void dump_varargs_enum_key_value_reply( const struct enum_key_value_request *req )
{
int count = min( req->len - req->offset, get_req_size( req, req->data, 1 ));
dump_bytes( req->data, count );
}
typedef void (*dump_func)( const void *req );
/* Everything below this line is generated automatically by tools/make_requests */
@ -1224,10 +1196,10 @@ static void dump_enum_key_value_reply( const struct enum_key_value_request *req
fprintf( stderr, " type=%d,", req->type );
fprintf( stderr, " len=%d,", req->len );
fprintf( stderr, " name=" );
dump_path_t( req, &req->name );
fprintf( stderr, "," );
cur_pos += dump_varargs_unicode_len_str( req );
fputc( ',', stderr );
fprintf( stderr, " data=" );
dump_varargs_enum_key_value_reply( req );
cur_pos += dump_varargs_bytes( req );
}
static void dump_delete_key_value_request( const struct delete_key_value_request *req )