From fb56058a98dcc81b34cffbdc46417d672b8926e1 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Wed, 30 Nov 2016 16:51:36 -0500 Subject: [PATCH] Do not restart dns client service as a part of --register-dns processing As reported and discussed on Trac #775, restarting dns service has unwanted side effects when there are dependent services. And it appears unnecessary to restart this service to get DNS registered on Windows. Resolve by removing two actions from --register-dns: 'net stop dnscache' and 'net start dnscache' run through the service or directly. Trac: #775 Signed-off-by: Selva Nair Acked-by: Gert Doering Message-Id: <1480542696-7123-1-git-send-email-selva.nair@gmail.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg13331.html Signed-off-by: Gert Doering --- Changes.rst | 4 ++++ doc/openvpn.8 | 3 +-- src/openvpn/options.c | 4 ++-- src/openvpn/tun.c | 18 ++---------------- src/openvpnserv/interactive.c | 8 +------- 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/Changes.rst b/Changes.rst index 1343034e..abd72586 100644 --- a/Changes.rst +++ b/Changes.rst @@ -251,6 +251,10 @@ User-visible Changes as the VPN server, are dropped. This could be disabled with --allow-recursive-routing option. +- on Windows, when the ``--register-dns`` option is set, OpenVPN no longer + restarts the ``dnscache`` service - this had unwanted side effects, and + seems to be no longer necessary with currently supported Windows versions. + Maintainer-visible changes -------------------------- - OpenVPN no longer supports building with crypto support, but without TLS diff --git a/doc/openvpn.8 b/doc/openvpn.8 index dd09c703..e61b6bbc 100644 --- a/doc/openvpn.8 +++ b/doc/openvpn.8 @@ -5811,8 +5811,7 @@ above. .\"********************************************************* .TP .B \-\-register\-dns -Run net stop dnscache, net start dnscache, ipconfig /flushdns -and ipconfig /registerdns on connection initiation. +Run ipconfig /flushdns and ipconfig /registerdns on connection initiation. This is known to kick Windows into recognizing pushed DNS servers. .\"********************************************************* diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 038fcd38..47acd97c 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -717,8 +717,8 @@ static const char usage_message[] = "--dhcp-pre-release : Ask Windows to release the previous TAP adapter lease on\n" " startup.\n" "--dhcp-release : Ask Windows to release the TAP adapter lease on shutdown.\n" - "--register-dns : Run net stop dnscache, net start dnscache, ipconfig /flushdns\n" - " and ipconfig /registerdns on connection initiation.\n" + "--register-dns : Run ipconfig /flushdns and ipconfig /registerdns\n" + " on connection initiation.\n" "--tap-sleep n : Sleep for n seconds after TAP adapter open before\n" " attempting to set adapter properties.\n" "--pause-exit : When run from a console window, pause before exiting.\n" diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 560b1a8e..572e168b 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -4597,23 +4597,9 @@ ipconfig_register_dns (const struct env_set *es) bool status; const char err[] = "ERROR: Windows ipconfig command failed"; - msg (D_TUNTAP_INFO, "Start net commands..."); + msg (D_TUNTAP_INFO, "Start ipconfig commands for register-dns..."); netcmd_semaphore_lock (); - argv_printf (&argv, "%s%sc stop dnscache", - get_win_sys_path(), - WIN_NET_PATH_SUFFIX); - argv_msg (D_TUNTAP_INFO, &argv); - status = openvpn_execve_check (&argv, es, 0, err); - argv_reset(&argv); - - argv_printf (&argv, "%s%sc start dnscache", - get_win_sys_path(), - WIN_NET_PATH_SUFFIX); - argv_msg (D_TUNTAP_INFO, &argv); - status = openvpn_execve_check (&argv, es, 0, err); - argv_reset(&argv); - argv_printf (&argv, "%s%sc /flushdns", get_win_sys_path(), WIN_IPCONFIG_PATH_SUFFIX); @@ -4629,7 +4615,7 @@ ipconfig_register_dns (const struct env_set *es) argv_reset(&argv); netcmd_semaphore_release (); - msg (D_TUNTAP_INFO, "End net commands..."); + msg (D_TUNTAP_INFO, "End ipconfig commands for register-dns..."); } void diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 608bb0c3..ec54216b 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -899,8 +899,7 @@ RegisterDNS (LPVOID unused) WCHAR sys_path[MAX_PATH]; DWORD timeout = RDNS_TIMEOUT * 1000; /* in milliseconds */ - /* default paths of net and ipconfig commands */ - WCHAR net[MAX_PATH] = L"C:\\Windows\\system32\\net.exe"; + /* default path of ipconfig command */ WCHAR ipcfg[MAX_PATH] = L"C:\\Windows\\system32\\ipconfig.exe"; struct @@ -909,8 +908,6 @@ RegisterDNS (LPVOID unused) WCHAR *cmdline; DWORD timeout; } cmds [] = { - { net, L"net stop dnscache", timeout }, - { net, L"net start dnscache", timeout }, { ipcfg, L"ipconfig /flushdns", timeout }, { ipcfg, L"ipconfig /registerdns", timeout }, }; @@ -920,9 +917,6 @@ RegisterDNS (LPVOID unused) if(GetSystemDirectory(sys_path, MAX_PATH)) { - _snwprintf (net, MAX_PATH, L"%s\\%s", sys_path, L"net.exe"); - net[MAX_PATH-1] = L'\0'; - _snwprintf (ipcfg, MAX_PATH, L"%s\\%s", sys_path, L"ipconfig.exe"); ipcfg[MAX_PATH-1] = L'\0'; }