/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: 2021-02-03 23:10:42 UTC
  • Revision ID: teddy@recompile.se-20210203231042-2z3egrvpo1zt7nej
mandos-ctl: Fix bad test for command.Remove and related minor issues

The test for command.Remove removes all clients from the spy server,
and then loops over all clients, looking for the corresponding Remove
command as recorded by the spy server.  But since since there aren't
any clients left after they were removed, no assertions are made, and
the test therefore does nothing.  Fix this.

In tests for command.Approve and command.Deny, add checks that clients
were not somehow removed by the command (in which case, likewise, no
assertions are made).

Add related checks to TestPropertySetterCmd.runTest; i.e. test that a
sequence is not empty before looping over it and making assertions.

* mandos-ctl (TestBaseCommands.test_Remove): Save a copy of the
  original "clients" dict, and loop over those instead.  Add assertion
  that all clients were indeed removed.  Also fix the code which looks
  for the Remove command, which now needs to actually work.
  (TestBaseCommands.test_Approve, TestBaseCommands.test_Deny): Add
  assertion that there are still clients before looping over them.
  (TestPropertySetterCmd.runTest): Add assertion that the list of
  values to get is not empty before looping over them.  Also add check
  that there are still clients before looping over clients.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# This script will be run by 'mkinitramfs' when it creates the image.
4
4
# Its job is to decide which files to install, then install them into
5
5
# the staging area, where the initramfs is being created.  This
6
 
# happens when a new 'linux-image' package is installed, or when the
 
6
# happens when a new 'linux-image' package is installed, or when an
7
7
# administrator runs 'update-initramfs' by hand to update an initramfs
8
8
# image.
9
9
 
29
29
 
30
30
. /usr/share/initramfs-tools/hook-functions
31
31
 
32
 
for d in /usr /usr/local; do
33
 
    if [ -d "$d"/lib/mandos ]; then
34
 
        prefix="$d"
 
32
for d in /usr/lib \
 
33
    "/usr/lib/`dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null`" \
 
34
    "`rpm --eval='%{_libdir}' 2>/dev/null`" /usr/local/lib; do
 
35
    if [ -d "$d"/mandos ]; then
 
36
        libdir="$d"
35
37
        break
36
38
    fi
37
39
done
38
 
if [ -z "$prefix" ]; then
 
40
if [ -z "$libdir" ]; then
39
41
    # Mandos not found
40
42
    exit 1
41
43
fi
68
70
CONFDIR="/conf/conf.d/mandos"
69
71
MANDOSDIR="/lib/mandos"
70
72
PLUGINDIR="${MANDOSDIR}/plugins.d"
 
73
PLUGINHELPERDIR="${MANDOSDIR}/plugin-helpers"
71
74
HOOKDIR="${MANDOSDIR}/network-hooks.d"
72
75
 
73
76
# Make directories
74
77
install --directory --mode=u=rwx,go=rx "${DESTDIR}${CONFDIR}" \
75
78
        "${DESTDIR}${MANDOSDIR}" "${DESTDIR}${HOOKDIR}"
76
79
install --owner=${mandos_user} --group=${mandos_group} --directory \
77
 
    --mode=u=rwx "${DESTDIR}${PLUGINDIR}"
 
80
        --mode=u=rwx "${DESTDIR}${PLUGINDIR}" \
 
81
        "${DESTDIR}${PLUGINHELPERDIR}"
 
82
 
 
83
copy_exec "$libdir"/mandos/mandos-to-cryptroot-unlock "${MANDOSDIR}"
78
84
 
79
85
# Copy the Mandos plugin runner
80
 
copy_exec "$prefix"/lib/mandos/plugin-runner "${MANDOSDIR}"
 
86
copy_exec "$libdir"/mandos/plugin-runner "${MANDOSDIR}"
81
87
 
82
88
# Copy the plugins
83
89
 
84
90
# Copy the packaged plugins
85
 
for file in "$prefix"/lib/mandos/plugins.d/*; do
 
91
for file in "$libdir"/mandos/plugins.d/*; do
86
92
    base="`basename \"$file\"`"
87
93
    # Is this plugin overridden?
88
94
    if [ -e "/etc/mandos/plugins.d/$base" ]; then
96
102
    esac
97
103
done
98
104
 
 
105
# Copy the packaged plugin helpers
 
106
for file in "$libdir"/mandos/plugin-helpers/*; do
 
107
    base="`basename \"$file\"`"
 
108
    # Is this plugin overridden?
 
109
    if [ -e "/etc/mandos/plugin-helpers/$base" ]; then
 
110
        continue
 
111
    fi
 
112
    case "$base" in
 
113
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
114
            : ;;
 
115
        "*") : ;;
 
116
        *) copy_exec "$file" "${PLUGINHELPERDIR}" ;;
 
117
    esac
 
118
done
 
119
 
99
120
# Copy any user-supplied plugins
100
121
for file in /etc/mandos/plugins.d/*; do
101
122
    base="`basename \"$file\"`"
107
128
    esac
108
129
done
109
130
 
 
131
# Copy any user-supplied plugin helpers
 
132
for file in /etc/mandos/plugin-helpers/*; do
 
133
    base="`basename \"$file\"`"
 
134
    case "$base" in
 
135
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
136
            : ;;
 
137
        "*") : ;;
 
138
        *) copy_exec "$file" "${PLUGINHELPERDIR}" ;;
 
139
    esac
 
140
done
 
141
 
110
142
# Get DEVICE from initramfs.conf and other files
111
143
. /etc/initramfs-tools/initramfs.conf
112
144
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}
 
145
    if [ -n "`basename \"$conf\" \
 
146
        | grep '^[[:alnum:]][[:alnum:]\._-]*$' \
 
147
        | grep -v '\.dpkg-.*$'`" ]; then
 
148
        [ -f "${conf}" ] && . "${conf}"
116
149
    fi
117
150
done
118
151
export DEVICE
127
160
    if [ -x "$hook" ]; then
128
161
        # Copy any files needed by the network hook
129
162
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=files \
130
 
            VERBOSITY=0 "$hook" files | while read file target; do
 
163
            VERBOSITY=0 "$hook" files | while read -r file target; do
131
164
            if [ ! -e "${file}" ]; then
132
165
                echo "WARNING: file ${file} not found, requested by Mandos network hook '${hook##*/}'" >&2
