2002-11-15 02:01:47 +01:00
|
|
|
/*
|
|
|
|
* Win32 kernel functions
|
|
|
|
*
|
|
|
|
* Copyright 1995 Martin von Loewis and Cameron Heide
|
|
|
|
* Copyright 1999 Peter Ganten
|
|
|
|
* Copyright 2002 Martin Wilck
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-11-15 02:01:47 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-11-15 02:01:47 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-11-15 02:01:47 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2002-11-19 00:12:15 +01:00
|
|
|
#include "winnls.h"
|
2002-11-15 02:01:47 +01:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "wine/exception.h"
|
|
|
|
|
2005-06-14 13:42:34 +02:00
|
|
|
#include "kernel_private.h"
|
|
|
|
|
2002-11-15 02:01:47 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetComputerNameW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
|
|
|
|
{
|
2019-12-12 19:19:12 +01:00
|
|
|
BOOL ret = GetComputerNameExW( ComputerNameNetBIOS, name, size );
|
|
|
|
if (!ret && GetLastError() == ERROR_MORE_DATA) SetLastError( ERROR_BUFFER_OVERFLOW );
|
|
|
|
return ret;
|
2002-11-15 02:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetComputerNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetComputerNameA(LPSTR name, LPDWORD size)
|
|
|
|
{
|
|
|
|
WCHAR nameW[ MAX_COMPUTERNAME_LENGTH + 1 ];
|
2007-03-03 04:03:53 +01:00
|
|
|
DWORD sizeW = MAX_COMPUTERNAME_LENGTH + 1;
|
2004-08-11 01:43:21 +02:00
|
|
|
unsigned int len;
|
2002-11-15 02:01:47 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if ( !GetComputerNameW (nameW, &sizeW) ) return FALSE;
|
|
|
|
|
2007-02-16 00:22:18 +01:00
|
|
|
len = WideCharToMultiByte ( CP_ACP, 0, nameW, -1, NULL, 0, NULL, 0 );
|
|
|
|
/* for compatibility with Win9x */
|
2002-11-15 02:01:47 +01:00
|
|
|
__TRY
|
|
|
|
{
|
2007-03-03 04:03:53 +01:00
|
|
|
if ( *size < len )
|
2002-11-15 02:01:47 +01:00
|
|
|
{
|
2007-03-03 04:03:53 +01:00
|
|
|
*size = len;
|
2010-08-22 11:40:00 +02:00
|
|
|
SetLastError( ERROR_BUFFER_OVERFLOW );
|
2002-11-15 02:01:47 +01:00
|
|
|
ret = FALSE;
|
|
|
|
}
|
2007-03-03 04:03:53 +01:00
|
|
|
else
|
2002-11-15 02:01:47 +01:00
|
|
|
{
|
2007-02-16 00:22:18 +01:00
|
|
|
WideCharToMultiByte ( CP_ACP, 0, nameW, -1, name, len, NULL, 0 );
|
2007-03-03 04:03:53 +01:00
|
|
|
*size = len - 1;
|
2002-11-15 02:01:47 +01:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2002-11-15 02:01:47 +01:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-11-27 22:38:06 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DnsHostnameToComputerNameA (KERNEL32.@)
|
|
|
|
*/
|
2005-03-30 19:04:55 +02:00
|
|
|
BOOL WINAPI DnsHostnameToComputerNameA(LPCSTR hostname,
|
|
|
|
LPSTR computername, LPDWORD size)
|
2002-11-27 22:38:06 +01:00
|
|
|
{
|
2019-12-12 19:19:12 +01:00
|
|
|
WCHAR *hostW, nameW[MAX_COMPUTERNAME_LENGTH + 1];
|
2005-03-30 19:04:55 +02:00
|
|
|
DWORD len;
|
2019-12-12 19:19:12 +01:00
|
|
|
BOOL ret;
|
2005-03-30 19:04:55 +02:00
|
|
|
|
|
|
|
if (!hostname || !size) return FALSE;
|
2019-12-12 19:19:12 +01:00
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, hostname, -1, NULL, 0 );
|
|
|
|
if (!(hostW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, hostname, -1, hostW, len );
|
|
|
|
len = ARRAY_SIZE(nameW);
|
|
|
|
if ((ret = DnsHostnameToComputerNameW( hostW, nameW, &len )))
|
2005-03-30 19:04:55 +02:00
|
|
|
{
|
2019-12-12 19:19:12 +01:00
|
|
|
if (!computername || !WideCharToMultiByte( CP_ACP, 0, nameW, -1, computername, *size, NULL, NULL ))
|
|
|
|
*size = WideCharToMultiByte( CP_ACP, 0, nameW, -1, NULL, 0, NULL, NULL );
|
|
|
|
else
|
|
|
|
*size = strlen(computername);
|
2005-03-30 19:04:55 +02:00
|
|
|
}
|
2019-12-12 19:19:12 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, hostW );
|
2005-03-30 19:04:55 +02:00
|
|
|
return TRUE;
|
2002-11-27 22:38:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DnsHostnameToComputerNameW (KERNEL32.@)
|
|
|
|
*/
|
2005-03-30 19:04:55 +02:00
|
|
|
BOOL WINAPI DnsHostnameToComputerNameW(LPCWSTR hostname,
|
|
|
|
LPWSTR computername, LPDWORD size)
|
2002-11-27 22:38:06 +01:00
|
|
|
{
|
2019-12-12 19:19:12 +01:00
|
|
|
return DnsHostnameToComputerNameExW( hostname, computername, size );
|
2002-11-27 22:38:06 +01:00
|
|
|
}
|