From: "d12fk (Code Review)" Date: Tue, 28 Oct 2025 22:40:06 +0000 In-Reply-To: References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <1a5454966cfa6e6cda950e0185864d55e9a41d7e-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="w6w+IlsJqEE="; 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 Cc: openvpn-devel --w6w+IlsJqEE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: d12fk, flichtenheld, plaisthos. Hello cron2, flichtenheld, plaisthos, 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 (#2). 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. Change-Id: I329b407693b97dd048bd3788ecad345d6e25dab2 Signed-off-by: Heiko Hund --- M src/openvpnserv/interactive.c 1 file changed, 26 insertions(+), 38 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/1308/2 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index ce0d4dd..52f9c66 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); @@ -2882,7 +2882,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 +2892,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 +2918,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 +2928,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 +3194,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: 2 Gerrit-Owner: d12fk Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: d12fk --w6w+IlsJqEE= 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 #2 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.

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

git pull ssh://gerrit.openvpn.=
net:29418/openvpn refs/changes/08/1308/2
diff --git a/src/openvpnse=
rv/interactive.c b/src/openvpnserv/interactive.c
index ce0d= 4dd..52f9c66 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -995,16= +995,16 @@
}

/**
- * Run the command: netsh i= nterface ip $action wins $if_name [static] $addr
+ * Run the command: netsh interface ip $action= wins $if_index [static] $addr
* @param action &quo= t;delete", "add" or "set"
- * @param if_name "name_of_interface= "
+ * @param if= _index index of the interface to modify WINS for
* @pa= ram addr IPv4 address as a string
*
* If addr is null and action =3D "delete" all addresses are = deleted.

* if action =3D "set" then "stati= c" is added before $addr
*/
static = DWORD
-netsh_wins_cmd(c= onst 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)
{
<= span> DWORD err =3D 0;

int timeout =3D 30000; /* i= n msec */
@@ -1030,10 +1030,10 @@
/* c= md template:
* netsh interface ip $action wins $if_na= me $static $addr
*/
- const wchar_t *fmt =3D L"netsh interface ip %l= s wins \"%ls\" %ls %ls";
+ const wchar_t *fmt =3D L"netsh interface ip %l= s wins %d %ls %ls";

/* max cmdl= ine length in wchars -- include room for worst case and some */
<= span style=3D"color: hsl(0, 100%, 40%);">- size_t ncmdline =3D wcslen(fm= t) + wcslen(if_name) + wcslen(action) + wcslen(addr)
+ size_t ncmdline =3D wcslen(fmt) + 11 = /*if_index*/ + wcslen(action) + wcslen(addr)
= + wcslen(addr_static) + 32 + 1;
cmdline =3D m= alloc(ncmdline * sizeof(wchar_t));
if (!cmdline)
@@ -1042,7 +1042,7 @@
goto out;<= br> }

- swprintf(cmdline, ncmdline, fmt, action, if_name, addr_stat= ic, addr);
+ swpri= ntf(cmdline, ncmdline, fmt, action, if_index, addr_static, addr);
err =3D ExecCommand(argv0, cmdline, timeout);=

@@ -2882,7 +2882,7 @@
s= tatic 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 ipv= 4 */
int addr_len =3D msg->addr_len;

@@ -2892,38 +2892,25 @@
addr_l= en =3D _countof(msg->addr);
}

- if (!msg->iface.na= me[0]) /* interface name is required */
+ if (!msg->iface.index) /* interface index is req= uired */
{
return ERROR_MESSA= GE_DATA;
}

- /* use a non-const reference with limited s= cope to enforce null-termination 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 c= urrent addresses before adding any
* OR if the messag= e type is del_wins_cfg
*/
if (ad= dr_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;<= br> }
- = free(RemoveListItem(&(*lists)[undo_wins], CmpWString, wide_name))= ;
+ free(Remov= eListItem(&(*lists)[undo_wins], CmpAny, NULL));
}<= /span>

- = if (msg->header.type =3D=3D msg_del_wins_cfg)
+ if (addr_len =3D=3D 0 || msg->header.ty= pe =3D=3D msg_del_wins_cfg)
{
= goto out; /* job done */
}
@@ -2931,7= +2918,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&quo= t;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 +2928,23 @@
= */
}

- err =3D 0;
-
- if (addr_len > 0)
+ int *if_index =3D malloc(sizeof(msg->iface.index));<= br>+ if (if_index) {
- = wchar_t *tmp_name =3D _wcsdup(wide_name);
- if (!tmp_name || AddListItem(&(*lists)[undo= _wins], tmp_name))
- = {
- fre= e(tmp_name);
- = netsh_wins_cmd(L"delete", wide_name, NULL);
- err =3D ERROR_OUTOFMEMORY;
- goto out;
- }
+ *if_index =3D msg->ifa= ce.index;

}

+ if (!if_index || AddListItem(&(*list= s)[undo_wins], if_index))
+ {
+ = free(if_index);
+ = netsh_wins_cmd(L"delete", msg->iface.index, NULL);<= br>+ err =3D ERROR_OUTOF= MEMORY;
+ goto= out;
+ }+
+ err =3D 0;
+
out:
- free(wide_name);
return er= r;
}

@@ -3206,7 +3194,7 = @@
break;

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

case wfp_block:

<= /pre>

To view, visit change 1308. To unsubscribe, or for help writing mail fi= lters, visit set= tings.

=
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I329b407693b97dd048bd3788eca= d345d6e25dab2
Gerrit-Change-Number: 1308
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
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-Attention: d12fk <heiko@...515...>= ;
= --w6w+IlsJqEE=--