On Tue, Aug 08, 2017 at 11:15:28PM +0200, Klemens Nanni wrote:
> On Tue, Jul 04, 2017 at 10:44:57PM +0200, Klemens Nanni wrote:
> > On Mon, Jul 03, 2017 at 12:45:32AM +0200, Klemens Nanni wrote:
> > > Thanks for looking into it.
> > > 
> > > On Sun, Jul 02, 2017 at 04:32:43PM +0000, Robert Peichaer wrote:
> > > > ieee80211_scan()
> > > > - Extract the needed information (nwid, bssid) using a very specific
> > > >   sed expression. Any line, not matching this expr is ignored.
> > > > 
> > > > - Remove leading and trailing double-quotes in case of nwids with
> > > >   spaces.
> > > I had the ugly case of an empty SSID in reach while testing this so I
> > > intentionally left double quotes in place within WLANLIST so that
> > > the list presented to the user wouldn't look broken, e.g.
> > >   "my wifi" chan 1 bssid ...
> > >   "" chan 2 bssid ...
> > > as opposed to
> > >   my wifi chan 1 bssid ...
> > >    chan 2 bssid ...
> > > 
> > > I'd also leave unqouting to the routine that actually requires it
> > > instead of the function that just provides the list.
> > > 
> > > > - Write nwid and bssid into WLANLIST as '<nwid><space>(<bssid>)'.
> > > Writing the simple format directly to cache seems like a good idea
> > > instead of just cutting ^nwid first here and .*$ somewhere else.
> > > 
> > > > ieee80211_config()
> > > > - just print WLANLIST using ieee80211_scan() if the user chooses
> > > >   '?' which has the right format already
> > > > 
> > > > - in case the user selects an entry from WLANLIST using a number,
> > > >   remove the '<space>(<bssid>)' part from the line, resulting in
> > > >   the nwid (without double-quotes)
> > > > 
> > > > - using the quote() function with the ifconfig command ensures,
> > > >   that the nwid is quoted properly with single-quotes in case it
> > > >   contains spaces
> > > This is not needed as "$_nwid" will even work if _nwid='my "wifi'.
> > > 
> > > > - using the quote() function when writing the nwid to the hostname.if
> > > >   files ensures that the nwid is quoted properly with single-quotes
> > > >   in case it contains spaces
> > > > 
> > > > The parse_hn_line() function in netstart does handle quoted nwids
> > > > properly when processing the hostname.if config lines as far as I
> > > > can see.
> > > Yes, it does. But it chokes on SSIDs containing a literal " for example.
> > > 
> > > 
> > > Here is an updated diff taking above considerations into account.
> > > 
> > > Note how ([[:xdigit:]:]*)$ when picking the answer must not be
> > > simplified to (.*)$ as this would fail on SSIDs like "my (hidden) wifi".
> > > 
> > > Feedback/OK?
> > That patch was mangled, sorry. Here it goes again.
> > 
> > Index: install.sub
> > ===================================================================
> > RCS file: /cvs/src/distrib/miniroot/install.sub,v
> > retrieving revision 1.1019
> > diff -u -p -r1.1019 install.sub
> > --- install.sub     2 Jul 2017 12:45:43 -0000       1.1019
> > +++ install.sub     4 Jul 2017 20:43:56 -0000
> > @@ -1060,10 +1060,9 @@ v6_config() {
> > # Perform an 802.11 network scan on interface $1.
> > # The result is cached in $WLANLIST.
> > ieee80211_scan() {
> > -   # N.B. Skipping quoted nwid's for now.
> >     [[ -f $WLANLIST ]] ||
> >             ifconfig $1 scan |
> > -           sed -n 's/^             nwid \([^"]\)/\1/p' >$WLANLIST
> > +                   sed -n 's/^[[:space:]]*nwid \(.*\) chan [0-9]* bssid 
> > \([[:xdigit:]:]*\).*/\1 (\2)/p' >$WLANLIST
> >     cat $WLANLIST
> > }
> > 
> > @@ -1082,12 +1081,12 @@ ieee80211_config() {
> >             ask_until "Access point? (ESSID, 'any', list# or '?')" "any"
> >             case "$resp" in
> >             +([0-9]))
> > -                   _nwid=$(ieee80211_scan $_if | sed -n "${resp}s/ .*//p")
> > +                   _nwid=$(ieee80211_scan $_if |
> > +                           sed -n ${resp}'{s/ ([[:xdigit:]:]*)$//p;q;}')
> >                     [[ -z $_nwid ]] && echo "There is no line $resp."
> > +                   [[ $_nwid = \"*\" ]] && _nwid=${_nwid#\"} 
> > _nwid=${_nwid%\"}
> >                     ;;
> > -           \?)     ieee80211_scan $_if |
> > -                           sed -n 's/^\([^ ]*\) chan .* bssid \([^ ]*\) 
> > .*$/       \1 (\2)/p' |
> > -                           cat -n | more -c
> > +           \?)     ieee80211_scan $_if | cat -n | more -c
> >                     ;;
> >             *)      _nwid=$resp
> >                     ;;
> > 
> Bump. Any progress on this? It still applies to the latest revision.
Rebased diff that I just tested again on a X230 with athn(4) where I
installed over an ESSID of the form "Wifi foo" just fine;  empty ESSIDs
showed up as "" in the list, all others still look normal and could be
chosen just fine.

The resulting hostname.athn0 contained

        nwid 'Wifi foo'
        dhcp

I'd like to finally commit this so occasional installations over said
wifi will just work.

OK?


Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1140
diff -u -p -r1.1140 install.sub
--- install.sub 21 Aug 2019 17:39:30 -0000      1.1140
+++ install.sub 6 Sep 2019 20:19:51 -0000
@@ -1171,10 +1171,9 @@ v6_config() {
 
 # Perform an 802.11 network scan on interface $1 and cache the result a file.
 ieee80211_scan() {
-       # N.B. Skipping quoted nwid's for now.
        [[ -f $WLANLIST ]] ||
                ifconfig $1 scan |
-               sed -n 's/^             nwid \([^"]\)/\1/p' >$WLANLIST
+                       sed -n 's/^[[:space:]]*nwid \(.*\) chan [0-9]* bssid 
\([[:xdigit:]:]*\).*/\1 (\2)/p' >$WLANLIST
        cat $WLANLIST
 }
 
@@ -1194,12 +1193,12 @@ ieee80211_config() {
                ask_until "Access point? (ESSID, 'any', list# or '?')" "any"
                case "$resp" in
                +([0-9]))
-                       _nwid=$(ieee80211_scan $_if | sed -n "${resp}s/ .*//p")
+                       _nwid=$(ieee80211_scan $_if |
+                           sed -n ${resp}'{s/ ([[:xdigit:]:]*)$//p;q;}')
                        [[ -z $_nwid ]] && echo "There is no line $resp."
+                       [[ $_nwid = \"*\" ]] && _nwid=${_nwid#\"} 
_nwid=${_nwid%\"}
                        ;;
-               \?)     ieee80211_scan $_if |
-                               sed -n 's/^\([^ ]*\) chan .* bssid \([^ ]*\) 
.*$/       \1 (\2)/p' |
-                               cat -n | more -c
+               \?)     ieee80211_scan $_if | cat -n | more -c
                        ;;
                *)      _nwid=$resp
                        ;;

Reply via email to