fix some kernel32 environ winetests

svn path=/trunk/; revision=36020
This commit is contained in:
Christoph von Wittich 2008-09-07 09:19:49 +00:00
parent 714e5fdc39
commit 26fef2b1c8

View file

@ -35,9 +35,9 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey, static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
LPWSTR ValueNameStr, LPWSTR ValueNameStr,
LPWSTR lpBuffer, LPWSTR lpBuffer,
LPDWORD nSize ) { LPDWORD nSize ) {
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo; PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
@ -49,62 +49,63 @@ static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
RtlInitUnicodeString (&KeyName,RegistryKey); RtlInitUnicodeString (&KeyName,RegistryKey);
InitializeObjectAttributes (&ObjectAttributes, InitializeObjectAttributes (&ObjectAttributes,
&KeyName, &KeyName,
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = ZwOpenKey (&KeyHandle, Status = ZwOpenKey (&KeyHandle,
KEY_READ, KEY_READ,
&ObjectAttributes); &ObjectAttributes);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
return FALSE; return FALSE;
} }
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
*nSize * sizeof(WCHAR); *nSize * sizeof(WCHAR);
KeyInfo = RtlAllocateHeap (RtlGetProcessHeap (), KeyInfo = RtlAllocateHeap (RtlGetProcessHeap (),
0, 0,
KeyInfoSize); KeyInfoSize);
if (KeyInfo == NULL) if (KeyInfo == NULL)
{ {
ZwClose (KeyHandle); ZwClose (KeyHandle);
SetLastError (ERROR_OUTOFMEMORY); SetLastError (ERROR_OUTOFMEMORY);
return FALSE; return FALSE;
} }
RtlInitUnicodeString (&ValueName,ValueNameStr); RtlInitUnicodeString (&ValueName,ValueNameStr);
Status = ZwQueryValueKey (KeyHandle, Status = ZwQueryValueKey (KeyHandle,
&ValueName, &ValueName,
KeyValuePartialInformation, KeyValuePartialInformation,
KeyInfo, KeyInfo,
KeyInfoSize, KeyInfoSize,
&ReturnSize); &ReturnSize);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
RtlFreeHeap (RtlGetProcessHeap (), RtlFreeHeap (RtlGetProcessHeap (),
0, 0,
KeyInfo); KeyInfo);
ZwClose (KeyHandle); ZwClose (KeyHandle);
SetLastErrorByStatus (Status); *nSize = ReturnSize;
return FALSE; SetLastErrorByStatus (Status);
return FALSE;
} }
if( *nSize > (KeyInfo->DataLength / sizeof(WCHAR)) ) { if( *nSize > (KeyInfo->DataLength / sizeof(WCHAR)) ) {
*nSize = KeyInfo->DataLength / sizeof(WCHAR); *nSize = KeyInfo->DataLength / sizeof(WCHAR);
lpBuffer[*nSize] = 0; lpBuffer[*nSize] = 0;
(*nSize)--;
} }
RtlCopyMemory (lpBuffer, RtlCopyMemory (lpBuffer,
KeyInfo->Data, KeyInfo->Data,
*nSize * sizeof(WCHAR)); *nSize * sizeof(WCHAR));
RtlFreeHeap (RtlGetProcessHeap (), RtlFreeHeap (RtlGetProcessHeap (),
0, 0,
KeyInfo) KeyInfo);
;
ZwClose (KeyHandle); ZwClose (KeyHandle);
return TRUE; return TRUE;
@ -124,23 +125,25 @@ GetComputerNameExW (
UNICODE_STRING DomainPart; UNICODE_STRING DomainPart;
RTL_QUERY_REGISTRY_TABLE QueryTable[2]; RTL_QUERY_REGISTRY_TABLE QueryTable[2];
NTSTATUS Status; NTSTATUS Status;
BOOL ret = TRUE;
DWORD HostSize;
switch( NameType ) { switch( NameType ) {
case ComputerNameNetBIOS: case ComputerNameNetBIOS:
return GetComputerNameFromRegistry return GetComputerNameFromRegistry
( L"\\Registry\\Machine\\System\\CurrentControlSet" ( L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Control\\ComputerName\\ComputerName", L"\\Control\\ComputerName\\ComputerName",
L"ComputerName", L"ComputerName",
lpBuffer, lpBuffer,
nSize ); nSize );
case ComputerNameDnsDomain: case ComputerNameDnsDomain:
return GetComputerNameFromRegistry return GetComputerNameFromRegistry
( L"\\Registry\\Machine\\System\\CurrentControlSet" ( L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Services\\Tcpip\\Parameters", L"\\Services\\Tcpip\\Parameters",
L"Domain", L"Domain",
lpBuffer, lpBuffer,
nSize ); nSize );
case ComputerNameDnsFullyQualified: case ComputerNameDnsFullyQualified:
ResultString.Length = 0; ResultString.Length = 0;
@ -152,7 +155,7 @@ GetComputerNameExW (
QueryTable[0].Name = L"HostName"; QueryTable[0].Name = L"HostName";
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[0].EntryContext = &DomainPart; QueryTable[0].EntryContext = &DomainPart;
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE, Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
L"\\Registry\\Machine\\System" L"\\Registry\\Machine\\System"
L"\\CurrentControlSet\\Services\\Tcpip" L"\\CurrentControlSet\\Services\\Tcpip"
@ -160,7 +163,11 @@ GetComputerNameExW (
QueryTable, NULL, NULL); QueryTable, NULL, NULL);
if( NT_SUCCESS(Status) ) { if( NT_SUCCESS(Status) ) {
RtlAppendUnicodeStringToString(&ResultString, &DomainPart); Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
HostSize = DomainPart.Length;
if (!NT_SUCCESS(Status)) {
ret = FALSE;
}
RtlAppendUnicodeToString(&ResultString, L"."); RtlAppendUnicodeToString(&ResultString, L".");
RtlFreeUnicodeString(&DomainPart); RtlFreeUnicodeString(&DomainPart);
@ -176,43 +183,49 @@ GetComputerNameExW (
QueryTable, NULL, NULL); QueryTable, NULL, NULL);
if( NT_SUCCESS(Status) ) { if( NT_SUCCESS(Status) ) {
RtlAppendUnicodeStringToString(&ResultString, &DomainPart); Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
if ( (!NT_SUCCESS(Status)) || (!ret)) {
*nSize = HostSize + DomainPart.Length;
SetLastError(ERROR_MORE_DATA);
RtlFreeUnicodeString(&DomainPart);
return FALSE;
}
RtlFreeUnicodeString(&DomainPart); RtlFreeUnicodeString(&DomainPart);
*nSize = ResultString.Length / sizeof(WCHAR); *nSize = ResultString.Length / sizeof(WCHAR) - 1;
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
case ComputerNameDnsHostname: case ComputerNameDnsHostname:
return GetComputerNameFromRegistry return GetComputerNameFromRegistry
( L"\\Registry\\Machine\\System\\CurrentControlSet" ( L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Services\\Tcpip\\Parameters", L"\\Services\\Tcpip\\Parameters",
L"Hostname", L"Hostname",
lpBuffer, lpBuffer,
nSize ); nSize );
case ComputerNamePhysicalDnsDomain: case ComputerNamePhysicalDnsDomain:
return GetComputerNameFromRegistry return GetComputerNameFromRegistry
( L"\\Registry\\Machine\\System\\CurrentControlSet" ( L"\\Registry\\Machine\\System\\CurrentControlSet"
L"\\Services\\Tcpip\\Parameters", L"\\Services\\Tcpip\\Parameters",
L"Domain", L"Domain",
lpBuffer, lpBuffer,
nSize ); nSize );
/* XXX Redo these */ /* XXX Redo these */
case ComputerNamePhysicalDnsFullyQualified: case ComputerNamePhysicalDnsFullyQualified:
return GetComputerNameExW( ComputerNameDnsFullyQualified, return GetComputerNameExW( ComputerNameDnsFullyQualified,
lpBuffer, nSize ); lpBuffer, nSize );
case ComputerNamePhysicalDnsHostname: case ComputerNamePhysicalDnsHostname:
return GetComputerNameExW( ComputerNameDnsHostname, return GetComputerNameExW( ComputerNameDnsHostname,
lpBuffer, nSize ); lpBuffer, nSize );
case ComputerNamePhysicalNetBIOS: case ComputerNamePhysicalNetBIOS:
return GetComputerNameExW( ComputerNameNetBIOS, return GetComputerNameExW( ComputerNameNetBIOS,
lpBuffer, nSize ); lpBuffer, nSize );
case ComputerNameMax: case ComputerNameMax:
return FALSE; return FALSE;
} }
return FALSE; return FALSE;
@ -235,7 +248,7 @@ GetComputerNameExA (
PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) ); PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
if( !TempBuffer ) { if( !TempBuffer ) {
return ERROR_OUTOFMEMORY; return ERROR_OUTOFMEMORY;
} }
AnsiString.MaximumLength = (USHORT)*nSize; AnsiString.MaximumLength = (USHORT)*nSize;
@ -245,13 +258,13 @@ GetComputerNameExA (
Result = GetComputerNameExW( NameType, TempBuffer, nSize ); Result = GetComputerNameExW( NameType, TempBuffer, nSize );
if( Result ) { if( Result ) {
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR); UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR); UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
UnicodeString.Buffer = TempBuffer; UnicodeString.Buffer = TempBuffer;
RtlUnicodeStringToAnsiString (&AnsiString, RtlUnicodeStringToAnsiString (&AnsiString,
&UnicodeString, &UnicodeString,
FALSE); FALSE);
} }
RtlFreeHeap( RtlGetProcessHeap(), 0, TempBuffer ); RtlFreeHeap( RtlGetProcessHeap(), 0, TempBuffer );