ReactOS  0.4.15-dev-425-gc40b086
compname.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for compname.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static BOOL GetComputerNameFromRegistry (LPWSTR RegistryKey, LPWSTR ValueNameStr, LPWSTR lpBuffer, LPDWORD nSize)
 
static BOOL SetActiveComputerNameToRegistry (LPCWSTR RegistryKey, LPCWSTR SubKey, LPCWSTR ValueNameStr, LPCWSTR lpBuffer)
 
BOOL WINAPI GetComputerNameExW (COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
 
BOOL WINAPI GetComputerNameExA (COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD nSize)
 
BOOL WINAPI GetComputerNameA (LPSTR lpBuffer, LPDWORD lpnSize)
 
BOOL WINAPI GetComputerNameW (LPWSTR lpBuffer, LPDWORD lpnSize)
 
static BOOL IsValidComputerName (COMPUTER_NAME_FORMAT NameType, LPCWSTR lpComputerName)
 
static BOOL SetComputerNameToRegistry (LPCWSTR RegistryKey, LPCWSTR ValueNameStr, LPCWSTR lpBuffer)
 
BOOL WINAPI SetComputerNameA (LPCSTR lpComputerName)
 
BOOL WINAPI SetComputerNameW (LPCWSTR lpComputerName)
 
BOOL WINAPI SetComputerNameExA (COMPUTER_NAME_FORMAT NameType, LPCSTR lpBuffer)
 
BOOL WINAPI SetComputerNameExW (COMPUTER_NAME_FORMAT NameType, LPCWSTR lpBuffer)
 
BOOL WINAPI DnsHostnameToComputerNameA (LPCSTR Hostname, LPSTR ComputerName, LPDWORD nSize)
 
BOOL WINAPI DnsHostnameToComputerNameW (LPCWSTR hostname, LPWSTR computername, LPDWORD size)
 
DWORD WINAPI AddLocalAlternateComputerNameA (LPSTR lpName, PNTSTATUS Status)
 
DWORD WINAPI AddLocalAlternateComputerNameW (LPWSTR lpName, PNTSTATUS Status)
 
DWORD WINAPI EnumerateLocalComputerNamesA (PVOID pUnknown, DWORD Size, LPSTR lpBuffer, LPDWORD lpnSize)
 
DWORD WINAPI EnumerateLocalComputerNamesW (PVOID pUnknown, DWORD Size, LPWSTR lpBuffer, LPDWORD lpnSize)
 
DWORD WINAPI RemoveLocalAlternateComputerNameA (LPSTR lpName, DWORD Unknown)
 
DWORD WINAPI RemoveLocalAlternateComputerNameW (LPWSTR lpName, DWORD Unknown)
 
BOOL WINAPI SetLocalPrimaryComputerNameA (IN DWORD Unknown1, IN DWORD Unknown2)
 
BOOL WINAPI SetLocalPrimaryComputerNameW (IN DWORD Unknown1, IN DWORD Unknown2)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 31 of file compname.c.

Function Documentation

◆ AddLocalAlternateComputerNameA()

DWORD WINAPI AddLocalAlternateComputerNameA ( LPSTR  lpName,
PNTSTATUS  Status 
)

Definition at line 714 of file compname.c.

715 {
716  STUB;
717  return 0;
718 }
#define STUB
Definition: kernel32.h:27

◆ AddLocalAlternateComputerNameW()

DWORD WINAPI AddLocalAlternateComputerNameW ( LPWSTR  lpName,
PNTSTATUS  Status 
)

Definition at line 722 of file compname.c.

723 {
724  STUB;
725  return 0;
726 }
#define STUB
Definition: kernel32.h:27

◆ DnsHostnameToComputerNameA()

BOOL WINAPI DnsHostnameToComputerNameA ( LPCSTR  Hostname,
LPSTR  ComputerName,
LPDWORD  nSize 
)

Definition at line 651 of file compname.c.

654 {
655  DWORD len;
656 
657  DPRINT("(%s, %p, %p)\n", Hostname, ComputerName, nSize);
658 
659  if (!Hostname || !nSize)
660  return FALSE;
661 
662  len = lstrlenA(Hostname);
663 
666 
667  if (*nSize < len)
668  {
669  *nSize = len;
670  return FALSE;
671  }
672 
673  if (!ComputerName) return FALSE;
674 
675  memcpy(ComputerName, Hostname, len);
676  ComputerName[len + 1] = 0;
677  return TRUE;
678 }
#define TRUE
Definition: types.h:120
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2037
void DPRINT(...)
Definition: polytest.cpp:61
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145

◆ DnsHostnameToComputerNameW()

BOOL WINAPI DnsHostnameToComputerNameW ( LPCWSTR  hostname,
LPWSTR  computername,
LPDWORD  size 
)

Definition at line 686 of file compname.c.

689 {
690  DWORD len;
691 
692  DPRINT("(%s, %p, %p): stub\n", hostname, computername, size);
693 
694  if (!hostname || !size) return FALSE;
695  len = lstrlenW(hostname);
696 
699 
700  if (*size < len)
701  {
702  *size = len;
703  return FALSE;
704  }
705  if (!computername) return FALSE;
706 
707  memcpy(computername, hostname, len * sizeof(WCHAR));
708  computername[len + 1] = 0;
709  return TRUE;
710 }
#define TRUE
Definition: types.h:120
#define lstrlenW
Definition: compat.h:416
char * hostname
Definition: ftp.c:88
void DPRINT(...)
Definition: polytest.cpp:61
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240

Referenced by UpdateNetbiosName().

◆ EnumerateLocalComputerNamesA()

DWORD WINAPI EnumerateLocalComputerNamesA ( PVOID  pUnknown,
DWORD  Size,
LPSTR  lpBuffer,
LPDWORD  lpnSize 
)

Definition at line 730 of file compname.c.

731 {
732  STUB;
734 }
#define STUB
Definition: kernel32.h:27
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ EnumerateLocalComputerNamesW()

DWORD WINAPI EnumerateLocalComputerNamesW ( PVOID  pUnknown,
DWORD  Size,
LPWSTR  lpBuffer,
LPDWORD  lpnSize 
)

Definition at line 738 of file compname.c.

739 {
740  STUB;
742 }
#define STUB
Definition: kernel32.h:27
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ GetComputerNameA()

BOOL WINAPI GetComputerNameA ( LPSTR  lpBuffer,
LPDWORD  lpnSize 
)

Definition at line 426 of file compname.c.

427 {
428  BOOL ret;
429 
430  ret = GetComputerNameExA(ComputerNameNetBIOS, lpBuffer, lpnSize);
431  if (!ret && GetLastError() == ERROR_MORE_DATA)
433 
434  return ret;
435 }
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
static LPSTR PULONG lpnSize
Definition: secur32.c:50
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define SetLastError(x)
Definition: compat.h:418
int ret
#define ERROR_MORE_DATA
Definition: dderror.h:13
BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:373

◆ GetComputerNameExA()

BOOL WINAPI GetComputerNameExA ( COMPUTER_NAME_FORMAT  NameType,
LPSTR  lpBuffer,
LPDWORD  nSize 
)

Definition at line 373 of file compname.c.

376 {
379  BOOL Result;
380  PWCHAR TempBuffer = NULL;
381 
382  if ((nSize == NULL) ||
383  (lpBuffer == NULL && *nSize > 0))
384  {
386  return FALSE;
387  }
388 
389  if (*nSize > 0)
390  {
391  TempBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, *nSize * sizeof(WCHAR));
392  if (!TempBuffer)
393  {
395  return FALSE;
396  }
397  }
398 
399  AnsiString.MaximumLength = (USHORT)*nSize;
400  AnsiString.Length = 0;
401  AnsiString.Buffer = lpBuffer;
402 
403  Result = GetComputerNameExW(NameType, TempBuffer, nSize);
404 
405  if (Result)
406  {
407  UnicodeString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR) + sizeof(WCHAR);
408  UnicodeString.Length = (USHORT)*nSize * sizeof(WCHAR);
409  UnicodeString.Buffer = TempBuffer;
410 
412  &UnicodeString,
413  FALSE);
414  }
415 
416  RtlFreeHeap(RtlGetProcessHeap(), 0, TempBuffer);
417 
418  return Result;
419 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1979
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2037
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
uint16_t * PWCHAR
Definition: typedefs.h:55
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:213
unsigned int BOOL
Definition: ntddk_ex.h:94
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:418
unsigned short USHORT
Definition: pedump.c:61
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 NameType
Definition: acpixf.h:654

Referenced by get_computer_name(), GetComputerNameA(), ShowInfo(), START_TEST(), test_getaddrinfo(), TestGetComputerNameEx(), and TestReturnValues().

◆ GetComputerNameExW()

BOOL WINAPI GetComputerNameExW ( COMPUTER_NAME_FORMAT  NameType,
LPWSTR  lpBuffer,
LPDWORD  nSize 
)

Definition at line 213 of file compname.c.

216 {
217  UNICODE_STRING ResultString;
218  UNICODE_STRING DomainPart;
221  BOOL ret = TRUE;
222  DWORD HostSize;
223 
224  if ((nSize == NULL) ||
225  (lpBuffer == NULL && *nSize > 0))
226  {
228  return FALSE;
229  }
230 
231  switch (NameType)
232  {
233  case ComputerNameNetBIOS:
234  ret = GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
235  L"\\Control\\ComputerName\\ActiveComputerName",
236  L"ComputerName",
237  lpBuffer,
238  nSize);
239  if ((ret == FALSE) &&
241  {
242  ret = GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
243  L"\\Control\\ComputerName\\ComputerName",
244  L"ComputerName",
245  lpBuffer,
246  nSize);
247  if (ret)
248  {
249  ret = SetActiveComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
250  L"\\Control\\ComputerName",
251  L"ActiveComputerName",
252  L"ComputerName",
253  lpBuffer);
254  }
255  }
256  return ret;
257 
258  case ComputerNameDnsDomain:
259  return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
260  L"\\Services\\Tcpip\\Parameters",
261  L"Domain",
262  lpBuffer,
263  nSize);
264 
265  case ComputerNameDnsFullyQualified:
266  ResultString.Length = 0;
267  ResultString.MaximumLength = (USHORT)*nSize * sizeof(WCHAR);
268  ResultString.Buffer = lpBuffer;
269 
271  RtlInitUnicodeString(&DomainPart, NULL);
272 
273  QueryTable[0].Name = L"HostName";
275  QueryTable[0].EntryContext = &DomainPart;
276 
278  L"\\Registry\\Machine\\System"
279  L"\\CurrentControlSet\\Services\\Tcpip"
280  L"\\Parameters",
281  QueryTable,
282  NULL,
283  NULL);
284 
285  if (NT_SUCCESS(Status))
286  {
287  Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
288  HostSize = DomainPart.Length;
289 
290  if (!NT_SUCCESS(Status))
291  {
292  ret = FALSE;
293  }
294 
295  RtlAppendUnicodeToString(&ResultString, L".");
296  RtlFreeUnicodeString(&DomainPart);
297 
298  RtlInitUnicodeString(&DomainPart, NULL);
299  QueryTable[0].Name = L"Domain";
301  QueryTable[0].EntryContext = &DomainPart;
302 
304  L"\\Registry\\Machine\\System"
305  L"\\CurrentControlSet\\Services\\Tcpip"
306  L"\\Parameters",
307  QueryTable,
308  NULL,
309  NULL);
310 
311  if (NT_SUCCESS(Status))
312  {
313  Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
314  if ((!NT_SUCCESS(Status)) || (!ret))
315  {
316  *nSize = HostSize + DomainPart.Length;
318  RtlFreeUnicodeString(&DomainPart);
319  return FALSE;
320  }
321  RtlFreeUnicodeString(&DomainPart);
322  *nSize = ResultString.Length / sizeof(WCHAR) - 1;
323  return TRUE;
324  }
325  }
326  return FALSE;
327 
328  case ComputerNameDnsHostname:
329  return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
330  L"\\Services\\Tcpip\\Parameters",
331  L"Hostname",
332  lpBuffer,
333  nSize);
334 
335  case ComputerNamePhysicalDnsDomain:
336  return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
337  L"\\Services\\Tcpip\\Parameters",
338  L"NV Domain",
339  lpBuffer,
340  nSize);
341 
342  /* XXX Redo this */
343  case ComputerNamePhysicalDnsFullyQualified:
344  return GetComputerNameExW(ComputerNameDnsFullyQualified,
345  lpBuffer,
346  nSize);
347 
348  case ComputerNamePhysicalDnsHostname:
349  return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
350  L"\\Services\\Tcpip\\Parameters",
351  L"NV Hostname",
352  lpBuffer,
353  nSize);
354 
355  /* XXX Redo this */
356  case ComputerNamePhysicalNetBIOS:
357  return GetComputerNameExW(ComputerNameNetBIOS,
358  lpBuffer,
359  nSize);
360 
361  case ComputerNameMax:
362  return FALSE;
363  }
364 
365  return FALSE;
366 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4050
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
USHORT MaximumLength
Definition: env_spec_w32.h:370
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2037
LONG NTSTATUS
Definition: precomp.h:26
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:213
unsigned int BOOL
Definition: ntddk_ex.h:94
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define SetLastError(x)
Definition: compat.h:418
static BOOL SetActiveComputerNameToRegistry(LPCWSTR RegistryKey, LPCWSTR SubKey, LPCWSTR ValueNameStr, LPCWSTR lpBuffer)
Definition: compname.c:128
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 NameType
Definition: acpixf.h:654
static BOOL GetComputerNameFromRegistry(LPWSTR RegistryKey, LPWSTR ValueNameStr, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:39
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144

Referenced by _LocalGetPrintServerHandleData(), GetComputerNameExA(), GetComputerNameW(), NSP_GetHostNameHeapAllocW(), test_GetAddrInfoW(), TestGetComputerNameEx(), and wmain().

◆ GetComputerNameFromRegistry()

static BOOL GetComputerNameFromRegistry ( LPWSTR  RegistryKey,
LPWSTR  ValueNameStr,
LPWSTR  lpBuffer,
LPDWORD  nSize 
)
static

Definition at line 39 of file compname.c.

43 {
49  ULONG KeyInfoSize;
50  ULONG ReturnSize;
52 
53  if (lpBuffer != NULL && *nSize > 0)
54  lpBuffer[0] = 0;
55 
56  RtlInitUnicodeString(&KeyName, RegistryKey);
58  &KeyName,
60  NULL,
61  NULL);
62 
64  KEY_READ,
66  if (!NT_SUCCESS(Status))
67  {
69  return FALSE;
70  }
71 
72  KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + *nSize * sizeof(WCHAR);
73  KeyInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, KeyInfoSize);
74  if (KeyInfo == NULL)
75  {
78  return FALSE;
79  }
80 
81  RtlInitUnicodeString(&ValueName, ValueNameStr);
82 
84  &ValueName,
86  KeyInfo,
87  KeyInfoSize,
88  &ReturnSize);
89 
91 
92  if (!NT_SUCCESS(Status))
93  {
94  *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
95  goto failed;
96  }
97 
98  if (KeyInfo->Type != REG_SZ)
99  {
101  goto failed;
102  }
103 
104  if (!lpBuffer || *nSize < (KeyInfo->DataLength / sizeof(WCHAR)))
105  {
106  *nSize = (ReturnSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data)) / sizeof(WCHAR);
108  goto failed;
109  }
110 
111  *nSize = KeyInfo->DataLength / sizeof(WCHAR) - 1;
112  RtlCopyMemory(lpBuffer, KeyInfo->Data, KeyInfo->DataLength);
113  lpBuffer[*nSize] = 0;
114 
115  RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
116 
117  return TRUE;
118 
119 failed:
120  RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
122  return FALSE;
123 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2037
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:418
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define REG_SZ
Definition: layer.c:22

