]>
Commit | Line | Data |
---|---|---|
906e3057 | 1 | #!/bin/sh |
2 | # | |
3 | # $Header$ | |
4 | ||
5 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/athena/bin:/usr/local/bin | |
6 | export PATH | |
7 | ||
8 | if [ -d /var/athena ] && [ -w /var/athena ]; then | |
9 | exec >/var/athena/moira_update.log 2>&1 | |
10 | else | |
11 | exec >/tmp/moira_update.log 2>&1 | |
12 | fi | |
13 | ||
14 | # The following exit codes are defined and MUST BE CONSISTENT with | |
15 | # error codes the library uses: | |
16 | MR_MKCRED=47836474 | |
17 | MR_MISSINGFILE=47836473 | |
18 | MR_NOCRED=47836470 | |
19 | ||
20 | root=/usr/local/sendmail | |
21 | ||
22 | if [ -s $root/etc/access.new ]; then | |
23 | cp /dev/null $root/etc/access.tmp | |
24 | ||
25 | if [ -s $root/etc/efl-access ]; then | |
26 | cat $root/etc/efl-access >> $root/etc/access.tmp | |
27 | fi | |
28 | ||
29 | cat $root/etc/access.new >> $root/etc/access.tmp | |
30 | mv $root/etc/access.tmp $root/etc/access.new | |
31 | chmod 644 $root/etc/access.new | |
32 | else | |
33 | exit $MR_MISSINGFILE | |
34 | fi | |
35 | ||
36 | if [ ! -s $root/etc/access ]; then | |
37 | logger -p mail.error -t access.sh "No current access file, aborting." | |
38 | exit $MR_NOCRED | |
39 | fi | |
40 | ||
41 | # Play it safe and be sure we have reasonable data | |
42 | olines=`wc -l $root/etc/access | awk '{print $1}'` | |
43 | nlines=`wc -l $root/etc/access.new | awk '{print $1}'` | |
44 | diff=`expr $nlines - $olines` | |
45 | thresh=`expr $olines / 10` | |
46 | ||
47 | # Catch the zero case | |
48 | if [ $nlines -eq 0 ]; then | |
49 | logger -p mail.error -t access.sh "Recieved empty access file, aborting." | |
50 | exit $MR_MISSINGFILE | |
51 | fi | |
52 | ||
53 | # If its a greater than 10% shift bomb out to be safe | |
54 | if [ $diff -gt $thresh ]; then | |
55 | logger -p mail.error -t access.sh "Access changes threshold exceeded, aborting." | |
56 | exit $MR_NOCRED | |
57 | fi | |
58 | ||
59 | cp /dev/null $root/etc/access.new.db | |
60 | ||
61 | $root/sbin/makemap btree $root/etc/access.new < $root/etc/access.new | |
62 | if [ $? != 0 ]; then | |
63 | exit $MR_MKCRED | |
64 | fi | |
65 | ||
66 | mv $root/etc/access $root/etc/access.old | |
67 | mv $root/etc/access.new $root/etc/access | |
68 | rm -f $root/etc/access.old.db | |
69 | ln $root/etc/access.db $root/etc/access.old.db | |
70 | mv $root/etc/access.new.db $root/etc/access.db | |
71 | ||
72 | rm -f $0 | |
73 | exit 0 |