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
|
2010-01-09 22:43:16 +00:00
|
|
|
* PROGRAMER: Eric Kohl
|
2003-06-08 21:00:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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 *****************************************************************/
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
GetComputerNameFromRegistry(LPWSTR RegistryKey,
|
|
|
|
LPWSTR ValueNameStr,
|
|
|
|
LPWSTR lpBuffer,
|
2011-04-20 21:31:41 +00:00
|
|
|
LPDWORD nSize)
|
2009-01-10 19:09:37 +00:00
|
|
|
{
|
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
|
|
|
|
2011-04-20 21:31:41 +00:00
|
|
|
RtlInitUnicodeString(&KeyName, RegistryKey);
|
2009-01-10 19:09:37 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2012-04-25 10:17:29 +00:00
|
|
|
Status = NtOpenKey(&KeyHandle,
|
2009-01-10 19:09:37 +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
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError (Status);
|
2008-09-07 09:19:49 +00:00
|
|
|
return FALSE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + *nSize * sizeof(WCHAR);
|
|
|
|
KeyInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, KeyInfoSize);
|
2004-02-15 07:03:56 +00:00
|
|
|
if (KeyInfo == NULL)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2012-04-25 10:17:29 +00:00
|
|
|
NtClose(KeyHandle);
|
2009-01-10 19:09:37 +00:00
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
2008-09-07 09:19:49 +00:00
|
|
|
return FALSE;
|
2004-02-15 07:03:56 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2011-04-20 21:31:41 +00:00
|
|
|
RtlInitUnicodeString(&ValueName, ValueNameStr);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2012-04-25 10:17:29 +00:00
|
|
|
Status = NtQueryValueKey(KeyHandle,
|
2009-01-10 19:09:37 +00:00
|
|
|
&ValueName,
|
|
|
|
KeyValuePartialInformation,
|
|
|
|
KeyInfo,
|
|
|
|
KeyInfoSize,
|
|
|
|
&ReturnSize);
|
2011-04-20 21:31:41 +00:00
|
|
|
|
2012-04-25 10:17:29 +00:00
|
|
|
NtClose(KeyHandle);
|
2011-04-20 21:31:41 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2008-09-07 09:19:49 +00:00
|
|
|
*nSize = ReturnSize;
|
2011-04-20 21:31:41 +00:00
|
|
|
goto failed;
|
2004-02-15 07:03:56 +00:00
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2011-04-20 21:31:41 +00:00
|
|
|
if (KeyInfo->Type != REG_SZ)
|
2009-01-10 19:09:37 +00:00
|
|
|
{
|
2011-04-20 21:31:41 +00:00
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
goto failed;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
2011-04-20 21:31:41 +00:00
|
|
|
|
|
|
|
if (!lpBuffer || *nSize < (KeyInfo->DataLength / sizeof(WCHAR)))
|
2009-07-11 14:18:06 +00:00
|
|
|
{
|
|
|
|
*nSize = ReturnSize;
|
2011-04-20 21:31:41 +00:00
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
|
|
|
goto failed;
|
2009-07-11 14:18:06 +00:00
|
|
|
}
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2011-04-20 21:31:41 +00:00
|
|
|
*nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1;
|
|
|
|
RtlCopyMemory(lpBuffer, KeyInfo->Data, KeyInfo->DataLength);
|
|
|
|
lpBuffer[*nSize] = 0;
|
2004-02-15 07:03:56 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
return TRUE;
|
2011-04-20 21:31:41 +00:00
|
|
|
|
|
|
|
failed:
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2011-04-20 21:31:41 +00:00
|
|
|
return FALSE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
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;
|
2008-09-07 09:19:49 +00:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
DWORD HostSize;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-10 19:09:37 +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);
|
2009-01-10 19:09:37 +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-19 08:41:31 +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",
|
2009-01-10 19:09:37 +00:00
|
|
|
QueryTable,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2005-06-30 13:50:21 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2008-09-07 09:19:49 +00:00
|
|
|
Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
2009-01-10 19:09:37 +00:00
|
|
|
HostSize = DomainPart.Length;
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
2008-09-07 09:19:49 +00:00
|
|
|
}
|
2009-01-10 19:09:37 +00:00
|
|
|
|
|
|
|
RtlAppendUnicodeToString(&ResultString, L".");
|
2005-06-30 13:50:21 +00:00
|
|
|
RtlFreeUnicodeString(&DomainPart);
|
2008-06-19 08:41:31 +00:00
|
|
|
|
2009-01-10 19:09:37 +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))
|
|
|
|
{
|
|
|
|
Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
|
|
|
if ((!NT_SUCCESS(Status)) || (!ret))
|
|
|
|
{
|
|
|
|
*nSize = HostSize + DomainPart.Length;
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
RtlFreeUnicodeString(&DomainPart);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RtlFreeUnicodeString(&DomainPart);
|
|
|
|
*nSize = ResultString.Length / sizeof(WCHAR) - 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2009-01-10 19:09:37 +00:00
|
|
|
GetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPSTR lpBuffer,
|
|
|
|
LPDWORD nSize)
|
2004-02-15 07:03:56 +00:00
|
|
|
{
|
|
|
|
UNICODE_STRING UnicodeString;
|
|
|
|
ANSI_STRING AnsiString;
|
|
|
|
BOOL Result;
|
2008-06-28 16:51:42 +00:00
|
|
|
PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
if (!TempBuffer)
|
|
|
|
{
|
2009-07-11 14:18:06 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
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
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
Result = GetComputerNameExW(NameType, TempBuffer, nSize);
|
2004-02-15 07:03:56 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
if (Result)
|
|
|
|
{
|
2008-09-07 09:19:49 +00:00
|
|
|
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
|
|
|
UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
|
|
|
UnicodeString.Buffer = TempBuffer;
|
2005-05-09 01:46:57 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
RtlUnicodeStringToAnsiString(&AnsiString,
|
|
|
|
&UnicodeString,
|
|
|
|
FALSE);
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 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
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
|
2004-02-15 07:03:56 +00:00
|
|
|
{
|
2009-06-13 15:33:33 +00:00
|
|
|
BOOL ret;
|
|
|
|
ret = GetComputerNameExA(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
|
|
|
if(!ret && GetLastError() == ERROR_MORE_DATA)
|
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
|
|
|
return ret;
|
2004-02-15 07:03:56 +00:00
|
|
|
}
|
2003-06-08 21:00:04 +00:00
|
|
|
|
|
|
|
|
2004-02-15 07:03:56 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
|
2004-02-15 07:03:56 +00:00
|
|
|
{
|
2009-06-13 15:33:33 +00:00
|
|
|
BOOL ret;
|
|
|
|
ret=GetComputerNameExW(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
|
|
|
if(!ret && GetLastError() == ERROR_MORE_DATA)
|
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
|
|
|
return ret;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
IsValidComputerName(COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPCWSTR lpComputerName)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2009-01-10 19:09:37 +00:00
|
|
|
PWCHAR p;
|
|
|
|
ULONG Length;
|
|
|
|
|
|
|
|
/* FIXME: do verification according to NameType */
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
Length = 0;
|
|
|
|
p = (PWCHAR)lpComputerName;
|
2008-06-19 08:41:31 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
while (*p != 0)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2009-01-10 19:09:37 +00:00
|
|
|
if (!(iswctype(*p, _ALPHA | _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
|
|
|
}
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
if (Length == 0 || Length > MAX_COMPUTERNAME_LENGTH)
|
|
|
|
return FALSE;
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
return TRUE;
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
SetComputerNameToRegistry(LPCWSTR RegistryKey,
|
|
|
|
LPCWSTR ValueNameStr,
|
|
|
|
LPCWSTR lpBuffer)
|
2005-09-04 20:11:51 +00:00
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
UNICODE_STRING ValueName;
|
|
|
|
HANDLE KeyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
RtlInitUnicodeString(&KeyName, RegistryKey);
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2005-09-04 20:11:51 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
Status = NtOpenKey(&KeyHandle,
|
|
|
|
KEY_WRITE,
|
|
|
|
&ObjectAttributes);
|
2005-09-04 20:11:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2005-09-04 20:11:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
RtlInitUnicodeString(&ValueName, ValueNameStr);
|
2005-09-04 20:11:51 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
Status = NtSetValueKey(KeyHandle,
|
|
|
|
&ValueName,
|
|
|
|
0,
|
|
|
|
REG_SZ,
|
|
|
|
(PVOID)lpBuffer,
|
|
|
|
(wcslen (lpBuffer) + 1) * sizeof(WCHAR));
|
2005-09-04 20:11:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2012-04-25 10:17:29 +00:00
|
|
|
NtClose(KeyHandle);
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2005-09-04 20:11:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
NtFlushKey(KeyHandle);
|
2012-04-25 10:17:29 +00:00
|
|
|
NtClose(KeyHandle);
|
2005-09-04 20:11:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetComputerNameA(LPCSTR lpComputerName)
|
2005-09-04 20:11:51 +00:00
|
|
|
{
|
2009-01-10 19:09:37 +00:00
|
|
|
return SetComputerNameExA(ComputerNamePhysicalNetBIOS, lpComputerName);
|
2005-09-04 20:11:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetComputerNameW(LPCWSTR lpComputerName)
|
2003-06-08 21:00:04 +00:00
|
|
|
{
|
2009-01-10 19:09:37 +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
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPCSTR lpBuffer)
|
2005-09-04 20:11:51 +00:00
|
|
|
{
|
|
|
|
UNICODE_STRING Buffer;
|
|
|
|
BOOL bResult;
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
RtlCreateUnicodeStringFromAsciiz(&Buffer, (LPSTR)lpBuffer);
|
2005-09-04 20:11:51 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
bResult = SetComputerNameExW(NameType, Buffer.Buffer);
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
RtlFreeUnicodeString(&Buffer);
|
2003-06-08 21:00:04 +00:00
|
|
|
|
2005-09-04 20:11:51 +00:00
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-01-10 19:09:37 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
|
|
|
|
LPCWSTR lpBuffer)
|
2005-09-04 20:11:51 +00:00
|
|
|
{
|
2009-01-10 19:09:37 +00:00
|
|
|
if (!IsValidComputerName(NameType, lpBuffer))
|
2008-06-18 15:37:44 +00:00
|
|
|
{
|
2009-01-10 19:09:37 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2008-06-18 15:37:44 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 19:09:37 +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;
|
|
|
|
}
|
2003-06-08 21:00:04 +00:00
|
|
|
}
|
|
|
|
|
2008-11-17 11:53:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2008-11-17 11:53:59 +00:00
|
|
|
DnsHostnameToComputerNameA(LPCSTR Hostname,
|
|
|
|
LPSTR ComputerName,
|
|
|
|
LPDWORD nSize)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
DPRINT("(%s, %p, %p)\n", Hostname, ComputerName, nSize);
|
|
|
|
|
|
|
|
if (!Hostname || !nSize)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
len = lstrlenA(Hostname);
|
|
|
|
|
|
|
|
if (len > MAX_COMPUTERNAME_LENGTH)
|
|
|
|
len = MAX_COMPUTERNAME_LENGTH;
|
|
|
|
|
|
|
|
if (*nSize < len)
|
|
|
|
{
|
|
|
|
*nSize = len;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ComputerName) return FALSE;
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
memcpy(ComputerName, Hostname, len);
|
2008-11-17 11:53:59 +00:00
|
|
|
ComputerName[len + 1] = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2009-01-10 19:09:37 +00:00
|
|
|
DnsHostnameToComputerNameW(LPCWSTR hostname,
|
|
|
|
LPWSTR computername,
|
|
|
|
LPDWORD size)
|
2008-11-17 11:53:59 +00:00
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
DPRINT("(%s, %p, %p): stub\n", hostname, computername, size);
|
|
|
|
|
|
|
|
if (!hostname || !size) return FALSE;
|
|
|
|
len = lstrlenW(hostname);
|
|
|
|
|
|
|
|
if (len > MAX_COMPUTERNAME_LENGTH)
|
|
|
|
len = MAX_COMPUTERNAME_LENGTH;
|
|
|
|
|
|
|
|
if (*size < len)
|
|
|
|
{
|
|
|
|
*size = len;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!computername) return FALSE;
|
|
|
|
|
2009-01-10 19:09:37 +00:00
|
|
|
memcpy(computername, hostname, len * sizeof(WCHAR));
|
2008-11-17 11:53:59 +00:00
|
|
|
computername[len + 1] = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-22 02:13:57 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
AddLocalAlternateComputerNameA(LPSTR lpName, PNTSTATUS Status)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
AddLocalAlternateComputerNameW(LPWSTR lpName, PNTSTATUS Status)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
EnumerateLocalComputerNamesA(PVOID pUnknown, DWORD Size, LPSTR lpBuffer, LPDWORD lpnSize)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
EnumerateLocalComputerNamesW(PVOID pUnknown, DWORD Size, LPWSTR lpBuffer, LPDWORD lpnSize)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
RemoveLocalAlternateComputerNameA(LPSTR lpName, DWORD Unknown)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
RemoveLocalAlternateComputerNameW(LPWSTR lpName, DWORD Unknown)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetLocalPrimaryComputerNameA(IN DWORD Unknown1,
|
|
|
|
IN DWORD Unknown2)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetLocalPrimaryComputerNameW(IN DWORD Unknown1,
|
|
|
|
IN DWORD Unknown2)
|
|
|
|
{
|
|
|
|
STUB;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-08 21:00:04 +00:00
|
|
|
/* EOF */
|