mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 17:44:45 +00:00
GetComputerName(Ex)?[AW] implemented. These are needed for the wine
iphlpapi_main. svn path=/trunk/; revision=8190
This commit is contained in:
parent
89d845f338
commit
b900afead3
3 changed files with 222 additions and 141 deletions
|
@ -1,4 +1,4 @@
|
|||
# $Id: makefile,v 1.75 2004/01/16 21:08:31 mf Exp $
|
||||
# $Id: makefile,v 1.76 2004/02/15 07:03:55 arty Exp $
|
||||
|
||||
PATH_TO_TOP = ../..
|
||||
|
||||
|
@ -70,11 +70,10 @@ DEBUG_OBJECTS = debug/debugger.o debug/output.o debug/break.o
|
|||
ARCH_OBJECTS = $(THREAD_I386_OBJECTS)
|
||||
|
||||
TARGET_OBJECTS = $(MISC_OBJECTS) $(FILE_OBJECTS) $(THREAD_OBJECTS) \
|
||||
$(PROCESS_OBJECTS) $(STRING_OBJECTS) $(MEM_OBJECTS) \
|
||||
$(SYNCH_OBJECTS) $(EXCEPT_OBJECTS) $(DEBUG_OBJECTS) \
|
||||
$(PROCESS_OBJECTS) $(STRING_OBJECTS) $(MEM_OBJECTS) \
|
||||
$(SYNCH_OBJECTS) $(EXCEPT_OBJECTS) $(DEBUG_OBJECTS) \
|
||||
$(ARCH_OBJECTS)
|
||||
|
||||
|
||||
DEP_OBJECTS = $(TARGET_OBJECTS)
|
||||
|
||||
include $(PATH_TO_TOP)/rules.mak
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id: computername.c,v 1.4 2004/01/23 21:16:03 ekohl Exp $
|
||||
/* $Id: computername.c,v 1.5 2004/02/15 07:03:56 arty Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -28,6 +28,8 @@
|
|||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <k32.h>
|
||||
#include <rosrtl/string.h>
|
||||
#include <rosrtl/registry.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include "../include/debug.h"
|
||||
|
@ -35,6 +37,217 @@
|
|||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
static BOOL GetComputerNameFromRegistry( LPWSTR RegistryKey,
|
||||
LPWSTR ValueNameStr,
|
||||
LPWSTR lpBuffer,
|
||||
LPDWORD nSize ) {
|
||||
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING KeyName;
|
||||
UNICODE_STRING ValueName;
|
||||
HANDLE KeyHandle;
|
||||
ULONG KeyInfoSize;
|
||||
ULONG ReturnSize;
|
||||
NTSTATUS Status;
|
||||
|
||||
RtlInitUnicodeString (&KeyName,RegistryKey);
|
||||
InitializeObjectAttributes (&ObjectAttributes,
|
||||
&KeyName,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
NULL,
|
||||
NULL);
|
||||
Status = ZwOpenKey (&KeyHandle,
|
||||
KEY_READ,
|
||||
&ObjectAttributes);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus (Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
|
||||
*nSize * sizeof(WCHAR);
|
||||
KeyInfo = RtlAllocateHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfoSize);
|
||||
if (KeyInfo == NULL)
|
||||
{
|
||||
ZwClose (KeyHandle);
|
||||
SetLastError (ERROR_OUTOFMEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RtlInitUnicodeString (&ValueName,ValueNameStr);
|
||||
|
||||
Status = ZwQueryValueKey (KeyHandle,
|
||||
&ValueName,
|
||||
KeyValuePartialInformation,
|
||||
KeyInfo,
|
||||
KeyInfoSize,
|
||||
&ReturnSize);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
RtlFreeHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfo);
|
||||
ZwClose (KeyHandle);
|
||||
SetLastErrorByStatus (Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DbgPrint("*nSize = %d, KeyInfo->DataLength = %d\n",
|
||||
*nSize, KeyInfo->DataLength);
|
||||
if( *nSize > (KeyInfo->DataLength / sizeof(WCHAR)) ) {
|
||||
*nSize = KeyInfo->DataLength / sizeof(WCHAR);
|
||||
lpBuffer[*nSize] = 0;
|
||||
}
|
||||
|
||||
RtlCopyMemory (lpBuffer,
|
||||
KeyInfo->Data,
|
||||
*nSize * sizeof(WCHAR));
|
||||
|
||||
RtlFreeHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfo)
|
||||
;
|
||||
ZwClose (KeyHandle);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
BOOL STDCALL
|
||||
GetComputerNameExW (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
LPWSTR lpBuffer,
|
||||
LPDWORD nSize
|
||||
)
|
||||
{
|
||||
UNICODE_STRING ResultString;
|
||||
UNICODE_STRING DomainPart, Dot;
|
||||
UNICODE_STRING RegKey, RegValue;
|
||||
|
||||
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:
|
||||
RtlInitUnicodeString(&Dot,L".");
|
||||
RosInitializeString(&ResultString,0,*nSize * sizeof(WCHAR),lpBuffer);
|
||||
RtlInitUnicodeString(&RegKey,
|
||||
L"\\Registry\\Machine\\System"
|
||||
L"\\CurrentControlSet\\Services\\Tcpip"
|
||||
L"\\Parameters");
|
||||
RtlInitUnicodeString(&RegValue,L"HostName");
|
||||
RtlInitUnicodeString(&DomainPart,L"");
|
||||
if( NT_SUCCESS(RosReadRegistryValue(&RegKey,&RegValue,&DomainPart)) ) {
|
||||
RtlAppendUnicodeStringToString(&ResultString,&DomainPart);
|
||||
RtlAppendUnicodeStringToString(&ResultString,&Dot);
|
||||
RtlFreeUnicodeString(&DomainPart);
|
||||
RtlInitUnicodeString(&RegValue,L"Domain");
|
||||
RtlInitUnicodeString(&DomainPart,L"");
|
||||
if( NT_SUCCESS(RosReadRegistryValue
|
||||
(&RegKey,&RegValue,&DomainPart)) ) {
|
||||
RtlAppendUnicodeStringToString(&ResultString,&DomainPart);
|
||||
RtlFreeUnicodeString(&DomainPart);
|
||||
*nSize = ResultString.Length / sizeof(WCHAR);
|
||||
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;
|
||||
}
|
||||
|
||||
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) );
|
||||
|
||||
if( !TempBuffer ) {
|
||||
return ERROR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
AnsiString.MaximumLength = *nSize;
|
||||
AnsiString.Length = 0;
|
||||
AnsiString.Buffer = lpBuffer;
|
||||
|
||||
Result = GetComputerNameExW( NameType, TempBuffer, nSize );
|
||||
|
||||
if( Result ) {
|
||||
UnicodeString.MaximumLength = *nSize * sizeof(WCHAR);
|
||||
UnicodeString.Length = *nSize * sizeof(WCHAR);
|
||||
UnicodeString.Buffer = TempBuffer;
|
||||
|
||||
DbgPrint("GetComputerNameExW Result: %wZ\n", &UnicodeString);
|
||||
|
||||
RtlUnicodeStringToAnsiString (&AnsiString,
|
||||
&UnicodeString,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
HeapFree( GetProcessHeap(), 0, TempBuffer );
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
|
@ -42,39 +255,7 @@ BOOL STDCALL
|
|||
GetComputerNameA (LPSTR lpBuffer,
|
||||
LPDWORD lpnSize)
|
||||
{
|
||||
UNICODE_STRING UnicodeString;
|
||||
ANSI_STRING AnsiString;
|
||||
|
||||
AnsiString.MaximumLength = *lpnSize;
|
||||
AnsiString.Length = 0;
|
||||
AnsiString.Buffer = lpBuffer;
|
||||
|
||||
UnicodeString.MaximumLength = *lpnSize * sizeof(WCHAR);
|
||||
UnicodeString.Length = 0;
|
||||
UnicodeString.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
UnicodeString.MaximumLength);
|
||||
if (UnicodeString.Buffer == NULL)
|
||||
{
|
||||
SetLastError (ERROR_OUTOFMEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!GetComputerNameW (UnicodeString.Buffer, lpnSize))
|
||||
{
|
||||
RtlFreeUnicodeString (&UnicodeString);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UnicodeString.Length = *lpnSize * sizeof(WCHAR);
|
||||
|
||||
RtlUnicodeStringToAnsiString (&AnsiString,
|
||||
&UnicodeString,
|
||||
FALSE);
|
||||
|
||||
RtlFreeUnicodeString (&UnicodeString);
|
||||
|
||||
return TRUE;
|
||||
return GetComputerNameExA( ComputerNameNetBIOS, lpBuffer, lpnSize );
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,76 +266,7 @@ BOOL STDCALL
|
|||
GetComputerNameW (LPWSTR lpBuffer,
|
||||
LPDWORD lpnSize)
|
||||
{
|
||||
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING KeyName;
|
||||
UNICODE_STRING ValueName;
|
||||
HANDLE KeyHandle;
|
||||
ULONG KeyInfoSize;
|
||||
ULONG ReturnSize;
|
||||
NTSTATUS Status;
|
||||
|
||||
RtlInitUnicodeString (&KeyName,
|
||||
L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\ComputerName\\ComputerName");
|
||||
InitializeObjectAttributes (&ObjectAttributes,
|
||||
&KeyName,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
NULL,
|
||||
NULL);
|
||||
Status = NtOpenKey (&KeyHandle,
|
||||
KEY_READ,
|
||||
&ObjectAttributes);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus (Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
|
||||
*lpnSize * sizeof(WCHAR);
|
||||
KeyInfo = RtlAllocateHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfoSize);
|
||||
if (KeyInfo == NULL)
|
||||
{
|
||||
NtClose (KeyHandle);
|
||||
SetLastError (ERROR_OUTOFMEMORY);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
RtlInitUnicodeString (&ValueName,
|
||||
L"ComputerName");
|
||||
|
||||
Status = NtQueryValueKey (KeyHandle,
|
||||
&ValueName,
|
||||
KeyValuePartialInformation,
|
||||
KeyInfo,
|
||||
KeyInfoSize,
|
||||
&ReturnSize);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
RtlFreeHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfo);
|
||||
NtClose (KeyHandle);
|
||||
SetLastErrorByStatus (Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*lpnSize =
|
||||
(KeyInfo->DataLength != 0) ? (KeyInfo->DataLength / sizeof(WCHAR)) - 1 : 0;
|
||||
|
||||
RtlCopyMemory (lpBuffer,
|
||||
KeyInfo->Data,
|
||||
KeyInfo->DataLength);
|
||||
lpBuffer[*lpnSize] = 0;
|
||||
|
||||
RtlFreeHeap (RtlGetProcessHeap (),
|
||||
0,
|
||||
KeyInfo);
|
||||
NtClose (KeyHandle);
|
||||
|
||||
return TRUE;
|
||||
return GetComputerNameExW( ComputerNameNetBIOS, lpBuffer, lpnSize );
|
||||
}
|
||||
|
||||
|
||||
|
@ -267,13 +379,13 @@ SetComputerNameW (LPCWSTR lpComputerName)
|
|||
(wcslen (lpComputerName) + 1) * sizeof(WCHAR));
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
NtClose (KeyHandle);
|
||||
ZwClose (KeyHandle);
|
||||
SetLastErrorByStatus (Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
NtFlushKey (KeyHandle);
|
||||
NtClose (KeyHandle);
|
||||
ZwClose (KeyHandle);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: stubs.c,v 1.61 2004/01/29 23:41:36 navaraf Exp $
|
||||
/* $Id: stubs.c,v 1.62 2004/02/15 07:03:56 arty Exp $
|
||||
*
|
||||
* KERNEL32.DLL stubs (unimplemented functions)
|
||||
* Remove from this file, if you implement them.
|
||||
|
@ -1786,21 +1786,6 @@ FindNextVolumeMountPointW(
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
BOOL
|
||||
STDCALL
|
||||
GetComputerNameExW (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
LPWSTR lpBuffer,
|
||||
LPDWORD nSize
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
|
@ -2190,21 +2175,6 @@ FindNextVolumeMountPointA(
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
BOOL
|
||||
STDCALL
|
||||
GetComputerNameExA (
|
||||
COMPUTER_NAME_FORMAT NameType,
|
||||
LPSTR lpBuffer,
|
||||
LPDWORD nSize
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue