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