Browse code

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 <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
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 <gert@greenie.muc.de>

Selva Nair authored on 2016/12/01 06:51:36
Showing 5 changed files
... ...
@@ -251,6 +251,10 @@ User-visible Changes
251 251
   as the VPN server, are dropped. This could be disabled with
252 252
   --allow-recursive-routing option.
253 253
 
254
+- on Windows, when the ``--register-dns`` option is set, OpenVPN no longer
255
+  restarts the ``dnscache`` service - this had unwanted side effects, and
256
+  seems to be no longer necessary with currently supported Windows versions.
257
+
254 258
 Maintainer-visible changes
255 259
 --------------------------
256 260
 - OpenVPN no longer supports building with crypto support, but without TLS
... ...
@@ -5811,8 +5811,7 @@ above.
5811 5811
 .\"*********************************************************
5812 5812
 .TP
5813 5813
 .B \-\-register\-dns
5814
-Run net stop dnscache, net start dnscache, ipconfig /flushdns
5815
-and ipconfig /registerdns on connection initiation.
5814
+Run ipconfig /flushdns and ipconfig /registerdns on connection initiation.
5816 5815
 This is known to kick Windows into
5817 5816
 recognizing pushed DNS servers.
5818 5817
 .\"*********************************************************
... ...
@@ -717,8 +717,8 @@ static const char usage_message[] =
717 717
   "--dhcp-pre-release : Ask Windows to release the previous TAP adapter lease on\n"
718 718
 "                       startup.\n"
719 719
   "--dhcp-release     : Ask Windows to release the TAP adapter lease on shutdown.\n"
720
-  "--register-dns  : Run net stop dnscache, net start dnscache, ipconfig /flushdns\n"
721
-  "                  and ipconfig /registerdns on connection initiation.\n"
720
+  "--register-dns  : Run ipconfig /flushdns and ipconfig /registerdns\n"
721
+  "                  on connection initiation.\n"
722 722
   "--tap-sleep n   : Sleep for n seconds after TAP adapter open before\n"
723 723
   "                  attempting to set adapter properties.\n"
724 724
   "--pause-exit         : When run from a console window, pause before exiting.\n"
... ...
@@ -4597,23 +4597,9 @@ ipconfig_register_dns (const struct env_set *es)
4597 4597
   bool status;
4598 4598
   const char err[] = "ERROR: Windows ipconfig command failed";
4599 4599
 
4600
-  msg (D_TUNTAP_INFO, "Start net commands...");
4600
+  msg (D_TUNTAP_INFO, "Start ipconfig commands for register-dns...");
4601 4601
   netcmd_semaphore_lock ();
4602 4602
 
4603
-  argv_printf (&argv, "%s%sc stop dnscache",
4604
-	       get_win_sys_path(),
4605
-	       WIN_NET_PATH_SUFFIX);
4606
-  argv_msg (D_TUNTAP_INFO, &argv);
4607
-  status = openvpn_execve_check (&argv, es, 0, err);
4608
-  argv_reset(&argv);
4609
-
4610
-  argv_printf (&argv, "%s%sc start dnscache",
4611
-	       get_win_sys_path(),
4612
-	       WIN_NET_PATH_SUFFIX);
4613
-  argv_msg (D_TUNTAP_INFO, &argv);
4614
-  status = openvpn_execve_check (&argv, es, 0, err);
4615
-  argv_reset(&argv);
4616
-
4617 4603
   argv_printf (&argv, "%s%sc /flushdns",
4618 4604
 	       get_win_sys_path(),
4619 4605
 	       WIN_IPCONFIG_PATH_SUFFIX);
... ...
@@ -4629,7 +4615,7 @@ ipconfig_register_dns (const struct env_set *es)
4629 4629
   argv_reset(&argv);
4630 4630
 
4631 4631
   netcmd_semaphore_release ();
4632
-  msg (D_TUNTAP_INFO, "End net commands...");
4632
+  msg (D_TUNTAP_INFO, "End ipconfig commands for register-dns...");
4633 4633
 }
4634 4634
 
4635 4635
 void
... ...
@@ -899,8 +899,7 @@ RegisterDNS (LPVOID unused)
899 899
   WCHAR sys_path[MAX_PATH];
900 900
   DWORD timeout = RDNS_TIMEOUT * 1000; /* in milliseconds */
901 901
 
902
-  /* default paths of net and ipconfig commands */
903
-  WCHAR net[MAX_PATH]   = L"C:\\Windows\\system32\\net.exe";
902
+  /* default path of ipconfig command */
904 903
   WCHAR ipcfg[MAX_PATH] = L"C:\\Windows\\system32\\ipconfig.exe";
905 904
 
906 905
   struct
... ...
@@ -909,8 +908,6 @@ RegisterDNS (LPVOID unused)
909 909
       WCHAR *cmdline;
910 910
       DWORD timeout;
911 911
     } cmds [] = {
912
-                  { net,   L"net stop dnscache",     timeout },
913
-                  { net,   L"net start dnscache",    timeout },
914 912
                   { ipcfg, L"ipconfig /flushdns",    timeout },
915 913
                   { ipcfg, L"ipconfig /registerdns", timeout },
916 914
                 };
... ...
@@ -920,9 +917,6 @@ RegisterDNS (LPVOID unused)
920 920
 
921 921
   if(GetSystemDirectory(sys_path, MAX_PATH))
922 922
     {
923
-      _snwprintf (net, MAX_PATH, L"%s\\%s", sys_path, L"net.exe");
924
-      net[MAX_PATH-1] = L'\0';
925
-
926 923
       _snwprintf (ipcfg, MAX_PATH, L"%s\\%s", sys_path, L"ipconfig.exe");
927 924
       ipcfg[MAX_PATH-1] = L'\0';
928 925
     }