Skip to content

Commit bb57f63

Browse files
committed
[NETCFGX] Store network interface settings in the correct location
1 parent 2840fdc commit bb57f63

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

dll/win32/netcfgx/installer.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ InstallNetDevice(
159159
LPWSTR DeviceName = NULL;
160160
LPWSTR ExportName = NULL;
161161
LONG rc;
162+
HKEY hInterfacesKey = NULL, hInterfaceKey = NULL;
162163
HKEY hKey = NULL;
163164
HKEY hNetworkKey = NULL;
164165
HKEY hLinkageKey = NULL;
@@ -256,61 +257,48 @@ InstallNetDevice(
256257
wcscat(ExportName, UuidString);
257258

258259
/* Write Tcpip parameters in new service Key */
259-
rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, NULL, &hKey, NULL);
260+
rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hInterfacesKey, NULL);
260261
if (rc != ERROR_SUCCESS)
261262
{
262263
ERR("RegCreateKeyExW() failed with error 0x%lx\n", rc);
263264
goto cleanup;
264265
}
265266

266-
rc = RegCreateKeyExW(hKey, UuidString, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, NULL, &hNetworkKey, NULL);
267+
rc = RegCreateKeyExW(hInterfacesKey, UuidString, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hInterfaceKey, NULL);
267268
if (rc != ERROR_SUCCESS)
268269
{
269270
ERR("RegCreateKeyExW() failed with error 0x%lx\n", rc);
270271
goto cleanup;
271272
}
272-
RegCloseKey(hKey);
273-
hKey = NULL;
274-
275-
rc = RegCreateKeyExW(hNetworkKey, L"Parameters\\Tcpip", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL);
276-
if (rc != ERROR_SUCCESS)
277-
{
278-
ERR("RegCreateKeyExW() failed with error 0x%lx\n", rc);
279-
goto cleanup;
280-
}
281-
RegCloseKey(hNetworkKey);
282-
hNetworkKey = NULL;
283273

284-
rc = RegSetValueExW(hKey, L"DefaultGateway", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
274+
rc = RegSetValueExW(hInterfaceKey, L"DefaultGateway", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
285275
if (rc != ERROR_SUCCESS)
286276
{
287277
ERR("RegSetValueExW() failed with error 0x%lx\n", rc);
288278
goto cleanup;
289279
}
290280

291-
rc = RegSetValueExW(hKey, L"IPAddress", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
281+
rc = RegSetValueExW(hInterfaceKey, L"IPAddress", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
292282
if (rc != ERROR_SUCCESS)
293283
{
294284
ERR("RegSetValueExW() failed with error 0x%lx\n", rc);
295285
goto cleanup;
296286
}
297287

298-
rc = RegSetValueExW(hKey, L"SubnetMask", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
288+
rc = RegSetValueExW(hInterfaceKey, L"SubnetMask", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
299289
if (rc != ERROR_SUCCESS)
300290
{
301291
ERR("RegSetValueExW() failed with error 0x%lx\n", rc);
302292
goto cleanup;
303293
}
304294

305295
dwValue = 1;
306-
rc = RegSetValueExW(hKey, L"EnableDHCP", 0, REG_DWORD, (const BYTE*)&dwValue, sizeof(DWORD));
296+
rc = RegSetValueExW(hInterfaceKey, L"EnableDHCP", 0, REG_DWORD, (const BYTE*)&dwValue, sizeof(DWORD));
307297
if (rc != ERROR_SUCCESS)
308298
{
309299
ERR("RegSetValueExW() failed with error 0x%lx\n", rc);
310300
goto cleanup;
311301
}
312-
RegCloseKey(hKey);
313-
hKey = NULL;
314302

315303
/* Write 'Linkage' key in hardware key */
316304
#if _WIN32_WINNT >= 0x502
@@ -492,6 +480,10 @@ InstallNetDevice(
492480
HeapFree(GetProcessHeap(), 0, ComponentId);
493481
HeapFree(GetProcessHeap(), 0, DeviceName);
494482
HeapFree(GetProcessHeap(), 0, ExportName);
483+
if (hInterfaceKey != NULL)
484+
RegCloseKey(hInterfaceKey);
485+
if (hInterfacesKey != NULL)
486+
RegCloseKey(hInterfacesKey);
495487
if (hKey != NULL)
496488
RegCloseKey(hKey);
497489
if (hNetworkKey != NULL)

0 commit comments

Comments
 (0)