kernel32: Remove the setting of the computer name keys.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
6a19b999f7
commit
48e88074cd
|
@ -25,14 +25,7 @@
|
|||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include "ntstatus.h"
|
||||
#define WIN32_NO_STATUS
|
||||
|
@ -43,155 +36,9 @@
|
|||
#include "winternl.h"
|
||||
#include "wine/unicode.h"
|
||||
#include "wine/exception.h"
|
||||
#include "wine/debug.h"
|
||||
|
||||
#include "kernel_private.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(computername);
|
||||
|
||||
/* Registry key and value names */
|
||||
static const WCHAR ComputerW[] = {'\\','R','e','g','i','s','t','r','y','\\',
|
||||
'M','a','c','h','i','n','e','\\',
|
||||
'S','y','s','t','e','m','\\',
|
||||
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
|
||||
'C','o','n','t','r','o','l','\\',
|
||||
'C','o','m','p','u','t','e','r','N','a','m','e',0};
|
||||
static const WCHAR ActiveComputerNameW[] = {'A','c','t','i','v','e','C','o','m','p','u','t','e','r','N','a','m','e',0};
|
||||
static const WCHAR ComputerNameW[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
|
||||
|
||||
static const WCHAR default_ComputerName[] = {'W','I','N','E',0};
|
||||
|
||||
/***********************************************************************
|
||||
* dns_gethostbyname (INTERNAL)
|
||||
*
|
||||
* From hostname(1):
|
||||
* "The FQDN is the name gethostbyname(2) returns for the host name returned by gethostname(2)."
|
||||
*
|
||||
* Wine can use this technique only if the thread-safe gethostbyname_r is available.
|
||||
*/
|
||||
static void dns_gethostbyname ( char *name, int size )
|
||||
{
|
||||
#ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
|
||||
struct hostent* host = NULL;
|
||||
char *extrabuf;
|
||||
int ebufsize = 1024;
|
||||
struct hostent hostentry;
|
||||
int locerr = ENOBUFS, res;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (!(extrabuf = HeapAlloc( GetProcessHeap(), 0, ebufsize ))) return;
|
||||
res = gethostbyname_r ( name, &hostentry, extrabuf, ebufsize, &host, &locerr );
|
||||
if( res != ERANGE ) break;
|
||||
ebufsize *= 2;
|
||||
HeapFree( GetProcessHeap(), 0, extrabuf );
|
||||
}
|
||||
|
||||
if ( res )
|
||||
WARN ("Error in gethostbyname_r %d (%d)\n", res, locerr);
|
||||
else if ( !host )
|
||||
WARN ("gethostbyname_r returned NULL host, locerr = %d\n", locerr);
|
||||
else
|
||||
if (strlen( host->h_name ) < size) strcpy( name, host->h_name );
|
||||
|
||||
HeapFree( GetProcessHeap(), 0, extrabuf );
|
||||
#endif
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* dns_fqdn (INTERNAL)
|
||||
*/
|
||||
static BOOL dns_fqdn ( char *name, int size )
|
||||
{
|
||||
if (gethostname( name, size ))
|
||||
{
|
||||
switch( errno )
|
||||
{
|
||||
case ENAMETOOLONG:
|
||||
SetLastError ( ERROR_MORE_DATA );
|
||||
break;
|
||||
default:
|
||||
SetLastError ( ERROR_INVALID_PARAMETER );
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
dns_gethostbyname( name, size );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* COMPUTERNAME_Init (INTERNAL)
|
||||
*/
|
||||
void COMPUTERNAME_Init (void)
|
||||
{
|
||||
HANDLE hkey = INVALID_HANDLE_VALUE, hsubkey = INVALID_HANDLE_VALUE;
|
||||
OBJECT_ATTRIBUTES attr;
|
||||
UNICODE_STRING nameW;
|
||||
char buf[offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ) + (MAX_COMPUTERNAME_LENGTH + 1) * sizeof( WCHAR )];
|
||||
DWORD len = sizeof( buf );
|
||||
const WCHAR *computer_name = (WCHAR *)(buf + offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ));
|
||||
NTSTATUS st = STATUS_INTERNAL_ERROR;
|
||||
char hbuf[256];
|
||||
WCHAR *dot, bufW[256];
|
||||
|
||||
if (dns_fqdn( hbuf, sizeof(hbuf) ))
|
||||
{
|
||||
MultiByteToWideChar( CP_UNIXCP, 0, hbuf, -1, bufW, ARRAY_SIZE(bufW) );
|
||||
dot = strchrW( bufW, '.' );
|
||||
if (dot) *dot++ = 0;
|
||||
else dot = bufW + strlenW(bufW);
|
||||
SetComputerNameExW( ComputerNamePhysicalDnsDomain, dot );
|
||||
SetComputerNameExW( ComputerNamePhysicalDnsHostname, bufW );
|
||||
}
|
||||
|
||||
TRACE("(void)\n");
|
||||
InitializeObjectAttributes( &attr, &nameW, 0, 0, NULL );
|
||||
RtlInitUnicodeString( &nameW, ComputerW );
|
||||
if ( ( st = NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) ) != STATUS_SUCCESS )
|
||||
goto out;
|
||||
|
||||
attr.RootDirectory = hkey;
|
||||
RtlInitUnicodeString( &nameW, ComputerNameW );
|
||||
if ( (st = NtCreateKey( &hsubkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) ) != STATUS_SUCCESS )
|
||||
goto out;
|
||||
|
||||
st = NtQueryValueKey( hsubkey, &nameW, KeyValuePartialInformation, buf, len, &len );
|
||||
|
||||
if ( st != STATUS_SUCCESS)
|
||||
{
|
||||
computer_name = default_ComputerName;
|
||||
len = sizeof(default_ComputerName);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = (len - offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ));
|
||||
}
|
||||
|
||||
NtClose( hsubkey );
|
||||
TRACE(" ComputerName: %s (%u)\n", debugstr_w (computer_name), len);
|
||||
|
||||
RtlInitUnicodeString( &nameW, ActiveComputerNameW );
|
||||
if ( ( st = NtCreateKey( &hsubkey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, NULL ) )
|
||||
!= STATUS_SUCCESS )
|
||||
goto out;
|
||||
|
||||
RtlInitUnicodeString( &nameW, ComputerNameW );
|
||||
st = NtSetValueKey( hsubkey, &nameW, 0, REG_SZ, computer_name, len );
|
||||
|
||||
out:
|
||||
NtClose( hsubkey );
|
||||
NtClose( hkey );
|
||||
|
||||
if ( st == STATUS_SUCCESS )
|
||||
TRACE( "success\n" );
|
||||
else
|
||||
{
|
||||
WARN( "status trying to set ComputerName: %x\n", st );
|
||||
SetLastError ( RtlNtStatusToDosError ( st ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* GetComputerNameW (KERNEL32.@)
|
||||
|
|
|
@ -132,9 +132,6 @@ static BOOL process_attach( HMODULE module )
|
|||
|
||||
NtQuerySystemInformation( SystemBasicInformation, &system_info, sizeof(system_info), NULL );
|
||||
|
||||
/* Setup computer name */
|
||||
COMPUTERNAME_Init();
|
||||
|
||||
CONSOLE_Init(params);
|
||||
|
||||
copy_startup_info();
|
||||
|
|
|
@ -58,7 +58,4 @@ extern const WCHAR DIR_System[] DECLSPEC_HIDDEN;
|
|||
extern WCHAR *FILE_name_AtoW( LPCSTR name, BOOL alloc ) DECLSPEC_HIDDEN;
|
||||
extern DWORD FILE_name_WtoA( LPCWSTR src, INT srclen, LPSTR dest, INT destlen ) DECLSPEC_HIDDEN;
|
||||
|
||||
/* computername.c */
|
||||
extern void COMPUTERNAME_Init(void) DECLSPEC_HIDDEN;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue