From: "cron2 (Code Review)" cron2 upl=
oaded patch set #4 to the change originally created by d12fk.
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=
span>
* @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;
}
=
span>
-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);
- 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;<=
br> }
+ if (!if_index || AddListItem(&(*lists)[undo_wins], if=
_index))
+ {
+ free(if_index);=
span>
+ 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.