+trap 'rm -f $ERR $TMP1 $TMP2 $TMP3 $LIST $OUTPUT' 0
+
+# Check the master password file syntax.
+MP=/etc/master.passwd
+awk -F: '{
+ if ($0 ~ /^[ ]*$/) {
+ printf("Line %d is a blank line.\n", NR);
+ next;
+ }
+ if (NF != 10)
+ printf("Line %d has the wrong number of fields.\n", NR);
+ if ($1 !~ /^[A-Za-z0-9]*$/)
+ printf("Login %s has non-alphanumeric characters.\n", $1);
+ if (length($1) > 8)
+ printf("Login %s has more than 8 characters.\n", $1);
+ if ($2 == "")
+ printf("Login %s has no password.\n", $1);
+ if (length($2) != 13 && ($10 ~ /.*sh$/ || $10 == ""))
+ printf("Login %s is off but still has a valid shell.\n", $1);
+ if ($3 == 0 && $1 != "root" && $1 != "toor")
+ printf("Login %s has a user id of 0.\n", $1);
+ if ($3 < 0)
+ printf("Login %s has a negative user id.\n", $1);
+ if ($4 < 0)
+ printf("Login %s has a negative group id.\n", $1);
+}' < $MP > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking the $MP file:\n"
+ cat $OUTPUT
+fi
+
+awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\n$MP has duplicate user names.\n"
+ column $OUTPUT
+fi
+
+awk -F: '{ print $1 " " $3 }' $MP | sort -n +1 | tee $TMP1 |
+uniq -d -f 1 | awk '{ print $2 }' > $TMP2
+if [ -s $TMP2 ] ; then
+ printf "\n$MP has duplicate user id's.\n"
+ while read uid; do
+ grep -w $uid $TMP1
+ done < $TMP2 | column
+fi
+
+# Backup the master password file; a special case, the normal backup
+# mechanisms also print out file differences and we don't want to do
+# that because this file has encrypted passwords in it.
+CUR=/var/backups/`basename $MP`.current
+BACK=/var/backups/`basename $MP`.backup
+if [ -s $CUR ] ; then
+ if cmp -s $CUR $MP; then
+ :
+ else
+ cp -p $CUR $BACK
+ cp -p $MP $CUR
+ chown root.wheel $CUR
+ fi
+else
+ cp -p $MP $CUR
+ chown root.wheel $CUR
+fi
+
+# Check the group file syntax.
+GRP=/etc/group
+awk -F: '{
+ if ($0 ~ /^[ ]*$/) {
+ printf("Line %d is a blank line.\n", NR);
+ next;
+ }
+ if (NF != 4)
+ printf("Line %d has the wrong number of fields.\n", NR);
+ if ($1 !~ /^[A-za-z0-9]*$/)
+ printf("Group %s has non-alphanumeric characters.\n", $1);
+ if (length($1) > 8)
+ printf("Group %s has more than 8 characters.\n", $1);
+ if ($3 !~ /[0-9]*/)
+ printf("Login %s has a negative group id.\n", $1);
+}' < $GRP > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking the $GRP file:\n"
+ cat $OUTPUT
+fi
+
+awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\n$GRP has duplicate group names.\n"
+ column $OUTPUT
+fi
+
+# Check for root paths, umask values in startup files.
+# The check for the root paths is problematical -- it's likely to fail
+# in other environments. Once the shells have been modified to warn
+# of '.' in the path, the path tests should go away.
+> $OUTPUT
+rhome=/root
+umaskset=no
+list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
+for i in $list ; do
+ if [ -f $i ] ; then
+ if egrep umask $i > /dev/null ; then
+ umaskset=yes
+ fi
+ egrep umask $i |
+ awk '$2 % 100 < 20 \
+ { print "Root umask is group writeable" }
+ $2 % 10 < 2 \
+ { print "Root umask is other writeable" }' >> $OUTPUT
+ /bin/csh -f -s << end-of-csh > /dev/null 2>&1
+ unset path
+ source $i
+ /bin/ls -ldgT \$path > $TMP1
+end-of-csh
+ awk '{
+ if ($10 ~ /^\.$/) {
+ print "The root path includes .";
+ next;
+ }
+ }
+ $1 ~ /^d....w/ \
+ { print "Root path directory " $10 " is group writeable." } \
+ $1 ~ /^d.......w/ \
+ { print "Root path directory " $10 " is other writeable." }' \
+ < $TMP1 >> $OUTPUT
+ fi
+done
+if [ $umaskset = "no" -o -s $OUTPUT ] ; then
+ printf "\nChecking root csh paths, umask values:\n$list\n"
+ if [ -s $OUTPUT ]; then
+ cat $OUTPUT
+ fi
+ if [ $umaskset = "no" ] ; then
+ printf "\nRoot csh startup files do not set the umask.\n"
+ fi
+fi
+
+> $OUTPUT
+rhome=/root
+umaskset=no
+list="${rhome}/.profile"
+for i in $list; do
+ if [ -f $i ] ; then
+ if egrep umask $i > /dev/null ; then
+ umaskset=yes
+ fi
+ egrep umask $i |
+ awk '$2 % 100 < 20 \
+ { print "Root umask is group writeable" } \
+ $2 % 10 < 2 \
+ { print "Root umask is other writeable" }' >> $OUTPUT
+ /bin/sh << end-of-sh > /dev/null 2>&1
+ PATH=
+ . $i
+ list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
+ /bin/ls -ldgT \$list > $TMP1
+end-of-sh
+ awk '{
+ if ($10 ~ /^\.$/) {
+ print "The root path includes .";
+ next;
+ }
+ }
+ $1 ~ /^d....w/ \
+ { print "Root path directory " $10 " is group writeable." } \
+ $1 ~ /^d.......w/ \
+ { print "Root path directory " $10 " is other writeable." }' \
+ < $TMP1 >> $OUTPUT
+
+ fi
+done
+if [ $umaskset = "no" -o -s $OUTPUT ] ; then
+ printf "\nChecking root sh paths, umask values:\n$list\n"
+ if [ -s $OUTPUT ]; then
+ cat $OUTPUT
+ fi
+ if [ $umaskset = "no" ] ; then
+ printf "\nRoot sh startup files do not set the umask.\n"
+ fi
+fi
+
+# Root and uucp should both be in /etc/ftpusers.
+if egrep root /etc/ftpusers > /dev/null ; then
+ :
+else
+ printf "\nRoot not listed in /etc/ftpusers file.\n"
+fi
+if egrep uucp /etc/ftpusers > /dev/null ; then
+ :
+else
+ printf "\nUucp not listed in /etc/ftpusers file.\n"
+fi
+
+# Uudecode should not be in the /etc/aliases file.
+if egrep 'uudecode|decode' /etc/aliases; then
+ printf "\nThere is an entry for uudecode in the /etc/aliases file.\n"
+fi
+
+# Files that should not have + signs.
+list="/etc/hosts.equiv /etc/hosts.lpd"
+for f in $list ; do
+ if egrep '\+' $f > /dev/null ; then
+ printf "\nPlus sign in $f file.\n"
+ fi
+done
+
+# Check for special users with .rhosts files. Only root and toor should
+# have a .rhosts files. Also, .rhosts files should not plus signs.
+awk -F: '$1 != "root" && $1 != "toor" && \
+ ($3 < 100 || $1 == "ftp" || $1 == "uucp") \
+ { print $1 " " $6 }' /etc/passwd |
+while read uid homedir; do
+ if [ -f ${homedir}/.rhosts ] ; then
+ rhost=`ls -ldgT ${homedir}/.rhosts`
+ printf "$uid: $rhost\n"
+ fi
+done > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking for special users with .rhosts files.\n"
+ cat $OUTPUT
+fi
+
+awk -F: '{ print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ if [ -f ${homedir}/.rhosts ] && \
+ egrep '\+' ${homedir}/.rhosts > /dev/null ; then
+ printf "$uid: + in .rhosts file.\n"
+ fi
+done > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking .rhosts files syntax.\n"
+ cat $OUTPUT
+fi
+
+# Check home directories. Directories should not be owned by someone else
+# or writeable.
+awk -F: '{ print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ if [ -d ${homedir}/ ] ; then
+ file=`ls -ldgT ${homedir}`
+ printf "$uid $file\n"
+ fi
+done |
+awk '$1 != $4 && $4 != "root" \
+ { print "user " $1 " home directory is owned by " $4 }
+ $2 ~ /^-....w/ \
+ { print "user " $1 " home directory is group writeable" }
+ $2 ~ /^-.......w/ \
+ { print "user " $1 " home directory is other writeable" }' > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking home directories.\n"
+ cat $OUTPUT
+fi
+
+# Files that should not be owned by someone else or readable.
+list=".netrc .rhosts"
+awk -F: '{ print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ for f in $list ; do
+ file=${homedir}/${f}
+ if [ -f $file ] ; then
+ printf "$uid $f `ls -ldgT $file`\n"
+ fi
+ done
+done |
+awk '$1 != $5 && $5 != "root" \
+ { print "user " $1 " " $2 " file is owned by " $5 }
+ $3 ~ /^-...r/ \
+ { print "user " $1 " " $2 " file is group readable" }
+ $3 ~ /^-......r/ \
+ { print "user " $1 " " $2 " file is other readable" }
+ $3 ~ /^-....w/ \
+ { print "user " $1 " " $2 " file is group writeable" }
+ $3 ~ /^-.......w/ \
+ { print "user " $1 " " $2 " file is other writeable" }' > $OUTPUT
+
+# Files that should not be owned by someone else or writeable.
+list=".bashrc .cshrc .emacsrc .exrc .forward .klogin .login .logout \
+ .profile .tcshrc"
+awk -F: '{ print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ for f in $list ; do
+ file=${homedir}/${f}
+ if [ -f $file ] ; then
+ printf "$uid $f `ls -ldgT $file`\n"
+ fi
+ done
+done |
+awk '$1 != $5 && $5 != "root" \
+ { print "user " $1 " " $2 " file is owned by " $5 }
+ $3 ~ /^-....w/ \
+ { print "user " $1 " " $2 " file is group writeable" }
+ $3 ~ /^-.......w/ \
+ { print "user " $1 " " $2 " file is other writeable" }' >> $OUTPUT
+if [ -s $OUTPUT ] ; then
+ printf "\nChecking dot files.\n"
+ cat $OUTPUT