3
# This file should be present in the root file system directory
 
 
4
# /usr/lib/dracut/modules.d/90mandos.  When dracut creates the
 
 
5
# initramfs image, dracut will source this file and run the shell
 
 
6
# functions defined in this file: "install", "check", "depends",
 
 
7
# "cmdline", and "installkernel".
 
 
9
# Despite the above #!/bin/sh line and the executable flag, this file
 
 
10
# is not executed; this file is sourced by dracut when creating the
 
 
11
# initramfs image file.
 
 
15
        "/usr/lib/`dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null`" \
 
 
16
        "`rpm --eval='%{_libdir}' 2>/dev/null`" /usr/local/lib; do
 
 
17
        if [ -d "$dir"/mandos ]; then
 
 
27
    for dir in /etc/keys/mandos /etc/mandos/keys; do
 
 
28
        if [ -d "$dir" ]; then
 
 
33
    # Mandos key directory not found
 
 
38
    if [ "${hostonly:-no}" = "no" ]; then
 
 
39
        dwarning "Mandos: Dracut not in hostonly mode"
 
 
43
    local libdir=`mandos_libdir`
 
 
44
    if [ -z "$libdir" ]; then
 
 
45
        dwarning "Mandos lib directory not found"
 
 
49
    local keydir=`mandos_keydir`
 
 
50
    if [ -z "$keydir" ]; then
 
 
51
        dwarning "Mandos key directory not found"
 
 
57
    chmod go+w,+t "$initdir"/tmp
 
 
58
    local libdir=`mandos_libdir`
 
 
59
    local keydir=`mandos_keydir`
 
 
60
    set `{ getent passwd _mandos \
 
 
61
        || getent passwd nobody \
 
 
62
        || echo ::65534:65534:::; } \
 
 
63
        | cut --delimiter=: --fields=3,4 --only-delimited \
 
 
64
        --output-delimiter=" "`
 
 
65
    local mandos_user="$1"
 
 
66
    local mandos_group="$2"
 
 
67
    inst "${libdir}" /lib/mandos
 
 
68
    if dracut_module_included "systemd"; then
 
 
70
        inst "${libdir}/plugins.d/mandos-client" \
 
 
71
             "${plugindir}/mandos-client"
 
 
72
        chmod u-s "${initdir}/${plugindir}/mandos-client"
 
 
73
        inst "${moddir}/ask-password-mandos.service" \
 
 
74
             "${systemdsystemunitdir}/ask-password-mandos.service"
 
 
75
        if [ ${mandos_user} != 65534 ]; then
 
 
77
                --expression="s,^ExecStart=/lib/mandos/password-agent ,&--user=${mandos_user} ," \
 
 
78
                "${initdir}/${systemdsystemunitdir}/ask-password-mandos.service"
 
 
80
        if [ ${mandos_group} != 65534 ]; then
 
 
82
                --expression="s,^ExecStart=/lib/mandos/password-agent ,&--group=${mandos_group} ," \
 
 
83
                "${initdir}/${systemdsystemunitdir}/ask-password-mandos.service"
 
 
86
        inst_hook cmdline 20 "$moddir"/cmdline-mandos.sh
 
 
87
        plugindir=/lib/mandos/plugins.d
 
 
88
        inst "${libdir}/plugin-runner" /lib/mandos/plugin-runner
 
 
89
        inst /etc/mandos/plugin-runner.conf
 
 
91
            --expression='1i--options-for=mandos-client:--pubkey=/etc/mandos/keys/pubkey.txt,--seckey=/etc/mandos/keys/seckey.txt,--tls-pubkey=/etc/mandos/keys/tls-pubkey.pem,--tls-privkey=/etc/mandos/keys/tls-privkey.pem' \
 
 
92
            "${initdir}/etc/mandos/plugin-runner.conf"
 
 
93
        if [ ${mandos_user} != 65534 ]; then
 
 
94
            sed --in-place --expression="1i--userid=${mandos_user}" \
 
 
95
                "${initdir}/etc/mandos/plugin-runner.conf"
 
 
97
        if [ ${mandos_group} != 65534 ]; then
 
 
99
                --expression="1i--groupid=${mandos_group}" \
 
 
100
                "${initdir}/etc/mandos/plugin-runner.conf"
 
 
102
        inst "${libdir}/plugins.d" "$plugindir"
 
 
103
        chown ${mandos_user}:${mandos_group} "${initdir}/${plugindir}"
 
 
104
        # Copy the packaged plugins
 
 
105
        for file in "$libdir"/plugins.d/*; do
 
 
106
            base="`basename \"$file\"`"
 
 
107
            # Is this plugin overridden?
 
 
108
            if [ -e "/etc/mandos/plugins.d/$base" ]; then
 
 
112
                *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
114
                "*") dwarning "Mandos client plugin directory is empty." >&2 ;;
 
 
115
                askpass-fifo) : ;; # Ignore packaged for dracut
 
 
116
                *) inst "${file}" "${plugindir}/${base}" ;;
 
 
119
        # Copy any user-supplied plugins
 
 
120
        for file in /etc/mandos/plugins.d/*; do
 
 
121
            base="`basename \"$file\"`"
 
 
123
                *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
126
                *) inst "$file" "${plugindir}/${base}" ;;
 
 
129
        # Copy any user-supplied plugin helpers
 
 
130
        for file in /etc/mandos/plugin-helpers/*; do
 
 
131
            base="`basename \"$file\"`"
 
 
133
                *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
136
                *) inst "$file" "/lib/mandos/plugin-helpers/$base";;
 
 
141
    for hook in /etc/mandos/network-hooks.d/*; do
 
 
142
        basename=`basename "$hook"`
 
 
145
            *[!A-Za-z0-9_.-]*) continue ;;
 
 
146
            *) test -d "$hook" || inst "$hook" "/lib/mandos/network-hooks.d/$basename" ;;
 
 
148
        if [ -x "$hook" ]; then
 
 
149
            # Copy any files needed by the network hook
 
 
150
            MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=files \
 
 
151
                VERBOSITY=0 "$hook" files | while read file target; do
 
 
152
                if [ ! -e "${file}" ]; then
 
 
153
                    dwarning "WARNING: file ${file} not found, requested by Mandos network hook '${basename}'" >&2
 
 
155
                if [ -z "${target}" ]; then
 
 
158
                    inst "$file" "$target"
 
 
163
    # Copy the packaged plugin helpers
 
 
164
    for file in "$libdir"/plugin-helpers/*; do
 
 
165
        base="`basename \"$file\"`"
 
 
166
        # Is this plugin overridden?
 
 
167
        if [ -e "/etc/mandos/plugin-helpers/$base" ]; then
 
 
171
            *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
174
            *) inst "$file" "/lib/mandos/plugin-helpers/$base";;
 
 
177
    local gpg=/usr/bin/gpg
 
 
178
    if [ -e /usr/bin/gpgconf ]; then
 
 
179
        inst /usr/bin/gpgconf
 
 
180
        gpg="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg:[^:]*://p'`"
 
 
181
        gpgagent="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg-agent:[^:]*://p'`"
 
 
182
        # Newer versions of GnuPG 2 requires the gpg-agent binary
 
 
183
        if [ -e "$gpgagent" ]; then
 
 
188
    if dracut_module_included "systemd"; then
 
 
189
        inst "${moddir}/password-agent" /lib/mandos/password-agent
 
 
190
        inst "${moddir}/ask-password-mandos.path" \
 
 
191
             "${systemdsystemunitdir}/ask-password-mandos.path"
 
 
192
        ln_r "${systemdsystemunitdir}/ask-password-mandos.path" \
 
 
193
             "${systemdsystemunitdir}/sysinit.target.wants/ask-password-mandos.path"
 
 
196
    for file in "$keydir"/*; do
 
 
197
        if [ -d "$file" ]; then
 
 
201
            *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
205
                inst "$file" "/etc/mandos/keys/`basename \"$file\"`"
 
 
206
                chown ${mandos_user}:${mandos_group} \
 
 
207
                      "${initdir}/etc/mandos/keys/`basename \"$file\"`"
 
 
208
                if [ `basename "$file"` = dhparams.pem ]; then
 
 
209
                    # Use Diffie-Hellman parameters file
 
 
210
                    if dracut_module_included "systemd"; then
 
 
212
                            --expression='/^ExecStart/s/$/ --dh-params=\/etc\/mandos\/keys\/dhparams.pem/' \
 
 
213
                            "${initdir}/${systemdsystemunitdir}/ask-password-mandos.service"
 
 
216
                            --expression="1i--options-for=mandos-client:--dh-params=/etc/mandos/keys/dhparams.pem" \
 
 
217
                            "${initdir}/etc/mandos/plugin-runner.conf"
 
 
226
    instmods =drivers/net
 
 
227
    hostonly='' instmods ipv6
 
 
228
    # Copy any kernel modules needed by network hooks
 
 
229
    for hook in /etc/mandos/network-hooks.d/*; do
 
 
230
        basename=`basename "$hook"`
 
 
233
            *[!A-Za-z0-9_.-]*) continue ;;
 
 
235
        if [ -x "$hook" ]; then
 
 
236
            # Copy and load any modules needed by the network hook
 
 
237
            MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=modules \
 
 
238
                VERBOSITY=0 "$hook" modules | while read module; do
 
 
239
                if [ -z "${target}" ]; then