/mandos/trunk

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

« back to all changes in this revision

Viewing changes to network-hooks.d/bridge

  • Committer: Teddy Hogeborn
  • Date: 2008-12-10 01:26:02 UTC
  • mfrom: (237.1.2 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20081210012602-vhz3h75xkj24t340
First version of a somewhat complete D-Bus server interface.  Also
change user/group name to "_mandos".

* debian/mandos.postinst: Rename old "mandos" user and group to
                          "_mandos"; create "_mandos" user and group
                          if none exist.
* debian/mandos-client.postinst: - '' -

* initramfs-tools-hook: Try "_mandos" before "mandos" as user and
                        group name.

* mandos (_datetime_to_dbus_struct): New; was previously local.
  (Client.started): Renamed to "last_started".  All users changed.
  (Client.started): New; boolean.
  (Client.dbus_object_path): New.
  (Client.check_command): Renamed to "checker_command".  All users
                          changed.
  (Client.__init__): Set and use "self.dbus_object_path".  Set
                     "self.started".
  (Client.start): Update "self.started".  Emit "self.PropertyChanged"
                  signals for both "started" and "last_started".
  (Client.stop): Update "self.started".  Emit "self.PropertyChanged"
                 signal for "started".
  (Client.checker_callback): Take additional "command" argument.  All
                             callers changed. Emit
                             "self.PropertyChanged" signal.
  (Client.bump_timeout): Emit "self.PropertyChanged" signal for
                         "last_checked_ok".
  (Client.start_checker): Emit "self.PropertyChanged" signal for
                          "checker_running".
  (Client.stop_checker): Emit "self.PropertyChanged" signal for
                         "checker_running".
  (Client.still_valid): Bug fix: use "getattr(self, started, False)"
                        instead of "self.started" in case this client
                        object is so new that the "started" attribute
                        has not been created yet.
  (Client.IntervalChanged, Client.CheckerIsRunning, Client.GetChecker,
  Client.GetCreated, Client.GetFingerprint, Client.GetHost,
  Client.GetInterval, Client.GetName, Client.GetStarted,
  Client.GetTimeout, Client.StateChanged, Client.TimeoutChanged):
  Removed; all callers changed.
  (Client.CheckerCompleted): Add "condition" and "command" arguments.
                             All callers changed.
  (Client.GetAllProperties, Client.PropertyChanged): New.
  (Client.StillValid): Renamed to "IsStillValid".
  (Client.StartChecker): Changed to its own function to avoid the
                         return value from "Client.start_checker()".
  (Client.Stop): Changed to its own function to avoid the return value
                 from "Client.stop()".
  (main): Try "_mandos" before "mandos" as user and group name.
          Removed inner function "remove_from_clients".  New inner
          class "MandosServer".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# This is an example of a Mandos client network hook.  This hook
4
 
# brings up a bridge interface as specified in a separate
5
 
# configuration file.  To be used, this file and any needed
6
 
# configuration file(s) should be copied into the
7
 
# /etc/mandos/network-hooks.d directory.
8
 
9
 
# Copyright © 2011 Teddy Hogeborn
10
 
# Copyright © 2011 Björn Påhlsson
11
 
12
 
# Copying and distribution of this file, with or without modification,
13
 
# are permitted in any medium without royalty provided the copyright
14
 
# notice and this notice are preserved.  This file is offered as-is,
15
 
# without any warranty.
16
 
 
17
 
set -e
18
 
 
19
 
CONFIG="$MANDOSNETHOOKDIR/bridge.conf"
20
 
 
21
 
addrtoif(){
22
 
    grep -liFe "$1" /sys/class/net/*/address \
23
 
        | sed -e 's,.*/\([^/]*\)/[^/]*,\1,' -e "/^${BRIDGE}\$/d"
24
 
}
25
 
 
26
 
# Read config file, which must set "BRIDGE", "PORT_ADDRESSES", and
27
 
# optionally "IPADDRS" and "ROUTES".
28
 
if [ -e "$CONFIG" ]; then
29
 
    . "$CONFIG"
30
 
fi
31
 
 
32
 
if [ -z "$BRIDGE" -o -z "$PORT_ADDRESSES" ]; then
33
 
    exit
34
 
fi
35
 
 
36
 
if [ -n "$DEVICE" -a "$DEVICE" != "$BRIDGE" ]; then
37
 
    exit
38
 
fi
39
 
 
40
 
brctl="/sbin/brctl"
41
 
for b in "$brctl" /usr/sbin/brctl; do
42
 
    if [ -e "$b" ]; then
43
 
        brctl="$b"
44
 
        break
45
 
    fi
46
 
done
47
 
 
48
 
case "$1" in
49
 
    start)
50
 
        "$brctl" addbr "$BRIDGE"
51
 
        for address in $PORT_ADDRESSES; do
52
 
            interface=`addrtoif "$address"`
53
 
            "$brctl" addif "$BRIDGE" "$interface"
54
 
            ip link set dev "$interface" up
55
 
        done
56
 
        ip link set dev "$BRIDGE" up
57
 
        sleep "${DELAY%%.*}"
58
 
        if [ -n "$IPADDRS" ]; then
59
 
            for ipaddr in $IPADDRS; do
60
 
                ip addr add "$ipaddr" dev "$BRIDGE"
61
 
            done
62
 
        fi
63
 
        if [ -n "$ROUTES" ]; then
64
 
            for route in $ROUTES; do
65
 
                ip route add "$route" dev "$BRIDGE"
66
 
            done
67
 
        fi
68
 
        ;;
69
 
    stop)
70
 
        ip link set dev "$BRIDGE" down
71
 
        for address in $PORT_ADDRESSES; do
72
 
            interface=`addrtoif "$address"`
73
 
            ip link set dev "$interface" down
74
 
            "$brctl" delif "$BRIDGE" "$interface"
75
 
        done
76
 
        "$brctl" delbr "$BRIDGE"
77
 
        ;;
78
 
    files)
79
 
        echo /bin/ip
80
 
        echo "$brctl"
81
 
        ;;
82
 
    modules)
83
 
        echo bridge
84
 
        ;;
85
 
esac