install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Klemens Nanni
Instead of ignoring SSIDs containing whitespaces, slightly adjust the
commands to take everything in between 'nwid ' and ' chan' as SSID; if
it has double quotes at start *and* end, simply remove those.

This enables users to select networks such as "Unitymedia WifiSpot"
"FRITZ!Box 7490" for example which are common among the quoted ones at
least here in germany.

The only SSIDs known to break this are those containing ' chan ' as this
substring is used as delimiter. Picking "some chan 4 me" would therefore
result in _nwid being assigned '"some' (literal double quote), but than
reasonably acceptable (compared to the current behaviour).


Since cat's -n flag already takes care of the space between numbers and
input lines, remove the leading tab to avoid excessive widths for lines
with long SSIDs.

Feedback/OK?

Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1014
diff -u -p -r1.1014 install.sub
--- install.sub 3 Jun 2017 22:27:41 -0000 1.1014
+++ install.sub 14 Jun 2017 22:06:47 -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 //p' >$WLANLIST
  cat $WLANLIST
 }
 
@@ -1078,15 +1077,16 @@ ieee80211_config() {
  # Empty scan cache.
  rm -f $WLANLIST
 
- while [[ -z $_nwid ]]; do
+ while [[ -z "$_nwid" ]]; do
  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/ chan .*//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' |
+ sed -n 's/^\(.*\) chan .* bssid \([^ ]*\) .*$/\1 (\2)/p' |
  cat -n | more -c
  ;;
  *) _nwid=$resp

Reply | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Klemens Nanni
No need for quoting $_nwid within [[ ... ]] since field splitting is not
applied.

Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1014
diff -u -p -r1.1014 install.sub
--- install.sub 3 Jun 2017 22:27:41 -0000 1.1014
+++ install.sub 15 Jun 2017 14:48: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 //p' >$WLANLIST
  cat $WLANLIST
 }
 
@@ -1082,11 +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/ chan .*//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' |
+ sed -n 's/^\(.*\) chan .* bssid \([^ ]*\) .*$/\1 (\2)/p' |
  cat -n | more -c
  ;;
  *) _nwid=$resp

Reply | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Robert Peichaer
In reply to this post by Klemens Nanni
On Thu, Jun 15, 2017 at 12:09:20AM +0200, Klemens Nanni wrote:

> Instead of ignoring SSIDs containing whitespaces, slightly adjust the
> commands to take everything in between 'nwid ' and ' chan' as SSID; if
> it has double quotes at start *and* end, simply remove those.
>
> This enables users to select networks such as "Unitymedia WifiSpot"
> "FRITZ!Box 7490" for example which are common among the quoted ones at
> least here in germany.
>
> The only SSIDs known to break this are those containing ' chan ' as this
> substring is used as delimiter. Picking "some chan 4 me" would therefore
> result in _nwid being assigned '"some' (literal double quote), but than
> reasonably acceptable (compared to the current behaviour).
>
>
> Since cat's -n flag already takes care of the space between numbers and
> input lines, remove the leading tab to avoid excessive widths for lines
> with long SSIDs.
>
> Feedback/OK?

I agree, that supporting SSIDs containing whitespaces would be an improvement.

>
> Index: install.sub
> ===================================================================
> RCS file: /cvs/src/distrib/miniroot/install.sub,v
> retrieving revision 1.1014
> diff -u -p -r1.1014 install.sub
> --- install.sub 3 Jun 2017 22:27:41 -0000 1.1014
> +++ install.sub 14 Jun 2017 22:06:47 -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 //p' >$WLANLIST
>   cat $WLANLIST
>  }
>  
> @@ -1078,15 +1077,16 @@ ieee80211_config() {
>   # Empty scan cache.
>   rm -f $WLANLIST
>  
> - while [[ -z $_nwid ]]; do
> + while [[ -z "$_nwid" ]]; do
>   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/ chan .*//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' |
> + sed -n 's/^\(.*\) chan .* bssid \([^ ]*\) .*$/\1 (\2)/p' |
>   cat -n | more -c
>   ;;
>   *) _nwid=$resp

Here's a slightly different but completely untested approach ...

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.

  - Write nwid and bssid into WLANLIST as '<nwid><space>(<bssid>)'.

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

  - 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.


Index: install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1019
diff -u -p -p -u -r1.1019 install.sub
--- install.sub 2 Jul 2017 12:45:43 -0000 1.1019
+++ install.sub 2 Jul 2017 16:21:42 -0000
@@ -1060,10 +1060,10 @@ 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 -En 's/^[[:space:]]+nwid (.*) chan [0-9]+ bssid ([[:xdigit:]:]+) .*$/\1 (\2)/p' |
+ sed 's/"\(.*\)"/\1/' >$WLANLIST
  cat $WLANLIST
 }
 
@@ -1082,12 +1082,11 @@ 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 -En "${resp}s/ \([[:xdigit:]:]+\)//p")
  [[ -z $_nwid ]] && echo "There is no line $resp."
  ;;
- \?) ieee80211_scan $_if |
- sed -n 's/^\([^ ]*\) chan .* bssid \([^ ]*\) .*$/ \1 (\2)/p' |
- cat -n | more -c
+ \?) ieee80211_scan $_if | cat -n | more -c
  ;;
  *) _nwid=$resp
  ;;
@@ -1096,7 +1095,7 @@ ieee80211_config() {
 
  # 'any' implies that only open access points are considered.
  if [[ $_nwid != any ]]; then
- ifconfig $_if nwid "$_nwid"
+ ifconfig $_if nwid $(quote "$_nwid")
  quote nwid "$_nwid" >>$_hn
 
  _prompt="Security protocol? (O)pen, (W)EP"
===================================================================
Stats: --- 7 lines 291 chars
Stats: +++ 6 lines 286 chars
Stats: -1 lines
Stats: -5 chars

Reply | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Klemens Nanni
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?

I'd say taking nasty characters in $_nwid further into account can be
put into a seperate diff.

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 2 Jul 2017 22:42:38 -0000
@@ -896,13 +896,14 @@ __EOT
 }
@ -1060,10 +1061,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 +1082,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 | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Klemens Nanni
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
  ;;

Reply | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Klemens Nanni
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.

Reply | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Klemens Nanni-2
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 | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Klemens Nanni-2
On Fri, Sep 06, 2019 at 11:01:35PM +0200, Klemens Nanni wrote:
> I'd like to finally commit this so occasional installations over said
> wifi will just work.
I'll commit this weekend unless someone objects.

Reply | Threaded
Open this post in threaded view
|

Re: install.sub: ieee80211_{scan,config}: Allow quoted SSIDs

Stefan Sperling-5
In reply to this post by Klemens Nanni-2
On Fri, Sep 06, 2019 at 11:01:35PM +0200, Klemens Nanni wrote:

> 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?
>

Yes please, thanks.

>
> 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
>   ;;
>