+# File systems should not be globally exported.
+awk '{
+ readonly = 0;
+ for (i = 2; i <= NF; ++i) {
+ if ($i ~ /-ro/)
+ readonly = 1;
+ else if ($i !~ /^-/)
+ next;
+ }
+ if (readonly)
+ print "File system " $1 " globally exported, read-only."
+ else
+ print "File system " $1 " globally exported, read-write."
+}' < /etc/exports > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking for globally exported file systems.\n"
+ cat $OUTPUT
+fi
+
+# Display any changes in setuid files and devices.
+printf "\nChecking setuid files and devices:\n"
+(find / ! -fstype local -a -prune -o \
+ \( -perm -u+s -o -perm -g+s -o ! -type d -a ! -type f -a ! -type l -a \
+ ! -type s \) | \
+sort | sed -e 's/^/ls -ldgT /' | sh > $LIST) 2> $OUTPUT
+
+# Display any errors that occurred during system file walk.
+if [ -s $OUTPUT ] ; then
+ printf "Setuid/device find errors:\n"
+ cat $OUTPUT
+ printf "\n"
+fi
+
+# Display any changes in the setuid file list.
+egrep -v '^[bc]' $LIST > $TMP1
+if [ -s $TMP1 ] ; then
+ # Check to make sure uudecode isn't setuid.
+ if grep -w uudecode $TMP1 > /dev/null ; then
+ printf "\nUudecode is setuid.\n"
+ fi
+
+ CUR=/var/backups/setuid.current
+ BACK=/var/backups/setuid.backup
+
+ if [ -s $CUR ] ; then
+ if cmp -s $CUR $TMP1 ; then
+ :
+ else
+ > $TMP2
+ join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "Setuid additions:\n"
+ tee -a $TMP2 < $OUTPUT
+ printf "\n"
+ fi
+
+ join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "Setuid deletions:\n"
+ tee -a $TMP2 < $OUTPUT
+ printf "\n"
+ fi
+
+ sort +9 $TMP2 $CUR $TMP1 | \
+ sed -e 's/[ ][ ]*/ /g' | uniq -u > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "Setuid changes:\n"
+ column -t $OUTPUT
+ printf "\n"
+ fi
+
+ cp $CUR $BACK
+ cp $TMP1 $CUR
+ fi
+ else
+ printf "Setuid additions:\n"
+ column -t $TMP1
+ printf "\n"
+ cp $TMP1 $CUR
+ fi
+fi
+
+# Check for block and character disk devices that are readable or writeable
+# or not owned by root.operator.
+>$TMP1
+DISKLIST="dk fd hd hk hp jb kra ra rb rd rl rx rz sd up wd"
+for i in $DISKLIST; do
+ egrep "^b.*/${i}[0-9][0-9]*[a-h]$" $LIST >> $TMP1
+ egrep "^c.*/r${i}[0-9][0-9]*[a-h]$" $LIST >> $TMP1
+done
+
+awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
+ { printf("Disk %s is user %s, group %s, permissions %s.\n", \
+ $11, $3, $4, $1); }' < $TMP1 > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking disk ownership and permissions.\n"
+ cat $OUTPUT
+ printf "\n"
+fi
+
+# Display any changes in the device file list.
+egrep '^[bc]' $LIST | sort +10 > $TMP1
+if [ -s $TMP1 ] ; then
+ CUR=/var/backups/device.current
+ BACK=/var/backups/device.backup
+
+ if [ -s $CUR ] ; then
+ if cmp -s $CUR $TMP1 ; then
+ :
+ else
+ > $TMP2
+ join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "Device additions:\n"
+ tee -a $TMP2 < $OUTPUT
+ printf "\n"
+ fi
+
+ join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "Device deletions:\n"
+ tee -a $TMP2 < $OUTPUT
+ printf "\n"
+ fi
+
+ # Report any block device change. Ignore character
+ # devices, only the name is significant.
+ cat $TMP2 $CUR $TMP1 | \
+ sed -e '/^c/d' | \
+ sort +10 | \
+ sed -e 's/[ ][ ]*/ /g' | \
+ uniq -u > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "Block device changes:\n"
+ column -t $OUTPUT
+ printf "\n"
+ fi
+
+ cp $CUR $BACK
+ cp $TMP1 $CUR
+ fi
+ else
+ printf "Device additions:\n"
+ column -t $TMP1
+ printf "\n"
+ cp $TMP1 $CUR
+ fi
+fi
+
+# Check special files.
+# Check system binaries.
+#
+# Create the mtree tree specifications using:
+#
+# mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure
+# chown root.wheel DIR.SECURE
+# chmod 600 DIR.SECURE
+#
+# Note, this is not complete protection against Trojan horsed binaries, as
+# the hacker can modify the tree specification to match the replaced binary.
+# For details on really protecting yourself against modified binaries, see
+# the mtree(8) manual page.
+if cd /etc/mtree; then
+ mtree -e -p / -f /etc/mtree/special > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "\nChecking special files and directories.\n"
+ cat $OUTPUT
+ fi
+
+ > $OUTPUT
+ for file in *.secure; do
+ tree=`sed -n -e '3s/.* //p' -e 3q $file`
+ mtree -f $file -p $tree > $TMP1
+ if [ -s $TMP1 ]; then
+ printf "\nChecking $tree:\n" >> $OUTPUT
+ cat $TMP1 >> $OUTPUT
+ fi
+ done
+ if [ -s $OUTPUT ] ; then
+ printf "\nChecking system binaries:\n"
+ cat $OUTPUT
+ fi
+fi
+
+# List of files that get backed up and checked for any modifications. Each
+# file is expected to have two backups, /var/backups/file.{current,backup}.
+# Any changes cause the files to rotate.
+if [ -s /etc/changelist ] ; then
+ for file in `cat /etc/changelist`; do
+ CUR=/var/backups/`basename $file`.current
+ BACK=/var/backups/`basename $file`.backup
+ if [ -s $file ]; then
+ if [ -s $CUR ] ; then
+ diff $CUR $file > $OUTPUT
+ if [ -s $OUTPUT ] ; then
+ printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file
+ cat $OUTPUT
+ cp -p $CUR $BACK
+ cp -p $file $CUR
+ chown root.wheel $CUR $BACK
+ fi
+ else
+ cp -p $file $CUR
+ chown root.wheel $CUR
+ fi
+ fi
+ done
+fi