summaryrefslogtreecommitdiffstats
path: root/src/wifi-menu
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2014-02-25 15:22:31 +0100
committerJouke Witteveen <j.witteveen@gmail.com>2014-02-27 13:48:49 +0100
commit349f9b0360f6f7305475fca57656f9e187d859d2 (patch)
tree89ff51ee5d4bcf053853f72f1c29d80a442edbf7 /src/wifi-menu
parent58e8dd21f999357497bbbe5c914b2d50f0a07e1d (diff)
downloadnetctl-349f9b0360f6f7305475fca57656f9e187d859d2.tar.gz
netctl-349f9b0360f6f7305475fca57656f9e187d859d2.tar.xz
wifi-menu: generate keys in proper quoting syntax
Diffstat (limited to 'src/wifi-menu')
-rwxr-xr-xsrc/wifi-menu30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/wifi-menu b/src/wifi-menu
index 0323e51..80eadd4 100755
--- a/src/wifi-menu
+++ b/src/wifi-menu
@@ -19,6 +19,16 @@ Arguments:
END
}
+# Prepares $1 for use in a special quoting context
+quote_safe()
+{
+ if [[ "$1" = \"* ]]; then
+ printf '""%s"' "$1"
+ else
+ printf "%s" "$1"
+ fi
+}
+
# Fills PROFILES and ESSIDS with the profile names and essids of the profiles
# for interface $1.
init_profiles()
@@ -125,13 +135,21 @@ create_profile()
[[ "$OBSCURE" ]] && box="--insecure --passwordbox" || box="--inputbox"
msg="Enter $security security key for\n'$1'"
key=$(dialog $box "$msg" 10 40 --stdout) || return $?
- if [[ "${#key}" -ge 8 && "${#key}" -le 63 ]]; then
+ if [[ "${BASH_REMATCH[0]}" = "WEP" ]]; then
+ if [[ "$key" = +([[:xdigit:]][[:xdigit:]]) ]]; then
+ key="\"$key"
+ else
+ key=$(quote_safe "$key")
+ fi
+ elif [[ "${#key}" -ge 8 && "${#key}" -le 63 ]]; then
if [[ "$OBSCURE" ]]; then
- key=$(wpa_passphrase "$1" "$key" | sed -n "s/^[[:space:]]*psk=//p")
+ key="\"$(wpa_passphrase "$1" "$key" | sed -n "s/^[[:space:]]*psk=//p")"
else
- key=$(printf "%q" "$key")
+ key=$(quote_safe "$key")
fi
- elif ! [[ "${#key}" -eq 64 && "$key" = +([[:xdigit:]]) ]]; then
+ elif [[ "${#key}" -eq 64 && "$key" = +([[:xdigit:]]) ]]; then
+ key="\"$key"
+ else
return 4
fi
fi
@@ -140,9 +158,9 @@ Description='Automatically generated profile by wifi-menu'
Interface=$INTERFACE
Connection=wireless
Security=$security
-ESSID=$(printf "%q" "$1")
+ESSID=$(printf "%q" "$(quote_safe "$1")")
IP=dhcp
-${key+Key=$key}
+${key+Key=$(printf "%q" "$key")}
EOF
printf "%s" "$PROFILE"
return 0