[NETID][WINLOGON] Fix Computer Name Change to update Domain/Hostname on reboot. ... master 1684/head
authorDoug-Lyons <douglyons@douglyons.com>
Sat, 22 Jun 2019 16:23:11 +0000 (11:23 -0500)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 21 Jul 2019 22:49:47 +0000 (00:49 +0200)
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>
base/system/winlogon/winlogon.c
dll/win32/netid/netid.c

index 68783c8..480272a 100644 (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");
index bcc9ce8..a9e30b0 100644 (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);
     }