xref: /freebsd/usr.sbin/periodic/etc/daily/200.backup-passwd (revision e9ac41698b2f322d55ccf9da50a3596edb2c1800)
1#!/bin/sh
2#
3#
4
5# If there is a global system configuration file, suck it in.
6#
7if [ -r /etc/defaults/periodic.conf ]
8then
9    . /etc/defaults/periodic.conf
10    source_periodic_confs
11fi
12
13case "$daily_backup_passwd_enable" in
14    [Yy][Ee][Ss])
15	if [ ! -f /etc/master.passwd ]
16	then
17	    echo '$daily_backup_passwd_enable" is set but /etc/master.passwd' \
18		"doesn't exist"
19	    rc=2
20	elif [ ! -f /etc/group ]
21	then
22	    echo '$daily_backup_passwd_enable" is set but /etc/group' \
23		"doesn't exist"
24	    rc=2
25	else
26	    bak=/var/backups
27	    rc=0
28
29	    echo ""
30	    echo "Backup passwd and group files:"
31
32	    if [ ! -f $bak/master.passwd.bak ]
33	    then
34		rc=1
35		echo "no $bak/master.passwd.bak"
36		cp -p /etc/master.passwd $bak/master.passwd.bak || rc=3
37	    fi
38
39	    if ! cmp -s $bak/master.passwd.bak /etc/master.passwd
40	    then
41		[ $rc -lt 1 ] && rc=1
42		echo "$host passwd diffs:"
43		diff ${daily_diff_flags} -I '^#' $bak/master.passwd.bak /etc/master.passwd |\
44			sed 's/^\([-+ ][^:]*\):[^:]*:/\1:(password):/'
45		mv $bak/master.passwd.bak $bak/master.passwd.bak2
46		cp -p /etc/master.passwd $bak/master.passwd.bak || rc=3
47	    fi
48
49	    if [ ! -f $bak/group.bak ]
50	    then
51		[ $rc -lt 1 ] && rc=1
52		echo "no $bak/group.bak"
53		cp -p /etc/group $bak/group.bak || rc=3
54	    fi
55
56	    if ! cmp -s $bak/group.bak /etc/group
57	    then
58		[ $rc -lt 1 ] && rc=1
59		echo "$host group diffs:"
60		diff ${daily_diff_flags} $bak/group.bak /etc/group
61		mv $bak/group.bak $bak/group.bak2
62		cp -p /etc/group $bak/group.bak || rc=3
63	    fi
64
65	    if [ -f /etc/group ]
66	    then
67	        echo ""
68		echo "Verifying group file syntax:"
69	        chkgrp /etc/group || rc=3
70	    fi
71	fi;;
72
73    *)  rc=0;;
74esac
75
76exit $rc
77