Implement SetComputerNameExA/W

svn path=/trunk/; revision=17639
This commit is contained in:
Hervé Poussineau 2005-09-04 20:11:51 +00:00
parent ff6172bd8f
commit 1037b8be47
3 changed files with 125 additions and 92 deletions

View file

@ -16,8 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id$
*
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* PURPOSE: Computer name functions
@ -282,35 +281,19 @@ GetComputerNameW (LPWSTR lpBuffer,
}
/*
* @implemented
*/
BOOL STDCALL
SetComputerNameA (LPCSTR lpComputerName)
{
UNICODE_STRING ComputerName;
BOOL bResult;
RtlCreateUnicodeStringFromAsciiz (&ComputerName,
(LPSTR)lpComputerName);
bResult = SetComputerNameW (ComputerName.Buffer);
RtlFreeUnicodeString (&ComputerName);
return bResult;
}
/*
* @implemented
*/
static BOOL
IsValidComputerName (LPCWSTR lpComputerName)
IsValidComputerName (
COMPUTER_NAME_FORMAT NameType,
LPCWSTR lpComputerName)
{
PWCHAR p;
ULONG Length;
/* FIXME: do verification according to NameType */
Length = 0;
p = (PWCHAR)lpComputerName;
while (*p != 0)
@ -346,11 +329,10 @@ IsValidComputerName (LPCWSTR lpComputerName)
}
/*
* @implemented
*/
BOOL STDCALL
SetComputerNameW (LPCWSTR lpComputerName)
static BOOL SetComputerNameToRegistry(
LPCWSTR RegistryKey,
LPCWSTR ValueNameStr,
LPCWSTR lpBuffer)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
@ -358,19 +340,13 @@ SetComputerNameW (LPCWSTR lpComputerName)
HANDLE KeyHandle;
NTSTATUS Status;
if (!IsValidComputerName (lpComputerName))
{
SetLastError (ERROR_INVALID_PARAMETER);
return FALSE;
}
RtlInitUnicodeString (&KeyName,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\ComputerName\\ComputerName");
RtlInitUnicodeString (&KeyName, RegistryKey);
InitializeObjectAttributes (&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
Status = NtOpenKey (&KeyHandle,
KEY_WRITE,
&ObjectAttributes);
@ -380,15 +356,14 @@ SetComputerNameW (LPCWSTR lpComputerName)
return FALSE;
}
RtlInitUnicodeString (&ValueName,
L"ComputerName");
RtlInitUnicodeString (&ValueName, ValueNameStr);
Status = NtSetValueKey (KeyHandle,
&ValueName,
0,
REG_SZ,
(PVOID)lpComputerName,
(wcslen (lpComputerName) + 1) * sizeof(WCHAR));
(PVOID)lpBuffer,
(wcslen (lpBuffer) + 1) * sizeof(WCHAR));
if (!NT_SUCCESS(Status))
{
ZwClose (KeyHandle);
@ -402,4 +377,89 @@ SetComputerNameW (LPCWSTR lpComputerName)
return TRUE;
}
/*
* @implemented
*/
BOOL STDCALL
SetComputerNameA (LPCSTR lpComputerName)
{
return SetComputerNameExA( ComputerNameNetBIOS, lpComputerName );
}
/*
* @implemented
*/
BOOL STDCALL
SetComputerNameW (LPCWSTR lpComputerName)
{
return SetComputerNameExW( ComputerNameNetBIOS, lpComputerName );
}
/*
* @implemented
*/
BOOL STDCALL
SetComputerNameExA (
COMPUTER_NAME_FORMAT NameType,
LPCSTR lpBuffer)
{
UNICODE_STRING Buffer;
BOOL bResult;
RtlCreateUnicodeStringFromAsciiz (&Buffer,
(LPSTR)lpBuffer);
bResult = SetComputerNameExW (NameType, Buffer.Buffer);
RtlFreeUnicodeString (&Buffer);
return bResult;
}
/*
* @implemented
*/
BOOL STDCALL
SetComputerNameExW (
COMPUTER_NAME_FORMAT NameType,
LPCWSTR lpBuffer)
{
if (!IsValidComputerName (NameType, lpBuffer))
{
SetLastError (ERROR_INVALID_PARAMETER);
return FALSE;
}
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;
}
}
/* EOF */

View file

@ -1,5 +1,4 @@
/* $Id$
*
/*
* KERNEL32.DLL stubs (STUB functions)
* Remove from this file, if you implement them.
*/
@ -1234,20 +1233,6 @@ ReplaceFileW(
return 0;
}
/*
* @unimplemented
*/
BOOL
STDCALL
SetComputerNameExW (
COMPUTER_NAME_FORMAT NameType,
LPCWSTR lpBuffer
)
{
STUB;
return 0;
}
/*
* @unimplemented
*/
@ -1493,20 +1478,6 @@ ReplaceFileA(
return 0;
}
/*
* @unimplemented
*/
BOOL
STDCALL
SetComputerNameExA (
COMPUTER_NAME_FORMAT NameType,
LPCSTR lpBuffer
)
{
STUB;
return 0;
}
/*
* @unimplemented
*/

View file

@ -2093,6 +2093,7 @@ typedef PCACTCTXW PCACTCTX;
#define ReportEvent ReportEventW
#define SearchPath SearchPathW
#define SetComputerName SetComputerNameW
#define SetComputerNameEx SetComputerNameExW
#define SetCurrentDirectory SetCurrentDirectoryW
#define SetDefaultCommConfig SetDefaultCommConfigW
#if (_WIN32_WINNT >= 0x0502)
@ -2291,6 +2292,7 @@ typedef ENUMRESTYPEPROCA ENUMRESTYPEPROC;
#define ReportEvent ReportEventA
#define SearchPath SearchPathA
#define SetComputerName SetComputerNameA
#define SetComputerNameEx SetComputerNameExA
#define SetCurrentDirectory SetCurrentDirectoryA
#define SetDefaultCommConfig SetDefaultCommConfigA
#if (_WIN32_WINNT >= 0x0502)