Referenced by GetComputerNameExW().

◆ GetComputerNameW()

BOOL WINAPI GetComputerNameW ( LPWSTR  lpBuffer,
LPDWORD  lpnSize 
)

Definition at line 443 of file compname.c.

444 {
445  BOOL ret;
446 
447  ret = GetComputerNameExW(ComputerNameNetBIOS, lpBuffer, lpnSize);
448  if (!ret && GetLastError() == ERROR_MORE_DATA)
450 
451  return ret;
452 }
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:213
unsigned int BOOL
Definition: ntddk_ex.h:94
static LPSTR PULONG lpnSize
Definition: secur32.c:50
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define SetLastError(x)
Definition: compat.h:418
int ret
#define ERROR_MORE_DATA
Definition: dderror.h:13

Referenced by _LocalEnumPrintersCheckName(), _LocalGetPrintServerHandleData(), ADVAPI_IsLocalComputer(), AllSysInfo(), BasepGetComputerNameFromNtPath(), build_servername(), build_systeminfo_tree(), CreateEnvironmentBlock(), CreateProfile(), ElfReportEventW(), EnumEventsThread(), fill_service(), get_computername(), get_owner(), get_username(), GetComputerObjectNameW(), GetUserNameExW(), init_access_tests(), init_wksta_tests(), InitializeSystemPage(), is_local_machine(), is_local_machineW(), LocalOpenPrinter(), LogfReportEvent(), LsaApLogonUserEx2(), LsapIsLocalComputer(), MSTASK_ITaskScheduler_GetTargetComputer(), MSTASK_ITaskScheduler_SetTargetComputer(), mstsc_ProtocolIOThread(), NETAPI_IsLocalComputer(), NetpGetComputerName(), NetrServerGetInfo(), NetWkstaGetInfo(), parse_path(), ProcessPortMessage(), RegConnectRegistryW(), set_installer_properties(), SetDomainComboBox(), CRootNode::SetupNode(), ShowHeader(), START_TEST(), test_GetComputerName(), test_RegQueryValueExPerformanceData(), test_SetTargetComputer(), test_Win32_ComputerSystem(), and test_Win32_Process().

◆ IsValidComputerName()

static BOOL IsValidComputerName ( COMPUTER_NAME_FORMAT  NameType,
LPCWSTR  lpComputerName 
)
static

Definition at line 460 of file compname.c.

462 {
463  PWCHAR p;
464  ULONG Length;
465 
466  /* FIXME: do verification according to NameType */
467 
468  Length = 0;
470 
471  while (*p != 0)
472  {
473  if (!(iswctype(*p, _ALPHA | _DIGIT) || *p == L'!' || *p == L'@' || *p == L'#' ||
474  *p == L'$' || *p == L'%' || *p == L'^' || *p == L'&' || *p == L'\'' ||
475  *p == L')' || *p == L'(' || *p == L'.' || *p == L'-' || *p == L'_' ||
476  *p == L'{' || *p == L'}' || *p == L'~'))
477  return FALSE;
478 
479  Length++;
480  p++;
481  }
482 
483  if (NameType == ComputerNamePhysicalDnsDomain)
484  return TRUE;
485 
486  if (Length == 0)
487  return FALSE;
488 
489  if (NameType == ComputerNamePhysicalNetBIOS &&
491  return FALSE;
492 
493  return TRUE;
494 }
#define TRUE
Definition: types.h:120
uint16_t * PWCHAR
Definition: typedefs.h:55
int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags)
Definition: freeldr.c:97
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR lpComputerName
Definition: eventvwr.c:91
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
#define _DIGIT
Definition: ctype.h:67
unsigned int ULONG
Definition: retypes.h:1
#define _ALPHA
Definition: ctype.h:76
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 NameType
Definition: acpixf.h:654
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by SetComputerNameExW().

◆ RemoveLocalAlternateComputerNameA()

DWORD WINAPI RemoveLocalAlternateComputerNameA ( LPSTR  lpName,
DWORD  Unknown 
)

Definition at line 746 of file compname.c.

747 {
748  STUB;
750 }
#define STUB
Definition: kernel32.h:27
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ RemoveLocalAlternateComputerNameW()

DWORD WINAPI RemoveLocalAlternateComputerNameW ( LPWSTR  lpName,
DWORD  Unknown 
)

Definition at line 754 of file compname.c.

755 {
756  STUB;
758 }
#define STUB
Definition: kernel32.h:27
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92

◆ SetActiveComputerNameToRegistry()

static BOOL SetActiveComputerNameToRegistry ( LPCWSTR  RegistryKey,
LPCWSTR  SubKey,
LPCWSTR  ValueNameStr,
LPCWSTR  lpBuffer 
)
static

Definition at line 128 of file compname.c.

132 {
137  SIZE_T StringLength;
140 
141  StringLength = wcslen(lpBuffer);
142  if (StringLength > ((MAXULONG / sizeof(WCHAR)) - 1))
143  {
144  return FALSE;
145  }
146 
147  RtlInitUnicodeString(&KeyName, RegistryKey);
149  &KeyName,
151  NULL,
152  NULL);
153 
155  KEY_WRITE,
157  if (!NT_SUCCESS(Status))
158  {
160  return FALSE;
161  }
162 
163  RtlInitUnicodeString(&KeyName, SubKey);
165  &KeyName,
167  KeyHandle,
168  NULL);
169 
171  KEY_WRITE,
173  0,
174  NULL,
176  &Disposition);
177  if (!NT_SUCCESS(Status))
178  {
181  return FALSE;
182  }
183 
184  RtlInitUnicodeString(&ValueName, ValueNameStr);
185 
187  &ValueName,
188  0,
189  REG_SZ,
190  (PVOID)lpBuffer,
191  (StringLength + 1) * sizeof(WCHAR));
192  if (!NT_SUCCESS(Status))
193  {
197  return FALSE;
198  }
199 
203 
204  return TRUE;
205 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
LONG NTSTATUS
Definition: precomp.h:26
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define KEY_WRITE
Definition: nt_native.h:1031
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING _Out_ PNDIS_HANDLE SubKeyHandle
Definition: ndis.h:4723
Status
Definition: gdiplustypes.h:24
#define MAXULONG
Definition: typedefs.h:250
ULONG_PTR SIZE_T
Definition: typedefs.h:79
NTSTATUS NTAPI NtFlushKey(IN HANDLE KeyHandle)
Definition: ntapi.c:1085
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22

Referenced by GetComputerNameExW().

◆ SetComputerNameA()

BOOL WINAPI SetComputerNameA ( LPCSTR  lpComputerName)

Definition at line 559 of file compname.c.

560 {
561  return SetComputerNameExA(ComputerNamePhysicalNetBIOS, lpComputerName);
562 }
BOOL WINAPI SetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPCSTR lpBuffer)
Definition: compname.c:581
LPWSTR lpComputerName
Definition: eventvwr.c:91

◆ SetComputerNameExA()

BOOL WINAPI SetComputerNameExA ( COMPUTER_NAME_FORMAT  NameType,
LPCSTR  lpBuffer 
)

Definition at line 581 of file compname.c.

583 {
585  BOOL bResult;
586 
588 
589  bResult = SetComputerNameExW(NameType, Buffer.Buffer);
590 
592 
593  return bResult;
594 }
char * LPSTR
Definition: xmlstorage.h:182
unsigned int BOOL
Definition: ntddk_ex.h:94
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
Definition: bufpool.h:45
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 NameType
Definition: acpixf.h:654
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
BOOL WINAPI SetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPCWSTR lpBuffer)
Definition: compname.c:602

Referenced by SetComputerNameA().

◆ SetComputerNameExW()

BOOL WINAPI SetComputerNameExW ( COMPUTER_NAME_FORMAT  NameType,
LPCWSTR  lpBuffer 
)

Definition at line 602 of file compname.c.

604 {
605  BOOL ret1, ret2;
606 
608  {
610  return FALSE;
611  }
612 
613  switch (NameType)
614  {
615  case ComputerNamePhysicalDnsDomain:
616  return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
617  L"\\Services\\Tcpip\\Parameters",
618  L"NV Domain",
619  lpBuffer);
620 
621  case ComputerNamePhysicalDnsHostname:
622  ret1 = SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
623  L"\\Services\\Tcpip\\Parameters",
624  L"NV Hostname",
625  lpBuffer);
626 
627  ret2 = SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
628  L"\\Control\\ComputerName\\ComputerName",
629  L"ComputerName",
630  lpBuffer);
631  return (ret1 && ret2);
632 
633  case ComputerNamePhysicalNetBIOS:
634  return SetComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
635  L"\\Control\\ComputerName\\ComputerName",
636  L"ComputerName",
637  lpBuffer);
638 
639  default:
641  return FALSE;
642  }
643 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL IsValidComputerName(COMPUTER_NAME_FORMAT NameType, LPCWSTR lpComputerName)
Definition: compname.c:460
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define SetLastError(x)
Definition: compat.h:418
static const WCHAR L[]
Definition: oid.c:1250
static BOOL SetComputerNameToRegistry(LPCWSTR RegistryKey, LPCWSTR ValueNameStr, LPCWSTR lpBuffer)
Definition: compname.c:499
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 NameType
Definition: acpixf.h:654

Referenced by DoTestComputerName(), NetworkDlg_OnOK(), SetComputerNameExA(), SetComputerNameW(), and WriteComputerSettings().

◆ SetComputerNameToRegistry()

static BOOL SetComputerNameToRegistry ( LPCWSTR  RegistryKey,
LPCWSTR  ValueNameStr,
LPCWSTR  lpBuffer 
)
static

Definition at line 499 of file compname.c.

502 {
507  SIZE_T StringLength;
509 
510  StringLength = wcslen(lpBuffer);
511  if (StringLength > ((MAXULONG / sizeof(WCHAR)) - 1))
512  {
513  return FALSE;
514  }
515 
516  RtlInitUnicodeString(&KeyName, RegistryKey);
518  &KeyName,
520  NULL,
521  NULL);
522 
524  KEY_WRITE,
526  if (!NT_SUCCESS(Status))
527  {
529  return FALSE;
530  }
531 
532  RtlInitUnicodeString(&ValueName, ValueNameStr);
533 
535  &ValueName,
536  0,
537  REG_SZ,
538  (PVOID)lpBuffer,
539  (StringLength + 1) * sizeof(WCHAR));
540  if (!NT_SUCCESS(Status))
541  {
544  return FALSE;
545  }
546 
549 
550  return TRUE;
551 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define TRUE
Definition: types.h:120
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
LONG NTSTATUS
Definition: precomp.h:26
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define KEY_WRITE
Definition: nt_native.h:1031
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
#define MAXULONG
Definition: typedefs.h:250
ULONG_PTR SIZE_T
Definition: typedefs.h:79
NTSTATUS NTAPI NtFlushKey(IN HANDLE KeyHandle)
Definition: ntapi.c:1085
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22

Referenced by SetComputerNameExW().

◆ SetComputerNameW()

BOOL WINAPI SetComputerNameW ( LPCWSTR  lpComputerName)

Definition at line 570 of file compname.c.

571 {
572  return SetComputerNameExW(ComputerNamePhysicalNetBIOS, lpComputerName);
573 }
LPWSTR lpComputerName
Definition: eventvwr.c:91
BOOL WINAPI SetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPCWSTR lpBuffer)
Definition: compname.c:602

Referenced by WriteComputerSettings().

◆ SetLocalPrimaryComputerNameA()

BOOL WINAPI SetLocalPrimaryComputerNameA ( IN DWORD  Unknown1,
IN DWORD  Unknown2 
)

Definition at line 765 of file compname.c.

767 {
768  STUB;
769  return FALSE;
770 }
#define STUB
Definition: kernel32.h:27

◆ SetLocalPrimaryComputerNameW()

BOOL WINAPI SetLocalPrimaryComputerNameW ( IN DWORD  Unknown1,
IN DWORD  Unknown2 
)

Definition at line 777 of file compname.c.

779 {
780  STUB;
781  return FALSE;
782 }
#define STUB
Definition: kernel32.h:27