[IPHLPAPI][KERNEL32] Revert r72722 and apply a proper fix based on tests. By Peter Hater. CORE-10440 ROSTESTS-243

svn path=/trunk/; revision=72851
This commit is contained in:
Amine Khaldi 2016-09-29 10:49:30 +00:00
parent d3aebbcedc
commit 6a6a58912e
2 changed files with 66 additions and 64 deletions

View file

@ -1404,7 +1404,7 @@ DWORD WINAPI GetIpStatisticsEx(PMIB_IPSTATS pStats, DWORD dwFamily)
*/ */
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen) DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
{ {
DWORD ret, size; DWORD ret, size, type;
LONG regReturn; LONG regReturn;
HKEY hKey; HKEY hKey;
PIPHLP_RES_INFO resInfo; PIPHLP_RES_INFO resInfo;
@ -1426,10 +1426,59 @@ DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
} }
memset(pFixedInfo, 0, size); memset(pFixedInfo, 0, size);
size = sizeof(pFixedInfo->HostName); /* Check for DhcpHostname and DhcpDomain first */
GetComputerNameExA(ComputerNameDnsHostname, pFixedInfo->HostName, &size); regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
size = sizeof(pFixedInfo->DomainName); "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
GetComputerNameExA(ComputerNameDnsDomain, pFixedInfo->DomainName, &size); 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); TRACE("GetComputerNameExA: %s\n", pFixedInfo->DomainName);

View file

@ -137,7 +137,6 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
NTSTATUS Status; NTSTATUS Status;
BOOL ret = TRUE; BOOL ret = TRUE;
DWORD HostSize; DWORD HostSize;
DWORD nBufferSize;
if ((nSize == NULL) || if ((nSize == NULL) ||
(lpBuffer == NULL && *nSize > 0)) (lpBuffer == NULL && *nSize > 0))
@ -156,27 +155,11 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
nSize); nSize);
case ComputerNameDnsDomain: case ComputerNameDnsDomain:
/* Save original buffer size for the second call if neccessery */ return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
nBufferSize = *nSize; L"\\Services\\Tcpip\\Parameters",
if (!GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet" L"Domain",
L"\\Services\\Tcpip\\Parameters", lpBuffer,
L"DhcpDomain", nSize);
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;
case ComputerNameDnsFullyQualified: case ComputerNameDnsFullyQualified:
ResultString.Length = 0; ResultString.Length = 0;
@ -212,7 +195,7 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
RtlFreeUnicodeString(&DomainPart); RtlFreeUnicodeString(&DomainPart);
RtlInitUnicodeString(&DomainPart, NULL); RtlInitUnicodeString(&DomainPart, NULL);
QueryTable[0].Name = L"DhcpDomain"; QueryTable[0].Name = L"Domain";
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[0].EntryContext = &DomainPart; QueryTable[0].EntryContext = &DomainPart;
@ -224,9 +207,7 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
NULL, NULL,
NULL); NULL);
if ((NT_SUCCESS(Status)) && if (NT_SUCCESS(Status))
(DomainPart.Buffer != NULL) &&
(wcslen(DomainPart.Buffer) > 0))
{ {
Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart); Status = RtlAppendUnicodeStringToString(&ResultString, &DomainPart);
if ((!NT_SUCCESS(Status)) || (!ret)) if ((!NT_SUCCESS(Status)) || (!ret))
@ -240,36 +221,6 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
*nSize = ResultString.Length / sizeof(WCHAR) - 1; *nSize = ResultString.Length / sizeof(WCHAR) - 1;
return TRUE; 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; return FALSE;
@ -281,9 +232,11 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
nSize); nSize);
case ComputerNamePhysicalDnsDomain: case ComputerNamePhysicalDnsDomain:
return GetComputerNameExW(ComputerNameDnsDomain, return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
lpBuffer, L"\\Services\\Tcpip\\Parameters",
nSize); L"Domain",
lpBuffer,
nSize);
/* XXX Redo these */ /* XXX Redo these */
case ComputerNamePhysicalDnsFullyQualified: case ComputerNamePhysicalDnsFullyQualified: