From: "d12fk (Code Review)" Date: Thu, 30 Oct 2025 08:16:57 +0000 In-Reply-To: References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277..., gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="u//LFQYWjWQ="; 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: plaisthos , flichtenheld , stipa Cc: openvpn-devel --u//LFQYWjWQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: d12fk, flichtenheld, plaisthos. Hello cron2, flichtenheld, plaisthos, stipa, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1308?usp=3Demail to look at the new patch set (#3). 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 --- M src/openvpnserv/interactive.c 1 file changed, 26 insertions(+), 44 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1308/3 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index ce0d4dd..50f1627 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; } =20 - 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; } -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: 3 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-Reviewer: stipa Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: d12fk --u//LFQYWjWQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: d12fk, flichtenheld, plaisthos.

d12fk uploaded patch set #3 to this change.

View Change

iservice: use interface index with netsh

We use = the interface index with netsh everywhere else, so convert this
invocati= on of netsh to index use as well.

Remove CmpWString() as it is no lo= nger used anywhere.

Change-Id: I329b407693b97dd048bd3788ecad345d6e25= dab2
Signed-off-by: Heiko Hund <heiko@...2662...>
---
M src/= openvpnserv/interactive.c
1 file changed, 26 insertions(+), 44 deletions= (-)

git pull ssh://gerrit.openvpn.net:29418/open=
vpn refs/changes/08/1308/3
diff --git a/src/openvpnserv/interactive=
.c b/src/openvpnserv/interactive.c
index ce0d4dd..50f1627 1= 00644
--- a/src/openvpnserv/interactive.c
+= ++ b/src/openvpnserv/interactive.c
@@ -995,16 +995,16 @@
}

/**
- * Run the command: netsh interface ip $a= ction wins $if_name [static] $addr
+ * Run the command: netsh interface ip $action wins $if_inde= x [static] $addr
* @param action "delete"= , "add" or "set"
- * @param if_name "name_of_interface"<= br>+ * @param if_index inde= x 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 add= ed 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)
{
DWO= RD err =3D 0;
int timeout =3D 30000; /* in msec */
@@ -1030,10 +1030,10 @@
/* cmd template:<= /span>
* netsh interface ip $action wins $if_name $static $a= ddr
*/
- 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 some */
- size_t ncmdline =3D wcslen(fmt) + wcslen(i= f_name) + wcslen(action) + wcslen(addr)
+ size_t ncmdline =3D wcslen(fmt) + 11 /*if_index*/ += wcslen(action) + wcslen(addr)
+ wcs= len(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, n= cmdline, fmt, action, if_index, addr_static, addr);

err =3D ExecCommand(argv0, cmdline, timeout);

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

-static BOOL
-CmpWString(LPVOID item, LPVOID str)
-{
= - return (wcscmp(item, str) =3D=3D 0) ? TRUE : FALSE;
-}
-
/**
* Signal the DNS res= olver (and others potentially) to reload the
* group poli= cy (DNS) settings on 32 bit Windows systems
@@ -2882,7 +287= 6,7 @@
static DWORD
HandleWINSConfigMessa= ge(const wins_cfg_message_t *msg, undo_lists_t *lists)
{
- DWORD err =3D 0;
+ DWORD err =3D NO_E= RROR;
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;
}
<= /span>
- /* use a non-const= reference with limited scope to enforce null-termination of strings from
- * client */=
- {
- wins_cfg_message_t *msgptr =3D (win= s_cfg_message_t *)msg;
= - msgptr->iface.name[_countof(msg->iface.name) - 1] =3D '\= 0';
- }-
- wchar_t *wide_name =3D utf8to16(msg->iface.n= ame); /* utf8 to wide-char */
- if (!wide_name)
- {
- re= turn 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_d= el_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)<= /span>
+ if (addr_len =3D= =3D 0 || msg->header.type =3D=3D msg_del_wins_cfg)
= {
goto out; /* job done */
}<= /span>
@@ -2931,7 +2912,7 @@
for (int i =3D 0= ; i < addr_len; ++i)
{
Rtl= Ipv4AddressToStringW(&msg->addr[i].ipv4, addr);
- err =3D netsh_wins_cmd(i =3D=3D 0 = ? L"set" : L"add", wide_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 +2= 922,23 @@
*/
}

- err =3D 0;
-
- if (addr_len > 0)
+ int *if_index =3D malloc(sizeof(ms= g->iface.index));
= + if (if_index)
{
- wchar_t *tmp_name =3D _wcsdup(wide_name);
- if (!tmp_name || Ad= dListItem(&(*lists)[undo_wins], tmp_name))
- {
- free(tmp_name);
- netsh_wins_cmd(L"delete", wide_nam= e, NULL);
- = err =3D ERROR_OUTOFMEMORY;
- goto out;
- }
+ = *if_index =3D msg->iface.index;
}

+ if (!if_inde= x || 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;
}
<= br>@@ -3206,7 +3188,7 @@
break;<= /span>

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

case wfp_block:<= /span>

To view, visit change 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: 3
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>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: d12fk <heiko@...515...>= ;
= --u//LFQYWjWQ=--