Sync etc/periodic with FreeBSD. Short summary:
[dragonfly.git] / etc / periodic / daily / 470.status-named
1 #!/bin/sh
2 #
3 # $FreeBSD: src/etc/periodic/daily/470.status-named,v 1.8 2006/06/11 20:39:12 maxim Exp $
4 # $DragonFly: src/etc/periodic/daily/470.status-named,v 1.4 2007/12/29 21:44:44 matthias Exp $
5 #
6
7 # If there is a global system configuration file, suck it in.
8 #
9 if [ -r /etc/defaults/periodic.conf ]
10 then
11     . /etc/defaults/periodic.conf
12     source_periodic_confs
13 fi
14
15 catmsgs() {
16         find /var/log -name 'messages.*' -mtime -2 |
17             sort -t. -r -n -k 2,2 |
18             while read f
19             do
20                 case $f in
21                     *.gz)       zcat -f $f;;
22                     *.bz2)      bzcat -f $f;;
23                 esac
24             done
25         [ -f /var/log/messages ] && cat /var/log/messages
26 }
27
28 case "$daily_status_named_enable" in
29     [Yy][Ee][Ss])
30         echo
31         echo 'Checking for denied zone transfers (AXFR and IXFR):'
32
33         start=`date -v-1d '+%b %e'`
34         rc=$(catmsgs |
35             fgrep -E "^$start.*named\[[[:digit:]]+\]: transfer of .*failed .*: REFUSED" |
36             sed -e "s/.*transfer of \'\(.*\)\/IN\' from \(.*\)#[0-9]*: .*/\1 from \2/" |
37             sort -f | uniq -ic | (
38                 usedns=0
39                 case "$daily_status_named_usedns" in
40                 '') ;;
41                 [yY][eE][sS]) usedns=1 ;;
42                 esac
43
44                 while read line ;do
45                         ipaddr=`echo "$line" | sed -e 's/^.*from //'`
46                         if [ $usedns -eq 1 ]; then
47                                 name=`host "${ipaddr}" 2>/dev/null | \
48                                    sed 's/.*domain name pointer \(.*\)\./\1/'`
49                         fi
50                         if [ -n "${name}" ]; then
51                                 echo "${line} (${name})"
52                         else
53                                 echo "${line}"
54                         fi
55                 done ) | \
56                 tee /dev/stderr | wc -l)
57         [ $rc -gt 0 ] && rc=1
58         ;;
59
60     *)  rc=0;;
61 esac
62
63 exit $rc