aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/postfix-fixcerts.sh
blob: b9ec25aa5274ddca5cfe0592f071403519b64362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

# This script lists the content of the directory / the files specifing
# the trusted CAs in Postfix's configuration, makes a copy in the chroot
# jail and rehash the directory if necessary.
# 
# Usage: sudo ./postfix-fixcerts.sh
#
# References:
# - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579247
# - https://bugs.launchpad.net/ubuntu/+source/postfix/+bug/828047

queue_directory=$(postconf -h queue_directory)

for K in smtp_tls_CAfile smtpd_tls_CAfile; do
    CAfile=$(postconf -h "$K")
    if [ -n "$CAfile" ]; then
        [ -f "$CAfile" -a -r "$CAfile" ] || exit 1

        certs=$(dirname "$queue_directory/${CAfile#/}")
        mkdir -m 0755 --parent "$certs"
        cp -L "$CAfile" "$certs"
    fi
done

for K in smtp_tls_CApath smtpd_tls_CApath; do
    CApath=$(postconf -h "$K")
    if [ -n "$CApath" ]; then
        [ -d "$CApath" -a -r "$CApath" ] || exit 1
        echo "$CApath" "$queue_directory/${CApath#/}"
    fi
done | sort -u | \
while read S T; do
    mkdir -m 0755 --parent "$T"
    find -L "$S" -type f -a \( \! -name '*.[0-9]' \) -print0 | xargs -r0 cp -Lf -t "$T"
    /usr/bin/c_rehash "$T"
done