Assorted spelling fixes.
[wine] / dlls / kernel32 / computername.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  * Copyright 1999 Peter Ganten
6  * Copyright 2002 Martin Wilck
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdarg.h>
27 #include <string.h>
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
31 #include <stdlib.h>
32 #include <errno.h>
33 #ifdef HAVE_NETDB_H
34 #include <netdb.h>
35 #endif
36
37 #include "ntstatus.h"
38 #define WIN32_NO_STATUS
39 #include "windef.h"
40 #include "winbase.h"
41 #include "winerror.h"
42 #include "winnls.h"
43 #include "winternl.h"
44 #include "wine/unicode.h"
45 #include "wine/exception.h"
46 #include "wine/debug.h"
47
48 #include "kernel_private.h"
49
50 WINE_DEFAULT_DEBUG_CHANNEL(computername);
51
52 /* Registry key and value names */
53 static const WCHAR ComputerW[] = {'M','a','c','h','i','n','e','\\',
54                                   'S','y','s','t','e','m','\\',
55                                   'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
56                                   'C','o','n','t','r','o','l','\\',
57                                   'C','o','m','p','u','t','e','r','N','a','m','e',0};
58 static const WCHAR ActiveComputerNameW[] =   {'A','c','t','i','v','e','C','o','m','p','u','t','e','r','N','a','m','e',0};
59 static const WCHAR ComputerNameW[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
60
61 static const char default_ComputerName[] = "WINE";
62
63 #define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')
64
65 /*********************************************************************** 
66  *                    dns_gethostbyname (INTERNAL)
67  *
68  *  From hostname(1):
69  *  "The FQDN is the name gethostbyname(2) returns for the host name returned by gethostname(2)."
70  *
71  *  Wine can use this technique only if the thread-safe gethostbyname_r is available.
72  */
73 #ifdef  HAVE_LINUX_GETHOSTBYNAME_R_6
74 static BOOL dns_gethostbyname ( char *name, int *size )
75 {
76     struct hostent* host = NULL;
77     char *extrabuf;
78     int ebufsize = 1024;
79     struct hostent hostentry;
80     int locerr = ENOBUFS, res = ENOMEM;
81
82     extrabuf = HeapAlloc( GetProcessHeap(), 0, ebufsize ) ;
83
84     while( extrabuf ) 
85     {
86         res = gethostbyname_r ( name, &hostentry, extrabuf, ebufsize, &host, &locerr );
87         if( res != ERANGE ) break;
88         ebufsize *= 2;
89         extrabuf = HeapReAlloc( GetProcessHeap(), 0, extrabuf, ebufsize ) ;
90     }
91
92     if ( res )
93         WARN ("Error in gethostbyname_r %d (%d)\n", res, locerr);
94     else if ( !host )
95     {
96         WARN ("gethostbyname_r returned NULL host, locerr = %d\n", locerr);
97         res = 1;
98     }
99     else
100     {
101         int len = strlen ( host->h_name );
102         if ( len < *size )
103         {
104             strcpy ( name, host->h_name );
105             *size = len;
106         }
107         else
108         {
109             memcpy ( name, host->h_name, *size );
110             name[*size] = 0;
111             SetLastError ( ERROR_MORE_DATA );
112             res = 1;
113         }
114     }
115
116     HeapFree( GetProcessHeap(), 0, extrabuf );
117     return !res;
118 }
119 #else
120 #  define dns_gethostbyname(name,size) 0
121 #endif
122
123 /*********************************************************************** 
124  *                     dns_fqdn (INTERNAL)
125  */
126 static BOOL dns_fqdn ( char *name, int *size )
127 {
128     if ( gethostname ( name, *size + 1 ) ) 
129     {
130         switch( errno )
131         {
132         case ENAMETOOLONG:
133             SetLastError ( ERROR_MORE_DATA );
134             break;
135         default:
136             SetLastError ( ERROR_INVALID_PARAMETER );
137             break;
138         }
139         return FALSE;
140     }
141
142     if ( !dns_gethostbyname ( name, size ) )
143         *size = strlen ( name );
144
145     return TRUE;
146 }
147
148 /*********************************************************************** 
149  *                     dns_hostname (INTERNAL)
150  */
151 static BOOL dns_hostname ( char *name, int *size )
152 {
153     char *c;
154     if ( ! dns_fqdn ( name, size ) ) return FALSE;
155     c = strchr ( name, '.' );
156     if (c)
157     {
158         *c = 0;
159         *size = (c - name);
160     }
161     return TRUE;
162 }
163
164 /*********************************************************************** 
165  *                     dns_domainname (INTERNAL)
166  */
167 static BOOL dns_domainname ( char *name, int *size )
168 {
169     char *c;
170     if ( ! dns_fqdn ( name, size ) ) return FALSE;
171     c = strchr ( name, '.' );
172     if (c)
173     {
174         c += 1;
175         *size -= (c - name);
176         memmove ( name, c, *size + 1 );
177     }
178     return TRUE;
179 }
180
181 /*********************************************************************** 
182  *                      _init_attr    (INTERNAL)
183  */
184 static inline void _init_attr ( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *name )
185 {
186     attr->Length = sizeof (OBJECT_ATTRIBUTES);
187     attr->RootDirectory = 0;
188     attr->ObjectName = name;
189     attr->Attributes = 0;
190     attr->SecurityDescriptor = NULL;
191     attr->SecurityQualityOfService = NULL;
192 }
193
194 /***********************************************************************
195  *           get_use_dns_option
196  */
197 static BOOL get_use_dns_option(void)
198 {
199     static const WCHAR NetworkW[] = {'S','o','f','t','w','a','r','e','\\',
200                                      'W','i','n','e','\\','N','e','t','w','o','r','k',0};
201     static const WCHAR UseDNSW[] = {'U','s','e','D','n','s','C','o','m','p','u','t','e','r','N','a','m','e',0};
202
203     char tmp[80];
204     HANDLE root, hkey;
205     DWORD dummy;
206     OBJECT_ATTRIBUTES attr;
207     UNICODE_STRING nameW;
208     BOOL ret = TRUE;
209
210     _init_attr( &attr, &nameW );
211     RtlOpenCurrentUser( KEY_READ, &root );
212     attr.RootDirectory = root;
213     RtlInitUnicodeString( &nameW, NetworkW );
214
215     /* @@ Wine registry key: HKCU\Software\Wine\Network */
216     if (!NtOpenKey( &hkey, KEY_READ, &attr ))
217     {
218         RtlInitUnicodeString( &nameW, UseDNSW );
219         if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
220         {
221             WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
222             ret = IS_OPTION_TRUE( str[0] );
223         }
224         NtClose( hkey );
225     }
226     NtClose( root );
227     return ret;
228 }
229
230
231 /*********************************************************************** 
232  *                      COMPUTERNAME_Init    (INTERNAL)
233  */
234 void COMPUTERNAME_Init (void)
235 {
236     HANDLE hkey = INVALID_HANDLE_VALUE, hsubkey = INVALID_HANDLE_VALUE;
237     OBJECT_ATTRIBUTES attr;
238     UNICODE_STRING nameW;
239     char buf[offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ) + (MAX_COMPUTERNAME_LENGTH + 1) * sizeof( WCHAR )];
240     DWORD len = sizeof( buf );
241     LPWSTR computer_name = (LPWSTR) (buf + offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ));
242     NTSTATUS st = STATUS_INTERNAL_ERROR;
243
244     TRACE("(void)\n");
245     _init_attr ( &attr, &nameW );
246     
247     RtlInitUnicodeString( &nameW, ComputerW );
248     if ( ( st = NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) ) != STATUS_SUCCESS )
249         goto out;
250     
251     attr.RootDirectory = hkey;
252     RtlInitUnicodeString( &nameW, ComputerNameW );
253     if ( (st = NtCreateKey( &hsubkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) ) != STATUS_SUCCESS )
254         goto out;
255     
256     st = NtQueryValueKey( hsubkey, &nameW, KeyValuePartialInformation, buf, len, &len );
257
258     if ( st != STATUS_SUCCESS || get_use_dns_option() )
259     {
260         char hbuf[256];
261         int hlen = sizeof (hbuf);
262         char *dot;
263         TRACE( "retrieving Unix host name\n" );
264         if ( gethostname ( hbuf, hlen ) )
265         {
266             strcpy ( hbuf, default_ComputerName );
267             WARN( "gethostname() error: %d, using host name %s\n", errno, hbuf );
268         }
269         hbuf[MAX_COMPUTERNAME_LENGTH] = 0;
270         dot = strchr ( hbuf, '.' );
271         if ( dot ) *dot = 0;
272         hlen = strlen ( hbuf );
273         len = MultiByteToWideChar( CP_UNIXCP, 0, hbuf, hlen + 1, computer_name, MAX_COMPUTERNAME_LENGTH + 1 )
274             * sizeof( WCHAR );
275         if ( NtSetValueKey( hsubkey, &nameW, 0, REG_SZ, computer_name, len ) != STATUS_SUCCESS )
276             WARN ( "failed to set ComputerName\n" );
277     }
278     else
279     {
280         len = (len - offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ));
281         TRACE( "found in registry\n" );
282     }
283
284     NtClose( hsubkey );
285     TRACE(" ComputerName: %s (%u)\n", debugstr_w (computer_name), len);
286
287     RtlInitUnicodeString( &nameW, ActiveComputerNameW );
288     if ( ( st = NtCreateKey( &hsubkey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, NULL ) )
289          != STATUS_SUCCESS )
290         goto out;
291     
292     RtlInitUnicodeString( &nameW, ComputerNameW );
293     st = NtSetValueKey( hsubkey, &nameW, 0, REG_SZ, computer_name, len );
294
295 out:
296     NtClose( hsubkey );
297     NtClose( hkey );
298
299     if ( st == STATUS_SUCCESS )
300         TRACE( "success\n" );
301     else
302     {
303         WARN( "status trying to set ComputerName: %x\n", st );
304         SetLastError ( RtlNtStatusToDosError ( st ) );
305     }
306 }
307
308
309 /***********************************************************************
310  *              GetComputerNameW         (KERNEL32.@)
311  */
312 BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
313 {
314     UNICODE_STRING nameW;
315     OBJECT_ATTRIBUTES attr;
316     HANDLE hkey = INVALID_HANDLE_VALUE, hsubkey = INVALID_HANDLE_VALUE;
317     char buf[offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ) + (MAX_COMPUTERNAME_LENGTH + 1) * sizeof( WCHAR )];
318     DWORD len = sizeof( buf );
319     LPWSTR theName = (LPWSTR) (buf + offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ));
320     NTSTATUS st = STATUS_INVALID_PARAMETER;
321     DWORD err = ERROR_SUCCESS;
322     
323     TRACE ("%p %p\n", name, size);
324
325     _init_attr ( &attr, &nameW );
326     RtlInitUnicodeString( &nameW, ComputerW );
327     if ( ( st = NtOpenKey( &hkey, KEY_READ, &attr ) ) != STATUS_SUCCESS )
328     {
329         err = RtlNtStatusToDosError ( st );
330         goto out;
331     }
332          
333     attr.RootDirectory = hkey;
334     RtlInitUnicodeString( &nameW, ActiveComputerNameW );
335     if ( ( st = NtOpenKey( &hsubkey, KEY_READ, &attr ) ) != STATUS_SUCCESS )
336     {
337         err = RtlNtStatusToDosError ( st );
338         goto out;
339     }
340     
341     RtlInitUnicodeString( &nameW, ComputerNameW );
342     if ( ( st = NtQueryValueKey( hsubkey, &nameW, KeyValuePartialInformation, buf, len, &len ) )
343          != STATUS_SUCCESS )
344     {
345         err = RtlNtStatusToDosError ( st );
346         goto out;
347     }
348
349     len = (len -offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data )) / sizeof (WCHAR) - 1;
350     TRACE ("ComputerName is %s (length %u)\n", debugstr_w ( theName ), len);
351
352     if ( *size < len + 1 )
353     {
354         *size = len + 1;
355         err = ERROR_BUFFER_OVERFLOW;
356     }
357     else
358     {
359         memcpy ( name, theName, len * sizeof (WCHAR) );
360         name[len] = 0;
361         *size = len;
362     }
363
364 out:
365     NtClose ( hsubkey );
366     NtClose ( hkey );
367
368     if ( err == ERROR_SUCCESS )
369         return TRUE;
370     else
371     {
372         SetLastError ( err );
373         WARN ( "Status %u reading computer name from registry\n", st );
374         return FALSE;
375     }
376 }
377
378 /***********************************************************************
379  *              GetComputerNameA         (KERNEL32.@)
380  */
381 BOOL WINAPI GetComputerNameA(LPSTR name, LPDWORD size)
382 {
383     WCHAR nameW[ MAX_COMPUTERNAME_LENGTH + 1 ];
384     DWORD sizeW = MAX_COMPUTERNAME_LENGTH + 1;
385     unsigned int len;
386     BOOL ret;
387
388     if ( !GetComputerNameW (nameW, &sizeW) ) return FALSE;
389
390     len = WideCharToMultiByte ( CP_ACP, 0, nameW, -1, NULL, 0, NULL, 0 );
391     /* for compatibility with Win9x */
392     __TRY
393     {
394         if ( *size < len )
395         {
396             *size = len;
397             SetLastError( ERROR_BUFFER_OVERFLOW );
398             ret = FALSE;
399         }
400         else
401         {
402             WideCharToMultiByte ( CP_ACP, 0, nameW, -1, name, len, NULL, 0 );
403             *size = len - 1;
404             ret = TRUE;
405         }
406     }
407     __EXCEPT_PAGE_FAULT
408     {
409         SetLastError( ERROR_INVALID_PARAMETER );
410         ret = FALSE;
411     }
412     __ENDTRY
413
414     return ret;
415 }
416
417 /***********************************************************************
418  *              GetComputerNameExA         (KERNEL32.@)
419  */
420 BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT type, LPSTR name, LPDWORD size)
421 {
422     char buf[256];
423     int len = sizeof(buf) - 1, ret;
424     TRACE("%d, %p, %p\n", type, name, size);
425     switch( type )
426     {
427     case ComputerNameNetBIOS:
428     case ComputerNamePhysicalNetBIOS:
429         ret = GetComputerNameA (name, size);
430         if (!ret && GetLastError() == ERROR_BUFFER_OVERFLOW)
431             SetLastError( ERROR_MORE_DATA );
432         return ret;
433
434     case ComputerNameDnsHostname:
435     case ComputerNamePhysicalDnsHostname:
436         ret = dns_hostname (buf, &len);
437         break;
438     case ComputerNameDnsDomain:
439     case ComputerNamePhysicalDnsDomain:
440         ret = dns_domainname (buf, &len);
441         break;
442     case ComputerNameDnsFullyQualified:
443     case ComputerNamePhysicalDnsFullyQualified:
444         ret = dns_fqdn (buf, &len);
445         break;
446     default:
447         SetLastError (ERROR_INVALID_PARAMETER);
448         return FALSE;
449     }
450
451     if ( ret )
452     {
453         TRACE ("-> %s (%d)\n", debugstr_a (buf), len);
454         if ( *size < len + 1 )
455         {
456             *size = len + 1;
457             SetLastError( ERROR_MORE_DATA );
458             ret = FALSE;
459         }
460         else
461         {
462             memcpy( name, buf, len );
463             name[len] = 0;
464             *size = len;
465             ret = TRUE;
466         }
467     }
468
469     return ret;
470 }
471
472
473 /***********************************************************************
474  *              GetComputerNameExW         (KERNEL32.@)
475  */
476 BOOL WINAPI GetComputerNameExW( COMPUTER_NAME_FORMAT type, LPWSTR name, LPDWORD size )
477 {
478     char buf[256];
479     int len = sizeof(buf) - 1, ret;
480
481     TRACE("%d, %p, %p\n", type, name, size);
482     switch( type )
483     {
484     case ComputerNameNetBIOS:
485     case ComputerNamePhysicalNetBIOS:
486         ret = GetComputerNameW (name, size);
487         if (!ret && GetLastError() == ERROR_BUFFER_OVERFLOW)
488             SetLastError( ERROR_MORE_DATA );
489         return ret;
490     case ComputerNameDnsHostname:
491     case ComputerNamePhysicalDnsHostname:
492         ret = dns_hostname (buf, &len);
493         break;
494     case ComputerNameDnsDomain:
495     case ComputerNamePhysicalDnsDomain:
496         ret = dns_domainname (buf, &len);
497         break;
498     case ComputerNameDnsFullyQualified:
499     case ComputerNamePhysicalDnsFullyQualified:
500         ret = dns_fqdn (buf, &len);
501         break;
502     default:
503         SetLastError (ERROR_INVALID_PARAMETER);
504         return FALSE;
505     }
506
507     if ( ret )
508     {
509         unsigned int lenW;
510
511         TRACE ("-> %s (%d)\n", debugstr_a (buf), len);
512
513         lenW = MultiByteToWideChar( CP_ACP, 0, buf, len, NULL, 0 );
514         if ( *size < lenW + 1 )
515         {
516             *size = lenW + 1;
517             SetLastError( ERROR_MORE_DATA );
518             ret = FALSE;
519         }
520         else
521         {
522             MultiByteToWideChar( CP_ACP, 0, buf, len, name, lenW );
523             name[lenW] = 0;
524             *size = lenW;
525             ret = TRUE;
526         }
527     }
528
529     return ret;
530 }
531
532 /******************************************************************************
533  * netbios_char (INTERNAL)
534  */
535 static WCHAR netbios_char ( WCHAR wc )
536 {
537     static const WCHAR special[] = {'!','@','#','$','%','^','&','\'',')','(','-','_','{','}','~'};
538     static const WCHAR deflt = '_';
539     unsigned int i;
540     
541     if ( isalnumW ( wc ) ) return wc;
542     for ( i = 0; i < sizeof (special) / sizeof (WCHAR); i++ )
543         if ( wc == special[i] ) return wc;
544     return deflt;
545 }
546
547 /******************************************************************************
548  * SetComputerNameW [KERNEL32.@]
549  *
550  * Set a new NetBIOS name for the local computer.
551  *
552  * PARAMS
553  *    lpComputerName [I] Address of new computer name
554  *
555  * RETURNS
556  *    Success: TRUE
557  *    Failure: FALSE
558  */
559 BOOL WINAPI SetComputerNameW( LPCWSTR lpComputerName )
560 {
561     UNICODE_STRING nameW;
562     OBJECT_ATTRIBUTES attr;
563     HANDLE hkey = INVALID_HANDLE_VALUE, hsubkey = INVALID_HANDLE_VALUE;
564     int plen = strlenW ( lpComputerName );
565     int i;
566     NTSTATUS st = STATUS_INTERNAL_ERROR;
567
568     if (get_use_dns_option())
569     {
570         /* This check isn't necessary, but may help debugging problems. */
571         WARN( "Disabled by Wine Configuration.\n" );
572         WARN( "Set \"UseDnsComputerName\" = \"N\" in HKCU\\Software\\Wine\\Network to enable.\n" );
573         SetLastError ( ERROR_ACCESS_DENIED );
574         return FALSE;
575     }
576
577     TRACE( "%s\n", debugstr_w (lpComputerName) );
578
579     /* Check parameter */
580     if ( plen > MAX_COMPUTERNAME_LENGTH ) 
581         goto out;
582
583     /* This is NT behaviour. Win 95/98 would coerce characters. */
584     for ( i = 0; i < plen; i++ )
585     {
586         WCHAR wc = lpComputerName[i];
587         if ( wc != netbios_char( wc ) )
588             goto out;
589     }
590     
591     _init_attr ( &attr, &nameW );
592     
593     RtlInitUnicodeString (&nameW, ComputerW);
594     if ( ( st = NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) ) != STATUS_SUCCESS )
595         goto out;
596     attr.RootDirectory = hkey;
597     RtlInitUnicodeString( &nameW, ComputerNameW );
598     if ( ( st = NtOpenKey( &hsubkey, KEY_ALL_ACCESS, &attr ) ) != STATUS_SUCCESS )
599         goto out;
600     if ( ( st = NtSetValueKey( hsubkey, &nameW, 0, REG_SZ, lpComputerName, ( plen + 1) * sizeof(WCHAR) ) )
601          != STATUS_SUCCESS )
602         goto out;
603
604 out:
605     NtClose( hsubkey );
606     NtClose( hkey );
607     
608     if ( st == STATUS_SUCCESS )
609     {
610         TRACE( "ComputerName changed\n" );
611         return TRUE;
612     }
613
614     else
615     {
616         SetLastError ( RtlNtStatusToDosError ( st ) );
617         WARN ( "status %u\n", st );
618         return FALSE;
619     }
620 }
621
622 /******************************************************************************
623  * SetComputerNameA [KERNEL32.@]
624  *
625  * See SetComputerNameW.
626  */
627 BOOL WINAPI SetComputerNameA( LPCSTR lpComputerName )
628 {
629     BOOL ret;
630     DWORD len = MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, NULL, 0 );
631     LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
632
633     MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, nameW, len );
634     ret = SetComputerNameW( nameW );
635     HeapFree( GetProcessHeap(), 0, nameW );
636     return ret;
637 }
638
639 /******************************************************************************
640  * SetComputerNameExW [KERNEL32.@]
641  *
642  */
643 BOOL WINAPI SetComputerNameExW( COMPUTER_NAME_FORMAT type, LPCWSTR lpComputerName )
644 {
645     TRACE("%d, %s\n", type, debugstr_w (lpComputerName));
646     switch( type )
647     {
648     case ComputerNameNetBIOS:
649     case ComputerNamePhysicalNetBIOS:
650         return SetComputerNameW( lpComputerName );
651     default:
652         SetLastError( ERROR_ACCESS_DENIED );
653         return FALSE;
654     }
655 }
656
657 /******************************************************************************
658  * SetComputerNameExA [KERNEL32.@]
659  *
660  */
661 BOOL WINAPI SetComputerNameExA( COMPUTER_NAME_FORMAT type, LPCSTR lpComputerName )
662 {
663     TRACE( "%d, %s\n", type, debugstr_a (lpComputerName) );
664     switch( type )
665     {
666     case ComputerNameNetBIOS:
667     case ComputerNamePhysicalNetBIOS:
668         return SetComputerNameA( lpComputerName );
669     default:
670         SetLastError( ERROR_ACCESS_DENIED );
671         return FALSE;
672     }
673 }
674
675 /***********************************************************************
676  *              DnsHostnameToComputerNameA         (KERNEL32.@)
677  */
678 BOOL WINAPI DnsHostnameToComputerNameA(LPCSTR hostname,
679     LPSTR computername, LPDWORD size)
680 {
681     DWORD len;
682
683     FIXME("(%s, %p, %p): stub\n", debugstr_a(hostname), computername, size);
684
685     if (!hostname || !size) return FALSE;
686     len = lstrlenA(hostname);
687
688     if (len > MAX_COMPUTERNAME_LENGTH)
689         len = MAX_COMPUTERNAME_LENGTH;
690
691     if (*size < len)
692     {
693         *size = len;
694         return FALSE;
695     }
696     if (!computername) return FALSE;
697
698     memcpy( computername, hostname, len );
699     computername[len + 1] = 0;
700     return TRUE;
701 }
702
703 /***********************************************************************
704  *              DnsHostnameToComputerNameW         (KERNEL32.@)
705  */
706 BOOL WINAPI DnsHostnameToComputerNameW(LPCWSTR hostname,
707     LPWSTR computername, LPDWORD size)
708 {
709     DWORD len;
710
711     FIXME("(%s, %p, %p): stub\n", debugstr_w(hostname), computername, size);
712
713     if (!hostname || !size) return FALSE;
714     len = lstrlenW(hostname);
715
716     if (len > MAX_COMPUTERNAME_LENGTH)
717         len = MAX_COMPUTERNAME_LENGTH;
718
719     if (*size < len)
720     {
721         *size = len;
722         return FALSE;
723     }
724     if (!computername) return FALSE;
725
726     memcpy( computername, hostname, len * sizeof(WCHAR) );
727     computername[len + 1] = 0;
728     return TRUE;
729 }