/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-08-16 03:29:08 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080816032908-ihw7c05r2mnyk389
Add feature to specify custom environment variables for plugins.

* plugin-runner.c (plugin): New members "environ" and "envc" to
                            contain possible custom environment.
  (getplugin): Return NULL on failure instead of doing exit(); all
               callers changed.
  (add_to_char_array): New helper function for "add_argument" and
                       "add_environment".
  (addargument): Renamed to "add_argument".  Return bool.  Call
                 "add_to_char_array" to actually do things.
  (add_environment): New; analogous to "add_argument".
  (addcustomargument): Renamed to "add_to_argv" to avoid confusion
                       with "add_argument".
  (main): New options "--global-envs" and "--envs-for" to specify
          custom environment for plugins.  Print environment for
          plugins in debug mode.  Use asprintf instead of strcpy and
          strcat.  Use execve() for plugins with custom environments.
          Free environment for plugin when freeing plugin list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"
35
 
        break
36
 
    fi
37
 
done
38
 
if [ -z "$prefix" ]; then
 
32
if [ -d /usr/lib/mandos ]; then
 
33
    prefix=/usr
 
34
elif [ -d /usr/local/lib/mandos ]; then
 
35
    prefix=/usr/local
 
36
else
39
37
    # Mandos not found
40
38
    exit 1
41
39
fi
42
40
 
43
 
for d in /etc/keys/mandos /etc/mandos/keys; do
44
 
    if [ -d "$d" ]; then
45
 
        keydir="$d"
46
 
        break
47
 
    fi
48
 
done
49
 
if [ -z "$keydir" ]; then
50
 
    # Mandos key directory not found
51
 
    exit 1
52
 
fi
53
 
 
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 }'`"
64
 
 
65
41
# The Mandos network client uses the network
66
42
auto_add_modules net
67
43
# The Mandos network client uses IPv6
73
49
PLUGINDIR="${MANDOSDIR}/plugins.d"
74
50
 
75
51
# Make directories
76
 
install --directory --mode=u=rwx,go=rx "${DESTDIR}${CONFDIR}" \
77
 
        "${DESTDIR}${MANDOSDIR}"
78
 
install --owner=${mandos_user} --group=${mandos_group} --directory \
79
 
    --mode=u=rwx "${DESTDIR}${PLUGINDIR}"
 
52
mkdir --parents "${DESTDIR}${CONFDIR}"
 
53
mkdir --parents "${DESTDIR}${PLUGINDIR}"
80
54
 
81
55
# Copy the Mandos plugin runner
82
 
copy_exec "$prefix"/lib/mandos/plugin-runner "${MANDOSDIR}"
 
56
copy_exec "$prefix"/lib/mandos/plugin-runner "${DESTDIR}${MANDOSDIR}"
83
57
 
84
58
# Copy the plugins
85
59
 
91
65
        continue
92
66
    fi
93
67
    case "$base" in
94
 
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert) : ;;
95
 
        "*") :;;
 
68
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-new|*.dpkg-divert) : ;;
96
69
        *) copy_exec "$file" "${PLUGINDIR}";;
97
70
    esac
98
71
done
101
74
for file in /etc/mandos/plugins.d/*; do
102
75
    base="`basename \"$file\"`"
103
76
    case "$base" in
104
 
        *~|.*|\#*\#|*.dpkg-old|*.dpkg-bak|*.dpkg-new|*.dpkg-divert) : ;;
105
 
        "*") :;;
 
77
        *~|.*|*.dpkg-old|*.dpkg-new|*.dpkg-divert) : ;;
106
78
        *) copy_exec "$file" "${PLUGINDIR}";;
107
79
    esac
108
80
done
109
81
 
110
82
# GPGME needs /usr/bin/gpg
111
 
if [ ! -e "${DESTDIR}/usr/bin/gpg" \
112
 
    -a -n "`ls \"${DESTDIR}\"/usr/lib/libgpgme.so* \
113
 
                2>/dev/null`" ]; then
 
83
if ! [ -e "${DESTDIR}/usr/bin/gpg" ] \
 
84
    && [ -n "`ls \"${DESTDIR}\"/usr/lib/libgpgme.so* 2>/dev/null`" ]; then
114
85
    copy_exec /usr/bin/gpg
115
86
fi
116
87
 
117
 
# Config files
 
88
# Key files
118
89
for file in /etc/mandos/*; do
119
90
    if [ -d "$file" ]; then
120
91
        continue
121
92
    fi
122
93
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
123
94
done
124
 
 
125
 
if [ ${mandos_user} != 65534 ]; then
126
 
    PLUGINRUNNERCONF="${DESTDIR}${CONFDIR}/plugin-runner.conf"
127
 
    echo "--userid=${mandos_user}" >> "$PLUGINRUNNERCONF"
128
 
fi
129
 
 
130
 
if [ ${mandos_group} != 65534 ]; then
131
 
    PLUGINRUNNERCONF="${DESTDIR}${CONFDIR}/plugin-runner.conf"
132
 
    echo "--groupid=${mandos_group}" >> "$PLUGINRUNNERCONF"
133
 
fi
134
 
 
135
 
# Key files 
136
 
for file in  "$keydir"/*; do
137
 
    if [ -d "$file" ]; then
138
 
        continue
139
 
    fi
140
 
    cp --archive --sparse=always "$file" "${DESTDIR}${CONFDIR}"
141
 
    chown ${mandos_user}:${mandos_group} \
142
 
        "${DESTDIR}${CONFDIR}/`basename \"$file\"`"
143
 
done
 
95
# Create key ring files
 
96
gpg --no-random-seed-file --quiet --batch --no-tty \
 
97
    --no-default-keyring --no-options \
 
98
    --homedir "${DESTDIR}${CONFDIR}" --no-permission-warning \
 
99
    --import-options import-minimal \
 
100
    --import "${DESTDIR}${CONFDIR}/seckey.txt"
 
101
chown nobody "${DESTDIR}${CONFDIR}/secring.gpg"
144
102
 
145
103
# /lib/mandos/plugin-runner will drop priviliges, but needs access to
146
104
# its plugin directory and its config file.  However, since almost all
154
112
# condition.  This umask is set by "initramfs-tools-hook-conf",
155
113
# installed as "/usr/share/initramfs-tools/conf-hooks.d/mandos".)
156
114
157
 
for full in "${MANDOSDIR}" "${CONFDIR}"; do
 
115
for full in "${PLUGINDIR}" "${CONFDIR}"; do
158
116
    while [ "$full" != "/" ]; do
159
117
        chmod a+rX "${DESTDIR}$full"
160
118
        full="`dirname \"$full\"`"
164
122
# Reset some other things to sane permissions which we have
165
123
# inadvertently affected with our umask setting.
166
124
for dir in / /bin /etc /keyscripts /sbin /scripts /usr /usr/bin; do
167
 
    if [ -d "${DESTDIR}$dir" ]; then
168
 
        chmod a+rX "${DESTDIR}$dir"
169
 
    fi
 
125
    chmod a+rX "${DESTDIR}$dir"
170
126
done
171
127
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
 
128
    chmod --recursive a+rX "${DESTDIR}$dir"
174
129
done