From: "stipa (Code Review)" Date: Wed, 10 Sep 2025 11:35:21 +0000 References: Reply-To: lstipakov@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <8f437ed33753e39fc3c8a1311f629371d195cc2c-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="MmfiFOP+j/I="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[release/2.6]: win: replace wmic invocation with powershell List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --MmfiFOP+j/I= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1175?usp=3Demail to review the following change. Change subject: win: replace wmic invocation with powershell ...................................................................... win: replace wmic invocation with powershell Since wmic has been recently deprecated and is absent on new systems, replace setting DNS domain "old-style" with powershell. GitHub: https://github.com/OpenVPN/openvpn/issues/642 Change-Id: Ie135e070b481b88033c43b76f872060fb237243c Signed-off-by: Lev Stipakov --- M src/openvpn/tun.c M src/openvpn/win32.h 2 files changed, 14 insertions(+), 9 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/1175/1 diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 92e71a3..1ece1e1 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -383,7 +383,7 @@ } static void -do_dns_domain_wmic(bool add, const struct tuntap *tt) +do_dns_domain_pwsh(bool add, const struct tuntap *tt) { if (!tt->options.domain) { @@ -391,9 +391,14 @@ } struct argv argv =3D argv_new(); - argv_printf(&argv, "%s%s nicconfig where (InterfaceIndex=3D%ld) call S= etDNSDomain '%s'", - get_win_sys_path(), WMIC_PATH_SUFFIX, tt->adapter_index, a= dd ? tt->options.domain : ""); - exec_command("WMIC", &argv, 1, M_WARN); + argv_printf(&argv, + "%s%s -NoProfile -NonInteractive -Command Set-DnsClient -I= nterfaceIndex %ld -ConnectionSpecificSuffix '%s'", + get_win_sys_path(), + POWERSHELL_PATH_SUFFIX, + tt->adapter_index, + add ? tt->options.domain : "" + ); + exec_command("PowerShell", &argv, 1, M_WARN); argv_free(&argv); } @@ -1269,7 +1274,7 @@ if (!tt->did_ifconfig_setup) { - do_dns_domain_wmic(true, tt); + do_dns_domain_pwsh(true, tt); } } #else /* platforms we have no IPv6 code for */ @@ -1625,7 +1630,7 @@ tt->adapter_netmask, NI_IP_NETMASK | NI_OPTIONS= ); } - do_dns_domain_wmic(true, tt); + do_dns_domain_pwsh(true, tt); } @@ -7024,7 +7029,7 @@ { if (!tt->did_ifconfig_setup) { - do_dns_domain_wmic(false, tt); + do_dns_domain_pwsh(false, tt); } netsh_delete_address_dns(tt, true, &gc); @@ -7050,7 +7055,7 @@ } else { - do_dns_domain_wmic(false, tt); + do_dns_domain_pwsh(false, tt); if (tt->options.ip_win32_type =3D=3D IPW32_SET_NETSH) { diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index 1b87fa3..67e6169 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -38,7 +38,7 @@ #define WIN_ROUTE_PATH_SUFFIX "\\system32\\route.exe" #define WIN_IPCONFIG_PATH_SUFFIX "\\system32\\ipconfig.exe" #define WIN_NET_PATH_SUFFIX "\\system32\\net.exe" -#define WMIC_PATH_SUFFIX "\\system32\\wbem\\wmic.exe" +#define POWERSHELL_PATH_SUFFIX "\\system32\\WindowsPowerShell\\v1.0\\power= shell.exe" /* * Win32-specific OpenVPN code, targeted at the mingw -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1175?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: release/2.6 Gerrit-Change-Id: Ie135e070b481b88033c43b76f872060fb237243c Gerrit-Change-Number: 1175 Gerrit-PatchSet: 1 Gerrit-Owner: stipa Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --MmfiFOP+j/I= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

stipa would like plaisthos and flichtenheld to review t= his change.

V= iew Change

win: replace wmic invocation with powershell

Since wm= ic has been recently deprecated and is absent on new
systems, replace se= tting DNS domain "old-style" with powershell.

GitHub: http= s://github.com/OpenVPN/openvpn/issues/642

Change-Id: Ie135e070b481b8= 8033c43b76f872060fb237243c
Signed-off-by: Lev Stipakov <lev@...515...= >
---
M src/openvpn/tun.c
M src/openvpn/win32.h
2 files chan= ged, 14 insertions(+), 9 deletions(-)

git pull ssh://gerrit.openv=
pn.net:29418/openvpn refs/changes/75/1175/1
diff --git a/src/openvp=
n/tun.c b/src/openvpn/tun.c
index 92e71a3..1ece1e1 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tu= n.c
@@ -383,7 +383,7 @@
}
=
static void
-do_dns_domain_wmic(bool add, const struct tuntap *tt)
+do_dns_domain_pwsh(bool add, con= st struct tuntap *tt)

{
if (!tt->o= ptions.domain)
{
@@ -391,9 +391,14 @@<= /span>
}

struct argv a= rgv =3D argv_new();
- = argv_printf(&argv, "%s%s nicconfig where (InterfaceIndex=3D%ld) = call SetDNSDomain '%s'",
- get_win_sys_path(), WMIC_PATH_SUFFIX, tt-&g= t;adapter_index, add ? tt->options.domain : "");
- exec_command("WMIC", = &argv, 1, M_WARN);

+ "%s%s -NoProfile -NonInteractive -Command Se= t-DnsClient -InterfaceIndex %ld -ConnectionSpecificSuffix '%s'"= ;,
+ g= et_win_sys_path(),
+ = POWERSHELL_PATH_SUFFIX,
+ tt->adapter_index,
+ add ? tt->options.d= omain : ""
= + );
+= exec_command("PowerShell", &argv, 1, M_WARN);
<= span>
argv_free(&argv);
}=
@@ -1269,7 +1274,7 @@

= if (!tt->did_ifconfig_setup)
{
- do_dns_domain_wmic(true, t= t);
+ do_d= ns_domain_pwsh(true, tt);
}
}=
#else /* platforms we have no IPv6 code for */
= @@ -1625,7 +1630,7 @@
tt-= >adapter_netmask, NI_IP_NETMASK | NI_OPTIONS);
= }

- = do_dns_domain_wmic(true, tt);
+ do_dns_domain_pwsh(true, tt);
= }


@@ -7024,7 +7029,7 @@=
{
if (!tt->did_if= config_setup)
{
- do_dns_domain_wmic(false, tt);
+ do_dns_do= main_pwsh(false, tt);
}

netsh_delete_address_dns(tt, true, &gc);
@@ -7050,7 +7055,7 @@
}
else

{
- do_dns_domain_wmic(false, tt);
+ do_dns_domain_pwsh(f= alse, tt);


if (tt->option= s.ip_win32_type =3D=3D IPW32_SET_NETSH)
{
diff --git a/src/openvpn/win32.h b/src/openvpn/win32.hindex 1b87fa3..67e6169 100644
--- a/src/openvpn/win= 32.h
+++ b/src/openvpn/win32.h
@@ -38,7 +38= ,7 @@
#define WIN_ROUTE_PATH_SUFFIX "\\system32\\rout= e.exe"
#define WIN_IPCONFIG_PATH_SUFFIX "\\syste= m32\\ipconfig.exe"
#define WIN_NET_PATH_SUFFIX "= \\system32\\net.exe"
-#define WMIC_PATH_SUFFIX "\\system32\\wbem\\wmic.exe"<= br>+#define POWERSHELL_PATH_SUF= FIX "\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"<= br>
/*
* Win32-specific OpenVPN c= ode, targeted at the mingw

To view, vis= it chang= e 1175. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: Ie135e070b481b88033c43b76f87= 2060fb237243c
Gerrit-Change-Number: 1175
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <lstipakov@...277...>= ;
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--MmfiFOP+j/I=--