2003-06-08 21:00:04 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
2005-09-04 20:11:51 +00:00
|
|
|
/*
|
2003-06-08 21:00:04 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* PURPOSE: Computer name functions
|
|
|
|
* FILE: lib/kernel32/misc/computername.c
|
|
|
|
* PROGRAMER: Eric Kohl (ekohl@rz-online.de)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <k32.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
2003-06-08 21:00:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
2008-06-18 15:37:44 +00:00
|
|
|
LPWSTR ValueNameStr,
|
|
|
|
LPWSTR lpBuffer,
|
|
|
|
LPDWORD nSize ) {
|
2004-02-15 07:03:56 +00:00
|
|
|
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
UNICODE_STRING ValueName;
|
|
|
|
HANDLE KeyHandle;
|
|
|
|
ULONG KeyInfoSize;
|
|
|
|
ULONG ReturnSize;
|
|
|
|
NTSTATUS Status;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
RtlInitUnicodeString (&KeyName,RegistryKey);
|
|
|
|
InitializeObjectAttributes (&ObjectAttributes,
|
2008-06-18 15:37:44 +00:00
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2004-02-15 07:03:56 +00:00
|
|
|
Status = ZwOpenKey (&KeyHandle,
|
2008-06-18 15:37:44 +00:00
|
|
|
KEY_READ,
|
|
|
|
&ObjectAttributes);
|
2004-02-15 07:03:56 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2008-06-18 15:37:44 +00:00
|
|
|
SetLastErrorByStatus (Status);
|
|
|
|
return FALSE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + *nSize * sizeof(WCHAR);
|
2004-02-15 07:03:56 +00:00
|
|
|
KeyInfo = RtlAllocateHeap (RtlGetProcessHeap (),
|
2008-06-18 15:37:44 +00:00
|
|
|
0,
|
|
|
|
KeyInfoSize);
|
2004-02-15 07:03:56 +00:00
|
|
|
if (KeyInfo == NULL)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2008-06-18 15:37:44 +00:00
|
|
|
ZwClose (KeyHandle);
|
|
|
|
SetLastError (ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
2004-02-15 07:03:56 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
RtlInitUnicodeString (&ValueName,ValueNameStr);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
Status = ZwQueryValueKey (KeyHandle,
|
2008-06-18 15:37:44 +00:00
|
|
|
&ValueName,
|
|
|
|
KeyValuePartialInformation,
|
|
|
|
KeyInfo,
|
|
|
|
KeyInfoSize,
|
|
|
|
&ReturnSize);
|
2004-02-15 07:03:56 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2008-06-18 15:37:44 +00:00
|
|
|
RtlFreeHeap (RtlGetProcessHeap (),
|
|
|
|
0,
|
|
|
|
KeyInfo);
|
|
|
|
ZwClose (KeyHandle);
|
|
|
|
SetLastErrorByStatus (Status);
|
|
|
|
return FALSE;
|
2004-02-15 07:03:56 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
if( *nSize > (KeyInfo->DataLength / sizeof(WCHAR)) )
|
|
|
|
{
|
|
|
|
*nSize = KeyInfo->DataLength / sizeof(WCHAR);
|
|
|
|
lpBuffer[*nSize] = 0;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
RtlCopyMemory (lpBuffer,
|
2008-06-18 15:37:44 +00:00
|
|
|
KeyInfo->Data,
|
|
|
|
*nSize * sizeof(WCHAR));
|
2004-02-15 07:03:56 +00:00
|
|
|
|
|
|
|
RtlFreeHeap (RtlGetProcessHeap (),
|
2008-06-18 15:37:44 +00:00
|
|
|
0,
|
|
|
|
KeyInfo);
|
2004-02-15 07:03:56 +00:00
|
|
|
ZwClose (KeyHandle);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
return TRUE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2003-06-08 21:00:04 +00:00
|
|
|
BOOL STDCALL
|
2004-02-15 07:03:56 +00:00
|
|
|
GetComputerNameExW (
|
|
|
|
COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPWSTR lpBuffer,
|
|
|
|
LPDWORD nSize
|
|
|
|
)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2004-02-15 07:03:56 +00:00
|
|
|
UNICODE_STRING ResultString;
|
2005-06-30 13:50:21 +00:00
|
|
|
UNICODE_STRING DomainPart;
|
|
|
|
RTL_QUERY_REGISTRY_TABLE QueryTable[2];
|
|
|
|
NTSTATUS Status;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
switch( NameType )
|
|
|
|
{
|
|
|
|
case ComputerNameNetBIOS:
|
|
|
|
return GetComputerNameFromRegistry(
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet"
|
|
|
|
L"\\Control\\ComputerName\\ComputerName",
|
|
|
|
L"ComputerName",
|
|
|
|
lpBuffer,
|
|
|
|
nSize);
|
|
|
|
|
|
|
|
case ComputerNameDnsDomain:
|
|
|
|
return GetComputerNameFromRegistry(
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet"
|
|
|
|
L"\\Services\\Tcpip\\Parameters",
|
|
|
|
L"Domain",
|
|
|
|
lpBuffer,
|
|
|
|
nSize);
|
|
|
|
|
|
|
|
case ComputerNameDnsFullyQualified:
|
|
|
|
ResultString.Length = 0;
|
|
|
|
ResultString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR);
|
|
|
|
ResultString.Buffer = lpBuffer;
|
|
|
|
|
|
|
|
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
2005-06-30 13:50:21 +00:00
|
|
|
RtlInitUnicodeString(&DomainPart, NULL);
|
2008-06-18 15:37:44 +00:00
|
|
|
QueryTable[0].Name = L"HostName";
|
2005-06-30 13:50:21 +00:00
|
|
|
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
|
|
|
QueryTable[0].EntryContext = &DomainPart;
|
2008-06-18 15:37:44 +00:00
|
|
|
|
2005-06-30 13:50:21 +00:00
|
|
|
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
|
|
|
|
L"\\Registry\\Machine\\System"
|
|
|
|
L"\\CurrentControlSet\\Services\\Tcpip"
|
|
|
|
L"\\Parameters",
|
|
|
|
QueryTable, NULL, NULL);
|
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
if( NT_SUCCESS(Status) )
|
|
|
|
{
|
2005-06-30 13:50:21 +00:00
|
|
|
RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
2008-06-18 15:37:44 +00:00
|
|
|
RtlAppendUnicodeToString(&ResultString, L".");
|
2005-06-30 13:50:21 +00:00
|
|
|
RtlFreeUnicodeString(&DomainPart);
|
2008-06-18 15:37:44 +00:00
|
|
|
|
|
|
|
RtlInitUnicodeString(&DomainPart, NULL);
|
|
|
|
QueryTable[0].Name = L"Domain";
|
|
|
|
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
|
|
|
QueryTable[0].EntryContext = &DomainPart;
|
|
|
|
|
|
|
|
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
|
|
|
|
L"\\Registry\\Machine\\System"
|
|
|
|
L"\\CurrentControlSet\\Services\\Tcpip"
|
|
|
|
L"\\Parameters",
|
|
|
|
QueryTable, NULL, NULL);
|
|
|
|
|
|
|
|
if( NT_SUCCESS(Status) )
|
|
|
|
{
|
|
|
|
RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
|
|
|
RtlFreeUnicodeString(&DomainPart);
|
|
|
|
*nSize = ResultString.Length / sizeof(WCHAR);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-06-30 13:50:21 +00:00
|
|
|
}
|
2008-06-18 15:37:44 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case ComputerNameDnsHostname:
|
|
|
|
return GetComputerNameFromRegistry(
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet"
|
|
|
|
L"\\Services\\Tcpip\\Parameters",
|
|
|
|
L"Hostname",
|
|
|
|
lpBuffer,
|
|
|
|
nSize);
|
|
|
|
|
|
|
|
case ComputerNamePhysicalDnsDomain:
|
|
|
|
return GetComputerNameFromRegistry(
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet"
|
|
|
|
L"\\Services\\Tcpip\\Parameters",
|
|
|
|
L"Domain",
|
|
|
|
lpBuffer,
|
|
|
|
nSize);
|
|
|
|
|
|
|
|
/* XXX Redo these */
|
|
|
|
case ComputerNamePhysicalDnsFullyQualified:
|
|
|
|
return GetComputerNameExW(ComputerNameDnsFullyQualified,
|
|
|
|
lpBuffer,
|
|
|
|
nSize);
|
|
|
|
|
|
|
|
case ComputerNamePhysicalDnsHostname:
|
|
|
|
return GetComputerNameExW(ComputerNameDnsHostname,
|
|
|
|
lpBuffer,
|
|
|
|
nSize);
|
|
|
|
|
|
|
|
case ComputerNamePhysicalNetBIOS:
|
|
|
|
return GetComputerNameExW(ComputerNameNetBIOS,
|
|
|
|
lpBuffer,
|
|
|
|
nSize);
|
|
|
|
|
|
|
|
case ComputerNameMax:
|
|
|
|
return FALSE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
STDCALL
|
|
|
|
GetComputerNameExA (
|
|
|
|
COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPSTR lpBuffer,
|
|
|
|
LPDWORD nSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UNICODE_STRING UnicodeString;
|
|
|
|
ANSI_STRING AnsiString;
|
|
|
|
BOOL Result;
|
|
|
|
PWCHAR TempBuffer = RtlAllocateHeap( GetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
if( !TempBuffer )
|
|
|
|
{
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2007-01-26 07:22:19 +00:00
|
|
|
AnsiString.MaximumLength = (USHORT)*nSize;
|
2004-02-15 07:03:56 +00:00
|
|
|
AnsiString.Length = 0;
|
|
|
|
AnsiString.Buffer = lpBuffer;
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
Result = GetComputerNameExW( NameType, TempBuffer, nSize );
|
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
if( Result )
|
|
|
|
{
|
|
|
|
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR);
|
|
|
|
UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR);
|
|
|
|
UnicodeString.Buffer = TempBuffer;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
RtlUnicodeStringToAnsiString (&AnsiString,
|
|
|
|
&UnicodeString,
|
|
|
|
FALSE);
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, TempBuffer );
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
return Result;
|
|
|
|
}
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL STDCALL
|
|
|
|
GetComputerNameA (LPSTR lpBuffer,
|
2008-06-18 15:37:44 +00:00
|
|
|
LPDWORD lpnSize)
|
2004-02-15 07:03:56 +00:00
|
|
|
{
|
|
|
|
return GetComputerNameExA( ComputerNameNetBIOS, lpBuffer, lpnSize );
|
|
|
|
}
|
2003-06-08 21:00:04 +00:00
|
|
|
|
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL STDCALL
|
|
|
|
GetComputerNameW (LPWSTR lpBuffer,
|
2008-06-18 15:37:44 +00:00
|
|
|
LPDWORD lpnSize)
|
2004-02-15 07:03:56 +00:00
|
|
|
{
|
|
|
|
return GetComputerNameExW( ComputerNameNetBIOS, lpBuffer, lpnSize );
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2003-06-08 21:00:04 +00:00
|
|
|
static BOOL
|
2005-09-04 20:11:51 +00:00
|
|
|
IsValidComputerName (
|
|
|
|
COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPCWSTR lpComputerName)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2008-06-18 15:37:44 +00:00
|
|
|
PWCHAR p;
|
|
|
|
ULONG Length;
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
/* FIXME: do verification according to NameType */
|
|
|
|
Length = 0;
|
|
|
|
p = (PWCHAR)lpComputerName;
|
|
|
|
while (*p != 0)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2008-06-18 15:37:44 +00:00
|
|
|
if ((!iswctype (*p, _ALPHA) && !iswctype (*p, _DIGIT)) ||
|
|
|
|
*p == L'!' ||
|
|
|
|
*p == L'@' ||
|
|
|
|
*p == L'#' ||
|
|
|
|
*p == L'$' ||
|
|
|
|
*p == L'%' ||
|
|
|
|
*p == L'^' ||
|
|
|
|
*p == L'&' ||
|
|
|
|
*p == L'\'' ||
|
|
|
|
*p == L')' ||
|
|
|
|
*p == L'(' ||
|
|
|
|
*p == L'.' ||
|
|
|
|
*p == L'-' ||
|
|
|
|
*p == L'_' ||
|
|
|
|
*p == L'{' ||
|
|
|
|
*p == L'}' ||
|
|
|
|
*p == L'~')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Length++;
|
|
|
|
p++;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
if (Length == 0 || Length > MAX_COMPUTERNAME_LENGTH)
|
|
|
|
return FALSE;
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
return TRUE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-04 20:11:51 +00:00
|
|
|
static BOOL SetComputerNameToRegistry(
|
|
|
|
LPCWSTR RegistryKey,
|
|
|
|
LPCWSTR ValueNameStr,
|
|
|
|
LPCWSTR lpBuffer)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
UNICODE_STRING ValueName;
|
|
|
|
HANDLE KeyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
RtlInitUnicodeString (&KeyName, RegistryKey);
|
|
|
|
InitializeObjectAttributes (&ObjectAttributes,
|
2008-06-18 15:37:44 +00:00
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2005-09-04 20:11:51 +00:00
|
|
|
|
|
|
|
Status = NtOpenKey (&KeyHandle,
|
2008-06-18 15:37:44 +00:00
|
|
|
KEY_WRITE,
|
|
|
|
&ObjectAttributes);
|
2005-09-04 20:11:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
SetLastErrorByStatus (Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlInitUnicodeString (&ValueName, ValueNameStr);
|
|
|
|
|
|
|
|
Status = NtSetValueKey (KeyHandle,
|
2008-06-18 15:37:44 +00:00
|
|
|
&ValueName,
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(PVOID)lpBuffer,
|
|
|
|
(wcslen (lpBuffer) + 1) * sizeof(WCHAR));
|
2005-09-04 20:11:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ZwClose (KeyHandle);
|
|
|
|
SetLastErrorByStatus (Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NtFlushKey (KeyHandle);
|
|
|
|
ZwClose (KeyHandle);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL STDCALL
|
|
|
|
SetComputerNameA (LPCSTR lpComputerName)
|
|
|
|
{
|
2005-09-04 22:20:22 +00:00
|
|
|
return SetComputerNameExA( ComputerNamePhysicalNetBIOS, lpComputerName );
|
2005-09-04 20:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2003-06-08 21:00:04 +00:00
|
|
|
BOOL STDCALL
|
|
|
|
SetComputerNameW (LPCWSTR lpComputerName)
|
|
|
|
{
|
2005-09-04 22:20:22 +00:00
|
|
|
return SetComputerNameExW( ComputerNamePhysicalNetBIOS, lpComputerName );
|
2005-09-04 20:11:51 +00:00
|
|
|
}
|
2003-06-08 21:00:04 +00:00
|
|
|
|
|
|
|
|
2005-09-04 20:11:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL STDCALL
|
|
|
|
SetComputerNameExA (
|
|
|
|
COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPCSTR lpBuffer)
|
|
|
|
{
|
|
|
|
UNICODE_STRING Buffer;
|
|
|
|
BOOL bResult;
|
|
|
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz (&Buffer,
|
2008-06-18 15:37:44 +00:00
|
|
|
(LPSTR)lpBuffer);
|
2005-09-04 20:11:51 +00:00
|
|
|
|
|
|
|
bResult = SetComputerNameExW (NameType, Buffer.Buffer);
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2005-09-04 20:11:51 +00:00
|
|
|
RtlFreeUnicodeString (&Buffer);
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2005-09-04 20:11:51 +00:00
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL STDCALL
|
|
|
|
SetComputerNameExW (
|
|
|
|
COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPCWSTR lpBuffer)
|
|
|
|
{
|
2008-06-18 15:37:44 +00:00
|
|
|
if (!IsValidComputerName (NameType, lpBuffer))
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2008-06-18 15:37:44 +00:00
|
|
|
SetLastError (ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 15:37:44 +00:00
|
|
|
switch( NameType )
|
|
|
|
{
|
|
|
|
case ComputerNamePhysicalDnsDomain:
|
|
|
|
return SetComputerNameToRegistry(
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet"
|
|
|
|
L"\\Services\\Tcpip\\Parameters",
|
|
|
|
L"Domain",
|
|
|
|
lpBuffer);
|
|
|
|
|
|
|
|
case ComputerNamePhysicalDnsHostname:
|
|
|
|
return SetComputerNameToRegistry(
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet"
|
|
|
|
L"\\Services\\Tcpip\\Parameters",
|
|
|
|
L"Hostname",
|
|
|
|
lpBuffer);
|
|
|
|
|
|
|
|
case ComputerNamePhysicalNetBIOS:
|
|
|
|
return SetComputerNameToRegistry(
|
|
|
|
L"\\Registry\\Machine\\System\\CurrentControlSet"
|
|
|
|
L"\\Control\\ComputerName\\ComputerName",
|
|
|
|
L"ComputerName",
|
|
|
|
lpBuffer);
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetLastError (ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
STDCALL
|
|
|
|
DnsHostnameToComputerNameW (
|
|
|
|
LPCWSTR Hostname,
|
|
|
|
LPWSTR ComputerName,
|
|
|
|
LPDWORD nSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
DPRINT1("(%s, %p, %p): stub\n", Hostname, ComputerName, nSize);
|
|
|
|
|
|
|
|
if (!Hostname || !nSize) return FALSE;
|
|
|
|
len = wcslen(Hostname);
|
|
|
|
|
|
|
|
if (len > MAX_COMPUTERNAME_LENGTH)
|
|
|
|
len = MAX_COMPUTERNAME_LENGTH;
|
|
|
|
|
|
|
|
if (*nSize < len)
|
|
|
|
{
|
|
|
|
*nSize = len;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!ComputerName) return FALSE;
|
|
|
|
|
|
|
|
memcpy( ComputerName, Hostname, len * sizeof(WCHAR) );
|
|
|
|
ComputerName[len + 1] = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
STDCALL
|
|
|
|
DnsHostnameToComputerNameA (
|
|
|
|
LPCSTR Hostname,
|
|
|
|
LPSTR ComputerName,
|
|
|
|
LPDWORD nSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
DPRINT1("(%s, %p, %p): stub\n", Hostname, ComputerName, nSize);
|
|
|
|
|
|
|
|
if (!Hostname || !nSize) return FALSE;
|
|
|
|
len = _tcslen(Hostname);
|
|
|
|
|
|
|
|
if (len > MAX_COMPUTERNAME_LENGTH)
|
|
|
|
len = MAX_COMPUTERNAME_LENGTH;
|
|
|
|
|
|
|
|
if (*nSize < len)
|
|
|
|
{
|
|
|
|
*nSize = len;
|
2005-09-04 20:11:51 +00:00
|
|
|
return FALSE;
|
2008-06-18 15:37:44 +00:00
|
|
|
}
|
|
|
|
if (!ComputerName) return FALSE;
|
|
|
|
|
|
|
|
memcpy( ComputerName, Hostname, len * sizeof(WCHAR) );
|
|
|
|
ComputerName[len + 1] = 0;
|
|
|
|
return TRUE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|