/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 initramfs-tools-hook

  • 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:
51
51
    exit 1
52
52
fi
53
53
 
54
 
set `{ getent passwd _mandos \
55
 
    || getent passwd nobody \
56
 
    || echo ::65534:65534:::; } \
57
 
    | cut --delimiter=: --fields=3,4 --only-delimited \
58
 
    --output-delimiter=" "`
59
 
mandos_user="$1"
60
 
mandos_group="$2"
 
54
mandos_user="`{ getent passwd _mandos \
 
55
                || getent passwd mandos \
 
56
                || getent passwd nobody \
 
57
                || echo ::65534::::; } \
 
58
        | awk --field-separator=: '{ print $3 }'`" 
 
59
mandos_group="`{ getent group _mandos \
 
60
                || getent group mandos \
 
61
                || getent group nogroup \
 
62
                || echo ::65534:; } \
 
63
        | awk --field-separator=: '{ print $3 }'`"
61
64
 
62
65
# The Mandos network client uses the network
63
66
auto_add_modules net
68
71
CONFDIR="/conf/conf.d/mandos"
69
72
MANDOSDIR="/lib/mandos"
70
73
PLUGINDIR="${MANDOSDIR}/plugins.d"
71
 
HOOKDIR="${MANDOSDIR}/network-hooks.d"
72
74
 
73
75
# Make directories
74
76
install --directory --mode=u=rwx,go=rx "${DESTDIR}${CONFDIR}" \
75
 
        "${DESTDIR}${MANDOSDIR}" "${DESTDIR}${HOOKDIR}"
 
77
        "${DESTDIR}${MANDOSDIR}"
76
78
install --owner=${mandos_user} --group=${mandos_group} --directory \
77
79
    --mode=u=rwx "${DESTDIR}${PLUGINDIR}"
78
80
 
89
91
        continue
90
92
    fi
91
93
    case "$base" in
92
 
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
93
 
            : ;;
94
 
        "*") echo "W: Mandos client plugin directory is empty." >&2 ;;
95
 
        *) copy_exec "$file" "${PLUGINDIR}" ;;
 
94
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert) : ;;
 
95
        "*") :;;
 
96
        *) copy_exec "$file" "${PLUGINDIR}";;
96
97
    esac
97
98
done
98
99
 
100
101
for file in /etc/mandos/plugins.d/*; do
101
102
    base="`basename \"$file\"`"
102
103
    case "$base" in
103
 
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
104
 
            : ;;
105
 
        "*") : ;;
106
 
        *) copy_exec "$file" "${PLUGINDIR}" ;;
107
 
    esac
108
 
done
109
 
 
110
 
# Get DEVICE from initramfs.conf and other files
111
 
. /etc/initramfs-tools/initramfs.conf
112
 
for conf in /etc/initramfs-tools/conf.d/*; do
113
 
    if [ -n `basename \"$conf\" | grep '^[[:alnum:]][[:alnum:]\._-]*$' \
114
 
        | grep -v '\.dpkg-.*$'` ]; then
115
 
        [ -f ${conf} ] && . ${conf}
116
 
    fi
117
 
done
118
 
export DEVICE
119
 
 
120
 
# Copy network hooks
121
 
for hook in /etc/mandos/network-hooks.d/*; do
122
 
    case "`basename \"$hook\"`" in
123
 
        "*") continue ;;
124
 
        *[!A-Za-z0-9_.-]*) continue ;;
125
 
        *) test -d "$hook" || copy_exec "$hook" "${HOOKDIR}" ;;
126
 
    esac
127
 
    if [ -x "$hook" ]; then
128
 
        # Copy any files needed by the network hook
129
 
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=files \
130
 
            VERBOSITY=0 "$hook" files | while read file target; do
131
 
            if [ ! -e "${file}" ]; then
132
 
                echo "WARNING: file ${file} not found, requested by Mandos network hook '${hook##*/}'" >&2
133
 
            fi
134
 
            if [ -z "${target}" ]; then
135
 
                copy_exec "$file"
136
 
            else
137
 
                copy_exec "$file" "$target"
138
 
            fi
139
 
        done
140
 
        # Copy and load any modules needed by the network hook
141
 
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=modules \
142
 
            VERBOSITY=0 "$hook" modules | while read module; do
143
 
            if [ -z "${target}" ]; then
144
 
                force_load "$module"
145
 
            fi
146
 
        done
147
 
    fi
 
104
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert) : ;;
 
105
        "*") :;;
 
106
        *) copy_exec "$file" "${PLUGINDIR}";;
 
107
    esac
148
108
done
149
109
 
150
110
# GPGME needs /usr/bin/gpg
155
115
fi
156
116
 
157
117
# Config files
158
 
for file in /etc/mandos/plugin-runner.conf; do
 
118
for file in /etc/mandos/*; do
159
119
    if [ -d "$file" ]; then
160
120
        continue
161
121
    fi
163
123
done
164
124
 
165
125
if [ ${mandos_user} != 65534 ]; then
166
 
    sed --in-place --expression="1i--userid=${mandos_user}" \
167
 
        "${DESTDIR}${CONFDIR}/plugin-runner.conf"
 
126
    PLUGINRUNNERCONF="${DESTDIR}${CONFDIR}/plugin-runner.conf"
 
127
    echo "--userid=${mandos_user}" >> "$PLUGINRUNNERCONF"
168
128
fi
169
129
 
170
130
if [ ${mandos_group} != 65534 ]; then
171
 
    sed --in-place --expression="1i--groupid=${mandos_group}" \
172
 
        "${DESTDIR}${CONFDIR}/plugin-runner.conf"
 
131
    PLUGINRUNNERCONF="${DESTDIR}${CONFDIR}/plugin-runner.conf"
 
132
    echo "--groupid=${mandos_group}" >> "$PLUGINRUNNERCONF"
173
133
fi
174
134
 
175
 
# Key files
176
 
for file in "$keydir"/*; do
 
135
# Key files 
 
136
for file in  "$keydir"/*; do
177
137
    if [ -d "$file" ]; then
178
138
        continue
179
139
    fi
208
168
        chmod a+rX "${DESTDIR}$dir"
209
169
    fi
210
170
done
211
 
for dir in "${DESTDIR}"/lib* "${DESTDIR}"/usr/lib*; do
212
 
    if [ -d "$dir" ]; then
213
 
        find "$dir" \! -perm -u+rw,g+r -prune -or -print0 \
214
 
            | xargs --null --no-run-if-empty chmod a+rX
215
 
    fi
 
171
for dir in /lib /usr/lib; do
 
172
    find "${DESTDIR}$dir" \! -perm -u+rw,g+r -prune -or -print0 \
 
173
        | xargs --null --no-run-if-empty chmod a+rX
216
174
done