~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/kernel32/computername.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.