/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to network-hooks.d/wireless

* mandos: Break some long lines.
  (ClientDBus.Timeout_dbus_property): If changed, only reschedule
                                      timeout if enabled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
CONFIG="$MANDOSNETHOOKDIR/wireless.conf"
22
22
 
 
23
addrtoif(){
 
24
    grep -liFe "$1" /sys/class/net/*/address \
 
25
        | sed -e 's,.*/\([^/]*\)/[^/]*,\1,'
 
26
}
 
27
 
23
28
# Read config file
24
29
if [ -e "$CONFIG" ]; then
25
30
    . "$CONFIG"
27
32
    exit
28
33
fi
29
34
 
30
 
interfaces="`env|sed -n -e 's/^\(MODULE\|IPADDRS\|ROUTES\|WPA_DRIVER\)_\([^=]*\)=.*/\2/p' \"$CONFIG\" |sort -u`"
 
35
ifkeys=`env | sed -n -e 's/^ADDRESS_\([^=]*\)=.*/\1/p' "$CONFIG" \
 
36
    | sort -u`
31
37
 
32
38
# Exit if DEVICE is set and is not any of the wireless interfaces
33
39
if [ -n "$DEVICE" ]; then
34
40
    while :; do
35
 
        for IF in $interfaces; do
36
 
            if [ "$IF" = "$DEVICE" ]; then
 
41
        for KEY in $ifkeys; do
 
42
            ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
 
43
            INTERFACE=`addrtoif "$ADDRESS"`
 
44
            if [ "$INTERFACE" = "$DEVICE" ]; then
37
45
                break 2
38
46
            fi
39
47
        done
66
74
    start)
67
75
        mkdir -m u=rwx,go= -p "$CTRLDIR"
68
76
        "$wpa_supplicant" -B -g "$CTRL" -p "$CTRLDIR" $WPAS_OPTIONS
69
 
        for INTERFACE in $interfaces; do
70
 
            DRIVER=`eval 'echo "$WPA_DRIVER_'"$INTERFACE"\"`
71
 
            DELAY=`eval 'echo "$DELAY_'"$INTERFACE"\"`
 
77
        for KEY in $ifkeys; do
 
78
            ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
 
79
            INTERFACE=`addrtoif "$ADDRESS"`
 
80
            DRIVER=`eval 'echo "$WPA_DRIVER_'"$KEY"\"`
 
81
            IFDELAY=`eval 'echo "$DELAY_'"$KEY"\"`
72
82
            "$wpa_cli" -g "$CTRL" interface_add "$INTERFACE" "" \
73
83
                "${DRIVER:-wext}" "$CTRLDIR" > /dev/null \
74
84
                | sed -e '/^OK$/d'
75
 
            NETWORK=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" add_network`
76
 
            eval wpa_interface_"$INTERFACE"
 
85
            NETWORK=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" \
 
86
                add_network`
 
87
            eval wpa_interface_"$KEY"
77
88
            "$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" enable_network \
78
89
                "$NETWORK" | sed -e '/^OK$/d'
79
 
            ( sleep "${DELAY:-$DELAY}" || : ) &
 
90
            sleep "${IFDELAY:-$DELAY}" &
80
91
            sleep=$!
81
92
            while :; do
82
 
                kill -0 $sleep || break
83
 
                STATE=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" status | sed -n -e 's/^wpa_state=//p'`
 
93
                kill -0 $sleep 2>/dev/null || break
 
94
                STATE=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" \
 
95
                    status | sed -n -e 's/^wpa_state=//p'`
84
96
                if [ "$STATE" = COMPLETED ]; then
85
 
                    kill $sleep
86
 
                    break
 
97
                    while :; do
 
98
                        kill -0 $sleep 2>/dev/null || break 2
 
99
                        UP=`cat /sys/class/net/"$INTERFACE"/operstate`
 
100
                        if [ "$UP" = up ]; then
 
101
                            kill $sleep 2>/dev/null
 
102
                            break 2
 
103
                        fi
 
104
                        sleep 1
 
105
                    done
87
106
                fi
88
107
                sleep 1
89
108
            done &
90
109
            wait $sleep || :
91
 
            IPADDRS=`eval 'echo "$IPADDRS_'"$INTERFACE"\"`
 
110
            IPADDRS=`eval 'echo "$IPADDRS_'"$KEY"\"`
92
111
            if [ -n "$IPADDRS" ]; then
93
112
                if [ "$IPADDRS" = dhcp ]; then
94
113
                    ipconfig -c dhcp -d "$INTERFACE" || :
99
118
                    done
100
119
                fi
101
120
            fi
102
 
            ROUTES=`eval 'echo "$ROUTES_'"$INTERFACE"\"`
 
121
            ROUTES=`eval 'echo "$ROUTES_'"$KEY"\"`
103
122
            if [ -n "$ROUTES" ]; then
104
123
                for route in $ROUTES; do
105
124
                    "$ip" route add "$route" dev "$BRIDGE"
109
128
        ;;
110
129
    stop)
111
130
        "$wpa_cli" -g "$CTRL" terminate 2>&1 | sed -e '/^OK$/d'
112
 
        for INTERFACE in $interfaces; do
 
131
        for KEY in $ifkeys; do
 
132
            ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
 
133
            INTERFACE=`addrtoif "$ADDRESS"`
113
134
            "$ip" addr show scope global permanent dev "$INTERFACE" \
114
135
                | while read type addr rest; do
115
136
                case "$type" in
130
151
        if [ "$IPADDRS" = dhcp ]; then
131
152
            echo af_packet
132
153
        fi
133
 
        sed -n -e 's/#.*$//' -e 's/[    ]*$//' -e 's/^MODULE=//p' \
134
 
            "$CONFIG"
 
154
        sed -n -e 's/#.*$//' -e 's/[    ]*$//' \
 
155
            -e 's/^MODULE_[^=]\+=//p' "$CONFIG"
135
156
        ;;
136
157
esac