133
166
            fi
139
172
        done
140
173
        # Copy and load any modules needed by the network hook
141
174
        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
 
175
            VERBOSITY=0 "$hook" modules | while read -r module; do
 
176
            force_load "$module"
146
177
        done
147
178
    fi
148
179
done
149
180
 
150
 
# GPGME needs /usr/bin/gpg
151
 
if [ ! -e "${DESTDIR}/usr/bin/gpg" \
152
 
    -a -n "`ls \"${DESTDIR}\"/usr/lib/libgpgme.so* \
153
 
                2>/dev/null`" ]; then
154
 
    copy_exec /usr/bin/gpg
155
 
fi
 
181
# GPGME needs GnuPG
 
182
gpg=/usr/bin/gpg
 
183
libgpgme11_version="`dpkg-query --showformat='${Version}' --show libgpgme11`"
 
184
if dpkg --compare-versions "$libgpgme11_version" ge 1.5.0-0.1; then
 
185
    if [ -e /usr/bin/gpgconf ]; then
 
186
        if [ ! -e "${DESTDIR}/usr/bin/gpgconf" ]; then
 
187
            copy_exec /usr/bin/gpgconf
 
188
        fi
 
189
        gpg="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg:[^:]*://p'`"
 
190
        gpgagent="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg-agent:[^:]*://p'`"
 
191
        # Newer versions of GnuPG 2 requires the gpg-agent binary
 
192
        if [ -e "$gpgagent" ] && [ ! -e "${DESTDIR}$gpgagent" ]; then
 
193
            copy_exec "$gpgagent"
 
194
        fi
 
195
    fi
 
196
elif dpkg --compare-versions "$libgpgme11_version" ge 1.4.1-0.1; then
 
197
    gpg=/usr/bin/gpg2
 
198
fi
 
199
if [ ! -e "${DESTDIR}$gpg" ]; then
 
200
    copy_exec "$gpg"
 
201
fi
 
202
unset gpg
 
203
unset libgpgme11_version
156
204
 
157
205
# Config files
158
206
for file in /etc/mandos/plugin-runner.conf; do
177
225
    if [ -d "$file" ]; then
178
226
        continue
179
227
    fi
180
 
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
181
 
    chown ${mandos_user}:${mandos_group} \
182
 
        "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
228
    case "$file" in
 
229
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
230
            : ;;
 
231
        "*") : ;;
 
232
        *)
 
233
            cp --archive --sparse=always "$file" \
 
234
               "${DESTDIR}${CONFDIR}"
 
235
            chown ${mandos_user}:${mandos_group} \
 
236
                  "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
237
            ;;
 
238
    esac
183
239
done
 
240
# Use Diffie-Hellman parameters file if available
 
241
if [ -e "${DESTDIR}${CONFDIR}"/dhparams.pem ]; then
 
242
    sed --in-place \
 
243
        --expression="1i--options-for=mandos-client:--dh-params=${CONFDIR}/dhparams.pem" \
 
244
        "${DESTDIR}/${CONFDIR}/plugin-runner.conf"
 
245
fi
184
246
 
185
247
# /lib/mandos/plugin-runner will drop priviliges, but needs access to
186
248
# its plugin directory and its config file.  However, since almost all
191
253
# initrd; it is intended to affect the initrd.img file itself, since
192
254
# it now contains secret key files.  There is, however, no other way
193
255
# to set the permission of the initrd.img file without a race
194
 
# condition.  This umask is set by "initramfs-tools-hook-conf",
195
 
# installed as "/usr/share/initramfs-tools/conf-hooks.d/mandos".)
 
256
# condition.  This umask is set by "initramfs-tools-conf", installed
 
257
# as "/usr/share/initramfs-tools/conf.d/mandos-conf".)
196
258
197
259
for full in "${MANDOSDIR}" "${CONFDIR}"; do
198
260
    while [ "$full" != "/" ]; do
210
272
done
211
273
for dir in "${DESTDIR}"/lib* "${DESTDIR}"/usr/lib*; do
212
274
    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
 
275
        find "$dir" \! -perm -u+rw,g+r -prune -or \! -type l -print0 \
 
276
            | xargs --null --no-run-if-empty chmod a+rX --
215
277
    fi
216
278
done