Alexandre Goujon : kernel32: Fix GetComputerName errors.
Alexandre Julliard
julliard at winehq.org
Mon Aug 23 10:50:16 CDT 2010
Module: wine
Branch: master
Commit: 49c5bd0365ebb32bb1bb9faf55cb587d4e407513
URL: http://source.winehq.org/git/wine.git/?a=commit;h=49c5bd0365ebb32bb1bb9faf55cb587d4e407513
Author: Alexandre Goujon <ale.goujon at gmail.com>
Date: Sun Aug 22 11:40:00 2010 +0200
kernel32: Fix GetComputerName errors.
---
dlls/kernel32/computername.c | 30 +++++++++++++++++++++++-------
dlls/kernel32/tests/environ.c | 2 --
2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/dlls/kernel32/computername.c b/dlls/kernel32/computername.c
index f710d7c..dabaae8 100644
--- a/dlls/kernel32/computername.c
+++ b/dlls/kernel32/computername.c
@@ -316,23 +316,33 @@ BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
DWORD len = sizeof( buf );
LPWSTR theName = (LPWSTR) (buf + offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ));
NTSTATUS st = STATUS_INVALID_PARAMETER;
+ DWORD err = ERROR_SUCCESS;
TRACE ("%p %p\n", name, size);
_init_attr ( &attr, &nameW );
RtlInitUnicodeString( &nameW, ComputerW );
if ( ( st = NtOpenKey( &hkey, KEY_READ, &attr ) ) != STATUS_SUCCESS )
+ {
+ err = RtlNtStatusToDosError ( st );
goto out;
+ }
attr.RootDirectory = hkey;
RtlInitUnicodeString( &nameW, ActiveComputerNameW );
if ( ( st = NtOpenKey( &hsubkey, KEY_READ, &attr ) ) != STATUS_SUCCESS )
+ {
+ err = RtlNtStatusToDosError ( st );
goto out;
+ }
RtlInitUnicodeString( &nameW, ComputerNameW );
if ( ( st = NtQueryValueKey( hsubkey, &nameW, KeyValuePartialInformation, buf, len, &len ) )
!= STATUS_SUCCESS )
+ {
+ err = RtlNtStatusToDosError ( st );
goto out;
+ }
len = (len -offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data )) / sizeof (WCHAR) - 1;
TRACE ("ComputerName is %s (length %u)\n", debugstr_w ( theName ), len);
@@ -340,25 +350,24 @@ BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
if ( *size < len + 1 )
{
*size = len + 1;
- st = STATUS_MORE_ENTRIES;
+ err = ERROR_BUFFER_OVERFLOW;
}
else
{
memcpy ( name, theName, len * sizeof (WCHAR) );
name[len] = 0;
*size = len;
- st = STATUS_SUCCESS;
}
out:
NtClose ( hsubkey );
NtClose ( hkey );
- if ( st == STATUS_SUCCESS )
+ if ( err == ERROR_SUCCESS )
return TRUE;
else
{
- SetLastError ( RtlNtStatusToDosError ( st ) );
+ SetLastError ( err );
WARN ( "Status %u reading computer name from registry\n", st );
return FALSE;
}
@@ -383,7 +392,7 @@ BOOL WINAPI GetComputerNameA(LPSTR name, LPDWORD size)
if ( *size < len )
{
*size = len;
- SetLastError( ERROR_MORE_DATA );
+ SetLastError( ERROR_BUFFER_OVERFLOW );
ret = FALSE;
}
else
@@ -415,7 +424,11 @@ BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT type, LPSTR name, LPDWORD si
{
case ComputerNameNetBIOS:
case ComputerNamePhysicalNetBIOS:
- return GetComputerNameA (name, size);
+ ret = GetComputerNameA (name, size);
+ if (!ret && GetLastError() == ERROR_BUFFER_OVERFLOW)
+ SetLastError( ERROR_MORE_DATA );
+ return ret;
+
case ComputerNameDnsHostname:
case ComputerNamePhysicalDnsHostname:
ret = dns_hostname (buf, &len);
@@ -468,7 +481,10 @@ BOOL WINAPI GetComputerNameExW( COMPUTER_NAME_FORMAT type, LPWSTR name, LPDWORD
{
case ComputerNameNetBIOS:
case ComputerNamePhysicalNetBIOS:
- return GetComputerNameW (name, size);
+ ret = GetComputerNameW (name, size);
+ if (!ret && GetLastError() == ERROR_BUFFER_OVERFLOW)
+ SetLastError( ERROR_MORE_DATA );
+ return ret;
case ComputerNameDnsHostname:
case ComputerNamePhysicalDnsHostname:
ret = dns_hostname (buf, &len);
diff --git a/dlls/kernel32/tests/environ.c b/dlls/kernel32/tests/environ.c
index 19d11b5..c38aef7 100644
--- a/dlls/kernel32/tests/environ.c
+++ b/dlls/kernel32/tests/environ.c
@@ -330,7 +330,6 @@ static void test_GetComputerName(void)
size = 0;
ret = GetComputerNameA((LPSTR)0xdeadbeef, &size);
error = GetLastError();
- todo_wine
ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameA should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
/* Only Vista returns the computer name length as documented in the MSDN */
@@ -362,7 +361,6 @@ static void test_GetComputerName(void)
win_skip("GetComputerNameW is not implemented\n");
else
{
- todo_wine
ok(!ret && error == ERROR_BUFFER_OVERFLOW, "GetComputerNameW should have failed with ERROR_BUFFER_OVERFLOW instead of %d\n", error);
size++; /* nul terminating character */
nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(nameW[0]));
More information about the wine-cvs
mailing list