summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Rayner <james@archlinux.org>2009-05-18 08:59:34 +0200
committerJames Rayner <james@archlinux.org>2009-05-18 08:59:34 +0200
commitbb3bade410cbfb4d19b65884b6525be7603dd686 (patch)
treed0defa7cffdfcbc084bf2124b661de249f8e79a9
parent92d6bde2e758466c5e524f84e424b7a98c749863 (diff)
downloadnetctl-bb3bade410cbfb4d19b65884b6525be7603dd686.tar.gz
netctl-bb3bade410cbfb4d19b65884b6525be7603dd686.tar.xz
wireless: check if iface is real, stop wpa_supplicant on failures
-rwxr-xr-xsrc-wireless/wireless-dbus26
-rw-r--r--src/8021x10
-rw-r--r--src/connections/wireless28
3 files changed, 45 insertions, 19 deletions
diff --git a/src-wireless/wireless-dbus b/src-wireless/wireless-dbus
index 0ddd5ab..6f53a6c 100755
--- a/src-wireless/wireless-dbus
+++ b/src-wireless/wireless-dbus
@@ -40,6 +40,13 @@ def wep_hex2dec(key):
return new_key
+def fail(msg=None):
+ if msg:
+ print " -", msg
+ kill(int(open("/var/run/wpa_supplicant.pid").read()),SIGTERM)
+ sys.exit(1)
+
+
def start(profile):
# TODO: Add check if it's even a wireless interface
# Interface up - probably redundant, should be 'ip' instead.
@@ -67,16 +74,14 @@ def start(profile):
except KeyError:
args.append("-c/etc/wpa_supplicant.conf")
elif not profile['SECURITY'] in ['wpa', 'wep', 'none']:
- print " - Invalid security chosen"
- return False
+ fail("Invalid security chosen")
# Start wpa_supplicant
supplicant = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
output = supplicant.communicate()[0]
if supplicant.returncode not in [255,0]:
print output
- print " - Could not start wpa_supplicant"
- return False
+ fail("Could not start wpa_supplicant")
# Connect to wpa_supplicant
bus = dbus.SystemBus()
@@ -149,25 +154,24 @@ def start(profile):
break
if n == timeout:
- print " - Association/Authentication failed:", state
- return False
+ fail("Association/Authentication failed:" + state)
# Run ethernet and get an ip.
try:
subprocess.check_call(["/usr/lib/network/connections/ethernet-iproute", "up", sys.argv[2]])
except subprocess.CalledProcessError:
- return False
- return True
+ fail()
+ sys.exit(0)
def stop(profile):
subprocess.call(["/usr/lib/network/connections/ethernet", "down", sys.argv[2]])
kill(int(open("/var/run/wpa_supplicant.pid").read()),SIGTERM)
- return True
+ sys.exit(0)
if __name__ == "__main__":
profile = read_config("/etc/network.d/"+sys.argv[2])
if sys.argv[1] == "up":
- sys.exit(not start(profile))
+ start(profile)
elif sys.argv[1] == "down":
- sys.exit(not stop(profile))
+ stop(profile)
diff --git a/src/8021x b/src/8021x
index 8dbff29..75030e9 100644
--- a/src/8021x
+++ b/src/8021x
@@ -34,3 +34,13 @@ start_wpa()
return 1
fi
}
+
+stop_wpa()
+{
+ wpa_cli terminate &> /dev/null
+ if [[ -f /var/run/wpa_supplicant_$1.pid ]]; then
+ kill $(cat /var/run/wpa_supplicant_$1.pid) &>/dev/null &
+ fi
+}
+
+# vim: set ts=4 et sw=4 ft=sh:
diff --git a/src/connections/wireless b/src/connections/wireless
index 66ccdab..653cb00 100644
--- a/src/connections/wireless
+++ b/src/connections/wireless
@@ -4,13 +4,19 @@
wireless_up() {
load_profile $1
-
+ . ${SUBR_DIR}/8021x
. ${SUBR_DIR}/wireless
+ # Check if interface exists
+ if [[ ! -e /sys/class/net/"$INTERFACE" ]]; then
+ if ! echo "$INTERFACE"|grep ":"; then
+ err_append "interface $INTERFACE does not exist"
+ return 1
+ fi
+ fi
+
# Kill any lingering wpa_supplicants.
- if [[ -f /var/run/wpa_supplicant_$INTERFACE.pid ]]; then
- kill $(cat /var/run/wpa_supplicant_$INTERFACE.pid)
- fi
+ stop_wpa $INTERFACE
# Most drivers (mac80211) need mode set before device is brought up
# Drivers generally default to managed, but set this to be sure.
@@ -57,7 +63,6 @@ wireless_up() {
wep_check $INTERFACE $TIMEOUT||return 1
;;
wpa)
- . ${SUBR_DIR}/8021x
# Quirk for broken drivers... http://bbs.archlinux.org/viewtopic.php?id=36384
quirk "wpaessid" && eval iwconfig $INTERFACE essid "\"$ESSID\""
@@ -78,14 +83,20 @@ wireless_up() {
# Connect!
[[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwext"
start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1
- wpa_check $INTERFACE $TIMEOUT || return 1
+ if ! wpa_check $INTERFACE $TIMEOUT; then
+ stop_wpa $INTERFACE
+ return 1
+ fi
;;
wpa-config)
. ${SUBR_DIR}/8021x
[[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" # defaults
[[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwext"
start_wpa $INTERFACE $WPA_CONF $WPA_OPTS || return 1
- wpa_check $INTERFACE $TIMEOUT || return 1
+ if ! wpa_check $INTERFACE $TIMEOUT; then
+ stop_wpa $INTERFACE
+ return 1
+ fi
;;
esac
@@ -97,11 +108,12 @@ wireless_up() {
wireless_down() {
load_profile $1
+ . ${SUBR_DIR}/8021x
PROFILE=$1 NOETHERNETDOWN=$2
if ! checkyesno $2; then
${CONN_DIR}/ethernet down $1
fi
- wpa_cli terminate &> /dev/null
+ stop_wpa $INTERFACE
[[ "$SECURITY" == "wpa" ]] && rm -f "/tmp/wpa.${1// /}" # remove wpa config
iwconfig $INTERFACE essid off key off &> /dev/null
ifconfig $INTERFACE down