mirror of
https://github.com/reactos/reactos.git
synced 2025-04-26 00:20:34 +00:00
- Formatting fix. No code change
svn path=/trunk/; revision=38688
This commit is contained in:
parent
faff43dadc
commit
a7f8cd9375
1 changed files with 247 additions and 241 deletions
|
@ -34,10 +34,13 @@
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
static
|
||||||
LPWSTR ValueNameStr,
|
BOOL
|
||||||
LPWSTR lpBuffer,
|
GetComputerNameFromRegistry(LPWSTR RegistryKey,
|
||||||
LPDWORD nSize ) {
|
LPWSTR ValueNameStr,
|
||||||
|
LPWSTR lpBuffer,
|
||||||
|
LPDWORD nSize )
|
||||||
|
{
|
||||||
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
UNICODE_STRING KeyName;
|
UNICODE_STRING KeyName;
|
||||||
|
@ -47,65 +50,58 @@ static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
||||||
ULONG ReturnSize;
|
ULONG ReturnSize;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
RtlInitUnicodeString (&KeyName,RegistryKey);
|
RtlInitUnicodeString(&KeyName,RegistryKey);
|
||||||
InitializeObjectAttributes (&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&KeyName,
|
&KeyName,
|
||||||
OBJ_CASE_INSENSITIVE,
|
OBJ_CASE_INSENSITIVE,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
Status = ZwOpenKey (&KeyHandle,
|
|
||||||
KEY_READ,
|
Status = ZwOpenKey(&KeyHandle,
|
||||||
&ObjectAttributes);
|
KEY_READ,
|
||||||
|
&ObjectAttributes);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
SetLastErrorByStatus (Status);
|
SetLastErrorByStatus (Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
|
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + *nSize * sizeof(WCHAR);
|
||||||
*nSize * sizeof(WCHAR);
|
KeyInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, KeyInfoSize);
|
||||||
KeyInfo = RtlAllocateHeap (RtlGetProcessHeap (),
|
|
||||||
0,
|
|
||||||
KeyInfoSize);
|
|
||||||
if (KeyInfo == NULL)
|
if (KeyInfo == NULL)
|
||||||
{
|
{
|
||||||
ZwClose (KeyHandle);
|
ZwClose(KeyHandle);
|
||||||
SetLastError (ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlInitUnicodeString (&ValueName,ValueNameStr);
|
RtlInitUnicodeString(&ValueName,ValueNameStr);
|
||||||
|
|
||||||
Status = ZwQueryValueKey (KeyHandle,
|
Status = ZwQueryValueKey(KeyHandle,
|
||||||
&ValueName,
|
&ValueName,
|
||||||
KeyValuePartialInformation,
|
KeyValuePartialInformation,
|
||||||
KeyInfo,
|
KeyInfo,
|
||||||
KeyInfoSize,
|
KeyInfoSize,
|
||||||
&ReturnSize);
|
&ReturnSize);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
RtlFreeHeap (RtlGetProcessHeap (),
|
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
||||||
0,
|
ZwClose(KeyHandle);
|
||||||
KeyInfo);
|
|
||||||
ZwClose (KeyHandle);
|
|
||||||
*nSize = ReturnSize;
|
*nSize = ReturnSize;
|
||||||
SetLastErrorByStatus (Status);
|
SetLastErrorByStatus(Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( *nSize > (KeyInfo->DataLength / sizeof(WCHAR)) ) {
|
if (*nSize > (KeyInfo->DataLength / sizeof(WCHAR)))
|
||||||
|
{
|
||||||
*nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1;
|
*nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1;
|
||||||
lpBuffer[*nSize] = 0;
|
lpBuffer[*nSize] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlCopyMemory (lpBuffer,
|
RtlCopyMemory(lpBuffer, KeyInfo->Data, *nSize * sizeof(WCHAR));
|
||||||
KeyInfo->Data,
|
|
||||||
*nSize * sizeof(WCHAR));
|
|
||||||
|
|
||||||
RtlFreeHeap (RtlGetProcessHeap (),
|
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
||||||
0,
|
ZwClose(KeyHandle);
|
||||||
KeyInfo);
|
|
||||||
ZwClose (KeyHandle);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -113,12 +109,11 @@ static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI
|
BOOL
|
||||||
GetComputerNameExW (
|
WINAPI
|
||||||
COMPUTER_NAME_FORMAT NameType,
|
GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
|
||||||
LPWSTR lpBuffer,
|
LPWSTR lpBuffer,
|
||||||
LPDWORD nSize
|
LPDWORD nSize)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
UNICODE_STRING ResultString;
|
UNICODE_STRING ResultString;
|
||||||
UNICODE_STRING DomainPart;
|
UNICODE_STRING DomainPart;
|
||||||
|
@ -127,51 +122,31 @@ GetComputerNameExW (
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
DWORD HostSize;
|
DWORD HostSize;
|
||||||
|
|
||||||
switch( NameType ) {
|
switch (NameType)
|
||||||
case ComputerNameNetBIOS:
|
{
|
||||||
return GetComputerNameFromRegistry
|
case ComputerNameNetBIOS:
|
||||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
L"\\Control\\ComputerName\\ComputerName",
|
L"\\Control\\ComputerName\\ComputerName",
|
||||||
L"ComputerName",
|
L"ComputerName",
|
||||||
lpBuffer,
|
lpBuffer,
|
||||||
nSize );
|
nSize);
|
||||||
|
|
||||||
case ComputerNameDnsDomain:
|
case ComputerNameDnsDomain:
|
||||||
return GetComputerNameFromRegistry
|
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
L"\\Services\\Tcpip\\Parameters",
|
||||||
L"\\Services\\Tcpip\\Parameters",
|
L"Domain",
|
||||||
L"Domain",
|
lpBuffer,
|
||||||
lpBuffer,
|
nSize);
|
||||||
nSize );
|
|
||||||
|
|
||||||
case ComputerNameDnsFullyQualified:
|
case ComputerNameDnsFullyQualified:
|
||||||
ResultString.Length = 0;
|
ResultString.Length = 0;
|
||||||
ResultString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR);
|
ResultString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR);
|
||||||
ResultString.Buffer = lpBuffer;
|
ResultString.Buffer = lpBuffer;
|
||||||
|
|
||||||
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
|
||||||
RtlInitUnicodeString(&DomainPart, NULL);
|
|
||||||
QueryTable[0].Name = L"HostName";
|
|
||||||
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);
|
|
||||||
HostSize = DomainPart.Length;
|
|
||||||
if (!NT_SUCCESS(Status)) {
|
|
||||||
ret = FALSE;
|
|
||||||
}
|
|
||||||
RtlAppendUnicodeToString(&ResultString, L".");
|
|
||||||
RtlFreeUnicodeString(&DomainPart);
|
|
||||||
|
|
||||||
|
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
||||||
RtlInitUnicodeString(&DomainPart, NULL);
|
RtlInitUnicodeString(&DomainPart, NULL);
|
||||||
QueryTable[0].Name = L"Domain";
|
|
||||||
|
QueryTable[0].Name = L"HostName";
|
||||||
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
||||||
QueryTable[0].EntryContext = &DomainPart;
|
QueryTable[0].EntryContext = &DomainPart;
|
||||||
|
|
||||||
|
@ -179,52 +154,85 @@ GetComputerNameExW (
|
||||||
L"\\Registry\\Machine\\System"
|
L"\\Registry\\Machine\\System"
|
||||||
L"\\CurrentControlSet\\Services\\Tcpip"
|
L"\\CurrentControlSet\\Services\\Tcpip"
|
||||||
L"\\Parameters",
|
L"\\Parameters",
|
||||||
QueryTable, NULL, NULL);
|
QueryTable,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if( NT_SUCCESS(Status) ) {
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
||||||
if ( (!NT_SUCCESS(Status)) || (!ret)) {
|
HostSize = DomainPart.Length;
|
||||||
*nSize = HostSize + DomainPart.Length;
|
|
||||||
SetLastError(ERROR_MORE_DATA);
|
if (!NT_SUCCESS(Status))
|
||||||
RtlFreeUnicodeString(&DomainPart);
|
{
|
||||||
return FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtlAppendUnicodeToString(&ResultString, L".");
|
||||||
RtlFreeUnicodeString(&DomainPart);
|
RtlFreeUnicodeString(&DomainPart);
|
||||||
*nSize = ResultString.Length / sizeof(WCHAR) - 1;
|
|
||||||
return TRUE;
|
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;
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
case ComputerNameDnsHostname:
|
case ComputerNameDnsHostname:
|
||||||
return GetComputerNameFromRegistry
|
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
L"\\Services\\Tcpip\\Parameters",
|
||||||
L"\\Services\\Tcpip\\Parameters",
|
L"Hostname",
|
||||||
L"Hostname",
|
lpBuffer,
|
||||||
lpBuffer,
|
nSize);
|
||||||
nSize );
|
|
||||||
|
|
||||||
case ComputerNamePhysicalDnsDomain:
|
case ComputerNamePhysicalDnsDomain:
|
||||||
return GetComputerNameFromRegistry
|
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
L"\\Services\\Tcpip\\Parameters",
|
||||||
L"\\Services\\Tcpip\\Parameters",
|
L"Domain",
|
||||||
L"Domain",
|
lpBuffer,
|
||||||
lpBuffer,
|
nSize);
|
||||||
nSize );
|
|
||||||
|
|
||||||
/* XXX Redo these */
|
/* XXX Redo these */
|
||||||
case ComputerNamePhysicalDnsFullyQualified:
|
case ComputerNamePhysicalDnsFullyQualified:
|
||||||
return GetComputerNameExW( ComputerNameDnsFullyQualified,
|
return GetComputerNameExW(ComputerNameDnsFullyQualified,
|
||||||
lpBuffer, nSize );
|
lpBuffer,
|
||||||
case ComputerNamePhysicalDnsHostname:
|
nSize);
|
||||||
return GetComputerNameExW( ComputerNameDnsHostname,
|
|
||||||
lpBuffer, nSize );
|
|
||||||
case ComputerNamePhysicalNetBIOS:
|
|
||||||
return GetComputerNameExW( ComputerNameNetBIOS,
|
|
||||||
lpBuffer, nSize );
|
|
||||||
|
|
||||||
case ComputerNameMax:
|
case ComputerNamePhysicalDnsHostname:
|
||||||
return FALSE;
|
return GetComputerNameExW(ComputerNameDnsHostname,
|
||||||
|
lpBuffer,
|
||||||
|
nSize);
|
||||||
|
|
||||||
|
case ComputerNamePhysicalNetBIOS:
|
||||||
|
return GetComputerNameExW(ComputerNameNetBIOS,
|
||||||
|
lpBuffer,
|
||||||
|
nSize);
|
||||||
|
|
||||||
|
case ComputerNameMax:
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -235,18 +243,17 @@ GetComputerNameExW (
|
||||||
*/
|
*/
|
||||||
BOOL
|
BOOL
|
||||||
WINAPI
|
WINAPI
|
||||||
GetComputerNameExA (
|
GetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
|
||||||
COMPUTER_NAME_FORMAT NameType,
|
LPSTR lpBuffer,
|
||||||
LPSTR lpBuffer,
|
LPDWORD nSize)
|
||||||
LPDWORD nSize
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
UNICODE_STRING UnicodeString;
|
UNICODE_STRING UnicodeString;
|
||||||
ANSI_STRING AnsiString;
|
ANSI_STRING AnsiString;
|
||||||
BOOL Result;
|
BOOL Result;
|
||||||
PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
|
PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
|
||||||
|
|
||||||
if( !TempBuffer ) {
|
if (!TempBuffer)
|
||||||
|
{
|
||||||
return ERROR_OUTOFMEMORY;
|
return ERROR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,19 +261,20 @@ GetComputerNameExA (
|
||||||
AnsiString.Length = 0;
|
AnsiString.Length = 0;
|
||||||
AnsiString.Buffer = lpBuffer;
|
AnsiString.Buffer = lpBuffer;
|
||||||
|
|
||||||
Result = GetComputerNameExW( NameType, TempBuffer, nSize );
|
Result = GetComputerNameExW(NameType, TempBuffer, nSize);
|
||||||
|
|
||||||
if( Result ) {
|
if (Result)
|
||||||
|
{
|
||||||
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
||||||
UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
||||||
UnicodeString.Buffer = TempBuffer;
|
UnicodeString.Buffer = TempBuffer;
|
||||||
|
|
||||||
RtlUnicodeStringToAnsiString (&AnsiString,
|
RtlUnicodeStringToAnsiString(&AnsiString,
|
||||||
&UnicodeString,
|
&UnicodeString,
|
||||||
FALSE);
|
FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlFreeHeap( RtlGetProcessHeap(), 0, TempBuffer );
|
RtlFreeHeap(RtlGetProcessHeap(), 0, TempBuffer);
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
@ -274,64 +282,65 @@ GetComputerNameExA (
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI
|
BOOL
|
||||||
GetComputerNameA (LPSTR lpBuffer,
|
WINAPI
|
||||||
LPDWORD lpnSize)
|
GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
|
||||||
{
|
{
|
||||||
return GetComputerNameExA( ComputerNameNetBIOS, lpBuffer, lpnSize );
|
return GetComputerNameExA(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI
|
BOOL
|
||||||
GetComputerNameW (LPWSTR lpBuffer,
|
WINAPI
|
||||||
LPDWORD lpnSize)
|
GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
|
||||||
{
|
{
|
||||||
return GetComputerNameExW( ComputerNameNetBIOS, lpBuffer, lpnSize );
|
return GetComputerNameExW(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
static BOOL
|
static
|
||||||
IsValidComputerName (
|
BOOL
|
||||||
COMPUTER_NAME_FORMAT NameType,
|
IsValidComputerName(COMPUTER_NAME_FORMAT NameType,
|
||||||
LPCWSTR lpComputerName)
|
LPCWSTR lpComputerName)
|
||||||
{
|
{
|
||||||
PWCHAR p;
|
PWCHAR p;
|
||||||
ULONG Length;
|
ULONG Length;
|
||||||
|
|
||||||
/* FIXME: do verification according to NameType */
|
/* FIXME: do verification according to NameType */
|
||||||
|
|
||||||
Length = 0;
|
Length = 0;
|
||||||
p = (PWCHAR)lpComputerName;
|
p = (PWCHAR)lpComputerName;
|
||||||
while (*p != 0)
|
|
||||||
|
while (*p != 0)
|
||||||
{
|
{
|
||||||
if (!(iswctype(*p, _ALPHA | _DIGIT) || *p == L'!' || *p == L'@' || *p == L'#' ||
|
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'.' || *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;
|
return FALSE;
|
||||||
|
|
||||||
Length++;
|
Length++;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Length == 0 ||
|
if (Length == 0 || Length > MAX_COMPUTERNAME_LENGTH)
|
||||||
Length > MAX_COMPUTERNAME_LENGTH)
|
return FALSE;
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static BOOL SetComputerNameToRegistry(
|
static
|
||||||
LPCWSTR RegistryKey,
|
BOOL
|
||||||
LPCWSTR ValueNameStr,
|
SetComputerNameToRegistry(LPCWSTR RegistryKey,
|
||||||
LPCWSTR lpBuffer)
|
LPCWSTR ValueNameStr,
|
||||||
|
LPCWSTR lpBuffer)
|
||||||
{
|
{
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
UNICODE_STRING KeyName;
|
UNICODE_STRING KeyName;
|
||||||
|
@ -339,39 +348,39 @@ static BOOL SetComputerNameToRegistry(
|
||||||
HANDLE KeyHandle;
|
HANDLE KeyHandle;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
RtlInitUnicodeString (&KeyName, RegistryKey);
|
RtlInitUnicodeString(&KeyName, RegistryKey);
|
||||||
InitializeObjectAttributes (&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&KeyName,
|
&KeyName,
|
||||||
OBJ_CASE_INSENSITIVE,
|
OBJ_CASE_INSENSITIVE,
|
||||||
NULL,
|
NULL,
|
||||||
NULL );
|
NULL);
|
||||||
|
|
||||||
Status = NtOpenKey (&KeyHandle,
|
Status = NtOpenKey(&KeyHandle,
|
||||||
KEY_WRITE,
|
KEY_WRITE,
|
||||||
&ObjectAttributes);
|
&ObjectAttributes);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
SetLastErrorByStatus (Status);
|
SetLastErrorByStatus(Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlInitUnicodeString (&ValueName, ValueNameStr);
|
RtlInitUnicodeString(&ValueName, ValueNameStr);
|
||||||
|
|
||||||
Status = NtSetValueKey (KeyHandle,
|
Status = NtSetValueKey(KeyHandle,
|
||||||
&ValueName,
|
&ValueName,
|
||||||
0,
|
0,
|
||||||
REG_SZ,
|
REG_SZ,
|
||||||
(PVOID)lpBuffer,
|
(PVOID)lpBuffer,
|
||||||
(wcslen (lpBuffer) + 1) * sizeof(WCHAR));
|
(wcslen (lpBuffer) + 1) * sizeof(WCHAR));
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
ZwClose (KeyHandle);
|
ZwClose(KeyHandle);
|
||||||
SetLastErrorByStatus (Status);
|
SetLastErrorByStatus(Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NtFlushKey (KeyHandle);
|
NtFlushKey(KeyHandle);
|
||||||
ZwClose (KeyHandle);
|
ZwClose(KeyHandle);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -380,40 +389,41 @@ static BOOL SetComputerNameToRegistry(
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI
|
BOOL
|
||||||
SetComputerNameA (LPCSTR lpComputerName)
|
WINAPI
|
||||||
|
SetComputerNameA(LPCSTR lpComputerName)
|
||||||
{
|
{
|
||||||
return SetComputerNameExA( ComputerNamePhysicalNetBIOS, lpComputerName );
|
return SetComputerNameExA(ComputerNamePhysicalNetBIOS, lpComputerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI
|
BOOL
|
||||||
SetComputerNameW (LPCWSTR lpComputerName)
|
WINAPI
|
||||||
|
SetComputerNameW(LPCWSTR lpComputerName)
|
||||||
{
|
{
|
||||||
return SetComputerNameExW( ComputerNamePhysicalNetBIOS, lpComputerName );
|
return SetComputerNameExW(ComputerNamePhysicalNetBIOS, lpComputerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI
|
BOOL
|
||||||
SetComputerNameExA (
|
WINAPI
|
||||||
COMPUTER_NAME_FORMAT NameType,
|
SetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
|
||||||
LPCSTR lpBuffer)
|
LPCSTR lpBuffer)
|
||||||
{
|
{
|
||||||
UNICODE_STRING Buffer;
|
UNICODE_STRING Buffer;
|
||||||
BOOL bResult;
|
BOOL bResult;
|
||||||
|
|
||||||
RtlCreateUnicodeStringFromAsciiz (&Buffer,
|
RtlCreateUnicodeStringFromAsciiz(&Buffer, (LPSTR)lpBuffer);
|
||||||
(LPSTR)lpBuffer);
|
|
||||||
|
|
||||||
bResult = SetComputerNameExW (NameType, Buffer.Buffer);
|
bResult = SetComputerNameExW(NameType, Buffer.Buffer);
|
||||||
|
|
||||||
RtlFreeUnicodeString (&Buffer);
|
RtlFreeUnicodeString(&Buffer);
|
||||||
|
|
||||||
return bResult;
|
return bResult;
|
||||||
}
|
}
|
||||||
|
@ -422,43 +432,41 @@ SetComputerNameExA (
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI
|
BOOL
|
||||||
SetComputerNameExW (
|
WINAPI
|
||||||
COMPUTER_NAME_FORMAT NameType,
|
SetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
|
||||||
LPCWSTR lpBuffer)
|
LPCWSTR lpBuffer)
|
||||||
{
|
{
|
||||||
if (!IsValidComputerName (NameType, lpBuffer))
|
if (!IsValidComputerName(NameType, lpBuffer))
|
||||||
{
|
{
|
||||||
SetLastError (ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( NameType ) {
|
switch( NameType )
|
||||||
case ComputerNamePhysicalDnsDomain:
|
{
|
||||||
return SetComputerNameToRegistry
|
case ComputerNamePhysicalDnsDomain:
|
||||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
L"\\Services\\Tcpip\\Parameters",
|
L"\\Services\\Tcpip\\Parameters",
|
||||||
L"Domain",
|
L"Domain",
|
||||||
lpBuffer );
|
lpBuffer);
|
||||||
|
|
||||||
case ComputerNamePhysicalDnsHostname:
|
case ComputerNamePhysicalDnsHostname:
|
||||||
return SetComputerNameToRegistry
|
return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
L"\\Services\\Tcpip\\Parameters",
|
||||||
L"\\Services\\Tcpip\\Parameters",
|
L"Hostname",
|
||||||
L"Hostname",
|
lpBuffer);
|
||||||
lpBuffer );
|
|
||||||
|
|
||||||
case ComputerNamePhysicalNetBIOS:
|
case ComputerNamePhysicalNetBIOS:
|
||||||
return SetComputerNameToRegistry
|
return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
L"\\Control\\ComputerName\\ComputerName",
|
||||||
L"\\Control\\ComputerName\\ComputerName",
|
L"ComputerName",
|
||||||
L"ComputerName",
|
lpBuffer);
|
||||||
lpBuffer );
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SetLastError (ERROR_INVALID_PARAMETER);
|
SetLastError (ERROR_INVALID_PARAMETER);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -491,7 +499,7 @@ DnsHostnameToComputerNameA(LPCSTR Hostname,
|
||||||
|
|
||||||
if (!ComputerName) return FALSE;
|
if (!ComputerName) return FALSE;
|
||||||
|
|
||||||
memcpy( ComputerName, Hostname, len );
|
memcpy(ComputerName, Hostname, len);
|
||||||
ComputerName[len + 1] = 0;
|
ComputerName[len + 1] = 0;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -502,11 +510,9 @@ DnsHostnameToComputerNameA(LPCSTR Hostname,
|
||||||
*/
|
*/
|
||||||
BOOL
|
BOOL
|
||||||
WINAPI
|
WINAPI
|
||||||
DnsHostnameToComputerNameW (
|
DnsHostnameToComputerNameW(LPCWSTR hostname,
|
||||||
LPCWSTR hostname,
|
LPWSTR computername,
|
||||||
LPWSTR computername,
|
LPDWORD size)
|
||||||
LPDWORD size
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
|
||||||
|
@ -525,7 +531,7 @@ DnsHostnameToComputerNameW (
|
||||||
}
|
}
|
||||||
if (!computername) return FALSE;
|
if (!computername) return FALSE;
|
||||||
|
|
||||||
memcpy( computername, hostname, len * sizeof(WCHAR) );
|
memcpy(computername, hostname, len * sizeof(WCHAR));
|
||||||
computername[len + 1] = 0;
|
computername[len + 1] = 0;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue