From d458df29afb38414c669d773d04b938e1f33f6dd Mon Sep 17 00:00:00 2001 From: benno Date: Sat, 11 Aug 2018 09:18:49 +0000 Subject: [PATCH] Fix problems ofthe ifconfig argument parser with "ifconfig join". Due to the way the parsing works, you cannot have an option that accepts strings as argument or no argument, without side effects: for example "join " could only join networks that did not have a nwid identical to another ifconfig option, i.e. "join mtu" or "join join" would not work. Solve this by making join always require an nwid. Listing all the configured nwids for auto-join is moved to the new option "joinlist". Removing _all_ auto-join configuration is moved to "-joinlist". deraadt@ likes it and ok phessler@ stsp@ --- sbin/ifconfig/ifconfig.8 | 21 +++++++++++---------- sbin/ifconfig/ifconfig.c | 21 +++++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index a07bf1cdb9d..c77c7dcea5e 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ifconfig.8,v 1.313 2018/08/03 11:21:27 halex Exp $ +.\" $OpenBSD: ifconfig.8,v 1.314 2018/08/11 09:18:49 benno Exp $ .\" $NetBSD: ifconfig.8,v 1.11 1996/01/04 21:27:29 pk Exp $ .\" $FreeBSD: ifconfig.8,v 1.16 1998/02/01 07:03:29 steve Exp $ .\" @@ -31,7 +31,7 @@ .\" .\" @(#)ifconfig.8 8.4 (Berkeley) 6/1/94 .\" -.Dd $Mdocdate: August 3 2018 $ +.Dd $Mdocdate: August 11 2018 $ .Dt IFCONFIG 8 .Os .Sh NAME @@ -895,7 +895,8 @@ will begin advertising as master. .Ar wireless-interface .Op Oo Fl Oc Ns Cm bssid Ar bssid .Op Oo Fl Oc Ns Cm chan Op Ar n -.Op Oo Fl Oc Ns Cm join Op Ar id +.Op Oo Fl Oc Ns Cm join Ar id +.Op Oo Fl Oc Ns Cm joinlist .Op Oo Fl Oc Ns Cm nwflag Ar flag .Op Oo Fl Oc Ns Cm nwid Ar id .Op Oo Fl Oc Ns Cm nwkey Ar key @@ -927,16 +928,13 @@ show the list of channels supported by the device. .It Cm -chan Unset the desired channel. It doesn't affect the channel to be created for IBSS or Host AP mode. -.It Cm join Op Ar id +.It Cm join Ar id Add the network with NWID/ESSID .Ar id to the list of auto-join networks. Information about such networks is retained, such that configured interfaces can automatically switch to such networks as necessary. -If no -.Ar id -is specified, show the list of currently configured auto-join networks. .Pp The .Ar id @@ -947,11 +945,14 @@ Any necessary or .Cm nwkey arguments should be specified on the same line. -.It Cm -join Op Ar id -Remove all networks, -or the network with NWID +.It Cm -join Ar id +Remove the network with NWID .Ar id , from the list of auto-join networks. +.It joinlist +Show the list of currently configured auto-join networks. +.It -joinlist +Remove all networks in the list of auto-join networks. .It Cm nwflag Ar flag Set specified flag. The flag name can be either diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index c16daef447e..7a89c26dadb 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.372 2018/08/08 17:26:52 florian Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.373 2018/08/11 09:18:49 benno Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -188,6 +188,7 @@ void setifllprio(const char *, int); void setifnwid(const char *, int); void setifjoin(const char *, int); void delifjoin(const char *, int); +void showjoin(const char *, int); void setifbssid(const char *, int); void setifnwkey(const char *, int); void setifwpa(const char *, int); @@ -376,8 +377,10 @@ const struct cmd { { "mtu", NEXTARG, 0, setifmtu }, { "nwid", NEXTARG, 0, setifnwid }, { "-nwid", -1, 0, setifnwid }, - { "join", NEXTARG0, 0, setifjoin }, - { "-join", NEXTARG0, 0, delifjoin }, + { "join", NEXTARG, 0, setifjoin }, + { "-join", NEXTARG, 0, delifjoin }, + { "joinlist", NEXTARG0, 0, showjoin }, + { "-joinlist", -1, 0, delifjoin }, { "bssid", NEXTARG, 0, setifbssid }, { "-bssid", -1, 0, setifbssid }, { "nwkey", NEXTARG, 0, setifnwkey }, @@ -1677,11 +1680,6 @@ setifjoin(const char *val, int d) struct ieee80211_join join; int len; - if (val == NULL) { - show_join = 1; - return; - } - if (d != 0) { /* no network id is especially desired */ memset(&join, 0, sizeof(join)); @@ -2323,6 +2321,13 @@ ieee80211_status(void) ieee80211_listnodes(); } +void +showjoin(const char *cmd, int val) +{ + show_join = 1; + return; +} + void join_status(void) { -- 2.20.1