mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 11:51:58 +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 *****************************************************************/
|
||||
|
||||
static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
||||
static
|
||||
BOOL
|
||||
GetComputerNameFromRegistry(LPWSTR RegistryKey,
|
||||
LPWSTR ValueNameStr,
|
||||
LPWSTR lpBuffer,
|
||||
LPDWORD nSize ) {
|
||||
LPDWORD nSize )
|
||||
{
|
||||
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING KeyName;
|
||||
|
@ -53,6 +56,7 @@ static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
|||
OBJ_CASE_INSENSITIVE,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
Status = ZwOpenKey(&KeyHandle,
|
||||
KEY_READ,
|
||||
&ObjectAttributes);
|
||||
|
@ -62,11 +66,8 @@ static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
|
||||
*nSize * sizeof(WCHAR);
|
||||
KeyInfo = RtlAllocateHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfoSize);
|
||||
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + *nSize * sizeof(WCHAR);
|
||||
KeyInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, KeyInfoSize);
|
||||
if (KeyInfo == NULL)
|
||||
{
|
||||
ZwClose(KeyHandle);
|
||||
|
@ -84,27 +85,22 @@ static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
|||
&ReturnSize);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
RtlFreeHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfo);
|
||||
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
||||
ZwClose(KeyHandle);
|
||||
*nSize = ReturnSize;
|
||||
SetLastErrorByStatus(Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( *nSize > (KeyInfo->DataLength / sizeof(WCHAR)) ) {
|
||||
if (*nSize > (KeyInfo->DataLength / sizeof(WCHAR)))
|
||||
{
|
||||
*nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1;
|
||||
lpBuffer[*nSize] = 0;
|
||||
}
|
||||
|
||||
RtlCopyMemory (lpBuffer,
|
||||
KeyInfo->Data,
|
||||
*nSize * sizeof(WCHAR));
|
||||
RtlCopyMemory(lpBuffer, KeyInfo->Data, *nSize * sizeof(WCHAR));
|
||||
|
||||
RtlFreeHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfo);
|
||||
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
||||
ZwClose(KeyHandle);
|
||||
|
||||
return TRUE;
|
||||
|
@ -113,12 +109,11 @@ static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL WINAPI
|
||||
GetComputerNameExW (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
BOOL
|
||||
WINAPI
|
||||
GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
|
||||
LPWSTR lpBuffer,
|
||||
LPDWORD nSize
|
||||
)
|
||||
LPDWORD nSize)
|
||||
{
|
||||
UNICODE_STRING ResultString;
|
||||
UNICODE_STRING DomainPart;
|
||||
|
@ -127,18 +122,17 @@ GetComputerNameExW (
|
|||
BOOL ret = TRUE;
|
||||
DWORD HostSize;
|
||||
|
||||
switch( NameType ) {
|
||||
switch (NameType)
|
||||
{
|
||||
case ComputerNameNetBIOS:
|
||||
return GetComputerNameFromRegistry
|
||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
L"\\Control\\ComputerName\\ComputerName",
|
||||
L"ComputerName",
|
||||
lpBuffer,
|
||||
nSize);
|
||||
|
||||
case ComputerNameDnsDomain:
|
||||
return GetComputerNameFromRegistry
|
||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
L"\\Services\\Tcpip\\Parameters",
|
||||
L"Domain",
|
||||
lpBuffer,
|
||||
|
@ -151,6 +145,7 @@ GetComputerNameExW (
|
|||
|
||||
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
||||
RtlInitUnicodeString(&DomainPart, NULL);
|
||||
|
||||
QueryTable[0].Name = L"HostName";
|
||||
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
|
||||
QueryTable[0].EntryContext = &DomainPart;
|
||||
|
@ -159,14 +154,20 @@ GetComputerNameExW (
|
|||
L"\\Registry\\Machine\\System"
|
||||
L"\\CurrentControlSet\\Services\\Tcpip"
|
||||
L"\\Parameters",
|
||||
QueryTable, NULL, NULL);
|
||||
QueryTable,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
||||
HostSize = DomainPart.Length;
|
||||
if (!NT_SUCCESS(Status)) {
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
ret = FALSE;
|
||||
}
|
||||
|
||||
RtlAppendUnicodeToString(&ResultString, L".");
|
||||
RtlFreeUnicodeString(&DomainPart);
|
||||
|
||||
|
@ -179,11 +180,15 @@ GetComputerNameExW (
|
|||
L"\\Registry\\Machine\\System"
|
||||
L"\\CurrentControlSet\\Services\\Tcpip"
|
||||
L"\\Parameters",
|
||||
QueryTable, NULL, NULL);
|
||||
QueryTable,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
|
||||
if ( (!NT_SUCCESS(Status)) || (!ret)) {
|
||||
if ((!NT_SUCCESS(Status)) || (!ret))
|
||||
{
|
||||
*nSize = HostSize + DomainPart.Length;
|
||||
SetLastError(ERROR_MORE_DATA);
|
||||
RtlFreeUnicodeString(&DomainPart);
|
||||
|
@ -197,16 +202,14 @@ GetComputerNameExW (
|
|||
return FALSE;
|
||||
|
||||
case ComputerNameDnsHostname:
|
||||
return GetComputerNameFromRegistry
|
||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
L"\\Services\\Tcpip\\Parameters",
|
||||
L"Hostname",
|
||||
lpBuffer,
|
||||
nSize);
|
||||
|
||||
case ComputerNamePhysicalDnsDomain:
|
||||
return GetComputerNameFromRegistry
|
||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
L"\\Services\\Tcpip\\Parameters",
|
||||
L"Domain",
|
||||
lpBuffer,
|
||||
|
@ -215,13 +218,18 @@ GetComputerNameExW (
|
|||
/* XXX Redo these */
|
||||
case ComputerNamePhysicalDnsFullyQualified:
|
||||
return GetComputerNameExW(ComputerNameDnsFullyQualified,
|
||||
lpBuffer, nSize );
|
||||
lpBuffer,
|
||||
nSize);
|
||||
|
||||
case ComputerNamePhysicalDnsHostname:
|
||||
return GetComputerNameExW(ComputerNameDnsHostname,
|
||||
lpBuffer, nSize );
|
||||
lpBuffer,
|
||||
nSize);
|
||||
|
||||
case ComputerNamePhysicalNetBIOS:
|
||||
return GetComputerNameExW(ComputerNameNetBIOS,
|
||||
lpBuffer, nSize );
|
||||
lpBuffer,
|
||||
nSize);
|
||||
|
||||
case ComputerNameMax:
|
||||
return FALSE;
|
||||
|
@ -235,18 +243,17 @@ GetComputerNameExW (
|
|||
*/
|
||||
BOOL
|
||||
WINAPI
|
||||
GetComputerNameExA (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
GetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
|
||||
LPSTR lpBuffer,
|
||||
LPDWORD nSize
|
||||
)
|
||||
LPDWORD nSize)
|
||||
{
|
||||
UNICODE_STRING UnicodeString;
|
||||
ANSI_STRING AnsiString;
|
||||
BOOL Result;
|
||||
PWCHAR TempBuffer = RtlAllocateHeap( RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR) );
|
||||
|
||||
if( !TempBuffer ) {
|
||||
if (!TempBuffer)
|
||||
{
|
||||
return ERROR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
|
@ -256,7 +263,8 @@ GetComputerNameExA (
|
|||
|
||||
Result = GetComputerNameExW(NameType, TempBuffer, nSize);
|
||||
|
||||
if( Result ) {
|
||||
if (Result)
|
||||
{
|
||||
UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
||||
UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
|
||||
UnicodeString.Buffer = TempBuffer;
|
||||
|
@ -274,9 +282,9 @@ GetComputerNameExA (
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL WINAPI
|
||||
GetComputerNameA (LPSTR lpBuffer,
|
||||
LPDWORD lpnSize)
|
||||
BOOL
|
||||
WINAPI
|
||||
GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
|
||||
{
|
||||
return GetComputerNameExA(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
||||
}
|
||||
|
@ -285,9 +293,9 @@ GetComputerNameA (LPSTR lpBuffer,
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL WINAPI
|
||||
GetComputerNameW (LPWSTR lpBuffer,
|
||||
LPDWORD lpnSize)
|
||||
BOOL
|
||||
WINAPI
|
||||
GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
|
||||
{
|
||||
return GetComputerNameExW(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
||||
}
|
||||
|
@ -296,9 +304,9 @@ GetComputerNameW (LPWSTR lpBuffer,
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
static BOOL
|
||||
IsValidComputerName (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
static
|
||||
BOOL
|
||||
IsValidComputerName(COMPUTER_NAME_FORMAT NameType,
|
||||
LPCWSTR lpComputerName)
|
||||
{
|
||||
PWCHAR p;
|
||||
|
@ -308,6 +316,7 @@ IsValidComputerName (
|
|||
|
||||
Length = 0;
|
||||
p = (PWCHAR)lpComputerName;
|
||||
|
||||
while (*p != 0)
|
||||
{
|
||||
if (!(iswctype(*p, _ALPHA | _DIGIT) || *p == L'!' || *p == L'@' || *p == L'#' ||
|
||||
|
@ -320,16 +329,16 @@ IsValidComputerName (
|
|||
p++;
|
||||
}
|
||||
|
||||
if (Length == 0 ||
|
||||
Length > MAX_COMPUTERNAME_LENGTH)
|
||||
if (Length == 0 || Length > MAX_COMPUTERNAME_LENGTH)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static BOOL SetComputerNameToRegistry(
|
||||
LPCWSTR RegistryKey,
|
||||
static
|
||||
BOOL
|
||||
SetComputerNameToRegistry(LPCWSTR RegistryKey,
|
||||
LPCWSTR ValueNameStr,
|
||||
LPCWSTR lpBuffer)
|
||||
{
|
||||
|
@ -380,7 +389,8 @@ static BOOL SetComputerNameToRegistry(
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL WINAPI
|
||||
BOOL
|
||||
WINAPI
|
||||
SetComputerNameA(LPCSTR lpComputerName)
|
||||
{
|
||||
return SetComputerNameExA(ComputerNamePhysicalNetBIOS, lpComputerName);
|
||||
|
@ -390,7 +400,8 @@ SetComputerNameA (LPCSTR lpComputerName)
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL WINAPI
|
||||
BOOL
|
||||
WINAPI
|
||||
SetComputerNameW(LPCWSTR lpComputerName)
|
||||
{
|
||||
return SetComputerNameExW(ComputerNamePhysicalNetBIOS, lpComputerName);
|
||||
|
@ -400,16 +411,15 @@ SetComputerNameW (LPCWSTR lpComputerName)
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL WINAPI
|
||||
SetComputerNameExA (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
BOOL
|
||||
WINAPI
|
||||
SetComputerNameExA(COMPUTER_NAME_FORMAT NameType,
|
||||
LPCSTR lpBuffer)
|
||||
{
|
||||
UNICODE_STRING Buffer;
|
||||
BOOL bResult;
|
||||
|
||||
RtlCreateUnicodeStringFromAsciiz (&Buffer,
|
||||
(LPSTR)lpBuffer);
|
||||
RtlCreateUnicodeStringFromAsciiz(&Buffer, (LPSTR)lpBuffer);
|
||||
|
||||
bResult = SetComputerNameExW(NameType, Buffer.Buffer);
|
||||
|
||||
|
@ -422,9 +432,9 @@ SetComputerNameExA (
|
|||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL WINAPI
|
||||
SetComputerNameExW (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
BOOL
|
||||
WINAPI
|
||||
SetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
|
||||
LPCWSTR lpBuffer)
|
||||
{
|
||||
if (!IsValidComputerName(NameType, lpBuffer))
|
||||
|
@ -433,24 +443,22 @@ SetComputerNameExW (
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
switch( NameType ) {
|
||||
switch( NameType )
|
||||
{
|
||||
case ComputerNamePhysicalDnsDomain:
|
||||
return SetComputerNameToRegistry
|
||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
L"\\Services\\Tcpip\\Parameters",
|
||||
L"Domain",
|
||||
lpBuffer);
|
||||
|
||||
case ComputerNamePhysicalDnsHostname:
|
||||
return SetComputerNameToRegistry
|
||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
L"\\Services\\Tcpip\\Parameters",
|
||||
L"Hostname",
|
||||
lpBuffer);
|
||||
|
||||
case ComputerNamePhysicalNetBIOS:
|
||||
return SetComputerNameToRegistry
|
||||
( L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||
L"\\Control\\ComputerName\\ComputerName",
|
||||
L"ComputerName",
|
||||
lpBuffer);
|
||||
|
@ -502,11 +510,9 @@ DnsHostnameToComputerNameA(LPCSTR Hostname,
|
|||
*/
|
||||
BOOL
|
||||
WINAPI
|
||||
DnsHostnameToComputerNameW (
|
||||
LPCWSTR hostname,
|
||||
DnsHostnameToComputerNameW(LPCWSTR hostname,
|
||||
LPWSTR computername,
|
||||
LPDWORD size
|
||||
)
|
||||
LPDWORD size)
|
||||
{
|
||||
DWORD len;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue