From 6a6a58912ec2f19c0c27a2bcd07486b779304739 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Thu, 29 Sep 2016 10:49:30 +0000 Subject: [PATCH] [IPHLPAPI][KERNEL32] Revert r72722 and apply a proper fix based on tests. By Peter Hater. CORE-10440 ROSTESTS-243 svn path=/trunk/; revision=72851 --- reactos/dll/win32/iphlpapi/iphlpapi_main.c | 59 ++++++++++++++-- reactos/dll/win32/kernel32/client/compname.c | 71 ++++---------------- 2 files changed, 66 insertions(+), 64 deletions(-) diff --git a/reactos/dll/win32/iphlpapi/iphlpapi_main.c b/reactos/dll/win32/iphlpapi/iphlpapi_main.c index 30d0b421ba3..c60dc1175fe 100644 --- a/reactos/dll/win32/iphlpapi/iphlpapi_main.c +++ b/reactos/dll/win32/iphlpapi/iphlpapi_main.c @@ -1404,7 +1404,7 @@ DWORD WINAPI GetIpStatisticsEx(PMIB_IPSTATS pStats, DWORD dwFamily) */ DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen) { - DWORD ret, size; + DWORD ret, size, type; LONG regReturn; HKEY hKey; PIPHLP_RES_INFO resInfo; @@ -1426,10 +1426,59 @@ DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen) } memset(pFixedInfo, 0, size); - size = sizeof(pFixedInfo->HostName); - GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size); - size = sizeof(pFixedInfo->DomainName); - GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size); + /* Check for DhcpHostname and DhcpDomain first */ + regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", + 0, + KEY_READ, + &hKey); + if (regReturn == ERROR_SUCCESS) { + /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */ +#if 0 + type = REG_SZ; + size = sizeof(pFixedInfo->HostName); + regReturn = RegQueryValueExA(hKey, + "DhcpHostname", + NULL, + &type, + (LPBYTE)pFixedInfo->HostName, + &size); + if (regReturn == ERROR_FILE_NOT_FOUND || (regReturn == ERROR_SUCCESS && size < 1)) + { +#endif + type = REG_SZ; + size = sizeof(pFixedInfo->HostName); + regReturn = RegQueryValueExA(hKey, + "Hostname", + NULL, + &type, + (LPBYTE)pFixedInfo->HostName, + &size); +#if 0 + } +#endif + + type = REG_SZ; + size = sizeof(pFixedInfo->DomainName); + regReturn = RegQueryValueExA(hKey, + "DhcpDomain", + NULL, + &type, + (LPBYTE)pFixedInfo->DomainName, + &size); + if (regReturn == ERROR_FILE_NOT_FOUND || (regReturn == ERROR_SUCCESS && size < 1)) + { + type = REG_SZ; + size = sizeof(pFixedInfo->DomainName); + regReturn = RegQueryValueExA(hKey, + "Domain", + NULL, + &type, + (LPBYTE)pFixedInfo->DomainName, + &size); + } + RegCloseKey(hKey); + } TRACE("GetComputerNameExA: %s\n", pFixedInfo->DomainName); diff --git a/reactos/dll/win32/kernel32/client/compname.c b/reactos/dll/win32/kernel32/client/compname.c index e9bcfc78aef..a336eaa9546 100644 --- a/reactos/dll/win32/kernel32/client/compname.c +++ b/reactos/dll/win32/kernel32/client/compname.c @@ -137,7 +137,6 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, NTSTATUS Status; BOOL ret = TRUE; DWORD HostSize; - DWORD nBufferSize; if ((nSize == NULL) || (lpBuffer == NULL && *nSize > 0)) @@ -156,27 +155,11 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, nSize); case ComputerNameDnsDomain: - /* Save original buffer size for the second call if neccessery */ - nBufferSize = *nSize; - if (!GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" - L"\\Services\\Tcpip\\Parameters", - L"DhcpDomain", - lpBuffer, - nSize)) - { - /* The value is there, just the buffer is insufficient in length */ - if (GetLastError() == ERROR_MORE_DATA) - return FALSE; - /* Restore original buffer size for the second call */ - *nSize = nBufferSize; - return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" - L"\\Services\\Tcpip\\Parameters", - L"Domain", - lpBuffer, - nSize); - } - else - return TRUE; + return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" + L"\\Services\\Tcpip\\Parameters", + L"Domain", + lpBuffer, + nSize); case ComputerNameDnsFullyQualified: ResultString.Length = 0; @@ -212,7 +195,7 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, RtlFreeUnicodeString(&DomainPart); RtlInitUnicodeString(&DomainPart, NULL); - QueryTable[0].Name = L"DhcpDomain"; + QueryTable[0].Name = L"Domain"; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].EntryContext = &DomainPart; @@ -224,9 +207,7 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, NULL, NULL); - if ((NT_SUCCESS(Status)) && - (DomainPart.Buffer != NULL) && - (wcslen(DomainPart.Buffer) > 0)) + if (NT_SUCCESS(Status)) { Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart); if ((!NT_SUCCESS(Status)) || (!ret)) @@ -240,36 +221,6 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, *nSize = ResultString.Length / sizeof(WCHAR) - 1; return TRUE; } - else - { - 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; @@ -281,9 +232,11 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, nSize); case ComputerNamePhysicalDnsDomain: - return GetComputerNameExW(ComputerNameDnsDomain, - lpBuffer, - nSize); + return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" + L"\\Services\\Tcpip\\Parameters", + L"Domain", + lpBuffer, + nSize); /* XXX Redo these */ case ComputerNamePhysicalDnsFullyQualified: