security revision 1.108
11.1Scgd#!/bin/sh -
21.1Scgd#
31.108Sjmmv#	$NetBSD: security,v 1.108 2010/02/05 16:29:02 jmmv 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.67Slukemmax_loginlen=${max_loginlen:-8}
291.67Slukemmax_grouplen=${max_grouplen:-8}
301.104Sadrianppkg_info=${pkg_info:-/usr/sbin/pkg_info}
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.102SmarttiSECUREDIR=$(mktemp -d -t _securedir) || 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.106ShaadLVM_LABELS=lvm.$$
611.91SlukemPKGS=pkgs.$$
621.91SlukemCHANGEFILES=changefiles.$$
631.91SlukemSPECIALSPEC=specialspec.$$
641.67Slukem
651.108Sjmmvif [ -n "${pkgdb_dir}" ]; then
661.108Sjmmv    echo "WARNING: Setting pkgdb_dir in security.conf(5) is deprecated"
671.108Sjmmv    echo "WARNING: Please define PKG_DBDIR in pkg_install.conf(5) instead"
681.108Sjmmv    _compat_K_flag="-K ${pkgdb_dir}"
691.108Sjmmvfi
701.108Sjmmv
711.108Sjmmvhave_pkgs() {
721.108Sjmmv	$pkg_info ${_compat_K_flag} -q -E '*'
731.108Sjmmv}
741.108Sjmmv
751.67Slukem# migrate_file old new
761.67Slukem#	Determine if the "${old}" path name needs to be migrated to the
771.67Slukem#	"${new}" path. Also checks if "${old}.current" needs migrating,
781.67Slukem#	and if so, migrate it and possibly "${old}.current,v" and
791.67Slukem#	"${old}.backup".
801.67Slukem#
811.67Slukemmigrate_file()
821.67Slukem{
831.67Slukem	_old=$1
841.67Slukem	_new=$2
851.67Slukem	if [ -z "$_old" -o -z "$_new" ]; then
861.67Slukem		err 3 "USAGE: migrate_file old new"
871.67Slukem	fi
881.67Slukem	if [ ! -d "${_new%/*}" ]; then
891.67Slukem		mkdir -p "${_new%/*}"
901.67Slukem	fi
911.67Slukem	if [ -f "${_old}" -a ! -f "${_new}" ]; then
921.67Slukem		echo "==> migrating ${_old}"
931.67Slukem		echo "           to ${_new}"
941.67Slukem		mv "${_old}" "${_new}"
951.67Slukem	fi
961.67Slukem	if [ -f "${_old}.current" -a ! -f "${_new}.current" ]; then
971.67Slukem		echo "==> migrating ${_old}.current"
981.67Slukem		echo "           to ${_new}.current"
991.67Slukem		mv "${_old}.current" "${_new}.current"
1001.67Slukem		if [ -f "${_old}.current,v" -a ! -f "${_new}.current,v" ]; then
1011.67Slukem			echo "==> migrating ${_old}.current,v"
1021.67Slukem			echo "           to ${_new}.current,v"
1031.67Slukem			mv "${_old}.current,v" "${_new}.current,v"
1041.67Slukem		fi
1051.67Slukem		if [ -f "${_old}.backup" -a ! -f "${_new}.backup" ]; then
1061.67Slukem			echo "==> migrating ${_old}.backup"
1071.67Slukem			echo "           to ${_new}.backup"
1081.67Slukem			mv "${_old}.backup" "${_new}.backup"
1091.67Slukem		fi
1101.67Slukem	fi
1111.67Slukem}
1121.67Slukem
1131.67Slukem
1141.67Slukem# backup_and_diff file printdiff
1151.67Slukem#	Determine if file needs backing up, and if so, do it.
1161.67Slukem#	If printdiff is yes, display the diffs, otherwise 
1171.67Slukem#	just print a message saying "[changes omitted]".
1181.67Slukem#
1191.67Slukembackup_and_diff()
1201.67Slukem{
1211.67Slukem	_file=$1
1221.67Slukem	_printdiff=$2
1231.67Slukem	if [ -z "$_file" -o -z "$_printdiff" ]; then
1241.67Slukem		err 3 "USAGE: backup_and_diff file printdiff"
1251.67Slukem	fi
1261.67Slukem	! checkyesno _printdiff
1271.67Slukem	_printdiff=$?
1281.67Slukem
1291.67Slukem	_old=$backup_dir/${_file##*/}
1301.67Slukem	case "$_file" in
1311.67Slukem	$work_dir/*)
1321.67Slukem		_new=$_file
1331.67Slukem		migrate_file "$backup_dir/$_old" "$_new"
1341.67Slukem		migrate_file "$_old" "$_new"
1351.67Slukem		;;
1361.67Slukem	*)
1371.67Slukem		_new=$backup_dir/$_file
1381.67Slukem		migrate_file "$_old" "$_new"
1391.67Slukem		;;
1401.67Slukem	esac
1411.67Slukem	CUR=${_new}.current
1421.67Slukem	BACK=${_new}.backup
1431.67Slukem	if [ -f $_file ]; then
1441.67Slukem		if [ -f $CUR ] ; then
1451.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1461.83Sjhawk				diff ${diff_options} $CUR $_file > $OUTPUT
1471.67Slukem			else
1481.67Slukem				if ! cmp -s $CUR $_file; then
1491.67Slukem					echo "[changes omitted]"
1501.67Slukem				fi > $OUTPUT
1511.67Slukem			fi
1521.67Slukem			if [ -s $OUTPUT ] ; then
1531.67Slukem				printf \
1541.67Slukem			"\n======\n%s diffs (OLD < > NEW)\n======\n" $_file
1551.67Slukem				cat $OUTPUT
1561.67Slukem				backup_file update $_file $CUR $BACK
1571.67Slukem			fi
1581.67Slukem		else
1591.67Slukem			printf "\n======\n%s added\n======\n" $_file
1601.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1611.83Sjhawk				diff ${diff_options} /dev/null $_file
1621.67Slukem			else
1631.67Slukem				echo "[changes omitted]"
1641.67Slukem			fi
1651.67Slukem			backup_file add $_file $CUR $BACK
1661.67Slukem		fi
1671.67Slukem	else
1681.67Slukem		if [ -f $CUR ]; then
1691.67Slukem			printf "\n======\n%s removed\n======\n" $_file
1701.67Slukem			if [ "$_printdiff" -ne 0 ]; then
1711.83Sjhawk				diff ${diff_options} $CUR /dev/null
1721.67Slukem			else
1731.67Slukem				echo "[changes omitted]"
1741.67Slukem			fi
1751.67Slukem			backup_file remove $_file $CUR $BACK
1761.67Slukem		fi
1771.67Slukem	fi
1781.67Slukem}
1791.48Sabs
1801.9Scgd
1811.67Slukem# These are used several times.
1821.67Slukem#
1831.91Slukemawk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID
1841.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH
1851.91Slukemfor file in $special_files; do
1861.91Slukem	[ -s $file ] && cat $file
1871.91Slukemdone | mtree -CM -k all > $SPECIALSPEC || exit 1
1881.9Scgd
1891.67Slukem
1901.9Scgd# Check the master password file syntax.
1911.32Slukem#
1921.31Slukemif checkyesno check_passwd; then
1931.85Sjhawk        # XXX: the sense of permit_star is reversed; the code works as
1941.85Sjhawk        # implemented, but usage needs to be negated.
1951.81Sjhawk	checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1
1961.94Sjdolecek	checkyesno check_passwd_permit_nonalpha \
1971.94Sjdolecek		 && permit_nonalpha=1 || permit_nonalpha=0
1981.94Sjdolecek
1991.81Sjhawk	awk -v "len=$max_loginlen" \
2001.81Sjhawk	    -v "nowarn_shells_list=$check_passwd_nowarn_shells" \
2011.81Sjhawk	    -v "nowarn_users_list=$check_passwd_nowarn_users" \
2021.94Sjdolecek	    -v "permit_star=$permit_star" \
2031.94Sjdolecek	    -v "permit_nonalpha=$permit_nonalpha" \
2041.94Sjdolecek	'
2051.25Slukem	BEGIN {
2061.25Slukem		while ( getline < "/etc/shells" > 0 ) {
2071.39Shubertf			if ($0 ~ /^\#/ || $0 ~ /^$/ )
2081.25Slukem				continue;
2091.25Slukem			shells[$1]++;
2101.25Slukem		}
2111.81Sjhawk		split(nowarn_shells_list, a);
2121.81Sjhawk		for (i in a) nowarn_shells[a[i]]++;
2131.81Sjhawk		split(nowarn_users_list, a);
2141.81Sjhawk		for (i in a) nowarn_users[a[i]]++;
2151.81Sjhawk		uid0_users_list="root toor"
2161.81Sjhawk		split(uid0_users_list, a);
2171.81Sjhawk		for (i in a) uid0_users[a[i]]++;
2181.25Slukem		FS=":";
2191.25Slukem	}
2201.25Slukem
2211.25Slukem	{
2221.15Smrg		if ($0 ~ /^[	 ]*$/) {
2231.25Slukem			printf "Line %d is a blank line.\n", NR;
2241.15Smrg			next;
2251.15Smrg		}
2261.105Sdholland
2271.105Sdholland		# NIS compat entry?
2281.105Sdholland		compatline = $1 ~ "^[\\+-]";
2291.105Sdholland		if (compatline) {
2301.105Sdholland			if ($1 == "+" && NF == 1) {
2311.105Sdholland				next;
2321.105Sdholland			}
2331.105Sdholland			sub("^.", "", $1);
2341.105Sdholland		}
2351.105Sdholland		if (NF != 10)
2361.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
2371.105Sdholland		if (compatline)  {
2381.105Sdholland			if ($3 == 0)
2391.81Sjhawk			    printf "Line %d includes entries with uid 0.\n",
2401.81Sjhawk			        NR;
2411.105Sdholland			if ($1 == "")
2421.105Sdholland			    next;
2431.34Sabs		}
2441.94Sjdolecek		if (!permit_nonalpha &&
2451.95Speter		    $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
2461.25Slukem			printf "Login %s has non-alphanumeric characters.\n",
2471.25Slukem			    $1;
2481.34Sabs		if (length($1) > len)
2491.81Sjhawk			printf "Login %s has more than "len" characters.\n",
2501.81Sjhawk			    $1;
2511.105Sdholland		if ($2 == "" && !compatline && !nowarn_users[$1])
2521.81Sjhawk			    printf "Login %s has no password.\n", $1;
2531.81Sjhawk		if (!nowarn_shells[$10] && !nowarn_users[$1]) {
2541.81Sjhawk		    if (length($2) != 13 &&
2551.81Sjhawk		    	length($2) != 20 &&
2561.81Sjhawk		    	$2 !~ /^\$1/ &&
2571.81Sjhawk		    	$2 !~ /^\$2/ &&
2581.99Sjmcneill			$2 !~ /^\$sha1/ &&
2591.81Sjhawk		    	$2 != "" &&
2601.81Sjhawk			(permit_star || $2 != "*") &&
2611.81Sjhawk		    	$2 !~ /^\*[A-z-]+$/ &&
2621.81Sjhawk			$1 != "toor") {
2631.81Sjhawk		    	    if ($10 == "" || shells[$10])
2641.81Sjhawk				printf "Login %s is off but still has "\
2651.81Sjhawk				  "a valid shell (%s)\n", $1, $10;
2661.105Sdholland		    } else if (compatline && $10 == "") {
2671.105Sdholland			    # nothing
2681.81Sjhawk		    } else if (! shells[$10])
2691.81Sjhawk		    	    printf "Login %s does not have a valid "\
2701.81Sjhawk			    "shell (%s)\n", $1, $10;
2711.81Sjhawk		}
2721.81Sjhawk		if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1])
2731.25Slukem			printf "Login %s has a user id of 0.\n", $1;
2741.105Sdholland		if ($3 != "" && $3 < 0)
2751.25Slukem			printf "Login %s has a negative user id.\n", $1;
2761.105Sdholland		if ($4 != "" && $4 < 0)
2771.25Slukem			printf "Login %s has a negative group id.\n", $1;
2781.15Smrg	}' < $MP > $OUTPUT
2791.15Smrg	if [ -s $OUTPUT ] ; then
2801.15Smrg		printf "\nChecking the $MP file:\n"
2811.15Smrg		cat $OUTPUT
2821.15Smrg	fi
2831.15Smrg
2841.15Smrg	awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
2851.15Smrg	if [ -s $OUTPUT ] ; then
2861.15Smrg		printf "\n$MP has duplicate user names.\n"
2871.15Smrg		column $OUTPUT
2881.15Smrg	fi
2891.15Smrg
2901.37Swrstuden# To not exclude 'toor', a standard duplicate root account, from the duplicate
2911.37Swrstuden# account test, uncomment the line below (without egrep in it)and comment
2921.37Swrstuden# out the line (with egrep in it) below it.
2931.37Swrstuden#
2941.37Swrstuden#	< $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2
2951.36Swrstuden	< $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2
2961.15Smrg	if [ -s $TMP2 ] ; then
2971.15Smrg		printf "\n$MP has duplicate user id's.\n"
2981.15Smrg		while read uid; do
2991.28Slukem			grep -w $uid $MPBYUID
3001.15Smrg		done < $TMP2 | column
3011.15Smrg	fi
3021.9Scgdfi
3031.9Scgd
3041.9Scgd# Check the group file syntax.
3051.32Slukem#
3061.31Slukemif checkyesno check_group; then
3071.15Smrg	GRP=/etc/group
3081.49Sjdolecek	awk -F: -v "len=$max_grouplen" '{
3091.15Smrg		if ($0 ~ /^[	 ]*$/) {
3101.25Slukem			printf "Line %d is a blank line.\n", NR;
3111.15Smrg			next;
3121.15Smrg		}
3131.34Sabs		if (NF != 4 && ($1 != "+" || NF != 1))
3141.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
3151.34Sabs		if ($1 == "+" )  {
3161.34Sabs			next;
3171.34Sabs		}
3181.95Speter		if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
3191.25Slukem			printf "Group %s has non-alphanumeric characters.\n",
3201.25Slukem			    $1;
3211.49Sjdolecek		if (length($1) > len)
3221.49Sjdolecek			printf "Group %s has more than "len" characters.\n", $1;
3231.15Smrg		if ($3 !~ /[0-9]*/)
3241.25Slukem			printf "Login %s has a negative group id.\n", $1;
3251.15Smrg	}' < $GRP > $OUTPUT
3261.15Smrg	if [ -s $OUTPUT ] ; then
3271.15Smrg		printf "\nChecking the $GRP file:\n"
3281.15Smrg		cat $OUTPUT
3291.15Smrg	fi
3301.15Smrg
3311.15Smrg	awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
3321.15Smrg	if [ -s $OUTPUT ] ; then
3331.15Smrg		printf "\n$GRP has duplicate group names.\n"
3341.15Smrg		column $OUTPUT
3351.15Smrg	fi
3361.9Scgdfi
3371.9Scgd
3381.9Scgd# Check for root paths, umask values in startup files.
3391.9Scgd# The check for the root paths is problematical -- it's likely to fail
3401.9Scgd# in other environments.  Once the shells have been modified to warn
3411.9Scgd# of '.' in the path, the path tests should go away.
3421.32Slukem#
3431.31Slukemif checkyesno check_rootdotfiles; then
3441.67Slukem	rhome=~root
3451.15Smrg	umaskset=no
3461.15Smrg	list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
3471.15Smrg	for i in $list ; do
3481.15Smrg		if [ -f $i ] ; then
3491.67Slukem			if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ;
3501.67Slukem			then
3511.15Smrg				umaskset=yes
3521.15Smrg			fi
3531.63Slukem			# Double check the umask value itself; ensure that
3541.67Slukem			# both the group and other write bits are set.
3551.67Slukem			#
3561.45Ssommerfe			egrep '^[ \t]*umask[ \t]+[0-7]+' $i |
3571.63Slukem			awk '{
3581.67Slukem				if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) {
3591.80Swiz					print "\tRoot umask is group writable"
3601.63Slukem				}
3611.67Slukem				if ($2 ~ /[^2367]$/) {
3621.80Swiz					print "\tRoot umask is other writable"
3631.63Slukem			    	}
3641.67Slukem			    }' | sort -u
3651.26Slukem			SAVE_PATH=$PATH
3661.26Slukem			unset PATH
3671.15Smrg			/bin/csh -f -s << end-of-csh > /dev/null 2>&1
3681.15Smrg				source $i
3691.15Smrg				/bin/ls -ldgT \$path > $TMP1
3701.9Scgdend-of-csh
3711.76Satatat			export PATH=$SAVE_PATH
3721.15Smrg			awk '{
3731.15Smrg				if ($10 ~ /^\.$/) {
3741.27Slukem					print "\tThe root path includes .";
3751.15Smrg					next;
3761.15Smrg				}
3771.15Smrg			     }
3781.15Smrg			     $1 ~ /^d....w/ \
3791.80Swiz		{ print "\tRoot path directory " $10 " is group writable." } \
3801.15Smrg			     $1 ~ /^d.......w/ \
3811.80Swiz		{ print "\tRoot path directory " $10 " is other writable." }' \
3821.67Slukem			< $TMP1
3831.15Smrg		fi
3841.67Slukem	done > $OUTPUT
3851.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
3861.27Slukem		printf "\nChecking root csh paths, umask values:\n$list\n\n"
3871.15Smrg		if [ -s $OUTPUT ]; then
3881.15Smrg			cat $OUTPUT
3891.15Smrg		fi
3901.15Smrg		if [ $umaskset = "no" ] ; then
3911.27Slukem		    printf "\tRoot csh startup files do not set the umask.\n"
3921.15Smrg		fi
3931.9Scgd	fi
3941.9Scgd
3951.15Smrg	umaskset=no
3961.23Slukem	list="/etc/profile ${rhome}/.profile"
3971.15Smrg	for i in $list; do
3981.15Smrg		if [ -f $i ] ; then
3991.15Smrg			if egrep umask $i > /dev/null ; then
4001.15Smrg				umaskset=yes
4011.15Smrg			fi
4021.15Smrg			egrep umask $i |
4031.67Slukem			awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \
4041.80Swiz				{ print "\tRoot umask is group writable" } \
4051.67Slukem			     $2 ~ /[^2367]$/ \
4061.80Swiz				{ print "\tRoot umask is other writable" }'
4071.26Slukem			SAVE_PATH=$PATH
4081.26Slukem			unset PATH
4091.15Smrg			/bin/sh << end-of-sh > /dev/null 2>&1
4101.15Smrg				. $i
4111.26Slukem				list=\`echo \$PATH | /usr/bin/sed -e \
4121.26Slukem				    's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\`
4131.15Smrg				/bin/ls -ldgT \$list > $TMP1
4141.9Scgdend-of-sh
4151.76Satatat			export PATH=$SAVE_PATH
4161.15Smrg			awk '{
4171.15Smrg				if ($10 ~ /^\.$/) {
4181.27Slukem					print "\tThe root path includes .";
4191.15Smrg					next;
4201.15Smrg				}
4211.15Smrg			     }
4221.15Smrg			     $1 ~ /^d....w/ \
4231.80Swiz		{ print "\tRoot path directory " $10 " is group writable." } \
4241.15Smrg			     $1 ~ /^d.......w/ \
4251.80Swiz		{ print "\tRoot path directory " $10 " is other writable." }' \
4261.67Slukem			< $TMP1
4271.9Scgd
4281.15Smrg		fi
4291.67Slukem	done > $OUTPUT
4301.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
4311.15Smrg		printf "\nChecking root sh paths, umask values:\n$list\n"
4321.15Smrg		if [ -s $OUTPUT ]; then
4331.15Smrg			cat $OUTPUT
4341.15Smrg		fi
4351.15Smrg		if [ $umaskset = "no" ] ; then
4361.27Slukem			printf "\tRoot sh startup files do not set the umask.\n"
4371.15Smrg		fi
4381.9Scgd	fi
4391.9Scgdfi
4401.9Scgd
4411.9Scgd# Root and uucp should both be in /etc/ftpusers.
4421.32Slukem#
4431.31Slukemif checkyesno check_ftpusers; then
4441.28Slukem	list="uucp "`awk '$2 == 0 { print $1 }' $MPBYUID`
4451.27Slukem	for i in $list; do
4461.29Slukem		if /usr/libexec/ftpd -C $i ; then
4471.67Slukem			printf "\t$i is not denied\n"
4481.27Slukem		fi
4491.67Slukem	done > $OUTPUT
4501.28Slukem	if [ -s $OUTPUT ]; then
4511.28Slukem		printf "\nChecking the /etc/ftpusers configuration:\n"
4521.28Slukem		cat $OUTPUT
4531.28Slukem	fi
4541.9Scgdfi
4551.9Scgd
4561.43Sitojun# Uudecode should not be in the /etc/mail/aliases file.
4571.32Slukem#
4581.31Slukemif checkyesno check_aliases; then
4591.43Sitojun	for f in /etc/mail/aliases /etc/aliases; do
4601.43Sitojun		if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then
4611.43Sitojun			printf "\nEntry for uudecode in $f file.\n"
4621.43Sitojun		fi
4631.43Sitojun	done
4641.9Scgdfi
4651.9Scgd
4661.9Scgd# Files that should not have + signs.
4671.32Slukem#
4681.31Slukemif checkyesno check_rhosts; then
4691.15Smrg	list="/etc/hosts.equiv /etc/hosts.lpd"
4701.15Smrg	for f in $list ; do
4711.15Smrg		if [ -f $f ] && egrep '\+' $f > /dev/null ; then
4721.15Smrg			printf "\nPlus sign in $f file.\n"
4731.15Smrg		fi
4741.15Smrg	done
4751.15Smrg
4761.15Smrg	# Check for special users with .rhosts files.  Only root and toor should
4771.16Smikel	# have .rhosts files.  Also, .rhosts files should not have plus signs.
4781.15Smrg	awk -F: '$1 != "root" && $1 != "toor" && \
4791.15Smrg		($3 < 100 || $1 == "ftp" || $1 == "uucp") \
4801.20Smycroft			{ print $1 " " $9 }' $MP |
4811.19Smycroft	sort -k2 |
4821.15Smrg	while read uid homedir; do
4831.15Smrg		if [ -f ${homedir}/.rhosts ] ; then
4841.15Smrg			rhost=`ls -ldgT ${homedir}/.rhosts`
4851.46Schristos			printf -- "$uid: $rhost\n"
4861.15Smrg		fi
4871.15Smrg	done > $OUTPUT
4881.15Smrg	if [ -s $OUTPUT ] ; then
4891.15Smrg		printf "\nChecking for special users with .rhosts files.\n"
4901.15Smrg		cat $OUTPUT
4911.15Smrg	fi
4921.15Smrg
4931.15Smrg	while read uid homedir; do
4941.35Sfair		if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \
4951.41Schristos		    cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then
4961.46Schristos			printf -- "$uid: + in .rhosts file.\n"
4971.15Smrg		fi
4981.29Slukem	done < $MPBYPATH > $OUTPUT
4991.15Smrg	if [ -s $OUTPUT ] ; then
5001.15Smrg		printf "\nChecking .rhosts files syntax.\n"
5011.15Smrg		cat $OUTPUT
5021.15Smrg	fi
5031.9Scgdfi
5041.9Scgd
5051.9Scgd# Check home directories.  Directories should not be owned by someone else
5061.80Swiz# or writable.
5071.32Slukem#
5081.31Slukemif checkyesno check_homes; then
5091.85Sjhawk	checkyesno check_homes_permit_usergroups && \
5101.85Sjhawk		permit_usergroups=1 || permit_usergroups=0
5111.15Smrg	while read uid homedir; do
5121.15Smrg		if [ -d ${homedir}/ ] ; then
5131.15Smrg			file=`ls -ldgT ${homedir}`
5141.46Schristos			printf -- "$uid $file\n"
5151.9Scgd		fi
5161.29Slukem	done < $MPBYPATH |
5171.85Sjhawk	awk -v "usergroups=$permit_usergroups" '
5181.85Sjhawk	     $1 != $4 && $4 != "root" \
5191.15Smrg		{ print "user " $1 " home directory is owned by " $4 }
5201.101Sjnemeth	     $2 ~ /^d....w/ && (!usergroups || $5 != $1) \
5211.80Swiz		{ print "user " $1 " home directory is group writable" }
5221.101Sjnemeth	     $2 ~ /^d.......w/ \
5231.80Swiz		{ print "user " $1 " home directory is other writable" }' \
5241.27Slukem	    > $OUTPUT
5251.15Smrg	if [ -s $OUTPUT ] ; then
5261.15Smrg		printf "\nChecking home directories.\n"
5271.15Smrg		cat $OUTPUT
5281.15Smrg	fi
5291.15Smrg
5301.15Smrg	# Files that should not be owned by someone else or readable.
5311.67Slukem	list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity"
5321.15Smrg	while read uid homedir; do
5331.15Smrg		for f in $list ; do
5341.15Smrg			file=${homedir}/${f}
5351.15Smrg			if [ -f $file ] ; then
5361.46Schristos				printf -- "$uid $f `ls -ldgT $file`\n"
5371.15Smrg			fi
5381.15Smrg		done
5391.29Slukem	done < $MPBYPATH |
5401.85Sjhawk	awk  -v "usergroups=$permit_usergroups" '
5411.85Sjhawk	     $1 != $5 && $5 != "root" \
5421.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
5431.85Sjhawk	     $3 ~ /^-...r/ && (!usergroups || $6 != $1) \
5441.15Smrg		{ print "user " $1 " " $2 " file is group readable" }
5451.15Smrg	     $3 ~ /^-......r/ \
5461.15Smrg		{ print "user " $1 " " $2 " file is other readable" }
5471.85Sjhawk	     $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
5481.80Swiz		{ print "user " $1 " " $2 " file is group writable" }
5491.15Smrg	     $3 ~ /^-.......w/ \
5501.80Swiz		{ print "user " $1 " " $2 " file is other writable" }' \
5511.27Slukem	    > $OUTPUT
5521.15Smrg
5531.80Swiz	# Files that should not be owned by someone else or writable.
5541.19Smycroft	list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \
5551.79Selric	      .cshrc .emacs .exrc .forward .history .k5login .klogin .login \
5561.79Selric	      .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \
5571.79Selric	      .twmrc .xinitrc .xsession .ssh/authorized_keys \
5581.79Selric	      .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \
5591.79Selric	      .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \
5601.79Selric	      .ssh/known_hosts2"
5611.15Smrg	while read uid homedir; do
5621.15Smrg		for f in $list ; do
5631.15Smrg			file=${homedir}/${f}
5641.15Smrg			if [ -f $file ] ; then
5651.46Schristos				printf -- "$uid $f `ls -ldgT $file`\n"
5661.15Smrg			fi
5671.15Smrg		done
5681.29Slukem	done < $MPBYPATH |
5691.85Sjhawk	awk -v "usergroups=$permit_usergroups" '
5701.85Sjhawk	     $1 != $5 && $5 != "root" \
5711.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
5721.85Sjhawk	     $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
5731.80Swiz		{ print "user " $1 " " $2 " file is group writable" }
5741.15Smrg	     $3 ~ /^-.......w/ \
5751.80Swiz		{ print "user " $1 " " $2 " file is other writable" }' \
5761.27Slukem	    >> $OUTPUT
5771.15Smrg	if [ -s $OUTPUT ] ; then
5781.15Smrg		printf "\nChecking dot files.\n"
5791.15Smrg		cat $OUTPUT
5801.15Smrg	fi
5811.9Scgdfi
5821.9Scgd
5831.9Scgd# Mailboxes should be owned by user and unreadable.
5841.32Slukem#
5851.31Slukemif checkyesno check_varmail; then
5861.86Sjhawk	ls -lA /var/mail | \
5871.63Slukem	awk '	NR == 1 { next; }
5881.86Sjhawk		$9 ~ /^\./ {next; }
5891.63Slukem	    	$3 != $9 {
5901.63Slukem			print "user " $9 " mailbox is owned by " $3
5911.63Slukem		}
5921.63Slukem		$1 != "-rw-------" {
5931.63Slukem			print "user " $9 " mailbox is " $1 ", group " $4
5941.63Slukem		}' > $OUTPUT
5951.15Smrg	if [ -s $OUTPUT ] ; then
5961.15Smrg		printf "\nChecking mailbox ownership.\n"
5971.15Smrg		cat $OUTPUT
5981.15Smrg	fi
5991.15Smrgfi
6001.15Smrg
6011.32Slukem# NFS exports shouldn't be globally exported
6021.32Slukem#
6031.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then
6041.32Slukem	awk '{
6051.22Slukem		# ignore comments and blank lines
6061.39Shubertf		if ($0 ~ /^\#/ || $0 ~ /^$/ )
6071.22Slukem			next;
6081.100Stron		# manage line continuation
6091.100Stron		while ($NF ~ /^\\$/) {
6101.100Stron			$NF = "";
6111.100Stron			line = $0 "";
6121.100Stron			getline;
6131.100Stron			$0 = line $0 "";
6141.100Stron		}
6151.22Slukem
6161.100Stron		delete dir;
6171.100Stron		readonly = ndir = 0;
6181.100Stron		for (i = 1; i <= NF; ++i) {
6191.100Stron			if ($i ~ /^\//) dir[ndir++] = $i;
6201.100Stron			else if ($i ~ /^-/) {
6211.100Stron				if ($i ~ /^-(ro|o)$/) readonly = 1;
6221.100Stron				if ($i ~ /^-network/) next;
6231.100Stron			}
6241.100Stron			else next;
6251.15Smrg		}
6261.15Smrg		if (readonly)
6271.100Stron			for (item in dir)
6281.100Stron				rodir[nrodir++] = dir[item];
6291.15Smrg		else
6301.100Stron			for (item in dir)
6311.100Stron				rwdir[nrwdir++] = dir[item];
6321.100Stron
6331.100Stron	}
6341.100Stron
6351.100Stron	END {
6361.100Stron		if (nrodir) {
6371.100Stron			printf("Globally exported file system%s, read-only:\n",
6381.100Stron				nrodir > 1 ? "s" : "");
6391.100Stron			for (item in rodir)
6401.100Stron				printf("\t%s\n", rodir[item]);
6411.100Stron		}
6421.100Stron		if (nrwdir) {
6431.100Stron			printf("Globally exported file system%s, read-write:\n",
6441.100Stron				nrwdir > 1 ? "s" : "");
6451.100Stron			for (item in rwdir)
6461.100Stron				printf("\t%s\n", rwdir[item]);
6471.100Stron		}
6481.32Slukem	}' < /etc/exports > $OUTPUT
6491.32Slukem	if [ -s $OUTPUT ] ; then
6501.15Smrg		printf "\nChecking for globally exported file systems.\n"
6511.15Smrg		cat $OUTPUT
6521.15Smrg	fi
6531.9Scgdfi
6541.9Scgd
6551.9Scgd# Display any changes in setuid files and devices.
6561.32Slukem#
6571.31Slukemif checkyesno check_devices; then
6581.28Slukem	> $ERR
6591.92Serh	(
6601.98Slukem
6611.98Slukem	# Convert check_devices_ignore_fstypes="foo !bar bax"
6621.98Slukem	#    into "-fstype foo -o ! -fstype bar -o -fstype bax"
6631.98Slukem	# and check_devices_ignore_paths="/foo !/bar /bax"
6641.98Slukem	#    into " -path /foo -o ! -path /bar -o -path /bax"
6651.98Slukem	#
6661.98Slukem	ignexpr=$(\
6671.98Slukem	    echo $check_devices_ignore_fstypes | \
6681.98Slukem		sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \
6691.98Slukem	    echo $check_devices_ignore_paths | \
6701.98Slukem		sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \
6711.98Slukem	)
6721.98Slukem
6731.98Slukem	# Massage the expression into ( $ignexpr ) -a -prune -o
6741.98Slukem	if [ -n "${ignexpr}" ]; then
6751.98Slukem		ignexpr=$(\
6761.98Slukem			echo $ignexpr | \
6771.98Slukem			    sed -e 's/^-o /( /' \
6781.98Slukem				-e 's/$/ ) -a -prune -o/' \
6791.98Slukem		)
6801.98Slukem	fi
6811.98Slukem
6821.98Slukem	find / $ignexpr \
6831.21Smycroft	    \( \( -perm -u+s -a ! -type d \) -o \
6841.21Smycroft	       \( -perm -g+s -a ! -type d \) -o \
6851.24Slukem	       -type b -o -type c \) -print0 | \
6861.98Slukem	xargs -0 ls -ldgTq | sort +9 > $LIST
6871.98Slukem
6881.98Slukem	) 2> $OUTPUT
6891.15Smrg
6901.15Smrg	# Display any errors that occurred during system file walk.
6911.15Smrg	if [ -s $OUTPUT ] ; then
6921.28Slukem		printf "Setuid/device find errors:\n" >> $ERR
6931.28Slukem		cat $OUTPUT >> $ERR
6941.28Slukem		printf "\n" >> $ERR
6951.15Smrg	fi
6961.15Smrg
6971.15Smrg	# Display any changes in the setuid file list.
6981.15Smrg	egrep -v '^[bc]' $LIST > $TMP1
6991.15Smrg	if [ -s $TMP1 ] ; then
7001.15Smrg		# Check to make sure uudecode isn't setuid.
7011.15Smrg		if grep -w uudecode $TMP1 > /dev/null ; then
7021.28Slukem			printf "\nUudecode is setuid.\n" >> $ERR
7031.15Smrg		fi
7041.15Smrg
7051.67Slukem		file=$work_dir/setuid
7061.67Slukem		migrate_file "$backup_dir/setuid" "$file"
7071.67Slukem		CUR=${file}.current
7081.67Slukem		BACK=${file}.backup
7091.15Smrg		if [ -s $CUR ] ; then
7101.15Smrg			if cmp -s $CUR $TMP1 ; then
7111.15Smrg				:
7121.15Smrg			else
7131.15Smrg				> $TMP2
7141.15Smrg				join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
7151.15Smrg				if [ -s $OUTPUT ] ; then
7161.28Slukem					printf "Setuid additions:\n" >> $ERR
7171.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7181.28Slukem					printf "\n" >> $ERR
7191.15Smrg				fi
7201.15Smrg
7211.15Smrg				join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
7221.15Smrg				if [ -s $OUTPUT ] ; then
7231.28Slukem					printf "Setuid deletions:\n" >> $ERR
7241.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7251.28Slukem					printf "\n" >> $ERR
7261.15Smrg				fi
7271.15Smrg
7281.20Smycroft				sort -k10 $TMP2 $CUR $TMP1 | \
7291.27Slukem				    sed -e 's/[	 ][	 ]*/ /g' | \
7301.27Slukem				    uniq -u > $OUTPUT
7311.15Smrg				if [ -s $OUTPUT ] ; then
7321.28Slukem					printf "Setuid changes:\n" >> $ERR
7331.28Slukem					column -t $OUTPUT >> $ERR
7341.28Slukem					printf "\n" >> $ERR
7351.15Smrg				fi
7361.9Scgd
7371.52Satatat				backup_file update $TMP1 $CUR $BACK
7381.9Scgd			fi
7391.15Smrg		else
7401.28Slukem			printf "Setuid additions:\n" >> $ERR
7411.28Slukem			column -t $TMP1 >> $ERR
7421.28Slukem			printf "\n" >> $ERR
7431.52Satatat			backup_file add $TMP1 $CUR $BACK
7441.9Scgd		fi
7451.15Smrg	fi
7461.15Smrg
7471.27Slukem	# Check for block and character disk devices that are readable or
7481.80Swiz	# writable or not owned by root.operator.
7491.15Smrg	>$TMP1
7501.61Slukem	DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \
7511.57Ssimonb	    sd se ss uk up vnd wd xd xy"
7521.27Slukem#	DISKLIST="$DISKLIST ct mt st wt"
7531.15Smrg	for i in $DISKLIST; do
7541.15Smrg		egrep "^b.*/${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
7551.15Smrg		egrep "^c.*/r${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
7561.15Smrg	done
7571.15Smrg
7581.15Smrg	awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
7591.25Slukem		{ printf "Disk %s is user %s, group %s, permissions %s.\n", \
7601.25Slukem		    $11, $3, $4, $1; }' < $TMP1 > $OUTPUT
7611.15Smrg	if [ -s $OUTPUT ] ; then
7621.28Slukem		printf "\nChecking disk ownership and permissions.\n" >> $ERR
7631.28Slukem		cat $OUTPUT >> $ERR
7641.28Slukem		printf "\n" >> $ERR
7651.9Scgd	fi
7661.9Scgd
7671.15Smrg	# Display any changes in the device file list.
7681.20Smycroft	egrep '^[bc]' $LIST | sort -k11 > $TMP1
7691.15Smrg	if [ -s $TMP1 ] ; then
7701.67Slukem		file=$work_dir/device
7711.67Slukem		migrate_file "$backup_dir/device" "$file"
7721.67Slukem		CUR=${file}.current
7731.67Slukem		BACK=${file}.backup
7741.15Smrg
7751.15Smrg		if [ -s $CUR ] ; then
7761.15Smrg			if cmp -s $CUR $TMP1 ; then
7771.15Smrg				:
7781.15Smrg			else
7791.15Smrg				> $TMP2
7801.15Smrg				join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
7811.15Smrg				if [ -s $OUTPUT ] ; then
7821.28Slukem					printf "Device additions:\n" >> $ERR
7831.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7841.28Slukem					printf "\n" >> $ERR
7851.15Smrg				fi
7861.15Smrg
7871.15Smrg				join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
7881.15Smrg				if [ -s $OUTPUT ] ; then
7891.28Slukem					printf "Device deletions:\n" >> $ERR
7901.28Slukem					tee -a $TMP2 < $OUTPUT >> $ERR
7911.28Slukem					printf "\n" >> $ERR
7921.15Smrg				fi
7931.15Smrg
7941.27Slukem				# Report any block device change. Ignore
7951.27Slukem				# character devices, only the name is
7961.27Slukem				# significant.
7971.15Smrg				cat $TMP2 $CUR $TMP1 | \
7981.27Slukem				    sed -e '/^c/d' | \
7991.27Slukem				    sort -k11 | \
8001.27Slukem				    sed -e 's/[	 ][	 ]*/ /g' | \
8011.27Slukem				    uniq -u > $OUTPUT
8021.15Smrg				if [ -s $OUTPUT ] ; then
8031.28Slukem					printf "Block device changes:\n" >> $ERR
8041.28Slukem					column -t $OUTPUT >> $ERR
8051.28Slukem					printf "\n" >> $ERR
8061.15Smrg				fi
8071.9Scgd
8081.52Satatat				backup_file update $TMP1 $CUR $BACK
8091.9Scgd			fi
8101.15Smrg		else
8111.28Slukem			printf "Device additions:\n" >> $ERR
8121.28Slukem			column -t $TMP1 >> $ERR
8131.28Slukem			printf "\n" >> $ERR
8141.52Satatat			backup_file add $TMP1 $CUR $BACK >> $ERR
8151.9Scgd		fi
8161.28Slukem	fi
8171.28Slukem	if [ -s $ERR ] ; then
8181.28Slukem		printf "\nChecking setuid files and devices:\n"
8191.28Slukem		cat $ERR
8201.28Slukem		printf "\n"
8211.9Scgd	fi
8221.9Scgdfi
8231.9Scgd
8241.9Scgd# Check special files.
8251.9Scgd# Check system binaries.
8261.9Scgd#
8271.9Scgd# Create the mtree tree specifications using:
8281.67Slukem#	mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure
8291.38Skleink#	chown root:wheel DIR.secure
8301.67Slukem#	chmod u+r,go= DIR.secure
8311.9Scgd#
8321.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as
8331.9Scgd# the hacker can modify the tree specification to match the replaced binary.
8341.9Scgd# For details on really protecting yourself against modified binaries, see
8351.9Scgd# the mtree(8) manual page.
8361.32Slukem#
8371.31Slukemif checkyesno check_mtree; then
8381.82Sjhawk	if checkyesno check_mtree_follow_symlinks; then
8391.82Sjhawk		check_mtree_flags="-L"
8401.82Sjhawk	else
8411.82Sjhawk		check_mtree_flags=""
8421.82Sjhawk	fi
8431.91Slukem	mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 |
8441.87Sjhawk		grep -v '^mtree: dev/tty: Device not configured$' >&2
8451.15Smrg	if [ -s $OUTPUT ]; then
8461.9Scgd		printf "\nChecking special files and directories.\n"
8471.9Scgd		cat $OUTPUT
8481.9Scgd	fi
8491.9Scgd
8501.16Smikel	for file in /etc/mtree/*.secure; do
8511.16Smikel		[ $file = '/etc/mtree/*.secure' ] && continue
8521.9Scgd		tree=`sed -n -e '3s/.* //p' -e 3q $file`
8531.82Sjhawk		mtree $check_mtree_flags -f $file -p $tree > $TMP1
8541.9Scgd		if [ -s $TMP1 ]; then
8551.67Slukem			printf "\nChecking $tree:\n"
8561.67Slukem			cat $TMP1
8571.9Scgd		fi
8581.67Slukem	done > $OUTPUT
8591.15Smrg	if [ -s $OUTPUT ]; then
8601.9Scgd		printf "\nChecking system binaries:\n"
8611.9Scgd		cat $OUTPUT
8621.9Scgd	fi
8631.9Scgdfi
8641.9Scgd
8651.32Slukem# Backup disklabels of available disks
8661.32Slukem#
8671.32Slukemif checkyesno check_disklabels; then
8681.67Slukem		# migrate old disklabels
8691.67Slukem	for file in `ls -1d $backup_dir/$backup_dir/disklabel.* \
8701.67Slukem	    $backup_dir/disklabel.* 2>/dev/null`; do
8711.67Slukem		migrate_file "$file" "$work_dir/${file##*/}"
8721.67Slukem	done
8731.67Slukem
8741.103Stron		# generate list of old disklabels, fdisks & wedges and remove them
8751.103Stron	ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
8761.52Satatat	    egrep -v '\.(backup|current)(,v)?$' > $LABELS
8771.32Slukem	xargs rm < $LABELS
8781.32Slukem
8791.103Stron		# generate disklabels of all disks excluding:	cd dk fd md st
8801.103Stron	disks=`iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|dk|st|nfs/ { print $1; }'`
8811.32Slukem	for i in $disks; do
8821.67Slukem		disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null
8831.32Slukem	done
8841.32Slukem
8851.67Slukem		# if fdisk is available, generate fdisks for:	ed ld sd wd
8861.67Slukem	if [ -x /sbin/fdisk ]; then
8871.67Slukem		disks=`iostat -x| awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }'`
8881.67Slukem		for i in $disks; do
8891.67Slukem			/sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null
8901.67Slukem		done
8911.67Slukem	fi
8921.67Slukem
8931.103Stron		# if dkctl is available, generate dkctl listwedges for:	ed ld sd wd cgd ofdisk ra rl raid
8941.103Stron	if [ -x /sbin/dkctl ]; then
8951.103Stron		disks=`iostat -x| awk 'NR > 1 && $1 ~ /^[elsw]d|cgd|ofdisk|r[al]|raid/ { print $1; }'`
8961.103Stron		for i in $disks; do
8971.103Stron			/sbin/dkctl $i listwedges > "$work_dir/wedges.$i" 2>/dev/null
8981.103Stron		done
8991.103Stron	fi
9001.103Stron
9011.103Stron		# append list of new disklabels, fdisks and wedges
9021.103Stron	ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
9031.52Satatat	    egrep -v '\.(backup|current)(,v)?$' >> $LABELS
9041.62Satatat	CHANGELIST="$LABELS $CHANGELIST"
9051.62Satatatfi
9061.62Satatat
9071.106Shaadif checkyesno check_lvm; then
9081.106Shaad    
9091.106Shaad    # generate list of existing LVM elements Physical Volumes, Volume Groups and Logical Volumes.
9101.106Shaadif [ -x /sbin/lvm ]; then
9111.106Shaad    lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null
9121.106Shaad    lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null
9131.106Shaad    lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null
9141.106Shaadfi
9151.106Shaad    ls -1d $work_dir/lvm.* 2>/dev/null |
9161.106Shaad        egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS 
9171.106Shaad    CHANGELIST="$CHANGELIST $LVM_LABELS"
9181.106Shaadfi
9191.106Shaad
9201.62Satatat# Check for changes in the list of installed pkgs
9211.62Satatat#
9221.108Sjmmvif checkyesno check_pkgs && have_pkgs; then
9231.67Slukem	pkgs=$work_dir/pkgs
9241.67Slukem	migrate_file "$backup_dir/pkgs" "$pkgs"
9251.108Sjmmv	pkg_dbdir=$(pkg_admin config-var PKG_DBDIR)
9261.108Sjmmv	: ${pkg_dbdir:=/var/db/pkg}
9271.108Sjmmv	(	cd $pkg_dbdir
9281.104Sadrianp		$pkg_info | sort
9291.62Satatat		echo ""
9301.62Satatat		find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 |
9311.72Slukem			xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,'
9321.62Satatat	 ) > $pkgs
9331.67Slukem	echo "$pkgs" > $PKGS
9341.62Satatat	CHANGELIST="$PKGS $CHANGELIST"
9351.32Slukemfi
9361.32Slukem
9371.67Slukem# List of files that get backed up and checked for any modifications.
9381.9Scgd# Any changes cause the files to rotate.
9391.32Slukem#
9401.67Slukemif checkyesno check_changelist ; then
9411.91Slukem	mtree -D -k type -f $SPECIALSPEC -E exclude |
9421.91Slukem	    sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES
9431.67Slukem
9441.75Slukem	(
9451.68Slukem		# Add other files which might dynamically exist:
9461.67Slukem		#	/etc/ifconfig.*
9471.67Slukem		#	/etc/raid*.conf
9481.68Slukem		#	/etc/rc.d/*
9491.67Slukem		#	/etc/rc.conf.d/*
9501.68Slukem		#
9511.75Slukem		echo "/etc/ifconfig.*"
9521.75Slukem		echo "/etc/raid*.conf"
9531.75Slukem		echo "/etc/rc.d/*"
9541.75Slukem		echo "/etc/rc.conf.d/*"
9551.106Shaad		echo "/etc/lvm/backup/*"
9561.106Shaad		echo "/etc/lvm/archive/*"
9571.67Slukem
9581.68Slukem		# Add /etc/changelist
9591.68Slukem		#
9601.75Slukem		if [ -s /etc/changelist ]; then
9611.75Slukem			grep -v '^#' /etc/changelist
9621.75Slukem		fi
9631.75Slukem	) | while read file; do
9641.75Slukem		case "$file" in
9651.75Slukem		*[\*\?\[]*)	# If changelist line is a glob ...
9661.75Slukem				# ... expand possible backup files
9671.75Slukem				#
9681.75Slukem			ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \
9691.75Slukem			    | sed "s,^$backup_dir/,, ; s,\.current$,,"
9701.75Slukem				
9711.75Slukem				# ... expand possible files
9721.75Slukem				#
9731.75Slukem			ls -1d $(echo $file) 2>/dev/null
9741.75Slukem			;;
9751.75Slukem		*)
9761.75Slukem				# Otherwise, just print the filename
9771.75Slukem			echo $file
9781.75Slukem			;;
9791.75Slukem		esac
9801.75Slukem	done >> $CHANGEFILES
9811.67Slukem	CHANGELIST="$CHANGEFILES $CHANGELIST"
9821.67Slukemfi
9831.67Slukem
9841.67Slukem# Special case backups, including the master password file and
9851.67Slukem# ssh private host keys. The normal backup mechanisms for
9861.67Slukem# $check_changelist (see below) also print out the actual file
9871.67Slukem# differences and we don't want to do that for these files
9881.67Slukem#
9891.67Slukemecho $MP > $TMP1			# always add /etc/master.passwd
9901.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff |
9911.91Slukem    sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1
9921.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2
9931.68Slukem
9941.69Slukemwhile read file; do
9951.67Slukem	backup_and_diff "$file" no
9961.69Slukemdone < $TMP2
9971.67Slukem
9981.32Slukem
9991.32Slukemif [ -n "$CHANGELIST" ]; then
10001.73Slukem	grep -h -v '^$' $CHANGELIST | sort -u > $TMP1
10011.68Slukem	comm -23 $TMP1 $TMP2 | while read file; do
10021.67Slukem		backup_and_diff "$file" yes
10031.9Scgd	done
10041.44Sadfi
10051.44Sad
10061.108Sjmmvif have_pkgs; then
10071.107Sjmmv	if checkyesno check_pkg_vulnerabilities; then
10081.108Sjmmv		pkg_admin ${_compat_K_flag} audit >${OUTPUT} 2>&1
10091.107Sjmmv		if [ -s ${OUTPUT} ]; then
10101.107Sjmmv			printf "\nInstalled vulnerable packages:\n"
10111.107Sjmmv			cat ${OUTPUT}
10121.107Sjmmv		fi
10131.107Sjmmv	fi
10141.107Sjmmv
10151.107Sjmmv	if checkyesno check_pkg_signatures; then
10161.108Sjmmv		pkg_admin ${_compat_K_flag} check >${OUTPUT} 2>&1
10171.107Sjmmv		if [ $? -ne 0 ]; then
10181.107Sjmmv			printf "\nFiles with invalid signatures:\n"
10191.107Sjmmv			cat ${OUTPUT}
10201.107Sjmmv		fi
10211.107Sjmmv	fi
10221.107Sjmmvfi
10231.107Sjmmv
10241.44Sadif [ -f /etc/security.local ]; then
10251.90Skim	. /etc/security.local > $OUTPUT 2>&1
10261.84Sjhawk	if [ -s $OUTPUT ] ; then
10271.84Sjhawk		printf "\nRunning /etc/security.local:\n"
10281.84Sjhawk		cat $OUTPUT
10291.84Sjhawk	fi
10301.9Scgdfi
1031