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