~ubuntu-branches/ubuntu/quantal/ca-certificates/quantal-security

« back to all changes in this revision

Viewing changes to sbin/update-ca-certificates

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Kern
  • Date: 2009-07-09 10:35:39 UTC
  • mfrom: (9.1.4 karmic)
  • Revision ID: james.westby@ubuntu.com-20090709103539-yntccp0wqnf4a361
Tags: 20090709
Fix purge by checking for `/etc/ssl/certs' first.  (Closes: #536331)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# update-ca-certificates
4
4
#
5
5
# Copyright (c) 2003 Fumitoshi UKAI <ukai@debian.or.jp>
 
6
# Copyright (c) 2009 Philipp Kern <pkern@debian.org>
6
7
7
8
# This program is free software; you can redistribute it and/or modify
8
9
# it under the terms of the GNU General Public License as published by
16
17
#
17
18
# You should have received a copy of the GNU General Public License
18
19
# along with this program; if not, write to the Free Software
19
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301,
 
21
# USA.
20
22
#
21
23
 
22
24
verbose=0
37
39
 
38
40
CERTSCONF=/etc/ca-certificates.conf
39
41
CERTSDIR=/usr/share/ca-certificates
 
42
LOCALCERTSDIR=/usr/local/share/ca-certificates
40
43
CERTBUNDLE=ca-certificates.crt
41
44
ETCCERTSDIR=/etc/ssl/certs
 
45
 
 
46
cleanup() {
 
47
  rm -f "$TEMPBUNDLE"
 
48
  rm -f "$ADDED"
 
49
  rm -f "$REMOVED"
 
50
}
 
51
trap cleanup 0
 
52
 
 
53
# Helper files.  (Some of them are not simple arrays because we spawn
 
54
# subshells later on.)
 
55
TEMPBUNDLE="$(mktemp -t "${CERTBUNDLE}.tmp.XXXXXX")"
 
56
ADDED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
 
57
REMOVED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
 
58
 
 
59
# Adds a certificate to the list of trusted ones.  This includes a symlink
 
60
# in /etc/ssl/certs to the certificate file and its inclusion into the
 
61
# bundle.
 
62
add() {
 
63
  CERT="$1"
 
64
  PEM="$ETCCERTSDIR/$(basename "$CERT" .crt | sed -e 's/ /_/g' \
 
65
                                                  -e 's/[()]/=/g' \
 
66
                                                  -e 's/,/_/g').pem"
 
67
  if ! test -e "$PEM" || [ "$(readlink "$PEM")" != "$CERT" ]
 
68
  then
 
69
    ln -sf "$CERT" "$PEM"
 
70
    echo +$PEM >> "$ADDED"
 
71
  fi
 
72
  cat "$CERT" >> "$TEMPBUNDLE"
 
73
}
 
74
 
 
75
remove() {
 
76
  CERT="$1"
 
77
  PEM="$ETCCERTSDIR/$(basename "$CERT" .crt).pem"
 
78
  if test -L "$PEM"
 
79
  then
 
80
    rm -f "$PEM"
 
81
    echo -$PEM >> "$REMOVED"
 
82
  fi
 
83
}
 
84
 
42
85
cd $ETCCERTSDIR
43
86
if [ "$fresh" = 1 ]; then
44
87
  echo -n "Clearing symlinks in $ETCCERTSDIR..."
54
97
  done
55
98
  echo "done."
56
99
fi
57
 
echo -n "Updating certificates in $ETCCERTSDIR...."
58
 
 
59
 
bundletmp=`mktemp "${CERTBUNDLE}.tmp.XXXXXX"`
60
 
removed="$(sed -ne 's/^!//p' $CERTSCONF | while read crt
61
 
do
62
 
 if test "$crt" = ""; then continue; fi
63
 
 pem=$(basename "$crt" .crt).pem
64
 
 if test -e "$pem"; then
65
 
  rm -f "$pem"
66
 
  echo "-$ETCCERTSDIR/$pem"
67
 
 fi
68
 
done)"
69
 
 
70
 
added="$(sed -e '/^#/d' -e '/^!/d' $CERTSCONF | while read crt
71
 
do
72
 
 if test "$crt" = ""; then continue; fi
73
 
 if ! test -f "$CERTSDIR/$crt"; then continue; fi
74
 
 pem=$(basename "$crt" .crt).pem
75
 
 if ! test -e "$pem"; then echo "+$ETCCERTSDIR/$pem"; fi
76
 
 ln -sf "$CERTSDIR/$crt" "$pem"
77
 
 cat "$CERTSDIR/$crt" >> "$bundletmp"
78
 
done)"
79
 
chmod 0644 "$bundletmp"
80
 
mv -f "$bundletmp" "$CERTBUNDLE"
81
 
 
82
 
if [ -n "$added" ] || [ -n "$removed" ]; then
 
100
 
 
101
echo -n "Updating certificates in $ETCCERTSDIR... "
 
102
 
 
103
# Handle certificates that should be removed.  This is an explicit act
 
104
# by prefixing lines in the configuration files with exclamation marks (!).
 
105
sed -n -e '/^$/d' -e 's/^!//p' $CERTSCONF | while read crt
 
106
do
 
107
  remove "$CERTSDIR/$crt"
 
108
done
 
109
 
 
110
sed -e '/^$/d' -e '/^#/d' -e '/^!/d' $CERTSCONF | while read crt
 
111
do
 
112
  if ! test -f "$CERTSDIR/$crt"
 
113
  then
 
114
    echo "W: $CERTSDIR/$crt not found, but listed in $CERTSCONF." >&2
 
115
    continue
 
116
  fi
 
117
  add "$CERTSDIR/$crt"
 
118
done
 
119
 
 
120
# Now process certificate authorities installed by the local system
 
121
# administrator.
 
122
if [ -d "$LOCALCERTSDIR" ]
 
123
then
 
124
  find -L "$LOCALCERTSDIR" -type f -name '*.crt' | while read crt
 
125
  do
 
126
    add "$crt"
 
127
  done
 
128
fi
 
129
 
 
130
chmod 0644 "$TEMPBUNDLE"
 
131
mv -f "$TEMPBUNDLE" "$CERTBUNDLE"
 
132
 
 
133
ADDED_CNT=$(wc -l < "$ADDED")
 
134
REMOVED_CNT=$(wc -l < "$REMOVED")
 
135
 
 
136
if [ "$ADDED_CNT" -gt 0 ] || [ "$REMOVED_CNT" -gt 0 ]
 
137
then
83
138
  # only run if set of files has changed
84
 
 
85
 
  if [ "$verbose" = 0 ]; then
86
 
    c_rehash . > /dev/null 2>&1
 
139
  if [ "$verbose" = 0 ]
 
140
  then
 
141
    c_rehash . > /dev/null
87
142
  else
88
143
    c_rehash .
89
144
  fi
90
 
  echo "done."
91
 
 
92
 
  HOOKSDIR=/etc/ca-certificates/update.d
93
 
  echo -n "Running hooks in $HOOKSDIR...."
94
 
  VERBOSE_ARG=
95
 
  [ "$verbose" = 0 ] || VERBOSE_ARG=--verbose
96
 
  eval run-parts $VERB_ARG --test -- $HOOKSDIR | while read hook; do
97
 
  printf -- "${removed:+$removed\n}${added:+$added\n}" | eval $hook
98
 
  done
99
 
  echo "done."
100
 
else
101
 
  echo "done."
102
145
fi
 
146
 
 
147
echo "$ADDED_CNT added, $REMOVED_CNT removed; done."
 
148
 
 
149
HOOKSDIR=/etc/ca-certificates/update.d
 
150
echo -n "Running hooks in $HOOKSDIR...."
 
151
VERBOSE_ARG=
 
152
[ "$verbose" = 0 ] || VERBOSE_ARG=--verbose
 
153
eval run-parts $VERBOSE_ARG --test -- $HOOKSDIR | while read hook
 
154
do
 
155
  ( cat $ADDED
 
156
    cat $REMOVED ) | $hook || echo E: $hook exited with code $?.
 
157
done
 
158
echo "done."
 
159
 
 
160
# vim:set et sw=2:
 
161