From: "cron2 (Code Review)" Date: Thu, 30 Oct 2025 16:37:35 +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: <4a06f987dd9ca65acb4a51694787b78ac426b9b9-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="JPRA97XZAQA="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: iservice: use interface index with netsh List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: d12fk , plaisthos , flichtenheld , stipa Cc: openvpn-devel --JPRA97XZAQA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#4) to the change originally created by= d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1308?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by stipa Change subject: iservice: use interface index with netsh ...................................................................... iservice: use interface index with netsh We use the interface index with netsh everywhere else, so convert this invocation of netsh to index use as well. Remove CmpWString() as it is no longer used anywhere. Change-Id: I329b407693b97dd048bd3788ecad345d6e25dab2 Signed-off-by: Heiko Hund Acked-by: Lev Stipakov Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1308 Message-Id: <20251030150214.4161-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 037.html Signed-off-by: Gert Doering --- M src/openvpnserv/interactive.c 1 file changed, 26 insertions(+), 44 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1308/4 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index cb31267..577d89c 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -995,16 +995,16 @@ } /** - * Run the command: netsh interface ip $action wins $if_name [static] $addr + * Run the command: netsh interface ip $action wins $if_index [static] $ad= dr * @param action "delete", "add" or "set" - * @param if_name "name_of_interface" + * @param if_index index of the interface to modify WINS for * @param addr IPv4 address as a string * * If addr is null and action =3D "delete" all addresses are deleted. * if action =3D "set" then "static" is added before $addr */ static DWORD -netsh_wins_cmd(const wchar_t *action, const wchar_t *if_name, const wchar_= t *addr) +netsh_wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr) { DWORD err =3D 0; int timeout =3D 30000; /* in msec */ @@ -1030,10 +1030,10 @@ /* cmd template: * netsh interface ip $action wins $if_name $static $addr */ - const wchar_t *fmt =3D L"netsh interface ip %ls wins \"%ls\" %ls %ls"; + const wchar_t *fmt =3D L"netsh interface ip %ls wins %d %ls %ls"; /* max cmdline length in wchars -- include room for worst case and som= e */ - size_t ncmdline =3D wcslen(fmt) + wcslen(if_name) + wcslen(action) + w= cslen(addr) + size_t ncmdline =3D wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + w= cslen(addr) + wcslen(addr_static) + 32 + 1; cmdline =3D malloc(ncmdline * sizeof(wchar_t)); if (!cmdline) @@ -1042,7 +1042,7 @@ goto out; } - swprintf(cmdline, ncmdline, fmt, action, if_name, addr_static, addr); + swprintf(cmdline, ncmdline, fmt, action, if_index, addr_static, addr); err =3D ExecCommand(argv0, cmdline, timeout); @@ -1051,12 +1051,6 @@ return err; } =20 -static BOOL -CmpWString(LPVOID item, LPVOID str) -{ - return (wcscmp(item, str) =3D=3D 0) ? TRUE : FALSE; -} - /** * Signal the DNS resolver (and others potentially) to reload the * group policy (DNS) settings on 32 bit Windows systems @@ -2882,7 +2876,7 @@ static DWORD HandleWINSConfigMessage(const wins_cfg_message_t *msg, undo_lists_t *lists) { - DWORD err =3D 0; + DWORD err =3D NO_ERROR; wchar_t addr[16]; /* large enough to hold string representation of an = ipv4 */ int addr_len =3D msg->addr_len; @@ -2892,38 +2886,25 @@ addr_len =3D _countof(msg->addr); } - if (!msg->iface.name[0]) /* interface name is required */ + if (!msg->iface.index) /* interface index is required */ { return ERROR_MESSAGE_DATA; } - /* use a non-const reference with limited scope to enforce null-termin= ation of strings from - * client */ - { - wins_cfg_message_t *msgptr =3D (wins_cfg_message_t *)msg; - msgptr->iface.name[_countof(msg->iface.name) - 1] =3D '\0'; - } - - wchar_t *wide_name =3D utf8to16(msg->iface.name); /* utf8 to wide-char= */ - if (!wide_name) - { - return ERROR_OUTOFMEMORY; - } - /* We delete all current addresses before adding any * OR if the message type is del_wins_cfg */ if (addr_len > 0 || msg->header.type =3D=3D msg_del_wins_cfg) { - err =3D netsh_wins_cmd(L"delete", wide_name, NULL); + err =3D netsh_wins_cmd(L"delete", msg->iface.index, NULL); if (err) { goto out; } - free(RemoveListItem(&(*lists)[undo_wins], CmpWString, wide_name)); + free(RemoveListItem(&(*lists)[undo_wins], CmpAny, NULL)); } - if (msg->header.type =3D=3D msg_del_wins_cfg) + if (addr_len =3D=3D 0 || msg->header.type =3D=3D msg_del_wins_cfg) { goto out; /* job done */ } @@ -2931,7 +2912,7 @@ for (int i =3D 0; i < addr_len; ++i) { RtlIpv4AddressToStringW(&msg->addr[i].ipv4, addr); - err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L"add", wide_name, ad= dr); + err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L"add", msg->iface.in= dex, addr); if (i =3D=3D 0 && err) { goto out; @@ -2941,22 +2922,23 @@ */ } - err =3D 0; - - if (addr_len > 0) + int *if_index =3D malloc(sizeof(msg->iface.index)); + if (if_index) { - wchar_t *tmp_name =3D _wcsdup(wide_name); - if (!tmp_name || AddListItem(&(*lists)[undo_wins], tmp_name)) - { - free(tmp_name); - netsh_wins_cmd(L"delete", wide_name, NULL); - err =3D ERROR_OUTOFMEMORY; - goto out; - } + *if_index =3D msg->iface.index; } + if (!if_index || AddListItem(&(*lists)[undo_wins], if_index)) + { + free(if_index); + netsh_wins_cmd(L"delete", msg->iface.index, NULL); + err =3D ERROR_OUTOFMEMORY; + goto out; + } + + err =3D 0; + out: - free(wide_name); return err; } @@ -3206,7 +3188,7 @@ break; case undo_wins: - netsh_wins_cmd(L"delete", item->data, NULL); + netsh_wins_cmd(L"delete", *(int *)item->data, NULL); break; case wfp_block: -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1308?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I329b407693b97dd048bd3788ecad345d6e25dab2 Gerrit-Change-Number: 1308 Gerrit-PatchSet: 4 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: stipa Gerrit-CC: openvpn-devel --JPRA97XZAQA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #4 to the change originally created by d12fk.

