security revision 1.26
11.1Scgd#!/bin/sh -
21.1Scgd#
31.26Slukem#	$NetBSD: security,v 1.26 1997/08/19 12:08:35 lukem 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.9Scgdumask 077
101.1Scgd
111.15Smrgif [ -s /etc/security.conf ]; then
121.15Smrg	. /etc/security.conf
131.15Smrgfi
141.15Smrg
151.15SmrgSECUREDIR=/tmp/_securedir.$$
161.15Smrgif ! mkdir $SECUREDIR; then
171.15Smrg	echo can not create $SECUREDIR.
181.15Smrg	exit 1
191.15Smrgfi
201.15Smrg
211.15Smrgif ! cd $SECUREDIR; then
221.15Smrg	echo can not chdir to $SECUREDIR.
231.15Smrg	exit 1
241.15Smrgfi
251.15Smrg
261.15SmrgERR=secure1.$$
271.15SmrgTMP1=secure2.$$
281.15SmrgTMP2=secure3.$$
291.15SmrgTMP3=secure4.$$
301.15SmrgLIST=secure5.$$
311.15SmrgOUTPUT=secure6.$$
321.15Smrg
331.15Smrgtrap 'rm -rf $SECUREDIR' 0
341.15Smrg
351.15SmrgMP=/etc/master.passwd
361.9Scgd
371.15Smrg# this is used several times.
381.20Smycroftawk -F: '{ print $1 " " $3 }' $MP | sort -k2n > $TMP1
391.9Scgd
401.9Scgd# Check the master password file syntax.
411.17Smycroftif [ "$check_passwd" = YES ]; then
421.25Slukem	awk '
431.25Slukem	BEGIN {
441.25Slukem		while ( getline < "/etc/shells" > 0 ) {
451.25Slukem			if ($LINE ~ /^\#/ || $LINE ~ /^$/ )
461.25Slukem				continue;
471.25Slukem			shells[$1]++;
481.25Slukem		}
491.25Slukem		FS=":";
501.25Slukem	}
511.25Slukem
521.25Slukem	{
531.15Smrg		if ($0 ~ /^[	 ]*$/) {
541.25Slukem			printf "Line %d is a blank line.\n", NR;
551.15Smrg			next;
561.15Smrg		}
571.15Smrg		if (NF != 10)
581.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
591.15Smrg		if ($1 !~ /^[A-Za-z0-9]*$/)
601.25Slukem			printf "Login %s has non-alphanumeric characters.\n",
611.25Slukem			    $1;
621.15Smrg		if (length($1) > 8)
631.25Slukem			printf "Login %s has more than 8 characters.\n", $1;
641.15Smrg		if ($2 == "")
651.25Slukem			printf "Login %s has no password.\n", $1;
661.25Slukem		if (length($2) != 13 && $2 != "") {
671.25Slukem			if ($10 == "" || shells[$10])
681.25Slukem				printf "Login %s is off but still has a valid shell (%s)\n",
691.25Slukem				    $1, $10;
701.25Slukem		} else if (! shells[$10])
711.25Slukem			printf "Login %s does not have a valid shell (%s)\n",
721.25Slukem			    $1, $10;
731.15Smrg		if ($3 == 0 && $1 != "root" && $1 != "toor")
741.25Slukem			printf "Login %s has a user id of 0.\n", $1;
751.15Smrg		if ($3 < 0)
761.25Slukem			printf "Login %s has a negative user id.\n", $1;
771.15Smrg		if ($4 < 0)
781.25Slukem			printf "Login %s has a negative group id.\n", $1;
791.15Smrg	}' < $MP > $OUTPUT
801.15Smrg	if [ -s $OUTPUT ] ; then
811.15Smrg		printf "\nChecking the $MP file:\n"
821.15Smrg		cat $OUTPUT
831.15Smrg	fi
841.15Smrg
851.15Smrg	awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
861.15Smrg	if [ -s $OUTPUT ] ; then
871.15Smrg		printf "\n$MP has duplicate user names.\n"
881.15Smrg		column $OUTPUT
891.15Smrg	fi
901.15Smrg
911.15Smrg	< $TMP1 uniq -d -f 1 | awk '{ print $2 }' > $TMP2
921.15Smrg	if [ -s $TMP2 ] ; then
931.15Smrg		printf "\n$MP has duplicate user id's.\n"
941.15Smrg		while read uid; do
951.15Smrg			grep -w $uid $TMP1
961.15Smrg		done < $TMP2 | column
971.15Smrg	fi
981.9Scgdfi
991.9Scgd
1001.9Scgd# Backup the master password file; a special case, the normal backup
1011.9Scgd# mechanisms also print out file differences and we don't want to do
1021.9Scgd# that because this file has encrypted passwords in it.
1031.9ScgdCUR=/var/backups/`basename $MP`.current
1041.9ScgdBACK=/var/backups/`basename $MP`.backup
1051.9Scgdif [ -s $CUR ] ; then
1061.9Scgd	if cmp -s $CUR $MP; then
1071.9Scgd		:
1081.9Scgd	else
1091.9Scgd		cp -p $CUR $BACK
1101.9Scgd		cp -p $MP $CUR
1111.9Scgd		chown root.wheel $CUR
1121.9Scgd	fi
1131.9Scgdelse
1141.9Scgd	cp -p $MP $CUR
1151.9Scgd	chown root.wheel $CUR
1161.9Scgdfi
1171.9Scgd
1181.9Scgd# Check the group file syntax.
1191.17Smycroftif [ "$check_group" = YES ]; then
1201.15Smrg	GRP=/etc/group
1211.15Smrg	awk -F: '{
1221.15Smrg		if ($0 ~ /^[	 ]*$/) {
1231.25Slukem			printf "Line %d is a blank line.\n", NR;
1241.15Smrg			next;
1251.15Smrg		}
1261.15Smrg		if (NF != 4)
1271.25Slukem			printf "Line %d has the wrong number of fields.\n", NR;
1281.15Smrg		if ($1 !~ /^[A-za-z0-9]*$/)
1291.25Slukem			printf "Group %s has non-alphanumeric characters.\n",
1301.25Slukem			    $1;
1311.15Smrg		if (length($1) > 8)
1321.25Slukem			printf "Group %s has more than 8 characters.\n", $1;
1331.15Smrg		if ($3 !~ /[0-9]*/)
1341.25Slukem			printf "Login %s has a negative group id.\n", $1;
1351.15Smrg	}' < $GRP > $OUTPUT
1361.15Smrg	if [ -s $OUTPUT ] ; then
1371.15Smrg		printf "\nChecking the $GRP file:\n"
1381.15Smrg		cat $OUTPUT
1391.15Smrg	fi
1401.15Smrg
1411.15Smrg	awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
1421.15Smrg	if [ -s $OUTPUT ] ; then
1431.15Smrg		printf "\n$GRP has duplicate group names.\n"
1441.15Smrg		column $OUTPUT
1451.15Smrg	fi
1461.9Scgdfi
1471.9Scgd
1481.9Scgd# Check for root paths, umask values in startup files.
1491.9Scgd# The check for the root paths is problematical -- it's likely to fail
1501.9Scgd# in other environments.  Once the shells have been modified to warn
1511.9Scgd# of '.' in the path, the path tests should go away.
1521.17Smycroftif [ "$check_rootdotfiles" = YES ]; then
1531.15Smrg	cp /dev/null $OUTPUT
1541.15Smrg	rhome=`csh -fc "echo ~root"`
1551.15Smrg	umaskset=no
1561.15Smrg	list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
1571.15Smrg	for i in $list ; do
1581.15Smrg		if [ -f $i ] ; then
1591.15Smrg			if egrep umask $i > /dev/null ; then
1601.15Smrg				umaskset=yes
1611.15Smrg			fi
1621.15Smrg			egrep umask $i |
1631.15Smrg			awk '$2 % 100 < 20 \
1641.15Smrg				{ print "Root umask is group writeable" }
1651.15Smrg			     $2 % 10 < 2 \
1661.15Smrg				{ print "Root umask is other writeable" }' >> $OUTPUT
1671.26Slukem			SAVE_PATH=$PATH
1681.26Slukem			unset PATH
1691.15Smrg			/bin/csh -f -s << end-of-csh > /dev/null 2>&1
1701.15Smrg				source $i
1711.15Smrg				/bin/ls -ldgT \$path > $TMP1
1721.9Scgdend-of-csh
1731.26Slukem			PATH=$SAVE_PATH
1741.15Smrg			awk '{
1751.15Smrg				if ($10 ~ /^\.$/) {
1761.15Smrg					print "The root path includes .";
1771.15Smrg					next;
1781.15Smrg				}
1791.15Smrg			     }
1801.15Smrg			     $1 ~ /^d....w/ \
1811.15Smrg		{ print "Root path directory " $10 " is group writeable." } \
1821.15Smrg			     $1 ~ /^d.......w/ \
1831.15Smrg		{ print "Root path directory " $10 " is other writeable." }' \
1841.15Smrg			< $TMP1 >> $OUTPUT
1851.15Smrg		fi
1861.15Smrg	done
1871.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
1881.15Smrg		printf "\nChecking root csh paths, umask values:\n$list\n"
1891.15Smrg		if [ -s $OUTPUT ]; then
1901.15Smrg			cat $OUTPUT
1911.15Smrg		fi
1921.15Smrg		if [ $umaskset = "no" ] ; then
1931.15Smrg			printf "\nRoot csh startup files do not set the umask.\n"
1941.15Smrg		fi
1951.9Scgd	fi
1961.9Scgd
1971.15Smrg	cp /dev/null $OUTPUT
1981.15Smrg	rhome=/root
1991.15Smrg	umaskset=no
2001.23Slukem	list="/etc/profile ${rhome}/.profile"
2011.15Smrg	for i in $list; do
2021.15Smrg		if [ -f $i ] ; then
2031.15Smrg			if egrep umask $i > /dev/null ; then
2041.15Smrg				umaskset=yes
2051.15Smrg			fi
2061.15Smrg			egrep umask $i |
2071.15Smrg			awk '$2 % 100 < 20 \
2081.15Smrg				{ print "Root umask is group writeable" } \
2091.15Smrg			     $2 % 10 < 2 \
2101.15Smrg				{ print "Root umask is other writeable" }' >> $OUTPUT
2111.26Slukem			SAVE_PATH=$PATH
2121.26Slukem			unset PATH
2131.15Smrg			/bin/sh << end-of-sh > /dev/null 2>&1
2141.15Smrg				. $i
2151.26Slukem				list=\`echo \$PATH | /usr/bin/sed -e \
2161.26Slukem				    's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\`
2171.15Smrg				/bin/ls -ldgT \$list > $TMP1
2181.9Scgdend-of-sh
2191.26Slukem			PATH=$SAVE_PATH
2201.15Smrg			awk '{
2211.15Smrg				if ($10 ~ /^\.$/) {
2221.15Smrg					print "The root path includes .";
2231.15Smrg					next;
2241.15Smrg				}
2251.15Smrg			     }
2261.15Smrg			     $1 ~ /^d....w/ \
2271.15Smrg		{ print "Root path directory " $10 " is group writeable." } \
2281.15Smrg			     $1 ~ /^d.......w/ \
2291.15Smrg		{ print "Root path directory " $10 " is other writeable." }' \
2301.15Smrg			< $TMP1 >> $OUTPUT
2311.9Scgd
2321.15Smrg		fi
2331.15Smrg	done
2341.15Smrg	if [ $umaskset = "no" -o -s $OUTPUT ] ; then
2351.15Smrg		printf "\nChecking root sh paths, umask values:\n$list\n"
2361.15Smrg		if [ -s $OUTPUT ]; then
2371.15Smrg			cat $OUTPUT
2381.15Smrg		fi
2391.15Smrg		if [ $umaskset = "no" ] ; then
2401.15Smrg			printf "\nRoot sh startup files do not set the umask.\n"
2411.15Smrg		fi
2421.9Scgd	fi
2431.9Scgdfi
2441.9Scgd
2451.9Scgd# Root and uucp should both be in /etc/ftpusers.
2461.17Smycroftif [ "$check_ftpusers" = YES ]; then
2471.15Smrg	if egrep root /etc/ftpusers > /dev/null ; then
2481.15Smrg		:
2491.15Smrg	else
2501.15Smrg		printf "\nRoot not listed in /etc/ftpusers file.\n"
2511.15Smrg	fi
2521.15Smrg	if egrep uucp /etc/ftpusers > /dev/null ; then
2531.15Smrg		:
2541.15Smrg	else
2551.15Smrg		printf "\nUucp not listed in /etc/ftpusers file.\n"
2561.15Smrg	fi
2571.9Scgdfi
2581.9Scgd
2591.9Scgd# Uudecode should not be in the /etc/aliases file.
2601.17Smycroftif [ "$check_aliases" = YES ]; then
2611.18Smikel	if egrep '^[^#]*(uudecode|decode).*\|' /etc/aliases; then
2621.18Smikel		printf "\nEntry for uudecode in /etc/aliases file.\n"
2631.15Smrg	fi
2641.9Scgdfi
2651.9Scgd
2661.9Scgd# Files that should not have + signs.
2671.17Smycroftif [ "$check_rhosts" = YES ]; then
2681.15Smrg	list="/etc/hosts.equiv /etc/hosts.lpd"
2691.15Smrg	for f in $list ; do
2701.15Smrg		if [ -f $f ] && egrep '\+' $f > /dev/null ; then
2711.15Smrg			printf "\nPlus sign in $f file.\n"
2721.15Smrg		fi
2731.15Smrg	done
2741.15Smrg
2751.15Smrg	# Check for special users with .rhosts files.  Only root and toor should
2761.16Smikel	# have .rhosts files.  Also, .rhosts files should not have plus signs.
2771.15Smrg	awk -F: '$1 != "root" && $1 != "toor" && \
2781.15Smrg		($3 < 100 || $1 == "ftp" || $1 == "uucp") \
2791.20Smycroft			{ print $1 " " $9 }' $MP |
2801.19Smycroft	sort -k2 |
2811.15Smrg	while read uid homedir; do
2821.15Smrg		if [ -f ${homedir}/.rhosts ] ; then
2831.15Smrg			rhost=`ls -ldgT ${homedir}/.rhosts`
2841.15Smrg			printf "$uid: $rhost\n"
2851.15Smrg		fi
2861.15Smrg	done > $OUTPUT
2871.15Smrg	if [ -s $OUTPUT ] ; then
2881.15Smrg		printf "\nChecking for special users with .rhosts files.\n"
2891.15Smrg		cat $OUTPUT
2901.15Smrg	fi
2911.15Smrg
2921.20Smycroft	awk -F: '{ print $1 " " $9 }' $MP |
2931.19Smycroft	sort -k2 |
2941.15Smrg	while read uid homedir; do
2951.15Smrg		if [ -f ${homedir}/.rhosts ] && \
2961.15Smrg		    egrep '\+' ${homedir}/.rhosts > /dev/null ; then
2971.15Smrg			printf "$uid: + in .rhosts file.\n"
2981.15Smrg		fi
2991.15Smrg	done > $OUTPUT
3001.15Smrg	if [ -s $OUTPUT ] ; then
3011.15Smrg		printf "\nChecking .rhosts files syntax.\n"
3021.15Smrg		cat $OUTPUT
3031.15Smrg	fi
3041.9Scgdfi
3051.9Scgd
3061.9Scgd# Check home directories.  Directories should not be owned by someone else
3071.9Scgd# or writeable.
3081.17Smycroftif [ "$check_homes" = YES ]; then
3091.20Smycroft	awk -F: '{ print $1 " " $9 }' $MP |
3101.19Smycroft	sort -k2 |
3111.15Smrg	while read uid homedir; do
3121.15Smrg		if [ -d ${homedir}/ ] ; then
3131.15Smrg			file=`ls -ldgT ${homedir}`
3141.15Smrg			printf "$uid $file\n"
3151.9Scgd		fi
3161.15Smrg	done |
3171.15Smrg	awk '$1 != $4 && $4 != "root" \
3181.15Smrg		{ print "user " $1 " home directory is owned by " $4 }
3191.15Smrg	     $2 ~ /^-....w/ \
3201.15Smrg		{ print "user " $1 " home directory is group writeable" }
3211.15Smrg	     $2 ~ /^-.......w/ \
3221.15Smrg		{ print "user " $1 " home directory is other writeable" }' > $OUTPUT
3231.15Smrg	if [ -s $OUTPUT ] ; then
3241.15Smrg		printf "\nChecking home directories.\n"
3251.15Smrg		cat $OUTPUT
3261.15Smrg	fi
3271.15Smrg
3281.15Smrg	# Files that should not be owned by someone else or readable.
3291.19Smycroft	list=".Xauthority .netrc .rhosts"
3301.20Smycroft	awk -F: '{ print $1 " " $9 }' $MP |
3311.19Smycroft	sort -k2 |
3321.15Smrg	while read uid homedir; do
3331.15Smrg		for f in $list ; do
3341.15Smrg			file=${homedir}/${f}
3351.15Smrg			if [ -f $file ] ; then
3361.15Smrg				printf "$uid $f `ls -ldgT $file`\n"
3371.15Smrg			fi
3381.15Smrg		done
3391.15Smrg	done |
3401.15Smrg	awk '$1 != $5 && $5 != "root" \
3411.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
3421.15Smrg	     $3 ~ /^-...r/ \
3431.15Smrg		{ print "user " $1 " " $2 " file is group readable" }
3441.15Smrg	     $3 ~ /^-......r/ \
3451.15Smrg		{ print "user " $1 " " $2 " file is other readable" }
3461.15Smrg	     $3 ~ /^-....w/ \
3471.15Smrg		{ print "user " $1 " " $2 " file is group writeable" }
3481.15Smrg	     $3 ~ /^-.......w/ \
3491.15Smrg		{ print "user " $1 " " $2 " file is other writeable" }' > $OUTPUT
3501.15Smrg
3511.15Smrg	# Files that should not be owned by someone else or writeable.
3521.19Smycroft	list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \
3531.19Smycroft	      .cshrc .emacs .exrc .forward .history .klogin .login .logout \
3541.19Smycroft	      .profile .qmail .rc_history .tcshrc .twmrc .xinitrc .xsession"
3551.20Smycroft	awk -F: '{ print $1 " " $9 }' $MP |
3561.19Smycroft	sort -k2 |
3571.15Smrg	while read uid homedir; do
3581.15Smrg		for f in $list ; do
3591.15Smrg			file=${homedir}/${f}
3601.15Smrg			if [ -f $file ] ; then
3611.15Smrg				printf "$uid $f `ls -ldgT $file`\n"
3621.15Smrg			fi
3631.15Smrg		done
3641.15Smrg	done |
3651.15Smrg	awk '$1 != $5 && $5 != "root" \
3661.15Smrg		{ print "user " $1 " " $2 " file is owned by " $5 }
3671.15Smrg	     $3 ~ /^-....w/ \
3681.15Smrg		{ print "user " $1 " " $2 " file is group writeable" }
3691.15Smrg	     $3 ~ /^-.......w/ \
3701.15Smrg		{ print "user " $1 " " $2 " file is other writeable" }' >> $OUTPUT
3711.15Smrg	if [ -s $OUTPUT ] ; then
3721.15Smrg		printf "\nChecking dot files.\n"
3731.15Smrg		cat $OUTPUT
3741.15Smrg	fi
3751.9Scgdfi
3761.9Scgd
3771.9Scgd# Mailboxes should be owned by user and unreadable.
3781.17Smycroftif [ "$check_varmail" = YES ]; then
3791.15Smrg	ls -l /var/mail | sed 1d | \
3801.15Smrg	awk '$3 != $9 \
3811.15Smrg		{ print "user " $9 " mailbox is owned by " $3 }
3821.15Smrg	     $1 != "-rw-------" \
3831.15Smrg		{ print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT
3841.15Smrg	if [ -s $OUTPUT ] ; then
3851.15Smrg		printf "\nChecking mailbox ownership.\n"
3861.15Smrg		cat $OUTPUT
3871.15Smrg	fi
3881.15Smrgfi
3891.15Smrg
3901.17Smycroftif [ "$check_nfs" = YES ]; then
3911.15Smrg	if [ -f /etc/exports ]; then
3921.15Smrg	    # File systems should not be globally exported.
3931.15Smrg	    awk '{
3941.22Slukem		# ignore comments and blank lines
3951.22Slukem		if ($LINE ~ /^\#/ || $LINE ~ /^$/ )
3961.22Slukem			next;
3971.22Slukem
3981.15Smrg		readonly = 0;
3991.15Smrg		for (i = 2; i <= NF; ++i) {
4001.15Smrg			if ($i ~ /-ro/)
4011.15Smrg				readonly = 1;
4021.15Smrg			else if ($i !~ /^-/)
4031.15Smrg				next;
4041.15Smrg		}
4051.15Smrg		if (readonly)
4061.15Smrg			print "File system " $1 " globally exported, read-only."
4071.15Smrg		else
4081.15Smrg			print "File system " $1 " globally exported, read-write."
4091.15Smrg	    }' < /etc/exports > $OUTPUT
4101.15Smrg	    if [ -s $OUTPUT ] ; then
4111.15Smrg		printf "\nChecking for globally exported file systems.\n"
4121.15Smrg		cat $OUTPUT
4131.15Smrg	    fi
4141.15Smrg	fi
4151.9Scgdfi
4161.9Scgd
4171.9Scgd# Display any changes in setuid files and devices.
4181.17Smycroftif [ "$check_devices" = YES ]; then
4191.15Smrg	printf "\nChecking setuid files and devices:\n"
4201.15Smrg	(find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \
4211.15Smrg			-o -fstype procfs \) -a -prune -o \
4221.21Smycroft	    \( \( -perm -u+s -a ! -type d \) -o \
4231.21Smycroft	       \( -perm -g+s -a ! -type d \) -o \
4241.24Slukem	       -type b -o -type c \) -print0 | \
4251.24Slukem	xargs -0 ls -ldgTq | sort +9 > $LIST) 2> $OUTPUT
4261.15Smrg
4271.15Smrg	# Display any errors that occurred during system file walk.
4281.15Smrg	if [ -s $OUTPUT ] ; then
4291.15Smrg		printf "Setuid/device find errors:\n"
4301.15Smrg		cat $OUTPUT
4311.15Smrg		printf "\n"
4321.15Smrg	fi
4331.15Smrg
4341.15Smrg	# Display any changes in the setuid file list.
4351.15Smrg	egrep -v '^[bc]' $LIST > $TMP1
4361.15Smrg	if [ -s $TMP1 ] ; then
4371.15Smrg		# Check to make sure uudecode isn't setuid.
4381.15Smrg		if grep -w uudecode $TMP1 > /dev/null ; then
4391.15Smrg			printf "\nUudecode is setuid.\n"
4401.15Smrg		fi
4411.15Smrg
4421.15Smrg		CUR=/var/backups/setuid.current
4431.15Smrg		BACK=/var/backups/setuid.backup
4441.9Scgd
4451.15Smrg		if [ -s $CUR ] ; then
4461.15Smrg			if cmp -s $CUR $TMP1 ; then
4471.15Smrg				:
4481.15Smrg			else
4491.15Smrg				> $TMP2
4501.15Smrg				join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
4511.15Smrg				if [ -s $OUTPUT ] ; then
4521.15Smrg					printf "Setuid additions:\n"
4531.15Smrg					tee -a $TMP2 < $OUTPUT
4541.15Smrg					printf "\n"
4551.15Smrg				fi
4561.15Smrg
4571.15Smrg				join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
4581.15Smrg				if [ -s $OUTPUT ] ; then
4591.15Smrg					printf "Setuid deletions:\n"
4601.15Smrg					tee -a $TMP2 < $OUTPUT
4611.15Smrg					printf "\n"
4621.15Smrg				fi
4631.15Smrg
4641.20Smycroft				sort -k10 $TMP2 $CUR $TMP1 | \
4651.15Smrg				    sed -e 's/[	 ][	 ]*/ /g' | uniq -u > $OUTPUT
4661.15Smrg				if [ -s $OUTPUT ] ; then
4671.15Smrg					printf "Setuid changes:\n"
4681.15Smrg					column -t $OUTPUT
4691.15Smrg					printf "\n"
4701.15Smrg				fi
4711.9Scgd
4721.15Smrg				cp $CUR $BACK
4731.15Smrg				cp $TMP1 $CUR
4741.9Scgd			fi
4751.15Smrg		else
4761.15Smrg			printf "Setuid additions:\n"
4771.15Smrg			column -t $TMP1
4781.15Smrg			printf "\n"
4791.9Scgd			cp $TMP1 $CUR
4801.9Scgd		fi
4811.15Smrg	fi
4821.15Smrg
4831.15Smrg	# Check for block and character disk devices that are readable or writeable
4841.15Smrg	# or not owned by root.operator.
4851.15Smrg	>$TMP1
4861.15Smrg	DISKLIST="dk fd hd hk hp jb kra ra rb rd rl rx rz sd up wd xd xy"
4871.15Smrg	for i in $DISKLIST; do
4881.15Smrg		egrep "^b.*/${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
4891.15Smrg		egrep "^c.*/r${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
4901.15Smrg	done
4911.15Smrg
4921.15Smrg	awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
4931.25Slukem		{ printf "Disk %s is user %s, group %s, permissions %s.\n", \
4941.25Slukem		    $11, $3, $4, $1; }' < $TMP1 > $OUTPUT
4951.15Smrg	if [ -s $OUTPUT ] ; then
4961.15Smrg		printf "\nChecking disk ownership and permissions.\n"
4971.15Smrg		cat $OUTPUT
4981.9Scgd		printf "\n"
4991.9Scgd	fi
5001.9Scgd
5011.15Smrg	# Display any changes in the device file list.
5021.20Smycroft	egrep '^[bc]' $LIST | sort -k11 > $TMP1
5031.15Smrg	if [ -s $TMP1 ] ; then
5041.15Smrg		CUR=/var/backups/device.current
5051.15Smrg		BACK=/var/backups/device.backup
5061.15Smrg
5071.15Smrg		if [ -s $CUR ] ; then
5081.15Smrg			if cmp -s $CUR $TMP1 ; then
5091.15Smrg				:
5101.15Smrg			else
5111.15Smrg				> $TMP2
5121.15Smrg				join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
5131.15Smrg				if [ -s $OUTPUT ] ; then
5141.15Smrg					printf "Device additions:\n"
5151.15Smrg					tee -a $TMP2 < $OUTPUT
5161.15Smrg					printf "\n"
5171.15Smrg				fi
5181.15Smrg
5191.15Smrg				join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
5201.15Smrg				if [ -s $OUTPUT ] ; then
5211.15Smrg					printf "Device deletions:\n"
5221.15Smrg					tee -a $TMP2 < $OUTPUT
5231.15Smrg					printf "\n"
5241.15Smrg				fi
5251.15Smrg
5261.15Smrg				# Report any block device change.  Ignore character
5271.15Smrg				# devices, only the name is significant.
5281.15Smrg				cat $TMP2 $CUR $TMP1 | \
5291.15Smrg				sed -e '/^c/d' | \
5301.20Smycroft				sort -k11 | \
5311.15Smrg				sed -e 's/[	 ][	 ]*/ /g' | \
5321.15Smrg				uniq -u > $OUTPUT
5331.15Smrg				if [ -s $OUTPUT ] ; then
5341.15Smrg					printf "Block device changes:\n"
5351.15Smrg					column -t $OUTPUT
5361.15Smrg					printf "\n"
5371.15Smrg				fi
5381.9Scgd
5391.15Smrg				cp $CUR $BACK
5401.15Smrg				cp $TMP1 $CUR
5411.9Scgd			fi
5421.15Smrg		else
5431.15Smrg			printf "Device additions:\n"
5441.15Smrg			column -t $TMP1
5451.15Smrg			printf "\n"
5461.9Scgd			cp $TMP1 $CUR
5471.9Scgd		fi
5481.9Scgd	fi
5491.9Scgdfi
5501.9Scgd
5511.9Scgd# Check special files.
5521.9Scgd# Check system binaries.
5531.9Scgd#
5541.9Scgd# Create the mtree tree specifications using:
5551.9Scgd#
5561.9Scgd#	mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure
5571.16Smikel#	chown root.wheel DIR.secure
5581.16Smikel#	chmod 600 DIR.secure
5591.9Scgd#
5601.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as
5611.9Scgd# the hacker can modify the tree specification to match the replaced binary.
5621.9Scgd# For details on really protecting yourself against modified binaries, see
5631.9Scgd# the mtree(8) manual page.
5641.17Smycroftif [ "$check_mtree" = YES ]; then
5651.9Scgd	mtree -e -p / -f /etc/mtree/special > $OUTPUT
5661.15Smrg	if [ -s $OUTPUT ]; then
5671.9Scgd		printf "\nChecking special files and directories.\n"
5681.9Scgd		cat $OUTPUT
5691.9Scgd	fi
5701.9Scgd
5711.9Scgd	> $OUTPUT
5721.16Smikel	for file in /etc/mtree/*.secure; do
5731.16Smikel		[ $file = '/etc/mtree/*.secure' ] && continue
5741.9Scgd		tree=`sed -n -e '3s/.* //p' -e 3q $file`
5751.9Scgd		mtree -f $file -p $tree > $TMP1
5761.9Scgd		if [ -s $TMP1 ]; then
5771.9Scgd			printf "\nChecking $tree:\n" >> $OUTPUT
5781.9Scgd			cat $TMP1 >> $OUTPUT
5791.9Scgd		fi
5801.9Scgd	done
5811.15Smrg	if [ -s $OUTPUT ]; then
5821.9Scgd		printf "\nChecking system binaries:\n"
5831.9Scgd		cat $OUTPUT
5841.9Scgd	fi
5851.9Scgdfi
5861.9Scgd
5871.9Scgd# List of files that get backed up and checked for any modifications.  Each
5881.9Scgd# file is expected to have two backups, /var/backups/file.{current,backup}.
5891.9Scgd# Any changes cause the files to rotate.
5901.17Smycroftif [ "$check_changelist" = YES ] && [ -s /etc/changelist ] ; then
5911.9Scgd	for file in `cat /etc/changelist`; do
5921.9Scgd		CUR=/var/backups/`basename $file`.current
5931.9Scgd		BACK=/var/backups/`basename $file`.backup
5941.9Scgd		if [ -s $file ]; then
5951.9Scgd			if [ -s $CUR ] ; then
5961.9Scgd				diff $CUR $file > $OUTPUT
5971.9Scgd				if [ -s $OUTPUT ] ; then
5981.9Scgd		printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file
5991.9Scgd					cat $OUTPUT
6001.9Scgd					cp -p $CUR $BACK
6011.9Scgd					cp -p $file $CUR
6021.9Scgd					chown root.wheel $CUR $BACK
6031.9Scgd				fi
6041.9Scgd			else
6051.9Scgd				cp -p $file $CUR
6061.9Scgd				chown root.wheel $CUR
6071.9Scgd			fi
6081.9Scgd		fi
6091.9Scgd	done
6101.9Scgdfi
611