/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: 2017-08-20 14:14:14 UTC
  • Revision ID: teddy@recompile.se-20170820141414-m034xuebg7ccaeui
Add some more restrictions to the systemd service file.

* mandos.service ([Service]/ProtectKernelTunables): New; set to "yes".
  ([Service]/ProtectControlGroups): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
CONFDIR="/conf/conf.d/mandos"
71
71
MANDOSDIR="/lib/mandos"
72
72
PLUGINDIR="${MANDOSDIR}/plugins.d"
73
 
PLUGINHELPERDIR="${MANDOSDIR}/plugins-helpers"
 
73
PLUGINHELPERDIR="${MANDOSDIR}/plugin-helpers"
74
74
HOOKDIR="${MANDOSDIR}/network-hooks.d"
75
75
 
76
76
# Make directories
77
77
install --directory --mode=u=rwx,go=rx "${DESTDIR}${CONFDIR}" \
78
 
        "${DESTDIR}${MANDOSDIR}" "${DESTDIR}${HOOKDIR}" \
 
78
        "${DESTDIR}${MANDOSDIR}" "${DESTDIR}${HOOKDIR}"
 
79
install --owner=${mandos_user} --group=${mandos_group} --directory \
 
80
        --mode=u=rwx "${DESTDIR}${PLUGINDIR}" \
79
81
        "${DESTDIR}${PLUGINHELPERDIR}"
80
 
install --owner=${mandos_user} --group=${mandos_group} --directory \
81
 
    --mode=u=rwx "${DESTDIR}${PLUGINDIR}"
82
82
 
83
83
# Copy the Mandos plugin runner
84
84
copy_exec "$libdir"/mandos/plugin-runner "${MANDOSDIR}"
142
142
for conf in /etc/initramfs-tools/conf.d/*; do
143
143
    if [ -n `basename \"$conf\" | grep '^[[:alnum:]][[:alnum:]\._-]*$' \
144
144
        | grep -v '\.dpkg-.*$'` ]; then
145
 
        [ -f ${conf} ] && . ${conf}
 
145
        [ -f "${conf}" ] && . "${conf}"
146
146
    fi
147
147
done
148
148
export DEVICE
157
157
    if [ -x "$hook" ]; then
158
158
        # Copy any files needed by the network hook
159
159
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=files \
160
 
            VERBOSITY=0 "$hook" files | while read file target; do
 
160
            VERBOSITY=0 "$hook" files | while read -r file target; do
161
161
            if [ ! -e "${file}" ]; then
162
162
                echo "WARNING: file ${file} not found, requested by Mandos network hook '${hook##*/}'" >&2
163
163
            fi
169
169
        done
170
170
        # Copy and load any modules needed by the network hook
171
171
        MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=modules \
172
 
            VERBOSITY=0 "$hook" modules | while read module; do
173
 
            if [ -z "${target}" ]; then
174
 
                force_load "$module"
175
 
            fi
 
172
            VERBOSITY=0 "$hook" modules | while read -r module; do
 
173
            force_load "$module"
176
174
        done
177
175
    fi
178
176
done
186
184
            copy_exec /usr/bin/gpgconf
187
185
        fi
188
186
        gpg="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg:[^:]*://p'`"
 
187
        gpgagent="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg-agent:[^:]*://p'`"
 
188
        # Newer versions of GnuPG 2 requires the gpg-agent binary
 
189
        if [ -e "$gpgagent" ] && [ ! -e "${DESTDIR}$gpgagent" ]; then
 
190
            copy_exec "$gpgagent"
 
191
        fi
189
192
    fi
190
193
elif dpkg --compare-versions "$libgpgme11_version" ge 1.4.1-0.1; then
191
194
    gpg=/usr/bin/gpg2
219
222
    if [ -d "$file" ]; then
220
223
        continue
221
224
    fi
222
 
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
223
 
    chown ${mandos_user}:${mandos_group} \
224
 
        "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
225
    case "$file" in
 
226
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
227
            : ;;
 
228
        "*") : ;;
 
229
        *)
 
230
            cp --archive --sparse=always "$file" \
 
231
               "${DESTDIR}${CONFDIR}"
 
232
            chown ${mandos_user}:${mandos_group} \
 
233
                  "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
 
234
            ;;
 
235
    esac
225
236
done
 
237
# Use Diffie-Hellman parameters file if available
 
238
if [ -e "${DESTDIR}${CONFDIR}"/dhparams.pem ]; then
 
239
    sed --in-place \
 
240
        --expression="1i--options-for=mandos-client:--dh-params=${CONFDIR}/dhparams.pem" \
 
241
        "${DESTDIR}/${CONFDIR}/plugin-runner.conf"
 
242
fi
226
243
 
227
244
# /lib/mandos/plugin-runner will drop priviliges, but needs access to
228
245
# its plugin directory and its config file.  However, since almost all
252
269
done
253
270
for dir in "${DESTDIR}"/lib* "${DESTDIR}"/usr/lib*; do
254
271
    if [ -d "$dir" ]; then
255
 
        find "$dir" \! -perm -u+rw,g+r -prune -or -print0 \
256
 
            | xargs --null --no-run-if-empty chmod a+rX
 
272
        find "$dir" \! -perm -u+rw,g+r -prune -or \! -type l -print0 \
 
273
            | xargs --null --no-run-if-empty chmod a+rX --
257
274
    fi
258
275
done