security revision 1.105
11.1Scgd#!/bin/sh -
21.1Scgd#
31.105Sdholland#	$NetBSD: security,v 1.105 2007/11/23 15:51:27 dholland 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.104Sadrianppkg_info=${pkg_info:-/usr/sbin/pkg_info}
321.67Slukem
331.67Slukem# Other configurable variables
341.67Slukem#
351.67Slukemspecial_files="/etc/mtree/special /etc/mtree/special.local"
361.67SlukemMP=/etc/master.passwd
371.67SlukemCHANGELIST=""
381.67Slukemwork_dir=$backup_dir/work
391.67Slukem
401.67Slukemif [ ! -d "$work_dir" ]; then
411.67Slukem	mkdir -p "$work_dir"
421.67Slukemfi
431.67Slukem
441.102SmarttiSECUREDIR=$(mktemp -d -t _securedir) || exit 1
451.56Slukem
461.67Slukemtrap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE
471.15Smrg
481.56Slukemif ! cd "$SECUREDIR"; then
491.56Slukem	echo "Can not cd to $SECUREDIR".
501.15Smrg	exit 1
511.15Smrgfi
521.15Smrg
531.91SlukemERR=err.$$
541.91SlukemTMP1=tmp1.$$
551.91SlukemTMP2=tmp2.$$
561.91SlukemMPBYUID=mpbyuid.$$
571.91SlukemMPBYPATH=mpbypath.$$
581.91SlukemLIST=list.$$
591.91SlukemOUTPUT=output.$$
601.91SlukemLABELS=labels.$$
611.91SlukemPKGS=pkgs.$$
621.91SlukemCHANGEFILES=changefiles.$$
631.91SlukemSPECIALSPEC=specialspec.$$
641.67Slukem
651.15Smrg
661.67Slukem# migrate_file old new
671.67Slukem#	Determine if the "${old}" path name needs to be migrated to the
681.67Slukem#	"${new}" path. Also checks if "${old}.current" needs migrating,
691.67Slukem#	and if so, migrate it and possibly "${old}.current,v" and
701.67Slukem#	"${old}.backup".
711.67Slukem#
721.67Slukemmigrate_file()
731.67Slukem{
741.67Slukem	_old=$1
751.67Slukem	_new=$2
761.67Slukem	if [ -z "$_old" -o -z "$_new" ]; then
771.67Slukem		err 3 "USAGE: migrate_file old new"
781.67Slukem	fi
791.67Slukem	if [ ! -d "${_new%/*}" ]; then
801.67Slukem		mkdir -p "${_new%/*}"
811.67Slukem	fi
821.67Slukem	if [ -f "${_old}" -a ! -f "${_new}" ]; then
831.67Slukem		echo "==> migrating ${_old}"
841.67Slukem		echo "           to ${_new}"
851.67Slukem		mv "${_old}" "${_new}"
861.67Slukem	fi
871.67Slukem	if [ -f "${_old}.current" -a ! -f "${_new}.current" ]; then
881.67Slukem		echo "==> migrating ${_old}.current"
891.67Slukem		echo "           to ${_new}.current"
901.67Slukem		mv "${_old}.current" "${_new}.current"
911.67Slukem		if [ -f "${_old}.current,v" -a ! -f "${_new}.current,v" ]; then
921.67Slukem			echo "==> migrating ${_old}.current,v"
931.67Slukem			echo "           to ${_new}.current,v"
941.67Slukem			mv "${_old}.current,v" "${_new}.current,v"
951.67Slukem		fi
961.67Slukem		if [ -f "${_old}.backup" -a ! -f "${_new}.backup" ]; then
971.67Slukem			echo "==> migrating ${_old}.backup"
981.67Slukem			echo "           to ${_new}.backup"
991.67Slukem			mv "${_old}.backup" "${_new}.backup"
1001.67Slukem		fi
1011.67Slukem	fi
1021.67Slukem}
1031.67Slukem
1041.67Slukem
1051.67Slukem# backup_and_diff file printdiff
1061.67Slukem#	Determine if file needs backing up, and if so, do it.
1071.67Slukem#	If printdiff is yes, display the diffs, otherwise 
1081.67Slukem#	just print a message saying "[changes omitted]".
1091.67Slukem#
1101.67Slukembackup_and_diff()
1111.67Slukem{
1121.67Slukem	_file=$1
1131.67Slukem	_printdiff=$2
1141.67Slukem	if [ -z "$_file" -o -z "$_printdiff" ]; then
1151.67Slukem		err 3 "USAGE: backup_and_diff file printdiff"
1161.67Slukem	fi
1171.67Slukem	! checkyesno _printdiff
1181.67Slukem	_printdiff=$?
1191.67Slukem
1201.67Slukem	_old=$backup_dir/${_file##*/}
1211.67Slukem	case "$_file" in
1221.67Slukem	$work_dir/*)
1231.67Slukem		_new=$_file
1241.67Slukem		migrate_file "$backup_dir/$_old" "$_new"
1251.67Slukem		migrate_file "$_old" "$_new"
1261.67Slukem		;;
1271.67Slukem	*)
1281.67Slukem		_new=$backup_dir/$_file
1291.67Slukem		migrate_file "$_old" "$_new"
1301.67Slukem		;;
1311.67Slukem	esac
1321.67Slukem	CUR=${_new}.current
1331.67Slukem	BACK=${_new}.backup
1341.67Slukem	if [ -f $_file ]; then
1351.67Slukem		if [ -f $CUR ] ; then
1361.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1371.83Sjhawk				diff ${diff_options} $CUR $_file > $OUTPUT
1381.67Slukem			else
1391.67Slukem				if ! cmp -s $CUR $_file; then
1401.67Slukem					echo "[changes omitted]"
1411.67Slukem				fi > $OUTPUT
1421.67Slukem			fi
1431.67Slukem			if [ -s $OUTPUT ] ; then
1441.67Slukem				printf \
1451.67Slukem			"\n======\n%s diffs (OLD < > NEW)\n======\n" $_file
1461.67Slukem				cat $OUTPUT
1471.67Slukem				backup_file update $_file $CUR $BACK
1481.67Slukem			fi
1491.67Slukem		else
1501.67Slukem			printf "\n======\n%s added\n======\n" $_file
1511.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1521.83Sjhawk				diff ${diff_options} /dev/null $_file
1531.67Slukem			else
1541.67Slukem				echo "[changes omitted]"
1551.67Slukem			fi
1561.67Slukem			backup_file add $_file $CUR $BACK
1571.67Slukem		fi
1581.67Slukem	else
1591.67Slukem		if [ -f $CUR ]; then
1601.67Slukem			printf "\n======\n%s removed\n======\n" $_file
1611.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1621.83Sjhawk				diff ${diff_options} $CUR /dev/null
1631.67Slukem			else
1641.67Slukem				echo "[changes omitted]"
1651.67Slukem			fi
1661.67Slukem			backup_file remove $_file $CUR $BACK
1671.67Slukem		fi
1681.67Slukem	fi
1691.67Slukem}
1701.48Sabs
1711.9Scgd
1721.67Slukem# These are used several times.
1731.67Slukem#
1741.91Slukemawk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID
1751.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH
1761.91Slukemfor file in $special_files; do
1771.91Slukem	[ -s $file ] && cat $file
1781.91Slukemdone | mtree -CM -k all > $SPECIALSPEC || exit 1
1791.9Scgd
1801.67Slukem
1811.9Scgd# Check the master password file syntax.
1821.32Slukem#
1831.31Slukemif checkyesno check_passwd; then
1841.85Sjhawk        # XXX: the sense of permit_star is reversed; the code works as
1851.85Sjhawk        # implemented, but usage needs to be negated.
1861.81Sjhawk	checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1
1871.94Sjdolecek	checkyesno check_passwd_permit_nonalpha \
1881.94Sjdolecek		 && permit_nonalpha=1 || permit_nonalpha=0
1891.94Sjdolecek
1901.81Sjhawk	awk -v "len=$max_loginlen" \
1911.81Sjhawk	    -v "nowarn_shells_list=$check_passwd_nowarn_shells" \
1921.81Sjhawk	    -v "nowarn_users_list=$check_passwd_nowarn_users" \
1931.94Sjdolecek	    -v "permit_star=$permit_star" \
1941.94Sjdolecek	    -v "permit_nonalpha=$permit_nonalpha" \
1951.94Sjdolecek	'
1961.25Slukem	BEGIN {
1971.25Slukem		while ( getline < "/etc/shells" > 0 ) {
1981.39Shubertf			if ($0 ~ /^\#/ || $0 ~ /^$/ )
1991.25Slukem				continue;
2001.25Slukem			shells[$1]++;
2011.25Slukem		}
2021.81Sjhawk		split(nowarn_shells_list, a);
2031.81Sjhawk		for (i in a) nowarn_shells[a[i]]++;
2041.81Sjhawk		split(nowarn_users_list, a);
2051.81Sjhawk		for (i in a) nowarn_users[a[i]]++;
2061.81Sjhawk		uid0_users_list="root toor"
2071.81Sjhawk		split(uid0_users_list, a);
2081.81Sjhawk		for (i in a) uid0_users[a[i]]++;
2091.25Slukem		FS=":";
2101.25Slukem	}
2111.25Slukem
2121.25Slukem	{
2131.15Smrg		if ($0 ~ /^[	 ]*$/) {
2141.25Slukem			printf "Line %d is a blank line.\n", NR;
2151.15Smrg			next;
2161.15Smrg		}
2171.105Sdholland
2181.105Sdholland		# NIS compat entry?
2191.105Sdholland		compatline = $1 ~ "^[\\+-]";
2201.105Sdholland		if (compatline) {
2211.105Sdholland			if ($1 == "+" && NF == 1) {
2221.105Sdholland				next;
2231.105Sdholland			}
2241.105Sdholland			sub("^.", "", $1);
2251.105Sdholland		}
2261.105Sdholland		if (NF != 10)
2271.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
2281.105Sdholland		if (compatline)  {
2291.105Sdholland			if ($3 == 0)
2301.81Sjhawk			    printf "Line %d includes entries with uid 0.\n",
2311.81Sjhawk			        NR;
2321.105Sdholland			if ($1 == "")
2331.105Sdholland			    next;
2341.34Sabs		}
2351.94Sjdolecek		if (!permit_nonalpha &&
2361.95Speter		    $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
2371.25Slukem			printf "Login %s has non-alphanumeric characters.\n",
2381.25Slukem			    $1;
2391.34Sabs		if (length($1) > len)
2401.81Sjhawk			printf "Login %s has more than "len" characters.\n",
2411.81Sjhawk			    $1;
2421.105Sdholland		if ($2 == "" && !compatline && !nowarn_users[$1])
2431.81Sjhawk			    printf "Login %s has no password.\n", $1;
2441.81Sjhawk		if (!nowarn_shells[$10] && !nowarn_users[$1]) {
2451.81Sjhawk		    if (length($2) != 13 &&
2461.81Sjhawk		    	length($2) != 20 &&
2471.81Sjhawk		    	$2 !~ /^\$1/ &&
2481.81Sjhawk		    	$2 !~ /^\$2/ &&
2491.99Sjmcneill			$2 !~ /^\$sha1/ &&
2501.81Sjhawk		    	$2 != "" &&
2511.81Sjhawk			(permit_star || $2 != "*") &&
2521.81Sjhawk		    	$2 !~ /^\*[A-z-]+$/ &&
2531.81Sjhawk			$1 != "toor") {
2541.81Sjhawk		    	    if ($10 == "" || shells[$10])
2551.81Sjhawk				printf "Login %s is off but still has "\
2561.81Sjhawk				  "a valid shell (%s)\n", $1, $10;
2571.105Sdholland		    } else if (compatline && $10 == "") {
2581.105Sdholland			    # nothing
2591.81Sjhawk		    } else if (! shells[$10])
2601.81Sjhawk		    	    printf "Login %s does not have a valid "\
2611.81Sjhawk			    "shell (%s)\n", $1, $10;
2621.81Sjhawk		}
2631.81Sjhawk		if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1])
2641.25Slukem			printf "Login %s has a user id of 0.\n", $1;
2651.105Sdholland		if ($3 != "" && $3 < 0)
2661.25Slukem			printf "Login %s has a negative user id.\n", $1;
2671.105Sdholland		if ($4 != "" && $4 < 0)
2681.25Slukem			printf "Login %s has a negative group id.\n", $1;
2691.15Smrg	}' < $MP > $OUTPUT
2701.15Smrg	if [ -s $OUTPUT ] ; then
2711.15Smrg		printf "\nChecking the $MP file:\n"
2721.15Smrg		cat $OUTPUT
2731.15Smrg	fi
2741.15Smrg
2751.15Smrg	awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
2761.15Smrg	if [ -s $OUTPUT ] ; then
2771.15Smrg		printf "\n$MP has duplicate user names.\n"
2781.15Smrg		column $OUTPUT
2791.15Smrg	fi
2801.15Smrg
2811.37Swrstuden# To not exclude 'toor', a standard duplicate root account, from the duplicate
2821.37Swrstuden# account test, uncomment the line below (without egrep in it)and comment
2831.37Swrstuden# out the line (with egrep in it) below it.
2841.37Swrstuden#
2851.37Swrstuden#	< $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2
2861.36Swrstuden	< $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2
2871.15Smrg	if [ -s $TMP2 ] ; then
2881.15Smrg		printf "\n$MP has duplicate user id's.\n"
2891.15Smrg		while read uid; do
2901.28Slukem			grep -w $uid $MPBYUID
2911.15Smrg		done < $TMP2 | column
2921.15Smrg	fi
2931.9Scgdfi
2941.9Scgd
2951.9Scgd# Check the group file syntax.
2961.32Slukem#
2971.31Slukemif checkyesno check_group; then
2981.15Smrg	GRP=/etc/group
2991.49Sjdolecek	awk -F: -v "len=$max_grouplen" '{
3001.15Smrg		if ($0 ~ /^[	 ]*$/) {
3011.25Slukem			printf "Line %d is a blank line.\n", NR;
3021.15Smrg			next;
3031.15Smrg		}
3041.34Sabs		if (NF != 4 && ($1 != "+" || NF != 1))
3051.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
3061.34Sabs		if ($1 == "+" )  {
3071.34Sabs			next;
3081.34Sabs		}
3091.95Speter		if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
3101.25Slukem			printf "Group %s has non-alphanumeric characters.\n",
3111.25Slukem			    $1;
3121.49Sjdolecek		if (length($1) > len)
3131.49Sjdolecek			printf "Group %s has more than "len" characters.\n", $1;
3141.15Smrg		if ($3 !~ /[0-9]*/)
3151.25Slukem			printf "Login %s has a negative group id.\n", $1;
3161.15Smrg	}' < $GRP > $OUTPUT
3171.15Smrg	if [ -s $OUTPUT ] ; then
3181.15Smrg		printf "\nChecking the $GRP file:\n"
3191.15Smrg		cat $OUTPUT
3201.15Smrg	fi
3211.15Smrg
3221.15Smrg	awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
3231.15Smrg	if [ -s $OUTPUT ] ; then
3241.15Smrg		printf "\n$GRP has duplicate group names.\n"
3251.15Smrg		column $OUTPUT
3261.15Smrg	fi
3271.9Scgdfi
3281.9Scgd
3291.9Scgd# Check for root paths, umask values in startup files.
3301.9Scgd# The check for the root paths is problematical -- it's likely to fail
3311.9Scgd# in other environments.  Once the shells have been modified to warn
3321.9Scgd# of '.' in the path, the path tests should go away.
3331.32Slukem#
3341.31Slukemif checkyesno check_rootdotfiles; then
3351.67Slukem	rhome=~root
3361.15Smrg	umaskset=no
3371.15Smrg	list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
3381.15Smrg	for i in $list ; do
3391.15Smrg		if [ -f $i ] ; then
3401.67Slukem			if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ;
3411.67Slukem			then
3421.15Smrg				umaskset=yes
3431.15Smrg			fi
3441.63Slukem			# Double check the umask value itself; ensure that
3451.67Slukem			# both the group and other write bits are set.
3461.67Slukem			#
3471.45Ssommerfe			egrep '^[ \t]*umask[ \t]+[0-7]+' $i |
3481.63Slukem			awk '{
3491.67Slukem				if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) {
3501.80Swiz					print "\tRoot umask is group writable"
3511.63Slukem				}
3521.67Slukem				if ($2 ~ /[^2367]$/) {
3531.80Swiz					print "\tRoot umask is other writable"
3541.63Slukem			    	}
3551.67Slukem			    }' | sort -u
3561.26Slukem			SAVE_PATH=$PATH
3571.26Slukem			unset PATH
3581.15Smrg			/bin/csh -f -s << end-of-csh > /dev/null 2>&1
3591.15Smrg				source $i
3601.15Smrg				/bin/ls -ldgT \$path > $TMP1
3611.9Scgdend-of-csh
3621.76Satatat			export PATH=$SAVE_PATH
3631.15Smrg			awk '{
3641.15Smrg				if ($10 ~ /^\.$/) {
3651.27Slukem					print "\tThe root path includes .";
3661.15Smrg					next;
3671.15Smrg				}
3681.15Smrg			     }
3691.15Smrg			     $1 ~ /^d....w/ \
3701.80Swiz		{ print "\tRoot path directory " $10 " is group writable." } \
3711.15Smrg			     $1 ~ /^d.......w/ \
3721.80Swiz		{ print "\tRoot path directory " $10 " is other writable." }' \
3731.67Slukem			< $TMP1
3741.15Smrg		fi
3751.67Slukem	done > $OUTPUT
3761.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
3771.27Slukem		printf "\nChecking root csh paths, umask values:\n$list\n\n"
3781.15Smrg		if [ -s $OUTPUT ]; then
3791.15Smrg			cat $OUTPUT
3801.15Smrg		fi
3811.15Smrg		if [ $umaskset = "no" ] ; then
3821.27Slukem		    printf "\tRoot csh startup files do not set the umask.\n"
3831.15Smrg		fi
3841.9Scgd	fi
3851.9Scgd
3861.15Smrg	umaskset=no
3871.23Slukem	list="/etc/profile ${rhome}/.profile"
3881.15Smrg	for i in $list; do
3891.15Smrg		if [ -f $i ] ; then
3901.15Smrg			if egrep umask $i > /dev/null ; then
3911.15Smrg				umaskset=yes
3921.15Smrg			fi
3931.15Smrg			egrep umask $i |
3941.67Slukem			awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \
3951.80Swiz				{ print "\tRoot umask is group writable" } \
3961.67Slukem			     $2 ~ /[^2367]$/ \
3971.80Swiz				{ print "\tRoot umask is other writable" }'
3981.26Slukem			SAVE_PATH=$PATH
3991.26Slukem			unset PATH
4001.15Smrg			/bin/sh << end-of-sh > /dev/null 2>&1
4011.15Smrg				. $i
4021.26Slukem				list=\`echo \$PATH | /usr/bin/sed -e \
4031.26Slukem				    's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\`
4041.15Smrg				/bin/ls -ldgT \$list > $TMP1
4051.9Scgdend-of-sh
4061.76Satatat			export PATH=$SAVE_PATH
4071.15Smrg			awk '{
4081.15Smrg				if ($10 ~ /^\.$/) {
4091.27Slukem					print "\tThe root path includes .";
4101.15Smrg					next;
4111.15Smrg				}
4121.15Smrg			     }
4131.15Smrg			     $1 ~ /^d....w/ \
4141.80Swiz		{ print "\tRoot path directory " $10 " is group writable." } \
4151.15Smrg			     $1 ~ /^d.......w/ \
4161.80Swiz		{ print "\tRoot path directory " $10 " is other writable." }' \
4171.67Slukem			< $TMP1
4181.9Scgd
4191.15Smrg		fi
4201.67Slukem	done > $OUTPUT
4211.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
4221.15Smrg		printf "\nChecking root sh paths, umask values:\n$list\n"
4231.15Smrg		if [ -s $OUTPUT ]; then
4241.15Smrg			cat $OUTPUT
4251.15Smrg		fi
4261.15Smrg		if [ $umaskset = "no" ] ; then
4271.27Slukem			printf "\tRoot sh startup files do not set the umask.\n"
4281.15Smrg		fi
4291.9Scgd	fi
4301.9Scgdfi
4311.9Scgd
4321.9Scgd# Root and uucp should both be in /etc/ftpusers.
4331.32Slukem#
4341.31Slukemif checkyesno check_ftpusers; then
4351.28Slukem	list="uucp "`awk '$2 == 0 { print $1 }' $MPBYUID`
4361.27Slukem	for i in $list; do
4371.29Slukem		if /usr/libexec/ftpd -C $i ; then
4381.67Slukem			printf "\t$i is not denied\n"
4391.27Slukem		fi
4401.67Slukem	done > $OUTPUT
4411.28Slukem	if [ -s $OUTPUT ]; then
4421.28Slukem		printf "\nChecking the /etc/ftpusers configuration:\n"
4431.28Slukem		cat $OUTPUT
4441.28Slukem	fi
4451.9Scgdfi
4461.9Scgd
4471.43Sitojun# Uudecode should not be in the /etc/mail/aliases file.
4481.32Slukem#
4491.31Slukemif checkyesno check_aliases; then
4501.43Sitojun	for f in /etc/mail/aliases /etc/aliases; do
4511.43Sitojun		if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then
4521.43Sitojun			printf "\nEntry for uudecode in $f file.\n"
4531.43Sitojun		fi
4541.43Sitojun	done
4551.9Scgdfi
4561.9Scgd
4571.9Scgd# Files that should not have + signs.
4581.32Slukem#
4591.31Slukemif checkyesno check_rhosts; then
4601.15Smrg	list="/etc/hosts.equiv /etc/hosts.lpd"
4611.15Smrg	for f in $list ; do
4621.15Smrg		if [ -f $f ] && egrep '\+' $f > /dev/null ; then
4631.15Smrg			printf "\nPlus sign in $f file.\n"
4641.15Smrg		fi
4651.15Smrg	done
4661.15Smrg
4671.15Smrg	# Check for special users with .rhosts files.  Only root and toor should
4681.16Smikel	# have .rhosts files.  Also, .rhosts files should not have plus signs.
4691.15Smrg	awk -F: '$1 != "root" && $1 != "toor" && \
4701.15Smrg		($3 < 100 || $1 == "ftp" || $1 == "uucp") \
4711.20Smycroft			{ print $1 " " $9 }' $MP |
4721.19Smycroft	sort -k2 |
4731.15Smrg	while read uid homedir; do
4741.15Smrg		if [ -f ${homedir}/.rhosts ] ; then
4751.15Smrg			rhost=`ls -ldgT ${homedir}/.rhosts`
4761.46Schristos			printf -- "$uid: $rhost\n"
4771.15Smrg		fi
4781.15Smrg	done > $OUTPUT
4791.15Smrg	if [ -s $OUTPUT ] ; then
4801.15Smrg		printf "\nChecking for special users with .rhosts files.\n"
4811.15Smrg		cat $OUTPUT
4821.15Smrg	fi
4831.15Smrg
4841.15Smrg	while read uid homedir; do
4851.35Sfair		if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \
4861.41Schristos		    cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then
4871.46Schristos			printf -- "$uid: + in .rhosts file.\n"
4881.15Smrg		fi
4891.29Slukem	done < $MPBYPATH > $OUTPUT
4901.15Smrg	if [ -s $OUTPUT ] ; then
4911.15Smrg		printf "\nChecking .rhosts files syntax.\n"
4921.15Smrg		cat $OUTPUT
4931.15Smrg	fi
4941.9Scgdfi
4951.9Scgd
4961.9Scgd# Check home directories.  Directories should not be owned by someone else
4971.80Swiz# or writable.
4981.32Slukem#
4991.31Slukemif checkyesno check_homes; then
5001.85Sjhawk	checkyesno check_homes_permit_usergroups && \
5011.85Sjhawk		permit_usergroups=1 || permit_usergroups=0
5021.15Smrg	while read uid homedir; do
5031.15Smrg		if [ -d ${homedir}/ ] ; then
5041.15Smrg			file=`ls -ldgT ${homedir}`
5051.46Schristos			printf -- "$uid $file\n"
5061.9Scgd		fi
5071.29Slukem	done < $MPBYPATH |
5081.85Sjhawk	awk -v "usergroups=$permit_usergroups" '
5091.85Sjhawk	     $1 != $4 && $4 != "root" \
5101.15Smrg		{ print "user " $1 " home directory is owned by " $4 }
5111.101Sjnemeth	     $2 ~ /^d....w/ && (!usergroups || $5 != $1) \
5121.80Swiz		{ print "user " $1 " home directory is group writable" }
5131.101Sjnemeth	     $2 ~ /^d.......w/ \
5141.80Swiz		{ print "user " $1 " home directory is other writable" }' \
5151.27Slukem	    > $OUTPUT
5161.15Smrg	if [ -s $OUTPUT ] ; then
5171.15Smrg		printf "\nChecking home directories.\n"
5181.15Smrg		cat $OUTPUT
5191.15Smrg	fi
5201.15Smrg
5211.15Smrg	# Files that should not be owned by someone else or readable.
5221.67Slukem	list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity"
5231.15Smrg	while read uid homedir; do
5241.15Smrg		for f in $list ; do
5251.15Smrg			file=${homedir}/${f}
5261.15Smrg			if [ -f $file ] ; then
5271.46Schristos				printf -- "$uid $f `ls -ldgT $file`\n"
5281.15Smrg			fi
5291.15Smrg		done
5301.29Slukem	done < $MPBYPATH |
5311.85Sjhawk	awk  -v "usergroups=$permit_usergroups" '
5321.85Sjhawk	     $1 != $5 && $5 != "root" \
5331.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
5341.85Sjhawk	     $3 ~ /^-...r/ && (!usergroups || $6 != $1) \
5351.15Smrg		{ print "user " $1 " " $2 " file is group readable" }
5361.15Smrg	     $3 ~ /^-......r/ \
5371.15Smrg		{ print "user " $1 " " $2 " file is other readable" }
5381.85Sjhawk	     $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
5391.80Swiz		{ print "user " $1 " " $2 " file is group writable" }
5401.15Smrg	     $3 ~ /^-.......w/ \
5411.80Swiz		{ print "user " $1 " " $2 " file is other writable" }' \
5421.27Slukem	    > $OUTPUT
5431.15Smrg
5441.80Swiz	# Files that should not be owned by someone else or writable.
5451.19Smycroft	list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \
5461.79Selric	      .cshrc .emacs .exrc .forward .history .k5login .klogin .login \
5471.79Selric	      .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \
5481.79Selric	      .twmrc .xinitrc .xsession .ssh/authorized_keys \
5491.79Selric	      .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \
5501.79Selric	      .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \
5511.79Selric	      .ssh/known_hosts2"
5521.15Smrg	while read uid homedir; do
5531.15Smrg		for f in $list ; do
5541.15Smrg			file=${homedir}/${f}
5551.15Smrg			if [ -f $file ] ; then
5561.46Schristos				printf -- "$uid $f `ls -ldgT $file`\n"
5571.15Smrg			fi
5581.15Smrg		done
5591.29Slukem	done < $MPBYPATH |
5601.85Sjhawk	awk -v "usergroups=$permit_usergroups" '
5611.85Sjhawk	     $1 != $5 && $5 != "root" \
5621.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
5631.85Sjhawk	     $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
5641.80Swiz		{ print "user " $1 " " $2 " file is group writable" }
5651.15Smrg	     $3 ~ /^-.......w/ \
5661.80Swiz		{ print "user " $1 " " $2 " file is other writable" }' \
5671.27Slukem	    >> $OUTPUT
5681.15Smrg	if [ -s $OUTPUT ] ; then
5691.15Smrg		printf "\nChecking dot files.\n"
5701.15Smrg		cat $OUTPUT
5711.15Smrg	fi
5721.9Scgdfi
5731.9Scgd
5741.9Scgd# Mailboxes should be owned by user and unreadable.
5751.32Slukem#
5761.31Slukemif checkyesno check_varmail; then
5771.86Sjhawk	ls -lA /var/mail | \
5781.63Slukem	awk '	NR == 1 { next; }
5791.86Sjhawk		$9 ~ /^\./ {next; }
5801.63Slukem	    	$3 != $9 {
5811.63Slukem			print "user " $9 " mailbox is owned by " $3
5821.63Slukem		}
5831.63Slukem		$1 != "-rw-------" {
5841.63Slukem			print "user " $9 " mailbox is " $1 ", group " $4
5851.63Slukem		}' > $OUTPUT
5861.15Smrg	if [ -s $OUTPUT ] ; then
5871.15Smrg		printf "\nChecking mailbox ownership.\n"
5881.15Smrg		cat $OUTPUT
5891.15Smrg	fi
5901.15Smrgfi
5911.15Smrg
5921.32Slukem# NFS exports shouldn't be globally exported
5931.32Slukem#
5941.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then
5951.32Slukem	awk '{
5961.22Slukem		# ignore comments and blank lines
5971.39Shubertf		if ($0 ~ /^\#/ || $0 ~ /^$/ )
5981.22Slukem			next;
5991.100Stron		# manage line continuation
6001.100Stron		while ($NF ~ /^\\$/) {
6011.100Stron			$NF = "";
6021.100Stron			line = $0 "";
6031.100Stron			getline;
6041.100Stron			$0 = line $0 "";
6051.100Stron		}
6061.22Slukem
6071.100Stron		delete dir;
6081.100Stron		readonly = ndir = 0;
6091.100Stron		for (i = 1; i <= NF; ++i) {
6101.100Stron			if ($i ~ /^\//) dir[ndir++] = $i;
6111.100Stron			else if ($i ~ /^-/) {
6121.100Stron				if ($i ~ /^-(ro|o)$/) readonly = 1;
6131.100Stron				if ($i ~ /^-network/) next;
6141.100Stron			}
6151.100Stron			else next;
6161.15Smrg		}
6171.15Smrg		if (readonly)
6181.100Stron			for (item in dir)
6191.100Stron				rodir[nrodir++] = dir[item];
6201.15Smrg		else
6211.100Stron			for (item in dir)
6221.100Stron				rwdir[nrwdir++] = dir[item];
6231.100Stron
6241.100Stron	}
6251.100Stron
6261.100Stron	END {
6271.100Stron		if (nrodir) {
6281.100Stron			printf("Globally exported file system%s, read-only:\n",
6291.100Stron				nrodir > 1 ? "s" : "");
6301.100Stron			for (item in rodir)
6311.100Stron				printf("\t%s\n", rodir[item]);
6321.100Stron		}
6331.100Stron		if (nrwdir) {
6341.100Stron			printf("Globally exported file system%s, read-write:\n",
6351.100Stron				nrwdir > 1 ? "s" : "");
6361.100Stron			for (item in rwdir)
6371.100Stron				printf("\t%s\n", rwdir[item]);
6381.100Stron		}
6391.32Slukem	}' < /etc/exports > $OUTPUT
6401.32Slukem	if [ -s $OUTPUT ] ; then
6411.15Smrg		printf "\nChecking for globally exported file systems.\n"
6421.15Smrg		cat $OUTPUT
6431.15Smrg	fi
6441.9Scgdfi
6451.9Scgd
6461.9Scgd# Display any changes in setuid files and devices.
6471.32Slukem#
6481.31Slukemif checkyesno check_devices; then
6491.28Slukem	> $ERR
6501.92Serh	(
6511.98Slukem
6521.98Slukem	# Convert check_devices_ignore_fstypes="foo !bar bax"
6531.98Slukem	#    into "-fstype foo -o ! -fstype bar -o -fstype bax"
6541.98Slukem	# and check_devices_ignore_paths="/foo !/bar /bax"
6551.98Slukem	#    into " -path /foo -o ! -path /bar -o -path /bax"
6561.98Slukem	#
6571.98Slukem	ignexpr=$(\
6581.98Slukem	    echo $check_devices_ignore_fstypes | \
6591.98Slukem		sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \
6601.98Slukem	    echo $check_devices_ignore_paths | \
6611.98Slukem		sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \
6621.98Slukem	)
6631.98Slukem
6641.98Slukem	# Massage the expression into ( $ignexpr ) -a -prune -o
6651.98Slukem	if [ -n "${ignexpr}" ]; then
6661.98Slukem		ignexpr=$(\
6671.98Slukem			echo $ignexpr | \
6681.98Slukem			    sed -e 's/^-o /( /' \
6691.98Slukem				-e 's/$/ ) -a -prune -o/' \
6701.98Slukem		)
6711.98Slukem	fi
6721.98Slukem
6731.98Slukem	find / $ignexpr \
6741.21Smycroft	    \( \( -perm -u+s -a ! -type d \) -o \
6751.21Smycroft	       \( -perm -g+s -a ! -type d \) -o \
6761.24Slukem	       -type b -o -type c \) -print0 | \
6771.98Slukem	xargs -0 ls -ldgTq | sort +9 > $LIST
6781.98Slukem
6791.98Slukem	) 2> $OUTPUT
6801.15Smrg
6811.15Smrg	# Display any errors that occurred during system file walk.
6821.15Smrg	if [ -s $OUTPUT ] ; then
6831.28Slukem		printf "Setuid/device find errors:\n" >> $ERR
6841.28Slukem		cat $OUTPUT >> $ERR
6851.28Slukem		printf "\n" >> $ERR
6861.15Smrg	fi
6871.15Smrg
6881.15Smrg	# Display any changes in the setuid file list.
6891.15Smrg	egrep -v '^[bc]' $LIST > $TMP1
6901.15Smrg	if [ -s $TMP1 ] ; then
6911.15Smrg		# Check to make sure uudecode isn't setuid.
6921.15Smrg		if grep -w uudecode $TMP1 > /dev/null ; then
6931.28Slukem			printf "\nUudecode is setuid.\n" >> $ERR
6941.15Smrg		fi
6951.15Smrg
6961.67Slukem		file=$work_dir/setuid
6971.67Slukem		migrate_file "$backup_dir/setuid" "$file"
6981.67Slukem		CUR=${file}.current
6991.67Slukem		BACK=${file}.backup
7001.15Smrg		if [ -s $CUR ] ; then
7011.15Smrg			if cmp -s $CUR $TMP1 ; then
7021.15Smrg				:
7031.15Smrg			else
7041.15Smrg				> $TMP2
7051.15Smrg				join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
7061.15Smrg				if [ -s $OUTPUT ] ; then
7071.28Slukem					printf "Setuid additions:\n" >> $ERR
7081.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7091.28Slukem					printf "\n" >> $ERR
7101.15Smrg				fi
7111.15Smrg
7121.15Smrg				join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
7131.15Smrg				if [ -s $OUTPUT ] ; then
7141.28Slukem					printf "Setuid deletions:\n" >> $ERR
7151.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7161.28Slukem					printf "\n" >> $ERR
7171.15Smrg				fi
7181.15Smrg
7191.20Smycroft				sort -k10 $TMP2 $CUR $TMP1 | \
7201.27Slukem				    sed -e 's/[	 ][	 ]*/ /g' | \
7211.27Slukem				    uniq -u > $OUTPUT
7221.15Smrg				if [ -s $OUTPUT ] ; then
7231.28Slukem					printf "Setuid changes:\n" >> $ERR
7241.28Slukem					column -t $OUTPUT >> $ERR
7251.28Slukem					printf "\n" >> $ERR
7261.15Smrg				fi
7271.9Scgd
7281.52Satatat				backup_file update $TMP1 $CUR $BACK
7291.9Scgd			fi
7301.15Smrg		else
7311.28Slukem			printf "Setuid additions:\n" >> $ERR
7321.28Slukem			column -t $TMP1 >> $ERR
7331.28Slukem			printf "\n" >> $ERR
7341.52Satatat			backup_file add $TMP1 $CUR $BACK
7351.9Scgd		fi
7361.15Smrg	fi
7371.15Smrg
7381.27Slukem	# Check for block and character disk devices that are readable or
7391.80Swiz	# writable or not owned by root.operator.
7401.15Smrg	>$TMP1
7411.61Slukem	DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \
7421.57Ssimonb	    sd se ss uk up vnd wd xd xy"
7431.27Slukem#	DISKLIST="$DISKLIST ct mt st wt"
7441.15Smrg	for i in $DISKLIST; do
7451.15Smrg		egrep "^b.*/${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
7461.15Smrg		egrep "^c.*/r${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
7471.15Smrg	done
7481.15Smrg
7491.15Smrg	awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
7501.25Slukem		{ printf "Disk %s is user %s, group %s, permissions %s.\n", \
7511.25Slukem		    $11, $3, $4, $1; }' < $TMP1 > $OUTPUT
7521.15Smrg	if [ -s $OUTPUT ] ; then
7531.28Slukem		printf "\nChecking disk ownership and permissions.\n" >> $ERR
7541.28Slukem		cat $OUTPUT >> $ERR
7551.28Slukem		printf "\n" >> $ERR
7561.9Scgd	fi
7571.9Scgd
7581.15Smrg	# Display any changes in the device file list.
7591.20Smycroft	egrep '^[bc]' $LIST | sort -k11 > $TMP1
7601.15Smrg	if [ -s $TMP1 ] ; then
7611.67Slukem		file=$work_dir/device
7621.67Slukem		migrate_file "$backup_dir/device" "$file"
7631.67Slukem		CUR=${file}.current
7641.67Slukem		BACK=${file}.backup
7651.15Smrg
7661.15Smrg		if [ -s $CUR ] ; then
7671.15Smrg			if cmp -s $CUR $TMP1 ; then
7681.15Smrg				:
7691.15Smrg			else
7701.15Smrg				> $TMP2
7711.15Smrg				join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
7721.15Smrg				if [ -s $OUTPUT ] ; then
7731.28Slukem					printf "Device additions:\n" >> $ERR
7741.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7751.28Slukem					printf "\n" >> $ERR
7761.15Smrg				fi
7771.15Smrg
7781.15Smrg				join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
7791.15Smrg				if [ -s $OUTPUT ] ; then
7801.28Slukem					printf "Device deletions:\n" >> $ERR
7811.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7821.28Slukem					printf "\n" >> $ERR
7831.15Smrg				fi
7841.15Smrg
7851.27Slukem				# Report any block device change. Ignore
7861.27Slukem				# character devices, only the name is
7871.27Slukem				# significant.
7881.15Smrg				cat $TMP2 $CUR $TMP1 | \
7891.27Slukem				    sed -e '/^c/d' | \
7901.27Slukem				    sort -k11 | \
7911.27Slukem				    sed -e 's/[	 ][	 ]*/ /g' | \
7921.27Slukem				    uniq -u > $OUTPUT
7931.15Smrg				if [ -s $OUTPUT ] ; then
7941.28Slukem					printf "Block device changes:\n" >> $ERR
7951.28Slukem					column -t $OUTPUT >> $ERR
7961.28Slukem					printf "\n" >> $ERR
7971.15Smrg				fi
7981.9Scgd
7991.52Satatat				backup_file update $TMP1 $CUR $BACK
8001.9Scgd			fi
8011.15Smrg		else
8021.28Slukem			printf "Device additions:\n" >> $ERR
8031.28Slukem			column -t $TMP1 >> $ERR
8041.28Slukem			printf "\n" >> $ERR
8051.52Satatat			backup_file add $TMP1 $CUR $BACK >> $ERR
8061.9Scgd		fi
8071.28Slukem	fi
8081.28Slukem	if [ -s $ERR ] ; then
8091.28Slukem		printf "\nChecking setuid files and devices:\n"
8101.28Slukem		cat $ERR
8111.28Slukem		printf "\n"
8121.9Scgd	fi
8131.9Scgdfi
8141.9Scgd
8151.9Scgd# Check special files.
8161.9Scgd# Check system binaries.
8171.9Scgd#
8181.9Scgd# Create the mtree tree specifications using:
8191.67Slukem#	mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure
8201.38Skleink#	chown root:wheel DIR.secure
8211.67Slukem#	chmod u+r,go= DIR.secure
8221.9Scgd#
8231.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as
8241.9Scgd# the hacker can modify the tree specification to match the replaced binary.
8251.9Scgd# For details on really protecting yourself against modified binaries, see
8261.9Scgd# the mtree(8) manual page.
8271.32Slukem#
8281.31Slukemif checkyesno check_mtree; then
8291.82Sjhawk	if checkyesno check_mtree_follow_symlinks; then
8301.82Sjhawk		check_mtree_flags="-L"
8311.82Sjhawk	else
8321.82Sjhawk		check_mtree_flags=""
8331.82Sjhawk	fi
8341.91Slukem	mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 |
8351.87Sjhawk		grep -v '^mtree: dev/tty: Device not configured$' >&2
8361.15Smrg	if [ -s $OUTPUT ]; then
8371.9Scgd		printf "\nChecking special files and directories.\n"
8381.9Scgd		cat $OUTPUT
8391.9Scgd	fi
8401.9Scgd
8411.16Smikel	for file in /etc/mtree/*.secure; do
8421.16Smikel		[ $file = '/etc/mtree/*.secure' ] && continue
8431.9Scgd		tree=`sed -n -e '3s/.* //p' -e 3q $file`
8441.82Sjhawk		mtree $check_mtree_flags -f $file -p $tree > $TMP1
8451.9Scgd		if [ -s $TMP1 ]; then
8461.67Slukem			printf "\nChecking $tree:\n"
8471.67Slukem			cat $TMP1
8481.9Scgd		fi
8491.67Slukem	done > $OUTPUT
8501.15Smrg	if [ -s $OUTPUT ]; then
8511.9Scgd		printf "\nChecking system binaries:\n"
8521.9Scgd		cat $OUTPUT
8531.9Scgd	fi
8541.9Scgdfi
8551.9Scgd
8561.32Slukem# Backup disklabels of available disks
8571.32Slukem#
8581.32Slukemif checkyesno check_disklabels; then
8591.67Slukem		# migrate old disklabels
8601.67Slukem	for file in `ls -1d $backup_dir/$backup_dir/disklabel.* \
8611.67Slukem	    $backup_dir/disklabel.* 2>/dev/null`; do
8621.67Slukem		migrate_file "$file" "$work_dir/${file##*/}"
8631.67Slukem	done
8641.67Slukem
8651.103Stron		# generate list of old disklabels, fdisks & wedges and remove them
8661.103Stron	ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
8671.52Satatat	    egrep -v '\.(backup|current)(,v)?$' > $LABELS
8681.32Slukem	xargs rm < $LABELS
8691.32Slukem
8701.103Stron		# generate disklabels of all disks excluding:	cd dk fd md st
8711.103Stron	disks=`iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|dk|st|nfs/ { print $1; }'`
8721.32Slukem	for i in $disks; do
8731.67Slukem		disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null
8741.32Slukem	done
8751.32Slukem
8761.67Slukem		# if fdisk is available, generate fdisks for:	ed ld sd wd
8771.67Slukem	if [ -x /sbin/fdisk ]; then
8781.67Slukem		disks=`iostat -x| awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }'`
8791.67Slukem		for i in $disks; do
8801.67Slukem			/sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null
8811.67Slukem		done
8821.67Slukem	fi
8831.67Slukem
8841.103Stron		# if dkctl is available, generate dkctl listwedges for:	ed ld sd wd cgd ofdisk ra rl raid
8851.103Stron	if [ -x /sbin/dkctl ]; then
8861.103Stron		disks=`iostat -x| awk 'NR > 1 && $1 ~ /^[elsw]d|cgd|ofdisk|r[al]|raid/ { print $1; }'`
8871.103Stron		for i in $disks; do
8881.103Stron			/sbin/dkctl $i listwedges > "$work_dir/wedges.$i" 2>/dev/null
8891.103Stron		done
8901.103Stron	fi
8911.103Stron
8921.103Stron		# append list of new disklabels, fdisks and wedges
8931.103Stron	ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
8941.52Satatat	    egrep -v '\.(backup|current)(,v)?$' >> $LABELS
8951.62Satatat	CHANGELIST="$LABELS $CHANGELIST"
8961.62Satatatfi
8971.62Satatat
8981.62Satatat# Check for changes in the list of installed pkgs
8991.62Satatat#
9001.65Slukemif checkyesno check_pkgs && [ -d $pkgdb_dir ]; then
9011.67Slukem	pkgs=$work_dir/pkgs
9021.67Slukem	migrate_file "$backup_dir/pkgs" "$pkgs"
9031.65Slukem	(	cd $pkgdb_dir
9041.104Sadrianp		$pkg_info | sort
9051.62Satatat		echo ""
9061.62Satatat		find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 |
9071.72Slukem			xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,'
9081.62Satatat	 ) > $pkgs
9091.67Slukem	echo "$pkgs" > $PKGS
9101.62Satatat	CHANGELIST="$PKGS $CHANGELIST"
9111.32Slukemfi
9121.32Slukem
9131.67Slukem# List of files that get backed up and checked for any modifications.
9141.9Scgd# Any changes cause the files to rotate.
9151.32Slukem#
9161.67Slukemif checkyesno check_changelist ; then
9171.91Slukem	mtree -D -k type -f $SPECIALSPEC -E exclude |
9181.91Slukem	    sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES
9191.67Slukem
9201.75Slukem	(
9211.68Slukem		# Add other files which might dynamically exist:
9221.67Slukem		#	/etc/ifconfig.*
9231.67Slukem		#	/etc/raid*.conf
9241.68Slukem		#	/etc/rc.d/*
9251.67Slukem		#	/etc/rc.conf.d/*
9261.68Slukem		#
9271.75Slukem		echo "/etc/ifconfig.*"
9281.75Slukem		echo "/etc/raid*.conf"
9291.75Slukem		echo "/etc/rc.d/*"
9301.75Slukem		echo "/etc/rc.conf.d/*"
9311.67Slukem
9321.68Slukem		# Add /etc/changelist
9331.68Slukem		#
9341.75Slukem		if [ -s /etc/changelist ]; then
9351.75Slukem			grep -v '^#' /etc/changelist
9361.75Slukem		fi
9371.75Slukem	) | while read file; do
9381.75Slukem		case "$file" in
9391.75Slukem		*[\*\?\[]*)	# If changelist line is a glob ...
9401.75Slukem				# ... expand possible backup files
9411.75Slukem				#
9421.75Slukem			ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \
9431.75Slukem			    | sed "s,^$backup_dir/,, ; s,\.current$,,"
9441.75Slukem				
9451.75Slukem				# ... expand possible files
9461.75Slukem				#
9471.75Slukem			ls -1d $(echo $file) 2>/dev/null
9481.75Slukem			;;
9491.75Slukem		*)
9501.75Slukem				# Otherwise, just print the filename
9511.75Slukem			echo $file
9521.75Slukem			;;
9531.75Slukem		esac
9541.75Slukem	done >> $CHANGEFILES
9551.67Slukem	CHANGELIST="$CHANGEFILES $CHANGELIST"
9561.67Slukemfi
9571.67Slukem
9581.67Slukem# Special case backups, including the master password file and
9591.67Slukem# ssh private host keys. The normal backup mechanisms for
9601.67Slukem# $check_changelist (see below) also print out the actual file
9611.67Slukem# differences and we don't want to do that for these files
9621.67Slukem#
9631.67Slukemecho $MP > $TMP1			# always add /etc/master.passwd
9641.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff |
9651.91Slukem    sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1
9661.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2
9671.68Slukem
9681.69Slukemwhile read file; do
9691.67Slukem	backup_and_diff "$file" no
9701.69Slukemdone < $TMP2
9711.67Slukem
9721.32Slukem
9731.32Slukemif [ -n "$CHANGELIST" ]; then
9741.73Slukem	grep -h -v '^$' $CHANGELIST | sort -u > $TMP1
9751.68Slukem	comm -23 $TMP1 $TMP2 | while read file; do
9761.67Slukem		backup_and_diff "$file" yes
9771.9Scgd	done
9781.44Sadfi
9791.44Sad
9801.44Sadif [ -f /etc/security.local ]; then
9811.90Skim	. /etc/security.local > $OUTPUT 2>&1
9821.84Sjhawk	if [ -s $OUTPUT ] ; then
9831.84Sjhawk		printf "\nRunning /etc/security.local:\n"
9841.84Sjhawk		cat $OUTPUT
9851.84Sjhawk	fi
9861.9Scgdfi
987