From 28a70eb3f4046fcaa53c991095e227fa4c484515 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 20 Jan 2014 15:01:53 +0000 Subject: [PATCH] Check that we have ctrl_interface defined in wpa_supplicant.conf and pass this parameter to wpa_cli(8). If not set, warn about not interacting with wpa_supplicant(8). --- dhcpcd-hooks/10-wpa_supplicant | 56 ++++++++++++++++++++++++++++------ dhcpcd-run-hooks.in | 15 +++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/dhcpcd-hooks/10-wpa_supplicant b/dhcpcd-hooks/10-wpa_supplicant index 8e065789..a0dc018e 100644 --- a/dhcpcd-hooks/10-wpa_supplicant +++ b/dhcpcd-hooks/10-wpa_supplicant @@ -5,8 +5,10 @@ if [ -z "$wpa_supplicant_conf" ]; then for x in \ - /etc/wpa_supplicant.conf \ + /etc/wpa_supplicant/wpa_supplicant-"$interface".conf \ /etc/wpa_supplicant/wpa_supplicant.conf \ + /etc/wpa_supplicant-"$interface".conf \ + /etc/wpa_supplicant.conf \ ; do if [ -s "$x" ]; then wpa_supplicant_conf="$x" @@ -16,11 +18,42 @@ if [ -z "$wpa_supplicant_conf" ]; then fi : ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf} +wpa_supplcant_ctrldir() { + local dir + + dir=$(key_get_value "[[:space:]]*ctrl_interface=" \ + "$wpa_supplicant_conf") + dir=$(trim "$dir") + case "$dir" in + DIR=*) + dir=${dir##DIR=} + dir=${dir%%[[:space:]]GROUP=*} + dir=$(trim "$dir") + ;; + esac + printf %s "$dir" +} + wpa_supplicant_start() { - local err errn + local dir err errn + + # Pre flight checks + if [ ! -s "$wpa_supplicant_conf" ]; then + syslog warn \ + "$wpa_supplicant_conf does not exist" + syslog warn "not interacting with wpa_supplicant(8)" + return 1 + fi + dir=$(wpa_supplcant_ctrldir) + if [ -z "$dir" ]; then + syslog warn \ + "ctrl_interface not defined in $wpa_supplicant_conf" + syslog warn "not interacting with wpa_supplicant(8)" + return 1 + fi - wpa_cli -i "$interface" status >/dev/null 2>&1 && return 0 + wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 && return 0 syslog info "starting wpa_supplicant" err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" 2>&1) errn=$? @@ -33,14 +66,16 @@ wpa_supplicant_start() wpa_supplicant_reconfigure() { - local err errn + local dir err errn - if ! wpa_cli -i "$interface" status >/dev/null 2>&1; then + dir=$(wpa_supplcant_ctrldir) + [ -z "$dir" ] && return 1 + if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then wpa_supplicant_start return $? fi syslog info "reconfiguring wpa_supplicant" - err=$(wpa_cli -i"$interface" reconfigure 2>&1) + err=$(wpa_cli -p "$dir" -i "$interface" reconfigure 2>&1) errn=$? if [ $errn != 0 ]; then syslog err "failed to reconfigure wpa_supplicant" @@ -51,9 +86,11 @@ wpa_supplicant_reconfigure() wpa_supplicant_stop() { - local err errn + local dir err errn - wpa_cli -i "$interface" status >/dev/null 2>&1 || return 0 + dir=$(wpa_supplcant_ctrldir) + [ -z "$dir" ] && return 1 + wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 || return 0 syslog info "stopping wpa_supplicant" err=$(wpa_cli -i"$interface" terminate 2>&1) errn=$? @@ -63,9 +100,8 @@ wpa_supplicant_stop() fi return $errn } - -if [ "$ifwireless" = "1" -a -s "$wpa_supplicant_conf" ] && \ +if [ "$ifwireless" = "1" ] && \ type wpa_supplicant >/dev/null 2>&1 && \ type wpa_cli >/dev/null 2>&1 then diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in index 93fdfda2..1bcbd495 100644 --- a/dhcpcd-run-hooks.in +++ b/dhcpcd-run-hooks.in @@ -59,6 +59,21 @@ list_interfaces() echo "$ifaces" } +# Trim function +trim() +{ + local var="$*" + + var=${var#"${var%%[![:space:]]*}"} + var=${var%"${var##*[![:space:]]}"} + if [ -z "$var" ]; then + # So it seems our shell doesn't support wctype(3) patterns + # Fall back to sed + var=$(echo "$var" | sed -e 's/^[ \t]*//;s/[ \t]*$//') + fi + printf %s "$var" +} + # We normally use sed to extract values using a key from a list of files # but sed may not always be available at the time. key_get_value() -- 2.47.3