https://git.reactos.org/?p=reactos.git;a=commitdiff;h=77671f0337ee5bf25b2ff…
commit 77671f0337ee5bf25b2ffad367438157e47cec0f
Author: Doug-Lyons <douglyons(a)douglyons.com>
AuthorDate: Sat Jun 22 11:23:11 2019 -0500
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Jul 22 00:49:47 2019 +0200
[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(a)reactos.org>
---
base/system/winlogon/winlogon.c | 136 ++++++++++++++++++++++++++++++++++++++++
dll/win32/netid/netid.c | 4 +-
2 files changed, 138 insertions(+), 2 deletions(-)
diff --git a/base/system/winlogon/winlogon.c b/base/system/winlogon/winlogon.c
index 68783c828b9..480272ac80a 100644
--- a/base/system/winlogon/winlogon.c
+++ b/base/system/winlogon/winlogon.c
@@ -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");
diff --git a/dll/win32/netid/netid.c b/dll/win32/netid/netid.c
index bcc9ce80c8f..a9e30b01bbf 100644
--- a/dll/win32/netid/netid.c
+++ b/dll/win32/netid/netid.c
@@ -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);
}