From: "cron2 (Code Review)" Date: Mon, 15 Sep 2025 07:01:46 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: <8f5100a45b63ffba4f6683b46701355eac504912-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="3nyBJZlpzo0="; charset=UTF-8 Subject: [Openvpn-devel] [M] 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: stipa , plaisthos , flichtenheld , d12fk Cc: openvpn-devel --3nyBJZlpzo0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#3) to the change originally created by= stipa. ( http://gerrit.openvpn.net/c/openvpn/+/1183?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+1 by d12fk, Code-Review+2 by cron2 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. Some changes to the service implementation: - remove action parameter and hardcode Set-DnsClient since this is the only used action - remove support of multiple domains, since we only pass a single domain (tuntap_options.domain) Github: fixes OpenVPN/openvpn#642 Change-Id: Iff2f4ea677fe2d88659d7814dab0f792f5004fb3 Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1183 Signed-off-by: Lev Stipakov Acked-by: Gert Doering Message-Id: <20250915062013.2555-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32= 938.html Signed-off-by: Gert Doering --- M src/openvpn/tun.c M src/openvpn/win32.h M src/openvpnserv/interactive.c 3 files changed, 21 insertions(+), 30 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/83/1183/3 diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 89d5f93..99dc490 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 %lu -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 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index a25d26f..ca58596 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -1150,45 +1150,31 @@ } /** - * Run command: wmic nicconfig (InterfaceIndex=3D$if_index) call $action (= $data) + * Run command: powershell -NoProfile -NonInteractive -Command Set-DnsClie= nt -InterfaceIndex %ld -ConnectionSpecificSuffix '%s' * @param if_index "index of interface" - * @param action e.g., "SetDNSDomain" * @param data data if required for action * - a single word for SetDNSDomain, empty or NULL to = delete - * - comma separated values for a list */ static DWORD -wmic_nicconfig_cmd(const wchar_t *action, const NET_IFINDEX if_index, - const wchar_t *data) +pwsh_setdns_cmd(const NET_IFINDEX if_index, const wchar_t *data) { DWORD err =3D 0; wchar_t argv0[MAX_PATH]; wchar_t *cmdline =3D NULL; int timeout =3D 10000; /* in msec */ - openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path= (), L"wbem\\wmic.exe"); + openvpn_swprintf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path= (), L"WindowsPowerShell\\v1.0\\powershell.exe"); - const wchar_t *fmt; - /* comma separated list must be enclosed in parenthesis */ - if (data && wcschr(data, L',')) - { - fmt =3D L"wmic nicconfig where (InterfaceIndex=3D%ld) call %ls (%l= s)"; - } - else - { - fmt =3D L"wmic nicconfig where (InterfaceIndex=3D%ld) call %ls \"%= ls\""; - } + const wchar_t *fmt =3D L"-NoProfile -NonInteractive -Command Set-DnsCl= ient -InterfaceIndex %lu -ConnectionSpecificSuffix '%s'"; - size_t ncmdline =3D wcslen(fmt) + 20 + wcslen(action) /* max 20 for if= index */ - + (data ? wcslen(data) + 1 : 1); + size_t ncmdline =3D wcslen(fmt) + 20 + /* max 20 for ifindex */ (data = ? wcslen(data) + 1 : 1); cmdline =3D malloc(ncmdline*sizeof(wchar_t)); if (!cmdline) { return ERROR_OUTOFMEMORY; } - openvpn_swprintf(cmdline, ncmdline, fmt, if_index, action, - data ? data : L""); + openvpn_swprintf(cmdline, ncmdline, fmt, if_index, data ? data : L""); err =3D ExecCommand(argv0, cmdline, timeout); free(cmdline); @@ -1248,7 +1234,7 @@ free(RemoveListItem(&(*lists)[undo_domain], CmpWString, (void *)if= _name)); } - err =3D wmic_nicconfig_cmd(L"SetDNSDomain", if_index, wdomain); + err =3D pwsh_setdns_cmd(if_index, wdomain); /* Add to undo list if domain is non-empty */ if (err =3D=3D 0 && wdomain[0] && lists) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1183?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: Iff2f4ea677fe2d88659d7814dab0f792f5004fb3 Gerrit-Change-Number: 1183 Gerrit-PatchSet: 3 Gerrit-Owner: stipa Gerrit-Reviewer: cron2 Gerrit-Reviewer: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --3nyBJZlpzo0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #3 to the change originally cr= eated by stipa.

View Change

The following approvals got outdated an= d were removed: Code-Review+1 by d12fk, Code-Review+2 by cron2

win: replace wmic invocation=
 with powershell

Since wmic has been recently deprecated and is abse= nt on new
systems, replace setting DNS domain "old-style" with= powershell.

Some changes to the service implementation:

- r= emove action parameter and hardcode Set-DnsClient since this is
the onl= y used action

- remove support of multiple domains, since we only p= ass a single domain
(tuntap_options.domain)

Github: fixes OpenVP= N/openvpn#642

Change-Id: Iff2f4ea677fe2d88659d7814dab0f792f5004fb3Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1183
Signed-off-by:= Lev Stipakov <lev@...515...>
Acked-by: Gert Doering <gert@...1386...= 296...>
Message-Id: <20250915062013.2555-1-gert@...1296...>
= URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32= 938.html
Signed-off-by: Gert Doering <gert@...1296...>
---
M= src/openvpn/tun.c
M src/openvpn/win32.h
M src/openvpnserv/interactiv= e.c
3 files changed, 21 insertions(+), 30 deletions(-)

git pul= l ssh://gerrit.openvpn.net:29418/openvpn refs/changes/83/1183/3
dif=
f --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 89d5f= 93..99dc490 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 tunt= ap *tt)
+do_dns_domai= n_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 (In= terfaceIndex=3D%ld) call SetDNSDomain '%s'",
- get_win_sys_path(), WMI= C_PATH_SUFFIX, tt->adapter_index, add ? tt->options.domain : "&q= uot;);
- exec_comman= d("WMIC", &argv, 1, M_WARN);
+ argv_printf(&argv,
+ "%s%s -NoProfile -NonInt= eractive -Command Set-DnsClient -InterfaceIndex %lu -ConnectionSpecificSuff= ix '%s'",
+ POWERSHELL_PATH_SUFFIX,
+ tt->adapter_index= ,
+ ad= d ? 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 co= de 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_wm= ic(false, tt);
+ = do_dns_domain_pwsh(false, tt);
}

netsh_delete_address_dns(tt, t= rue, &gc);
@@ -7050,7 +7055,7 @@
= }
else
{
- do_dns_domain_wmic(fals= e, 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/open= vpn/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 &q= uot;\\system32\\route.exe"
#define WIN_IPCONFIG_PATH_= SUFFIX "\\system32\\ipconfig.exe"
#define WIN_NE= T_PATH_SUFFIX "\\system32\\net.exe"
-#define WMIC_PATH_SUFFIX "\\system32\\wbem\\wm= ic.exe"
+#define= POWERSHELL_PATH_SUFFIX "\\system32\\WindowsPowerShell\\v1.0\\powershe= ll.exe"

/*
* Win3= 2-specific OpenVPN code, targeted at the mingw
diff --git a= /src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index a25d26f..ca58596 100644

--- a/src/openvpnserv/int= eractive.c
+++ b/src/openvpnserv/interactive.c
@@ -1150,45 +1150,31 @@

}

= /**
- * Run comm= and: wmic nicconfig (InterfaceIndex=3D$if_index) call $action ($data)
+ * Run command: powershel= l -NoProfile -NonInteractive -Command Set-DnsClient -InterfaceIndex %ld -Co= nnectionSpecificSuffix '%s'
* @param if_index = "index of interface"
- * @param action e.g., "SetDNSDomain"
<= span> * @param data data if required for action

= * - a single word for SetDNSDomain, empty or NULL to de= lete
- * = - comma separated values for a list
*/
static DWORD

-wmic= _nicconfig_cmd(const wchar_t *action, const NET_IFINDEX if_index,- const wchar_= t *data)
+pwsh_setdns= _cmd(const NET_IFINDEX if_index, const wchar_t *data)
{
DWORD err =3D 0;
wchar_t argv0[MAX_= PATH];
wchar_t *cmdline =3D NULL;
= int timeout =3D 10000; /* in msec */

- openvpn_swprintf(argv0, _countof(argv= 0), L"%ls\\%ls", get_win_sys_path(), L"wbem\\wmic.exe")= ;
+ openvpn_swprin= tf(argv0, _countof(argv0), L"%ls\\%ls", get_win_sys_path(), L&quo= t;WindowsPowerShell\\v1.0\\powershell.exe");
<= br>- const wchar_t *fmt;
- /* comma separated list= must be enclosed in parenthesis */
- if (data && wcschr(data, L','))- {
- fmt =3D L"wmic nicconfig where (In= terfaceIndex=3D%ld) call %ls (%ls)";
- }
- else
- {
- fmt =3D L"wm= ic nicconfig where (InterfaceIndex=3D%ld) call %ls \"%ls\"";=
- }
+ const wchar_t *fmt =3D L"-= NoProfile -NonInteractive -Command Set-DnsClient -InterfaceIndex %lu -Conne= ctionSpecificSuffix '%s'";


- size_t ncmdline =3D wcslen(fmt) + 2= 0 + wcslen(action) /* max 20 for ifindex */
- + (data ? wcslen(data) + 1 : 1)= ;
+ size_t ncmdlin= e =3D wcslen(fmt) + 20 + /* max 20 for ifindex */ (data ? wcslen(data) + 1 = : 1);
cmdline =3D malloc(ncmdline*sizeof(wchar_t));
if (!cmdline)
{
= return ERROR_OUTOFMEMORY;
}

- openvpn_swprintf(cmd= line, ncmdline, fmt, if_index, action,
- data ? data : L"");<= br>+ openvpn_swprintf(cmdlin= e, ncmdline, fmt, if_index, data ? data : L"");
= err =3D ExecCommand(argv0, cmdline, timeout);
<= br> free(cmdline);
@@ -1248,7 +1234,7 @@ free(RemoveListItem(&(*lists)[undo_domain], CmpWString= , (void *)if_name));
}

- err =3D wmic_nicconfig_cmd(L&qu= ot;SetDNSDomain", if_index, wdomain);

+ err =3D pwsh_setdns_cmd(if_index, wdomain);

/* Add to undo list if domain is non-emp= ty */
if (err =3D=3D 0 && wdomain[0] &&= ; lists)

To view, visit change 1183. To uns= ubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: Iff2f4ea677fe2d88659d7814dab= 0f792f5004fb3
Gerrit-Change-Number: 1183
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <lstipakov@...277...>= ;
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: d12fk <heiko@...515...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--3nyBJZlpzo0=--