[NETID][WINLOGON] Fix Computer Name Change to update Domain/Hostname on reboot. (#1684)

CORE-16123

- NETID: Correct the call when using the "Computer Name Change" in ReactOS.
- WINLOGON: Update the volatile "Hostname" and "Domain" variables from
  their non-volatile counterparts.

Co-authored-by: Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
This commit is contained in:
Doug-Lyons 2019-06-22 11:23:11 -05:00 committed by Hermès Bélusca-Maïto
parent eede1b9b7a
commit 77671f0337
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 138 additions and 2 deletions

View file

@ -147,6 +147,139 @@ WaitForLsass(VOID)
}
static
VOID
UpdateTcpIpInformation(VOID)
{
LONG lError;
HKEY hKey = NULL;
DWORD dwType, dwSize;
PWSTR pszBuffer;
WCHAR szBuffer[128] = L"";
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
0,
KEY_QUERY_VALUE | KEY_SET_VALUE,
&hKey);
if (lError != ERROR_SUCCESS)
{
ERR("WL: RegOpenKeyExW(\"HKLM\\System\\CurrentControlSet\\Services\\Tcpip\\Parameters\") failed (error %lu)\n", lError);
return;
}
/*
* Read the "NV Hostname" value and copy it into the "Hostname" value.
*/
pszBuffer = szBuffer;
dwSize = ARRAYSIZE(szBuffer);
lError = RegQueryValueExW(hKey,
L"NV Hostname",
NULL,
&dwType,
(LPBYTE)pszBuffer,
&dwSize);
if (((lError == ERROR_INSUFFICIENT_BUFFER) || (lError == ERROR_MORE_DATA)) && (dwType == REG_SZ))
{
pszBuffer = HeapAlloc(GetProcessHeap(), 0, dwSize);
if (pszBuffer)
{
lError = RegQueryValueExW(hKey,
L"NV Hostname",
NULL,
&dwType,
(LPBYTE)pszBuffer,
&dwSize);
}
else
{
ERR("WL: Could not reallocate memory for pszBuffer\n");
}
}
if ((lError == ERROR_SUCCESS) && (dwType == REG_SZ))
{
TRACE("NV Hostname is '%S'.\n", pszBuffer);
lError = RegSetValueExW(hKey,
L"Hostname",
0,
REG_SZ,
(LPBYTE)pszBuffer,
dwSize);
if (lError != ERROR_SUCCESS)
ERR("WL: RegSetValueExW(\"Hostname\") failed (error %lu)\n", lError);
}
/*
* Read the "NV Domain" value and copy it into the "Domain" value.
*/
// pszBuffer = szBuffer;
// dwSize = ARRAYSIZE(szBuffer);
lError = RegQueryValueExW(hKey,
L"NV Domain",
NULL,
&dwType,
(LPBYTE)pszBuffer,
&dwSize);
if (((lError == ERROR_INSUFFICIENT_BUFFER) || (lError == ERROR_MORE_DATA)) && (dwType == REG_SZ))
{
if (pszBuffer != szBuffer)
{
PWSTR pszNewBuffer;
pszNewBuffer = HeapReAlloc(GetProcessHeap(), 0, pszBuffer, dwSize);
if (pszNewBuffer)
{
pszBuffer = pszNewBuffer;
}
else
{
HeapFree(GetProcessHeap(), 0, pszBuffer);
pszBuffer = NULL;
}
}
else
{
pszBuffer = HeapAlloc(GetProcessHeap(), 0, dwSize);
}
if (pszBuffer)
{
lError = RegQueryValueExW(hKey,
L"NV Domain",
NULL,
&dwType,
(LPBYTE)pszBuffer,
&dwSize);
}
else
{
ERR("WL: Could not reallocate memory for pszBuffer\n");
}
}
if ((lError == ERROR_SUCCESS) && (dwType == REG_SZ))
{
TRACE("NV Domain is '%S'.\n", pszBuffer);
lError = RegSetValueExW(hKey,
L"Domain",
0,
REG_SZ,
(LPBYTE)pszBuffer,
dwSize);
if (lError != ERROR_SUCCESS)
ERR("WL: RegSetValueExW(\"Domain\") failed (error %lu)\n", lError);
}
if (pszBuffer != szBuffer)
HeapFree(GetProcessHeap(), 0, pszBuffer);
RegCloseKey(hKey);
}
static
BOOL
InitKeyboardLayouts(VOID)
@ -322,6 +455,9 @@ WinMain(
RtlSetProcessIsCritical(TRUE, NULL, FALSE);
RtlSetThreadIsCritical(TRUE, NULL, FALSE);
/* Update the cached TCP/IP Information in the registry */
UpdateTcpIpInformation();
if (!RegisterLogonProcess(GetCurrentProcessId(), TRUE))
{
ERR("WL: Could not register logon process\n");

View file

@ -232,7 +232,7 @@ NetworkPropDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
SetFocus(GetDlgItem(hDlg, 1002));
break;
}
else if (!SetComputerName(NewComputerName))
else if (!SetComputerNameExW(ComputerNamePhysicalDnsHostname, NewComputerName))
{
TCHAR szMsgText[MAX_PATH];
@ -308,7 +308,7 @@ NetIDPage_OnInitDialog(
RegCloseKey(KeyHandle);
}
if (GetComputerName(ComputerName,&Size))
if (GetComputerName(ComputerName, &Size))
{
SetDlgItemText(hwndDlg, IDC_COMPUTERNAME, ComputerName);
}