<= p>View C= hange

The following approvals got outdated and were removed: Code-Review+2 by stipa

iservice: use interface index with =
netsh

We use the interface index with netsh everywhere else, so conv= ert this
invocation of netsh to index use as well.

Remove CmpWStr= ing() as it is no longer used anywhere.

Change-Id: I329b407693b97dd0= 48bd3788ecad345d6e25dab2
Signed-off-by: Heiko Hund <heiko@...2662...&= gt;
Acked-by: Lev Stipakov <lstipakov@...277...>
Gerrit URL: ht= tps://gerrit.openvpn.net/c/openvpn/+/1308
Message-Id: <20251030150214= .4161-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-de= vel@lists.sourceforge.net/msg34037.html
Signed-off-by: Gert Doering <= gert@...1296...>
---
M src/openvpnserv/interactive.c
1 file cha= nged, 26 insertions(+), 44 deletions(-)

git pull=
 ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1308/4
diff=
 --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index cb31267..577d89c 100644
--- a/src/openvpn= serv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -995,16 +995,16 @@
}

/**
- * Ru= n the command: netsh interface ip $action wins $if_name [static] $addr
+ * Run the command: nets= h interface ip $action wins $if_index [static] $addr
* @p= aram action "delete", "add" or "set"
- * @param if_name &= quot;name_of_interface"
+ * @param if_index index of the interface to modify WINS for
* @param addr IPv4 address as a string
<= span> *

* If addr is null and action =3D "delete&qu= ot; all addresses are deleted.
* if action =3D "set&= quot; then "static" is added before $addr
*/
static DWORD
-netsh_wins_cmd(const wchar_t *action, const wchar_t *if_name, const w= char_t *addr)
+netsh_= wins_cmd(const wchar_t *action, int if_index, const wchar_t *addr) {
DWORD err =3D 0;
int t= imeout =3D 30000; /* in msec */
@@ -1030,10 +1030,10 @@
/* cmd template:
* netsh interface = ip $action wins $if_name $static $addr
*/
<= span style=3D"color: hsl(0, 100%, 40%);">- const wchar_t *fmt =3D L"= ;netsh interface ip %ls wins \"%ls\" %ls %ls";

+ const wchar_t *fmt =3D L"= ;netsh interface ip %ls wins %d %ls %ls";


= /* max cmdline length in wchars -- include room for worst case a= nd some */
- size_t = ncmdline =3D wcslen(fmt) + wcslen(if_name) + wcslen(action) + wcslen(addr)<= /span>
+ size_t ncmdline = =3D wcslen(fmt) + 11 /*if_index*/ + wcslen(action) + wcslen(addr) + wcslen(addr_static) + 32 + 1;
cmdline =3D malloc(ncmdline * sizeof(wchar_t));

= if (!cmdline)
@@ -1042,7 +1042,7 @@
= goto out;
}

- swprintf(cmdline, ncmdline, fmt, actio= n, if_name, addr_static, addr);
+ swprintf(cmdline, ncmdline, fmt, action, if_index, addr_sta= tic, addr);

err =3D ExecCommand(argv= 0, cmdline, timeout);

@@ -1051,12 +1051,6= @@
return err;
}

-static BOOL
<= span style=3D"color: hsl(0, 100%, 40%);">-CmpWString(LPVOID item, LPVOID st= r)

-{
- return (wcscmp(item, str) =3D=3D 0)= ? TRUE : FALSE;
-}
-
/**
* Signal the DNS resolver (and others potentially) to reload= the
* group policy (DNS) settings on 32 bit Windows syst= ems
@@ -2882,7 +2876,7 @@
static DWORD
HandleWINSConfigMessage(const wins_cfg_message_t *msg, undo_l= ists_t *lists)
{
- DWORD err =3D 0;
+ DWORD err =3D NO_ERROR;
wchar_t addr[= 16]; /* large enough to hold string representation of an ipv4 */
= int addr_len =3D msg->addr_len;

<= span>@@ -2892,38 +2886,25 @@

addr_len =3D _countof= (msg->addr);
}

- if (!msg->iface.name[0]) /* inter= face name is required */
+ if (!msg->iface.index) /* interface index is required */=
{
return ERROR_MESSAGE_DATA;=
}

- /* use a non-const reference with limited scope to enforce= null-termination of strings from
- * client */
- {
- w= ins_cfg_message_t *msgptr =3D (wins_cfg_message_t *)msg;
- msgptr->iface.name[_countof(m= sg->iface.name) - 1] =3D '\0';
- }
-
- wchar_t *wide= _name =3D utf8to16(msg->iface.name); /* utf8 to wide-char */
<= span style=3D"color: hsl(0, 100%, 40%);">- if (!wide_name)

- {

- return ERROR_OUTOFMEMORY;
- }
-
/* We delete all current addresse= s before adding any
* OR if the message type is del_w= ins_cfg
*/
if (addr_len > 0 |= | msg->header.type =3D=3D msg_del_wins_cfg)
{
- err =3D netsh_wins_= cmd(L"delete", wide_name, NULL);
+ err =3D netsh_wins_cmd(L"delete", = msg->iface.index, NULL);
if (err)
{

goto out;
= }
- free(Remo= veListItem(&(*lists)[undo_wins], CmpWString, wide_name));
+ free(RemoveListItem(&= (*lists)[undo_wins], CmpAny, NULL));

}

- if (msg->hea= der.type =3D=3D msg_del_wins_cfg)
+ if (addr_len =3D=3D 0 || msg->header.type =3D=3D msg_d= el_wins_cfg)
{
goto out; /* j= ob done */
}
@@ -2931,7 +2912,7 @@
for (int i =3D 0; i < addr_len; ++i)
= {
RtlIpv4AddressToStringW(&msg->addr[i]= .ipv4, addr);
- = err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L"add", wi= de_name, addr);
+ = err =3D netsh_wins_cmd(i =3D=3D 0 ? L"set" : L"add"= , msg->iface.index, addr);
if (i =3D=3D 0 &= & err)
{
goto out= ;
@@ -2941,22 +2922,23 @@
*/
}

- err =3D 0;
-
- if (addr_= len > 0)
+ int = *if_index =3D malloc(sizeof(msg->iface.index));
+ if (if_index)
{
- wchar_t *tmp_name= =3D _wcsdup(wide_name);
- {
= - free(tmp_name);
- netsh_wins_cmd= (L"delete", wide_name, NULL);
- err =3D ERROR_OUTOFMEMORY;
- goto out;
- }
+ *if_index =3D msg->iface.index;<= br> }

+ if (!if_index || AddListItem(&(*lists)[undo_wins], if= _index))
+ {
+ free(if_index);
+ netsh_wins_cm= d(L"delete", msg->iface.index, NULL);
+ err =3D ERROR_OUTOFMEMORY;+ goto out;
<= span style=3D"color: hsl(120, 100%, 40%);">+ }

+
+ err =3D 0;
+
out:
- free(wide_name);
return err;
}


@@ -3206,7 +3188,7 @@
break;


= case undo_wins:
-= netsh_wins_cmd(L"delete", item->data, NULL= );
+ = netsh_wins_cmd(L"delete", *(int *)item->data, NULL);=
break;

= case wfp_block:

To view, = visit ch= ange 1308. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I329b407693b97dd048bd3788eca= d345d6e25dab2
Gerrit-Change-Number: 1308
Gerrit-PatchSet: 4
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-Reviewer: stipa <lstipakov@...277...= >
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --JPRA97XZAQA=--