security revision 1.99
11.1Scgd#!/bin/sh -
21.1Scgd#
31.99Sjmcneill#	$NetBSD: security,v 1.99 2006/09/23 04:07:01 jmcneill Exp $
41.9Scgd#	from: @(#)security	8.1 (Berkeley) 6/9/93
51.1Scgd#
61.1Scgd
71.9ScgdPATH=/sbin:/usr/sbin:/bin:/usr/bin
81.1Scgd
91.89Sjmmvrcvar_manpage='security.conf(5)'
101.89Sjmmv
111.31Slukemif [ -f /etc/rc.subr ]; then
121.31Slukem	. /etc/rc.subr
131.31Slukemelse
141.31Slukem	echo "Can't read /etc/rc.subr; aborting."
151.31Slukem	exit 1;
161.31Slukemfi
171.31Slukem
181.9Scgdumask 077
191.64ScjsTZ=UTC; export TZ
201.1Scgd
211.15Smrgif [ -s /etc/security.conf ]; then
221.15Smrg	. /etc/security.conf
231.15Smrgfi
241.15Smrg
251.67Slukem# Set reasonable defaults (if they're not set in security.conf)
261.67Slukem#
271.67Slukembackup_dir=${backup_dir:-/var/backups}
281.67Slukempkgdb_dir=${pkgdb_dir:-/var/db/pkg}
291.67Slukemmax_loginlen=${max_loginlen:-8}
301.67Slukemmax_grouplen=${max_grouplen:-8}
311.67Slukem
321.67Slukem# Other configurable variables
331.67Slukem#
341.67Slukemspecial_files="/etc/mtree/special /etc/mtree/special.local"
351.67SlukemMP=/etc/master.passwd
361.67SlukemCHANGELIST=""
371.67Slukemwork_dir=$backup_dir/work
381.67Slukem
391.67Slukemif [ ! -d "$work_dir" ]; then
401.67Slukem	mkdir -p "$work_dir"
411.67Slukemfi
421.67Slukem
431.56SlukemSECUREDIR=`mktemp -d /tmp/_securedir.XXXXXX` || exit 1
441.56Slukem
451.67Slukemtrap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE
461.15Smrg
471.56Slukemif ! cd "$SECUREDIR"; then
481.56Slukem	echo "Can not cd to $SECUREDIR".
491.15Smrg	exit 1
501.15Smrgfi
511.15Smrg
521.91SlukemERR=err.$$
531.91SlukemTMP1=tmp1.$$
541.91SlukemTMP2=tmp2.$$
551.91SlukemMPBYUID=mpbyuid.$$
561.91SlukemMPBYPATH=mpbypath.$$
571.91SlukemLIST=list.$$
581.91SlukemOUTPUT=output.$$
591.91SlukemLABELS=labels.$$
601.91SlukemPKGS=pkgs.$$
611.91SlukemCHANGEFILES=changefiles.$$
621.91SlukemSPECIALSPEC=specialspec.$$
631.67Slukem
641.15Smrg
651.67Slukem# migrate_file old new
661.67Slukem#	Determine if the "${old}" path name needs to be migrated to the
671.67Slukem#	"${new}" path. Also checks if "${old}.current" needs migrating,
681.67Slukem#	and if so, migrate it and possibly "${old}.current,v" and
691.67Slukem#	"${old}.backup".
701.67Slukem#
711.67Slukemmigrate_file()
721.67Slukem{
731.67Slukem	_old=$1
741.67Slukem	_new=$2
751.67Slukem	if [ -z "$_old" -o -z "$_new" ]; then
761.67Slukem		err 3 "USAGE: migrate_file old new"
771.67Slukem	fi
781.67Slukem	if [ ! -d "${_new%/*}" ]; then
791.67Slukem		mkdir -p "${_new%/*}"
801.67Slukem	fi
811.67Slukem	if [ -f "${_old}" -a ! -f "${_new}" ]; then
821.67Slukem		echo "==> migrating ${_old}"
831.67Slukem		echo "           to ${_new}"
841.67Slukem		mv "${_old}" "${_new}"
851.67Slukem	fi
861.67Slukem	if [ -f "${_old}.current" -a ! -f "${_new}.current" ]; then
871.67Slukem		echo "==> migrating ${_old}.current"
881.67Slukem		echo "           to ${_new}.current"
891.67Slukem		mv "${_old}.current" "${_new}.current"
901.67Slukem		if [ -f "${_old}.current,v" -a ! -f "${_new}.current,v" ]; then
911.67Slukem			echo "==> migrating ${_old}.current,v"
921.67Slukem			echo "           to ${_new}.current,v"
931.67Slukem			mv "${_old}.current,v" "${_new}.current,v"
941.67Slukem		fi
951.67Slukem		if [ -f "${_old}.backup" -a ! -f "${_new}.backup" ]; then
961.67Slukem			echo "==> migrating ${_old}.backup"
971.67Slukem			echo "           to ${_new}.backup"
981.67Slukem			mv "${_old}.backup" "${_new}.backup"
991.67Slukem		fi
1001.67Slukem	fi
1011.67Slukem}
1021.67Slukem
1031.67Slukem
1041.67Slukem# backup_and_diff file printdiff
1051.67Slukem#	Determine if file needs backing up, and if so, do it.
1061.67Slukem#	If printdiff is yes, display the diffs, otherwise 
1071.67Slukem#	just print a message saying "[changes omitted]".
1081.67Slukem#
1091.67Slukembackup_and_diff()
1101.67Slukem{
1111.67Slukem	_file=$1
1121.67Slukem	_printdiff=$2
1131.67Slukem	if [ -z "$_file" -o -z "$_printdiff" ]; then
1141.67Slukem		err 3 "USAGE: backup_and_diff file printdiff"
1151.67Slukem	fi
1161.67Slukem	! checkyesno _printdiff
1171.67Slukem	_printdiff=$?
1181.67Slukem
1191.67Slukem	_old=$backup_dir/${_file##*/}
1201.67Slukem	case "$_file" in
1211.67Slukem	$work_dir/*)
1221.67Slukem		_new=$_file
1231.67Slukem		migrate_file "$backup_dir/$_old" "$_new"
1241.67Slukem		migrate_file "$_old" "$_new"
1251.67Slukem		;;
1261.67Slukem	*)
1271.67Slukem		_new=$backup_dir/$_file
1281.67Slukem		migrate_file "$_old" "$_new"
1291.67Slukem		;;
1301.67Slukem	esac
1311.67Slukem	CUR=${_new}.current
1321.67Slukem	BACK=${_new}.backup
1331.67Slukem	if [ -f $_file ]; then
1341.67Slukem		if [ -f $CUR ] ; then
1351.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1361.83Sjhawk				diff ${diff_options} $CUR $_file > $OUTPUT
1371.67Slukem			else
1381.67Slukem				if ! cmp -s $CUR $_file; then
1391.67Slukem					echo "[changes omitted]"
1401.67Slukem				fi > $OUTPUT
1411.67Slukem			fi
1421.67Slukem			if [ -s $OUTPUT ] ; then
1431.67Slukem				printf \
1441.67Slukem			"\n======\n%s diffs (OLD < > NEW)\n======\n" $_file
1451.67Slukem				cat $OUTPUT
1461.67Slukem				backup_file update $_file $CUR $BACK
1471.67Slukem			fi
1481.67Slukem		else
1491.67Slukem			printf "\n======\n%s added\n======\n" $_file
1501.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1511.83Sjhawk				diff ${diff_options} /dev/null $_file
1521.67Slukem			else
1531.67Slukem				echo "[changes omitted]"
1541.67Slukem			fi
1551.67Slukem			backup_file add $_file $CUR $BACK
1561.67Slukem		fi
1571.67Slukem	else
1581.67Slukem		if [ -f $CUR ]; then
1591.67Slukem			printf "\n======\n%s removed\n======\n" $_file
1601.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1611.83Sjhawk				diff ${diff_options} $CUR /dev/null
1621.67Slukem			else
1631.67Slukem				echo "[changes omitted]"
1641.67Slukem			fi
1651.67Slukem			backup_file remove $_file $CUR $BACK
1661.67Slukem		fi
1671.67Slukem	fi
1681.67Slukem}
1691.48Sabs
1701.9Scgd
1711.67Slukem# These are used several times.
1721.67Slukem#
1731.91Slukemawk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID
1741.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH
1751.91Slukemfor file in $special_files; do
1761.91Slukem	[ -s $file ] && cat $file
1771.91Slukemdone | mtree -CM -k all > $SPECIALSPEC || exit 1
1781.9Scgd
1791.67Slukem
1801.9Scgd# Check the master password file syntax.
1811.32Slukem#
1821.31Slukemif checkyesno check_passwd; then
1831.85Sjhawk        # XXX: the sense of permit_star is reversed; the code works as
1841.85Sjhawk        # implemented, but usage needs to be negated.
1851.81Sjhawk	checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1
1861.94Sjdolecek	checkyesno check_passwd_permit_nonalpha \
1871.94Sjdolecek		 && permit_nonalpha=1 || permit_nonalpha=0
1881.94Sjdolecek
1891.81Sjhawk	awk -v "len=$max_loginlen" \
1901.81Sjhawk	    -v "nowarn_shells_list=$check_passwd_nowarn_shells" \
1911.81Sjhawk	    -v "nowarn_users_list=$check_passwd_nowarn_users" \
1921.94Sjdolecek	    -v "permit_star=$permit_star" \
1931.94Sjdolecek	    -v "permit_nonalpha=$permit_nonalpha" \
1941.94Sjdolecek	'
1951.25Slukem	BEGIN {
1961.25Slukem		while ( getline < "/etc/shells" > 0 ) {
1971.39Shubertf			if ($0 ~ /^\#/ || $0 ~ /^$/ )
1981.25Slukem				continue;
1991.25Slukem			shells[$1]++;
2001.25Slukem		}
2011.81Sjhawk		split(nowarn_shells_list, a);
2021.81Sjhawk		for (i in a) nowarn_shells[a[i]]++;
2031.81Sjhawk		split(nowarn_users_list, a);
2041.81Sjhawk		for (i in a) nowarn_users[a[i]]++;
2051.81Sjhawk		uid0_users_list="root toor"
2061.81Sjhawk		split(uid0_users_list, a);
2071.81Sjhawk		for (i in a) uid0_users[a[i]]++;
2081.25Slukem		FS=":";
2091.25Slukem	}
2101.25Slukem
2111.25Slukem	{
2121.15Smrg		if ($0 ~ /^[	 ]*$/) {
2131.25Slukem			printf "Line %d is a blank line.\n", NR;
2141.15Smrg			next;
2151.15Smrg		}
2161.34Sabs		if (NF != 10 && ($1 != "+" || NF != 1))
2171.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
2181.34Sabs		if ($1 == "+" )  {
2191.34Sabs			if (NF != 1 && $3 == 0)
2201.81Sjhawk			    printf "Line %d includes entries with uid 0.\n",
2211.81Sjhawk			        NR;
2221.34Sabs			next;
2231.34Sabs		}
2241.94Sjdolecek		if (!permit_nonalpha &&
2251.95Speter		    $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
2261.25Slukem			printf "Login %s has non-alphanumeric characters.\n",
2271.25Slukem			    $1;
2281.34Sabs		if (length($1) > len)
2291.81Sjhawk			printf "Login %s has more than "len" characters.\n",
2301.81Sjhawk			    $1;
2311.81Sjhawk		if ($2 == "" && !nowarn_users[$1])
2321.81Sjhawk			    printf "Login %s has no password.\n", $1;
2331.81Sjhawk		if (!nowarn_shells[$10] && !nowarn_users[$1]) {
2341.81Sjhawk		    if (length($2) != 13 &&
2351.81Sjhawk		    	length($2) != 20 &&
2361.81Sjhawk		    	$2 !~ /^\$1/ &&
2371.81Sjhawk		    	$2 !~ /^\$2/ &&
2381.99Sjmcneill			$2 !~ /^\$sha1/ &&
2391.81Sjhawk		    	$2 != "" &&
2401.81Sjhawk			(permit_star || $2 != "*") &&
2411.81Sjhawk		    	$2 !~ /^\*[A-z-]+$/ &&
2421.81Sjhawk			$1 != "toor") {
2431.81Sjhawk		    	    if ($10 == "" || shells[$10])
2441.81Sjhawk				printf "Login %s is off but still has "\
2451.81Sjhawk				  "a valid shell (%s)\n", $1, $10;
2461.81Sjhawk		    } else if (! shells[$10])
2471.81Sjhawk		    	    printf "Login %s does not have a valid "\
2481.81Sjhawk			    "shell (%s)\n", $1, $10;
2491.81Sjhawk		}
2501.81Sjhawk		if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1])
2511.25Slukem			printf "Login %s has a user id of 0.\n", $1;
2521.15Smrg		if ($3 < 0)
2531.25Slukem			printf "Login %s has a negative user id.\n", $1;
2541.15Smrg		if ($4 < 0)
2551.25Slukem			printf "Login %s has a negative group id.\n", $1;
2561.15Smrg	}' < $MP > $OUTPUT
2571.15Smrg	if [ -s $OUTPUT ] ; then
2581.15Smrg		printf "\nChecking the $MP file:\n"
2591.15Smrg		cat $OUTPUT
2601.15Smrg	fi
2611.15Smrg
2621.15Smrg	awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
2631.15Smrg	if [ -s $OUTPUT ] ; then
2641.15Smrg		printf "\n$MP has duplicate user names.\n"
2651.15Smrg		column $OUTPUT
2661.15Smrg	fi
2671.15Smrg
2681.37Swrstuden# To not exclude 'toor', a standard duplicate root account, from the duplicate
2691.37Swrstuden# account test, uncomment the line below (without egrep in it)and comment
2701.37Swrstuden# out the line (with egrep in it) below it.
2711.37Swrstuden#
2721.37Swrstuden#	< $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2
2731.36Swrstuden	< $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2
2741.15Smrg	if [ -s $TMP2 ] ; then
2751.15Smrg		printf "\n$MP has duplicate user id's.\n"
2761.15Smrg		while read uid; do
2771.28Slukem			grep -w $uid $MPBYUID
2781.15Smrg		done < $TMP2 | column
2791.15Smrg	fi
2801.9Scgdfi
2811.9Scgd
2821.9Scgd# Check the group file syntax.
2831.32Slukem#
2841.31Slukemif checkyesno check_group; then
2851.15Smrg	GRP=/etc/group
2861.49Sjdolecek	awk -F: -v "len=$max_grouplen" '{
2871.15Smrg		if ($0 ~ /^[	 ]*$/) {
2881.25Slukem			printf "Line %d is a blank line.\n", NR;
2891.15Smrg			next;
2901.15Smrg		}
2911.34Sabs		if (NF != 4 && ($1 != "+" || NF != 1))
2921.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
2931.34Sabs		if ($1 == "+" )  {
2941.34Sabs			next;
2951.34Sabs		}
2961.95Speter		if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
2971.25Slukem			printf "Group %s has non-alphanumeric characters.\n",
2981.25Slukem			    $1;
2991.49Sjdolecek		if (length($1) > len)
3001.49Sjdolecek			printf "Group %s has more than "len" characters.\n", $1;
3011.15Smrg		if ($3 !~ /[0-9]*/)
3021.25Slukem			printf "Login %s has a negative group id.\n", $1;
3031.15Smrg	}' < $GRP > $OUTPUT
3041.15Smrg	if [ -s $OUTPUT ] ; then
3051.15Smrg		printf "\nChecking the $GRP file:\n"
3061.15Smrg		cat $OUTPUT
3071.15Smrg	fi
3081.15Smrg
3091.15Smrg	awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
3101.15Smrg	if [ -s $OUTPUT ] ; then
3111.15Smrg		printf "\n$GRP has duplicate group names.\n"
3121.15Smrg		column $OUTPUT
3131.15Smrg	fi
3141.9Scgdfi
3151.9Scgd
3161.9Scgd# Check for root paths, umask values in startup files.
3171.9Scgd# The check for the root paths is problematical -- it's likely to fail
3181.9Scgd# in other environments.  Once the shells have been modified to warn
3191.9Scgd# of '.' in the path, the path tests should go away.
3201.32Slukem#
3211.31Slukemif checkyesno check_rootdotfiles; then
3221.67Slukem	rhome=~root
3231.15Smrg	umaskset=no
3241.15Smrg	list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
3251.15Smrg	for i in $list ; do
3261.15Smrg		if [ -f $i ] ; then
3271.67Slukem			if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ;
3281.67Slukem			then
3291.15Smrg				umaskset=yes
3301.15Smrg			fi
3311.63Slukem			# Double check the umask value itself; ensure that
3321.67Slukem			# both the group and other write bits are set.
3331.67Slukem			#
3341.45Ssommerfe			egrep '^[ \t]*umask[ \t]+[0-7]+' $i |
3351.63Slukem			awk '{
3361.67Slukem				if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) {
3371.80Swiz					print "\tRoot umask is group writable"
3381.63Slukem				}
3391.67Slukem				if ($2 ~ /[^2367]$/) {
3401.80Swiz					print "\tRoot umask is other writable"
3411.63Slukem			    	}
3421.67Slukem			    }' | sort -u
3431.26Slukem			SAVE_PATH=$PATH
3441.26Slukem			unset PATH
3451.15Smrg			/bin/csh -f -s << end-of-csh > /dev/null 2>&1
3461.15Smrg				source $i
3471.15Smrg				/bin/ls -ldgT \$path > $TMP1
3481.9Scgdend-of-csh
3491.76Satatat			export PATH=$SAVE_PATH
3501.15Smrg			awk '{
3511.15Smrg				if ($10 ~ /^\.$/) {
3521.27Slukem					print "\tThe root path includes .";
3531.15Smrg					next;
3541.15Smrg				}
3551.15Smrg			     }
3561.15Smrg			     $1 ~ /^d....w/ \
3571.80Swiz		{ print "\tRoot path directory " $10 " is group writable." } \
3581.15Smrg			     $1 ~ /^d.......w/ \
3591.80Swiz		{ print "\tRoot path directory " $10 " is other writable." }' \
3601.67Slukem			< $TMP1
3611.15Smrg		fi
3621.67Slukem	done > $OUTPUT
3631.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
3641.27Slukem		printf "\nChecking root csh paths, umask values:\n$list\n\n"
3651.15Smrg		if [ -s $OUTPUT ]; then
3661.15Smrg			cat $OUTPUT
3671.15Smrg		fi
3681.15Smrg		if [ $umaskset = "no" ] ; then
3691.27Slukem		    printf "\tRoot csh startup files do not set the umask.\n"
3701.15Smrg		fi
3711.9Scgd	fi
3721.9Scgd
3731.15Smrg	umaskset=no
3741.23Slukem	list="/etc/profile ${rhome}/.profile"
3751.15Smrg	for i in $list; do
3761.15Smrg		if [ -f $i ] ; then
3771.15Smrg			if egrep umask $i > /dev/null ; then
3781.15Smrg				umaskset=yes
3791.15Smrg			fi
3801.15Smrg			egrep umask $i |
3811.67Slukem			awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \
3821.80Swiz				{ print "\tRoot umask is group writable" } \
3831.67Slukem			     $2 ~ /[^2367]$/ \
3841.80Swiz				{ print "\tRoot umask is other writable" }'
3851.26Slukem			SAVE_PATH=$PATH
3861.26Slukem			unset PATH
3871.15Smrg			/bin/sh << end-of-sh > /dev/null 2>&1
3881.15Smrg				. $i
3891.26Slukem				list=\`echo \$PATH | /usr/bin/sed -e \
3901.26Slukem				    's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\`
3911.15Smrg				/bin/ls -ldgT \$list > $TMP1
3921.9Scgdend-of-sh
3931.76Satatat			export PATH=$SAVE_PATH
3941.15Smrg			awk '{
3951.15Smrg				if ($10 ~ /^\.$/) {
3961.27Slukem					print "\tThe root path includes .";
3971.15Smrg					next;
3981.15Smrg				}
3991.15Smrg			     }
4001.15Smrg			     $1 ~ /^d....w/ \
4011.80Swiz		{ print "\tRoot path directory " $10 " is group writable." } \
4021.15Smrg			     $1 ~ /^d.......w/ \
4031.80Swiz		{ print "\tRoot path directory " $10 " is other writable." }' \
4041.67Slukem			< $TMP1
4051.9Scgd
4061.15Smrg		fi
4071.67Slukem	done > $OUTPUT
4081.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
4091.15Smrg		printf "\nChecking root sh paths, umask values:\n$list\n"
4101.15Smrg		if [ -s $OUTPUT ]; then
4111.15Smrg			cat $OUTPUT
4121.15Smrg		fi
4131.15Smrg		if [ $umaskset = "no" ] ; then
4141.27Slukem			printf "\tRoot sh startup files do not set the umask.\n"
4151.15Smrg		fi
4161.9Scgd	fi
4171.9Scgdfi
4181.9Scgd
4191.9Scgd# Root and uucp should both be in /etc/ftpusers.
4201.32Slukem#
4211.31Slukemif checkyesno check_ftpusers; then
4221.28Slukem	list="uucp "`awk '$2 == 0 { print $1 }' $MPBYUID`
4231.27Slukem	for i in $list; do
4241.29Slukem		if /usr/libexec/ftpd -C $i ; then
4251.67Slukem			printf "\t$i is not denied\n"
4261.27Slukem		fi
4271.67Slukem	done > $OUTPUT
4281.28Slukem	if [ -s $OUTPUT ]; then
4291.28Slukem		printf "\nChecking the /etc/ftpusers configuration:\n"
4301.28Slukem		cat $OUTPUT
4311.28Slukem	fi
4321.9Scgdfi
4331.9Scgd
4341.43Sitojun# Uudecode should not be in the /etc/mail/aliases file.
4351.32Slukem#
4361.31Slukemif checkyesno check_aliases; then
4371.43Sitojun	for f in /etc/mail/aliases /etc/aliases; do
4381.43Sitojun		if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then
4391.43Sitojun			printf "\nEntry for uudecode in $f file.\n"
4401.43Sitojun		fi
4411.43Sitojun	done
4421.9Scgdfi
4431.9Scgd
4441.9Scgd# Files that should not have + signs.
4451.32Slukem#
4461.31Slukemif checkyesno check_rhosts; then
4471.15Smrg	list="/etc/hosts.equiv /etc/hosts.lpd"
4481.15Smrg	for f in $list ; do
4491.15Smrg		if [ -f $f ] && egrep '\+' $f > /dev/null ; then
4501.15Smrg			printf "\nPlus sign in $f file.\n"
4511.15Smrg		fi
4521.15Smrg	done
4531.15Smrg
4541.15Smrg	# Check for special users with .rhosts files.  Only root and toor should
4551.16Smikel	# have .rhosts files.  Also, .rhosts files should not have plus signs.
4561.15Smrg	awk -F: '$1 != "root" && $1 != "toor" && \
4571.15Smrg		($3 < 100 || $1 == "ftp" || $1 == "uucp") \
4581.20Smycroft			{ print $1 " " $9 }' $MP |
4591.19Smycroft	sort -k2 |
4601.15Smrg	while read uid homedir; do
4611.15Smrg		if [ -f ${homedir}/.rhosts ] ; then
4621.15Smrg			rhost=`ls -ldgT ${homedir}/.rhosts`
4631.46Schristos			printf -- "$uid: $rhost\n"
4641.15Smrg		fi
4651.15Smrg	done > $OUTPUT
4661.15Smrg	if [ -s $OUTPUT ] ; then
4671.15Smrg		printf "\nChecking for special users with .rhosts files.\n"
4681.15Smrg		cat $OUTPUT
4691.15Smrg	fi
4701.15Smrg
4711.15Smrg	while read uid homedir; do
4721.35Sfair		if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \
4731.41Schristos		    cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then
4741.46Schristos			printf -- "$uid: + in .rhosts file.\n"
4751.15Smrg		fi
4761.29Slukem	done < $MPBYPATH > $OUTPUT
4771.15Smrg	if [ -s $OUTPUT ] ; then
4781.15Smrg		printf "\nChecking .rhosts files syntax.\n"
4791.15Smrg		cat $OUTPUT
4801.15Smrg	fi
4811.9Scgdfi
4821.9Scgd
4831.9Scgd# Check home directories.  Directories should not be owned by someone else
4841.80Swiz# or writable.
4851.32Slukem#
4861.31Slukemif checkyesno check_homes; then
4871.85Sjhawk	checkyesno check_homes_permit_usergroups && \
4881.85Sjhawk		permit_usergroups=1 || permit_usergroups=0
4891.15Smrg	while read uid homedir; do
4901.15Smrg		if [ -d ${homedir}/ ] ; then
4911.15Smrg			file=`ls -ldgT ${homedir}`
4921.46Schristos			printf -- "$uid $file\n"
4931.9Scgd		fi
4941.29Slukem	done < $MPBYPATH |
4951.85Sjhawk	awk -v "usergroups=$permit_usergroups" '
4961.85Sjhawk	     $1 != $4 && $4 != "root" \
4971.15Smrg		{ print "user " $1 " home directory is owned by " $4 }
4981.88Sjdolecek	     $2 ~ /^-....w/ && (!usergroups || $5 != $1) \
4991.80Swiz		{ print "user " $1 " home directory is group writable" }
5001.15Smrg	     $2 ~ /^-.......w/ \
5011.80Swiz		{ print "user " $1 " home directory is other writable" }' \
5021.27Slukem	    > $OUTPUT
5031.15Smrg	if [ -s $OUTPUT ] ; then
5041.15Smrg		printf "\nChecking home directories.\n"
5051.15Smrg		cat $OUTPUT
5061.15Smrg	fi
5071.15Smrg
5081.15Smrg	# Files that should not be owned by someone else or readable.
5091.67Slukem	list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity"
5101.15Smrg	while read uid homedir; do
5111.15Smrg		for f in $list ; do
5121.15Smrg			file=${homedir}/${f}
5131.15Smrg			if [ -f $file ] ; then
5141.46Schristos				printf -- "$uid $f `ls -ldgT $file`\n"
5151.15Smrg			fi
5161.15Smrg		done
5171.29Slukem	done < $MPBYPATH |
5181.85Sjhawk	awk  -v "usergroups=$permit_usergroups" '
5191.85Sjhawk	     $1 != $5 && $5 != "root" \
5201.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
5211.85Sjhawk	     $3 ~ /^-...r/ && (!usergroups || $6 != $1) \
5221.15Smrg		{ print "user " $1 " " $2 " file is group readable" }
5231.15Smrg	     $3 ~ /^-......r/ \
5241.15Smrg		{ print "user " $1 " " $2 " file is other readable" }
5251.85Sjhawk	     $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
5261.80Swiz		{ print "user " $1 " " $2 " file is group writable" }
5271.15Smrg	     $3 ~ /^-.......w/ \
5281.80Swiz		{ print "user " $1 " " $2 " file is other writable" }' \
5291.27Slukem	    > $OUTPUT
5301.15Smrg
5311.80Swiz	# Files that should not be owned by someone else or writable.
5321.19Smycroft	list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \
5331.79Selric	      .cshrc .emacs .exrc .forward .history .k5login .klogin .login \
5341.79Selric	      .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \
5351.79Selric	      .twmrc .xinitrc .xsession .ssh/authorized_keys \
5361.79Selric	      .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \
5371.79Selric	      .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \
5381.79Selric	      .ssh/known_hosts2"
5391.15Smrg	while read uid homedir; do
5401.15Smrg		for f in $list ; do
5411.15Smrg			file=${homedir}/${f}
5421.15Smrg			if [ -f $file ] ; then
5431.46Schristos				printf -- "$uid $f `ls -ldgT $file`\n"
5441.15Smrg			fi
5451.15Smrg		done
5461.29Slukem	done < $MPBYPATH |
5471.85Sjhawk	awk -v "usergroups=$permit_usergroups" '
5481.85Sjhawk	     $1 != $5 && $5 != "root" \
5491.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
5501.85Sjhawk	     $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
5511.80Swiz		{ print "user " $1 " " $2 " file is group writable" }
5521.15Smrg	     $3 ~ /^-.......w/ \
5531.80Swiz		{ print "user " $1 " " $2 " file is other writable" }' \
5541.27Slukem	    >> $OUTPUT
5551.15Smrg	if [ -s $OUTPUT ] ; then
5561.15Smrg		printf "\nChecking dot files.\n"
5571.15Smrg		cat $OUTPUT
5581.15Smrg	fi
5591.9Scgdfi
5601.9Scgd
5611.9Scgd# Mailboxes should be owned by user and unreadable.
5621.32Slukem#
5631.31Slukemif checkyesno check_varmail; then
5641.86Sjhawk	ls -lA /var/mail | \
5651.63Slukem	awk '	NR == 1 { next; }
5661.86Sjhawk		$9 ~ /^\./ {next; }
5671.63Slukem	    	$3 != $9 {
5681.63Slukem			print "user " $9 " mailbox is owned by " $3
5691.63Slukem		}
5701.63Slukem		$1 != "-rw-------" {
5711.63Slukem			print "user " $9 " mailbox is " $1 ", group " $4
5721.63Slukem		}' > $OUTPUT
5731.15Smrg	if [ -s $OUTPUT ] ; then
5741.15Smrg		printf "\nChecking mailbox ownership.\n"
5751.15Smrg		cat $OUTPUT
5761.15Smrg	fi
5771.15Smrgfi
5781.15Smrg
5791.32Slukem# NFS exports shouldn't be globally exported
5801.32Slukem#
5811.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then
5821.32Slukem	awk '{
5831.22Slukem		# ignore comments and blank lines
5841.39Shubertf		if ($0 ~ /^\#/ || $0 ~ /^$/ )
5851.22Slukem			next;
5861.22Slukem
5871.15Smrg		readonly = 0;
5881.15Smrg		for (i = 2; i <= NF; ++i) {
5891.15Smrg			if ($i ~ /-ro/)
5901.15Smrg				readonly = 1;
5911.93Skim			else if ($i ~ /^-network=/)
5921.93Skim				next;
5931.15Smrg			else if ($i !~ /^-/)
5941.15Smrg				next;
5951.15Smrg		}
5961.15Smrg		if (readonly)
5971.15Smrg			print "File system " $1 " globally exported, read-only."
5981.15Smrg		else
5991.15Smrg			print "File system " $1 " globally exported, read-write."
6001.32Slukem	}' < /etc/exports > $OUTPUT
6011.32Slukem	if [ -s $OUTPUT ] ; then
6021.15Smrg		printf "\nChecking for globally exported file systems.\n"
6031.15Smrg		cat $OUTPUT
6041.15Smrg	fi
6051.9Scgdfi
6061.9Scgd
6071.9Scgd# Display any changes in setuid files and devices.
6081.32Slukem#
6091.31Slukemif checkyesno check_devices; then
6101.28Slukem	> $ERR
6111.92Serh	(
6121.98Slukem
6131.98Slukem	# Convert check_devices_ignore_fstypes="foo !bar bax"
6141.98Slukem	#    into "-fstype foo -o ! -fstype bar -o -fstype bax"
6151.98Slukem	# and check_devices_ignore_paths="/foo !/bar /bax"
6161.98Slukem	#    into " -path /foo -o ! -path /bar -o -path /bax"
6171.98Slukem	#
6181.98Slukem	ignexpr=$(\
6191.98Slukem	    echo $check_devices_ignore_fstypes | \
6201.98Slukem		sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \
6211.98Slukem	    echo $check_devices_ignore_paths | \
6221.98Slukem		sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \
6231.98Slukem	)
6241.98Slukem
6251.98Slukem	# Massage the expression into ( $ignexpr ) -a -prune -o
6261.98Slukem	if [ -n "${ignexpr}" ]; then
6271.98Slukem		ignexpr=$(\
6281.98Slukem			echo $ignexpr | \
6291.98Slukem			    sed -e 's/^-o /( /' \
6301.98Slukem				-e 's/$/ ) -a -prune -o/' \
6311.98Slukem		)
6321.98Slukem	fi
6331.98Slukem
6341.98Slukem	find / $ignexpr \
6351.21Smycroft	    \( \( -perm -u+s -a ! -type d \) -o \
6361.21Smycroft	       \( -perm -g+s -a ! -type d \) -o \
6371.24Slukem	       -type b -o -type c \) -print0 | \
6381.98Slukem	xargs -0 ls -ldgTq | sort +9 > $LIST
6391.98Slukem
6401.98Slukem	) 2> $OUTPUT
6411.15Smrg
6421.15Smrg	# Display any errors that occurred during system file walk.
6431.15Smrg	if [ -s $OUTPUT ] ; then
6441.28Slukem		printf "Setuid/device find errors:\n" >> $ERR
6451.28Slukem		cat $OUTPUT >> $ERR
6461.28Slukem		printf "\n" >> $ERR
6471.15Smrg	fi
6481.15Smrg
6491.15Smrg	# Display any changes in the setuid file list.
6501.15Smrg	egrep -v '^[bc]' $LIST > $TMP1
6511.15Smrg	if [ -s $TMP1 ] ; then
6521.15Smrg		# Check to make sure uudecode isn't setuid.
6531.15Smrg		if grep -w uudecode $TMP1 > /dev/null ; then
6541.28Slukem			printf "\nUudecode is setuid.\n" >> $ERR
6551.15Smrg		fi
6561.15Smrg
6571.67Slukem		file=$work_dir/setuid
6581.67Slukem		migrate_file "$backup_dir/setuid" "$file"
6591.67Slukem		CUR=${file}.current
6601.67Slukem		BACK=${file}.backup
6611.15Smrg		if [ -s $CUR ] ; then
6621.15Smrg			if cmp -s $CUR $TMP1 ; then
6631.15Smrg				:
6641.15Smrg			else
6651.15Smrg				> $TMP2
6661.15Smrg				join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
6671.15Smrg				if [ -s $OUTPUT ] ; then
6681.28Slukem					printf "Setuid additions:\n" >> $ERR
6691.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
6701.28Slukem					printf "\n" >> $ERR
6711.15Smrg				fi
6721.15Smrg
6731.15Smrg				join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
6741.15Smrg				if [ -s $OUTPUT ] ; then
6751.28Slukem					printf "Setuid deletions:\n" >> $ERR
6761.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
6771.28Slukem					printf "\n" >> $ERR
6781.15Smrg				fi
6791.15Smrg
6801.20Smycroft				sort -k10 $TMP2 $CUR $TMP1 | \
6811.27Slukem				    sed -e 's/[	 ][	 ]*/ /g' | \
6821.27Slukem				    uniq -u > $OUTPUT
6831.15Smrg				if [ -s $OUTPUT ] ; then
6841.28Slukem					printf "Setuid changes:\n" >> $ERR
6851.28Slukem					column -t $OUTPUT >> $ERR
6861.28Slukem					printf "\n" >> $ERR
6871.15Smrg				fi
6881.9Scgd
6891.52Satatat				backup_file update $TMP1 $CUR $BACK
6901.9Scgd			fi
6911.15Smrg		else
6921.28Slukem			printf "Setuid additions:\n" >> $ERR
6931.28Slukem			column -t $TMP1 >> $ERR
6941.28Slukem			printf "\n" >> $ERR
6951.52Satatat			backup_file add $TMP1 $CUR $BACK
6961.9Scgd		fi
6971.15Smrg	fi
6981.15Smrg
6991.27Slukem	# Check for block and character disk devices that are readable or
7001.80Swiz	# writable or not owned by root.operator.
7011.15Smrg	>$TMP1
7021.61Slukem	DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \
7031.57Ssimonb	    sd se ss uk up vnd wd xd xy"
7041.27Slukem#	DISKLIST="$DISKLIST ct mt st wt"
7051.15Smrg	for i in $DISKLIST; do
7061.15Smrg		egrep "^b.*/${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
7071.15Smrg		egrep "^c.*/r${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
7081.15Smrg	done
7091.15Smrg
7101.15Smrg	awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
7111.25Slukem		{ printf "Disk %s is user %s, group %s, permissions %s.\n", \
7121.25Slukem		    $11, $3, $4, $1; }' < $TMP1 > $OUTPUT
7131.15Smrg	if [ -s $OUTPUT ] ; then
7141.28Slukem		printf "\nChecking disk ownership and permissions.\n" >> $ERR
7151.28Slukem		cat $OUTPUT >> $ERR
7161.28Slukem		printf "\n" >> $ERR
7171.9Scgd	fi
7181.9Scgd
7191.15Smrg	# Display any changes in the device file list.
7201.20Smycroft	egrep '^[bc]' $LIST | sort -k11 > $TMP1
7211.15Smrg	if [ -s $TMP1 ] ; then
7221.67Slukem		file=$work_dir/device
7231.67Slukem		migrate_file "$backup_dir/device" "$file"
7241.67Slukem		CUR=${file}.current
7251.67Slukem		BACK=${file}.backup
7261.15Smrg
7271.15Smrg		if [ -s $CUR ] ; then
7281.15Smrg			if cmp -s $CUR $TMP1 ; then
7291.15Smrg				:
7301.15Smrg			else
7311.15Smrg				> $TMP2
7321.15Smrg				join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
7331.15Smrg				if [ -s $OUTPUT ] ; then
7341.28Slukem					printf "Device additions:\n" >> $ERR
7351.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7361.28Slukem					printf "\n" >> $ERR
7371.15Smrg				fi
7381.15Smrg
7391.15Smrg				join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
7401.15Smrg				if [ -s $OUTPUT ] ; then
7411.28Slukem					printf "Device deletions:\n" >> $ERR
7421.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7431.28Slukem					printf "\n" >> $ERR
7441.15Smrg				fi
7451.15Smrg
7461.27Slukem				# Report any block device change. Ignore
7471.27Slukem				# character devices, only the name is
7481.27Slukem				# significant.
7491.15Smrg				cat $TMP2 $CUR $TMP1 | \
7501.27Slukem				    sed -e '/^c/d' | \
7511.27Slukem				    sort -k11 | \
7521.27Slukem				    sed -e 's/[	 ][	 ]*/ /g' | \
7531.27Slukem				    uniq -u > $OUTPUT
7541.15Smrg				if [ -s $OUTPUT ] ; then
7551.28Slukem					printf "Block device changes:\n" >> $ERR
7561.28Slukem					column -t $OUTPUT >> $ERR
7571.28Slukem					printf "\n" >> $ERR
7581.15Smrg				fi
7591.9Scgd
7601.52Satatat				backup_file update $TMP1 $CUR $BACK
7611.9Scgd			fi
7621.15Smrg		else
7631.28Slukem			printf "Device additions:\n" >> $ERR
7641.28Slukem			column -t $TMP1 >> $ERR
7651.28Slukem			printf "\n" >> $ERR
7661.52Satatat			backup_file add $TMP1 $CUR $BACK >> $ERR
7671.9Scgd		fi
7681.28Slukem	fi
7691.28Slukem	if [ -s $ERR ] ; then
7701.28Slukem		printf "\nChecking setuid files and devices:\n"
7711.28Slukem		cat $ERR
7721.28Slukem		printf "\n"
7731.9Scgd	fi
7741.9Scgdfi
7751.9Scgd
7761.9Scgd# Check special files.
7771.9Scgd# Check system binaries.
7781.9Scgd#
7791.9Scgd# Create the mtree tree specifications using:
7801.67Slukem#	mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure
7811.38Skleink#	chown root:wheel DIR.secure
7821.67Slukem#	chmod u+r,go= DIR.secure
7831.9Scgd#
7841.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as
7851.9Scgd# the hacker can modify the tree specification to match the replaced binary.
7861.9Scgd# For details on really protecting yourself against modified binaries, see
7871.9Scgd# the mtree(8) manual page.
7881.32Slukem#
7891.31Slukemif checkyesno check_mtree; then
7901.82Sjhawk	if checkyesno check_mtree_follow_symlinks; then
7911.82Sjhawk		check_mtree_flags="-L"
7921.82Sjhawk	else
7931.82Sjhawk		check_mtree_flags=""
7941.82Sjhawk	fi
7951.91Slukem	mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 |
7961.87Sjhawk		grep -v '^mtree: dev/tty: Device not configured$' >&2
7971.15Smrg	if [ -s $OUTPUT ]; then
7981.9Scgd		printf "\nChecking special files and directories.\n"
7991.9Scgd		cat $OUTPUT
8001.9Scgd	fi
8011.9Scgd
8021.16Smikel	for file in /etc/mtree/*.secure; do
8031.16Smikel		[ $file = '/etc/mtree/*.secure' ] && continue
8041.9Scgd		tree=`sed -n -e '3s/.* //p' -e 3q $file`
8051.82Sjhawk		mtree $check_mtree_flags -f $file -p $tree > $TMP1
8061.9Scgd		if [ -s $TMP1 ]; then
8071.67Slukem			printf "\nChecking $tree:\n"
8081.67Slukem			cat $TMP1
8091.9Scgd		fi
8101.67Slukem	done > $OUTPUT
8111.15Smrg	if [ -s $OUTPUT ]; then
8121.9Scgd		printf "\nChecking system binaries:\n"
8131.9Scgd		cat $OUTPUT
8141.9Scgd	fi
8151.9Scgdfi
8161.9Scgd
8171.32Slukem# Backup disklabels of available disks
8181.32Slukem#
8191.32Slukemif checkyesno check_disklabels; then
8201.67Slukem		# migrate old disklabels
8211.67Slukem	for file in `ls -1d $backup_dir/$backup_dir/disklabel.* \
8221.67Slukem	    $backup_dir/disklabel.* 2>/dev/null`; do
8231.67Slukem		migrate_file "$file" "$work_dir/${file##*/}"
8241.67Slukem	done
8251.67Slukem
8261.67Slukem		# generate list of old disklabels & fdisks and remove them
8271.67Slukem	ls -1d $work_dir/disklabel.* $work_dir/fdisk.* 2>/dev/null |
8281.52Satatat	    egrep -v '\.(backup|current)(,v)?$' > $LABELS
8291.32Slukem	xargs rm < $LABELS
8301.32Slukem
8311.96Srpaulo		# generate disklabels of all disks excluding:	cd fd md st
8321.97Sveego	disks=`iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|st|nfs/ { print $1; }'`
8331.32Slukem	for i in $disks; do
8341.67Slukem		disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null
8351.32Slukem	done
8361.32Slukem
8371.67Slukem		# if fdisk is available, generate fdisks for:	ed ld sd wd
8381.67Slukem	if [ -x /sbin/fdisk ]; then
8391.67Slukem		disks=`iostat -x| awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }'`
8401.67Slukem		for i in $disks; do
8411.67Slukem			/sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null
8421.67Slukem		done
8431.67Slukem	fi
8441.67Slukem
8451.67Slukem		# append list of new disklabels and fdisks
8461.67Slukem	ls -1d $work_dir/disklabel.* $work_dir/fdisk.* 2>/dev/null |
8471.52Satatat	    egrep -v '\.(backup|current)(,v)?$' >> $LABELS
8481.62Satatat	CHANGELIST="$LABELS $CHANGELIST"
8491.62Satatatfi
8501.62Satatat
8511.62Satatat# Check for changes in the list of installed pkgs
8521.62Satatat#
8531.65Slukemif checkyesno check_pkgs && [ -d $pkgdb_dir ]; then
8541.67Slukem	pkgs=$work_dir/pkgs
8551.67Slukem	migrate_file "$backup_dir/pkgs" "$pkgs"
8561.65Slukem	(	cd $pkgdb_dir
8571.62Satatat		pkg_info | sort
8581.62Satatat		echo ""
8591.62Satatat		find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 |
8601.72Slukem			xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,'
8611.62Satatat	 ) > $pkgs
8621.67Slukem	echo "$pkgs" > $PKGS
8631.62Satatat	CHANGELIST="$PKGS $CHANGELIST"
8641.32Slukemfi
8651.32Slukem
8661.67Slukem# List of files that get backed up and checked for any modifications.
8671.9Scgd# Any changes cause the files to rotate.
8681.32Slukem#
8691.67Slukemif checkyesno check_changelist ; then
8701.91Slukem	mtree -D -k type -f $SPECIALSPEC -E exclude |
8711.91Slukem	    sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES
8721.67Slukem
8731.75Slukem	(
8741.68Slukem		# Add other files which might dynamically exist:
8751.67Slukem		#	/etc/ifconfig.*
8761.67Slukem		#	/etc/raid*.conf
8771.68Slukem		#	/etc/rc.d/*
8781.67Slukem		#	/etc/rc.conf.d/*
8791.68Slukem		#
8801.75Slukem		echo "/etc/ifconfig.*"
8811.75Slukem		echo "/etc/raid*.conf"
8821.75Slukem		echo "/etc/rc.d/*"
8831.75Slukem		echo "/etc/rc.conf.d/*"
8841.67Slukem
8851.68Slukem		# Add /etc/changelist
8861.68Slukem		#
8871.75Slukem		if [ -s /etc/changelist ]; then
8881.75Slukem			grep -v '^#' /etc/changelist
8891.75Slukem		fi
8901.75Slukem	) | while read file; do
8911.75Slukem		case "$file" in
8921.75Slukem		*[\*\?\[]*)	# If changelist line is a glob ...
8931.75Slukem				# ... expand possible backup files
8941.75Slukem				#
8951.75Slukem			ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \
8961.75Slukem			    | sed "s,^$backup_dir/,, ; s,\.current$,,"
8971.75Slukem				
8981.75Slukem				# ... expand possible files
8991.75Slukem				#
9001.75Slukem			ls -1d $(echo $file) 2>/dev/null
9011.75Slukem			;;
9021.75Slukem		*)
9031.75Slukem				# Otherwise, just print the filename
9041.75Slukem			echo $file
9051.75Slukem			;;
9061.75Slukem		esac
9071.75Slukem	done >> $CHANGEFILES
9081.67Slukem	CHANGELIST="$CHANGEFILES $CHANGELIST"
9091.67Slukemfi
9101.67Slukem
9111.67Slukem# Special case backups, including the master password file and
9121.67Slukem# ssh private host keys. The normal backup mechanisms for
9131.67Slukem# $check_changelist (see below) also print out the actual file
9141.67Slukem# differences and we don't want to do that for these files
9151.67Slukem#
9161.67Slukemecho $MP > $TMP1			# always add /etc/master.passwd
9171.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff |
9181.91Slukem    sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1
9191.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2
9201.68Slukem
9211.69Slukemwhile read file; do
9221.67Slukem	backup_and_diff "$file" no
9231.69Slukemdone < $TMP2
9241.67Slukem
9251.32Slukem
9261.32Slukemif [ -n "$CHANGELIST" ]; then
9271.73Slukem	grep -h -v '^$' $CHANGELIST | sort -u > $TMP1
9281.68Slukem	comm -23 $TMP1 $TMP2 | while read file; do
9291.67Slukem		backup_and_diff "$file" yes
9301.9Scgd	done
9311.44Sadfi
9321.44Sad
9331.44Sadif [ -f /etc/security.local ]; then
9341.90Skim	. /etc/security.local > $OUTPUT 2>&1
9351.84Sjhawk	if [ -s $OUTPUT ] ; then
9361.84Sjhawk		printf "\nRunning /etc/security.local:\n"
9371.84Sjhawk		cat $OUTPUT
9381.84Sjhawk	fi
9391.9Scgdfi
940