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 [ -d /etc/systemd/system/ask-password-mandos.service.d ]; then
 
 
76
            inst /etc/systemd/system/ask-password-mandos.service.d
 
 
77
            inst_multiple -o /etc/systemd/system/ask-password-mandos.service.d/*.conf
 
 
79
        if [ ${mandos_user} != 65534 ]; then
 
 
81
                --expression="s,^ExecStart=/lib/mandos/password-agent ,&--user=${mandos_user} ," \
 
 
82
                "${initdir}/${systemdsystemunitdir}/ask-password-mandos.service"
 
 
84
        if [ ${mandos_group} != 65534 ]; then
 
 
86
                --expression="s,^ExecStart=/lib/mandos/password-agent ,&--group=${mandos_group} ," \
 
 
87
                "${initdir}/${systemdsystemunitdir}/ask-password-mandos.service"
 
 
90
        inst_hook cmdline 20 "$moddir"/cmdline-mandos.sh
 
 
91
        plugindir=/lib/mandos/plugins.d
 
 
92
        inst "${libdir}/plugin-runner" /lib/mandos/plugin-runner
 
 
93
        inst /etc/mandos/plugin-runner.conf
 
 
95
            --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' \
 
 
96
            "${initdir}/etc/mandos/plugin-runner.conf"
 
 
97
        if [ ${mandos_user} != 65534 ]; then
 
 
98
            sed --in-place --expression="1i--userid=${mandos_user}" \
 
 
99
                "${initdir}/etc/mandos/plugin-runner.conf"
 
 
101
        if [ ${mandos_group} != 65534 ]; then
 
 
103
                --expression="1i--groupid=${mandos_group}" \
 
 
104
                "${initdir}/etc/mandos/plugin-runner.conf"
 
 
106
        inst "${libdir}/plugins.d" "$plugindir"
 
 
107
        chown ${mandos_user}:${mandos_group} "${initdir}/${plugindir}"
 
 
108
        # Copy the packaged plugins
 
 
109
        for file in "$libdir"/plugins.d/*; do
 
 
110
            base="`basename \"$file\"`"
 
 
111
            # Is this plugin overridden?
 
 
112
            if [ -e "/etc/mandos/plugins.d/$base" ]; then
 
 
116
                *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
118
                "*") dwarning "Mandos client plugin directory is empty." >&2 ;;
 
 
119
                askpass-fifo) : ;; # Ignore packaged for dracut
 
 
120
                *) inst "${file}" "${plugindir}/${base}" ;;
 
 
123
        # Copy any user-supplied plugins
 
 
124
        for file in /etc/mandos/plugins.d/*; do
 
 
125
            base="`basename \"$file\"`"
 
 
127
                *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
130
                *) inst "$file" "${plugindir}/${base}" ;;
 
 
133
        # Copy any user-supplied plugin helpers
 
 
134
        for file in /etc/mandos/plugin-helpers/*; do
 
 
135
            base="`basename \"$file\"`"
 
 
137
                *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
140
                *) inst "$file" "/lib/mandos/plugin-helpers/$base";;
 
 
145
    for hook in /etc/mandos/network-hooks.d/*; do
 
 
146
        basename=`basename "$hook"`
 
 
149
            *[!A-Za-z0-9_.-]*) continue ;;
 
 
150
            *) test -d "$hook" || inst "$hook" "/lib/mandos/network-hooks.d/$basename" ;;
 
 
152
        if [ -x "$hook" ]; then
 
 
153
            # Copy any files needed by the network hook
 
 
154
            MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=files \
 
 
155
                VERBOSITY=0 "$hook" files | while read file target; do
 
 
156
                if [ ! -e "${file}" ]; then
 
 
157
                    dwarning "WARNING: file ${file} not found, requested by Mandos network hook '${basename}'" >&2
 
 
159
                if [ -z "${target}" ]; then
 
 
162
                    inst "$file" "$target"
 
 
167
    # Copy the packaged plugin helpers
 
 
168
    for file in "$libdir"/plugin-helpers/*; do
 
 
169
        base="`basename \"$file\"`"
 
 
170
        # Is this plugin overridden?
 
 
171
        if [ -e "/etc/mandos/plugin-helpers/$base" ]; then
 
 
175
            *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
178
            *) inst "$file" "/lib/mandos/plugin-helpers/$base";;
 
 
181
    local gpg=/usr/bin/gpg
 
 
182
    if [ -e /usr/bin/gpgconf ]; then
 
 
183
        inst /usr/bin/gpgconf
 
 
184
        gpg="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg:[^:]*://p'`"
 
 
185
        gpgagent="`/usr/bin/gpgconf|sed --quiet --expression='s/^gpg-agent:[^:]*://p'`"
 
 
186
        # Newer versions of GnuPG 2 requires the gpg-agent binary
 
 
187
        if [ -e "$gpgagent" ]; then
 
 
192
    if dracut_module_included "systemd"; then
 
 
193
        inst "${moddir}/password-agent" /lib/mandos/password-agent
 
 
194
        inst "${moddir}/ask-password-mandos.path" \
 
 
195
             "${systemdsystemunitdir}/ask-password-mandos.path"
 
 
196
        ln_r "${systemdsystemunitdir}/ask-password-mandos.path" \
 
 
197
             "${systemdsystemunitdir}/sysinit.target.wants/ask-password-mandos.path"
 
 
200
    for file in "$keydir"/*; do
 
 
201
        if [ -d "$file" ]; then
 
 
205
            *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert)
 
 
209
                inst "$file" "/etc/mandos/keys/`basename \"$file\"`"
 
 
210
                chown ${mandos_user}:${mandos_group} \
 
 
211
                      "${initdir}/etc/mandos/keys/`basename \"$file\"`"
 
 
212
                if [ `basename "$file"` = dhparams.pem ]; then
 
 
213
                    # Use Diffie-Hellman parameters file
 
 
214
                    if dracut_module_included "systemd"; then
 
 
216
                            --expression='/^ExecStart/s/ \$MANDOS_CLIENT_OPTIONS/ --dh-params=\/etc\/mandos\/keys\/dhparams.pem&/' \
 
 
217
                            "${initdir}/${systemdsystemunitdir}/ask-password-mandos.service"
 
 
220
                            --expression="1i--options-for=mandos-client:--dh-params=/etc/mandos/keys/dhparams.pem" \
 
 
221
                            "${initdir}/etc/mandos/plugin-runner.conf"
 
 
230
    instmods =drivers/net
 
 
231
    hostonly='' instmods ipv6
 
 
232
    # Copy any kernel modules needed by network hooks
 
 
233
    for hook in /etc/mandos/network-hooks.d/*; do
 
 
234
        basename=`basename "$hook"`
 
 
237
            *[!A-Za-z0-9_.-]*) continue ;;
 
 
239
        if [ -x "$hook" ]; then
 
 
240
            # Copy and load any modules needed by the network hook
 
 
241
            MANDOSNETHOOKDIR=/etc/mandos/network-hooks.d MODE=modules \
 
 
242
                VERBOSITY=0 "$hook" modules | while read module; do
 
 
243
                if [ -z "${target}" ]; then