[BACK]Return to security CVS log [TXT][DIR] Up to [local] / src / etc

Annotation of src/etc/security, Revision 1.23

1.1       deraadt     1: #!/bin/sh -
                      2: #
1.23    ! deraadt     3: #      $OpenBSD: security,v 1.22 1997/09/29 22:15:58 deraadt Exp $
1.13      millert     4: #      from: @(#)security      8.1 (Berkeley) 6/9/93
1.1       deraadt     5: #
1.13      millert     6:
1.1       deraadt     7: PATH=/sbin:/usr/sbin:/bin:/usr/bin
                      8:
                      9: umask 077
                     10:
1.7       deraadt    11: DIR=/tmp/_secure$$
                     12: ERR=$DIR/_secure1
                     13: TMP1=$DIR/_secure2
                     14: TMP2=$DIR/_secure3
                     15: TMP3=$DIR/_secure4
                     16: LIST=$DIR/_secure5
                     17: OUTPUT=$DIR/_secure6
1.1       deraadt    18:
1.7       deraadt    19: if ! mkdir $DIR ; then
                     20:        printf "tmp directory %s already exists, looks like:\n" $DIR
                     21:        ls -alF $DIR
                     22:        exit 1
                     23: fi
1.8       deraadt    24:
1.17      deraadt    25: trap 'rm -rf $DIR' 0 1 15
1.1       deraadt    26:
                     27: # Check the master password file syntax.
                     28: MP=/etc/master.passwd
                     29: awk -F: '{
                     30:        if ($0 ~ /^[     ]*$/) {
                     31:                printf("Line %d is a blank line.\n", NR);
                     32:                next;
                     33:        }
                     34:        if (NF != 10)
                     35:                printf("Line %d has the wrong number of fields.\n", NR);
1.15      millert    36:        if ($1 ~ /^[+-]/)
1.2       deraadt    37:                next;
                     38:        if ($1 == "")
1.13      millert    39:                printf("Line %d has an empty login field.\n", NR);
1.2       deraadt    40:        else if ($1 !~ /^[A-Za-z0-9][A-Za-z0-9_-]*$/)
1.1       deraadt    41:                printf("Login %s has non-alphanumeric characters.\n", $1);
                     42:        if (length($1) > 8)
                     43:                printf("Login %s has more than 8 characters.\n", $1);
                     44:        if ($2 == "")
                     45:                printf("Login %s has no password.\n", $1);
1.23    ! deraadt    46:        if ($2 != "" && length($2) != 13 && ($10 ~ /.*sh$/ || $10 == "") &&
        !            47:            ($2 !~ /^\$[0-9a-f]+\$/) && ($2 != "skey")) {
        !            48:                if (system("grep -q \"^"$1" \" /etc/skeykeys") == 0)
        !            49:                        printf("Login %s is off but still has a valid shell and an entry in /etc/skeykeys.\n", $1);
        !            50:                if (system("test -d "$9" -a ! -r "$9"") == 0)
        !            51:                        printf("Login %s if off but still has valid shell and home directory is unreadable\n\t by root; cannot check for existance of alternate access files.\n", $1);
        !            52:                else if (system("for file in .ssh .rhosts .shosts .klogin; do if test -e "$9"/$file; then if ((ls -ld "$9"/$file | cut -b 2-10 | grep -q r) && (test ! -O "$9"/$file)) ; then exit 1; fi; fi; done"))
        !            53:                         printf("Login %s is off but still has a valid shell and alternate access files in\n\t home directory are still readable.\n",$1);
        !            54:        }
1.9       deraadt    55:        if ($3 == 0 && $1 != "root")
1.1       deraadt    56:                printf("Login %s has a user id of 0.\n", $1);
                     57:        if ($3 < 0)
                     58:                printf("Login %s has a negative user id.\n", $1);
                     59:        if ($4 < 0)
                     60:                printf("Login %s has a negative group id.\n", $1);
                     61: }' < $MP > $OUTPUT
                     62: if [ -s $OUTPUT ] ; then
                     63:        printf "\nChecking the $MP file:\n"
                     64:        cat $OUTPUT
                     65: fi
                     66:
                     67: awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
                     68: if [ -s $OUTPUT ] ; then
                     69:        printf "\n$MP has duplicate user names.\n"
                     70:        column $OUTPUT
                     71: fi
                     72:
1.9       deraadt    73: awk -F: '{ print $1 " " $3 }' $MP | sort -n +1 | tee $TMP1 |
1.1       deraadt    74: uniq -d -f 1 | awk '{ print $2 }' > $TMP2
                     75: if [ -s $TMP2 ] ; then
                     76:        printf "\n$MP has duplicate user id's.\n"
                     77:         while read uid; do
                     78:                 grep -w $uid $TMP1
                     79:         done < $TMP2 | column
                     80: fi
                     81:
                     82: # Backup the master password file; a special case, the normal backup
                     83: # mechanisms also print out file differences and we don't want to do
                     84: # that because this file has encrypted passwords in it.
1.2       deraadt    85: if [ ! -d /var/backups ] ; then
                     86:        mkdir /var/backups
                     87:        chmod 755 /var/backups
                     88: fi
1.1       deraadt    89: CUR=/var/backups/`basename $MP`.current
                     90: BACK=/var/backups/`basename $MP`.backup
                     91: if [ -s $CUR ] ; then
                     92:        if cmp -s $CUR $MP; then
                     93:                :
                     94:        else
                     95:                cp -p $CUR $BACK
                     96:                cp -p $MP $CUR
                     97:                chown root.wheel $CUR
                     98:        fi
                     99: else
                    100:        cp -p $MP $CUR
                    101:        chown root.wheel $CUR
                    102: fi
                    103:
                    104: # Check the group file syntax.
                    105: GRP=/etc/group
                    106: awk -F: '{
                    107:        if ($0 ~ /^[     ]*$/) {
                    108:                printf("Line %d is a blank line.\n", NR);
                    109:                next;
                    110:        }
1.2       deraadt   111:        if ($1 ~ /^[+-].*$/)
                    112:                next;
1.1       deraadt   113:        if (NF != 4)
                    114:                printf("Line %d has the wrong number of fields.\n", NR);
1.13      millert   115:        if ($1 !~ /^[A-za-z0-9][A-za-z0-9_-]*$/)
1.1       deraadt   116:                printf("Group %s has non-alphanumeric characters.\n", $1);
                    117:        if (length($1) > 8)
                    118:                printf("Group %s has more than 8 characters.\n", $1);
                    119:        if ($3 !~ /[0-9]*/)
                    120:                printf("Login %s has a negative group id.\n", $1);
                    121: }' < $GRP > $OUTPUT
                    122: if [ -s $OUTPUT ] ; then
                    123:        printf "\nChecking the $GRP file:\n"
                    124:        cat $OUTPUT
                    125: fi
                    126:
                    127: awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
                    128: if [ -s $OUTPUT ] ; then
                    129:        printf "\n$GRP has duplicate group names.\n"
                    130:        column $OUTPUT
                    131: fi
                    132:
                    133: # Check for root paths, umask values in startup files.
                    134: # The check for the root paths is problematical -- it's likely to fail
                    135: # in other environments.  Once the shells have been modified to warn
                    136: # of '.' in the path, the path tests should go away.
                    137: > $OUTPUT
                    138: rhome=/root
                    139: umaskset=no
                    140: list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
                    141: for i in $list ; do
1.15      millert   142:        if [ -s $i ] ; then
1.1       deraadt   143:                if egrep umask $i > /dev/null ; then
                    144:                        umaskset=yes
                    145:                fi
                    146:                egrep umask $i |
                    147:                awk '$2 % 100 < 20 \
                    148:                        { print "Root umask is group writeable" }
                    149:                     $2 % 10 < 2 \
                    150:                        { print "Root umask is other writeable" }' >> $OUTPUT
1.21      deraadt   151:                SAVE_PATH=$PATH
                    152:                unset PATH
1.1       deraadt   153:                /bin/csh -f -s << end-of-csh > /dev/null 2>&1
                    154:                        source $i
                    155:                        /bin/ls -ldgT \$path > $TMP1
                    156: end-of-csh
1.21      deraadt   157:                PATH=$SAVE_PATH
1.1       deraadt   158:                awk '{
                    159:                        if ($10 ~ /^\.$/) {
                    160:                                print "The root path includes .";
                    161:                                next;
                    162:                        }
                    163:                     }
                    164:                     $1 ~ /^d....w/ \
                    165:         { print "Root path directory " $10 " is group writeable." } \
                    166:                     $1 ~ /^d.......w/ \
                    167:         { print "Root path directory " $10 " is other writeable." }' \
                    168:                < $TMP1 >> $OUTPUT
                    169:        fi
                    170: done
                    171: if [ $umaskset = "no" -o -s $OUTPUT ] ; then
                    172:        printf "\nChecking root csh paths, umask values:\n$list\n"
1.13      millert   173:        if [ -s $OUTPUT ] ; then
1.1       deraadt   174:                cat $OUTPUT
                    175:        fi
                    176:        if [ $umaskset = "no" ] ; then
                    177:                printf "\nRoot csh startup files do not set the umask.\n"
                    178:        fi
                    179: fi
                    180:
                    181: > $OUTPUT
                    182: rhome=/root
                    183: umaskset=no
1.20      millert   184: list="/etc/profile ${rhome}/.profile"
1.1       deraadt   185: for i in $list; do
1.15      millert   186:        if [ -s $i ] ; then
1.1       deraadt   187:                if egrep umask $i > /dev/null ; then
                    188:                        umaskset=yes
                    189:                fi
                    190:                egrep umask $i |
                    191:                awk '$2 % 100 < 20 \
                    192:                        { print "Root umask is group writeable" } \
                    193:                     $2 % 10 < 2 \
                    194:                        { print "Root umask is other writeable" }' >> $OUTPUT
1.21      deraadt   195:                SAVE_PATH=$PATH
                    196:                unset PATH
1.1       deraadt   197:                /bin/sh << end-of-sh > /dev/null 2>&1
                    198:                        . $i
                    199:                        list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
                    200:                        /bin/ls -ldgT \$list > $TMP1
                    201: end-of-sh
1.21      deraadt   202:                PATH=$SAVE_PATH
1.1       deraadt   203:                awk '{
                    204:                        if ($10 ~ /^\.$/) {
                    205:                                print "The root path includes .";
                    206:                                next;
                    207:                        }
                    208:                     }
                    209:                     $1 ~ /^d....w/ \
                    210:         { print "Root path directory " $10 " is group writeable." } \
                    211:                     $1 ~ /^d.......w/ \
                    212:         { print "Root path directory " $10 " is other writeable." }' \
                    213:                < $TMP1 >> $OUTPUT
                    214:
                    215:        fi
                    216: done
                    217: if [ $umaskset = "no" -o -s $OUTPUT ] ; then
                    218:        printf "\nChecking root sh paths, umask values:\n$list\n"
1.13      millert   219:        if [ -s $OUTPUT ] ; then
1.1       deraadt   220:                cat $OUTPUT
                    221:        fi
                    222:        if [ $umaskset = "no" ] ; then
                    223:                printf "\nRoot sh startup files do not set the umask.\n"
                    224:        fi
                    225: fi
                    226:
                    227: # Root and uucp should both be in /etc/ftpusers.
                    228: if egrep root /etc/ftpusers > /dev/null ; then
                    229:        :
                    230: else
                    231:        printf "\nRoot not listed in /etc/ftpusers file.\n"
                    232: fi
                    233: if egrep uucp /etc/ftpusers > /dev/null ; then
                    234:        :
                    235: else
                    236:        printf "\nUucp not listed in /etc/ftpusers file.\n"
                    237: fi
                    238:
                    239: # Uudecode should not be in the /etc/aliases file.
                    240: if egrep 'uudecode|decode' /etc/aliases; then
                    241:        printf "\nThere is an entry for uudecode in the /etc/aliases file.\n"
                    242: fi
                    243:
                    244: # Files that should not have + signs.
1.2       deraadt   245: list="/etc/hosts.equiv /etc/shosts.equiv /etc/hosts.lpd"
1.1       deraadt   246: for f in $list ; do
1.6       millert   247:        if [ -s $f ] ; then
1.2       deraadt   248:                awk '{
1.13      millert   249:                        if ($0 ~ /^\+@.*$/)
1.2       deraadt   250:                                next;
1.13      millert   251:                        if ($0 ~ /^\+.*$/)
1.2       deraadt   252:                                printf("\nPlus sign in %s file.\n", FILENAME);
                    253:                }' $f
1.1       deraadt   254:        fi
                    255: done
                    256:
1.13      millert   257: # Check for special users with .rhosts/.shosts files.  Only root
                    258: # should have .rhosts/.shosts files.  Also, .rhosts/.shosts
                    259: # files should not have plus signs.
1.14      millert   260: awk -F: '$1 != "root" && $1 !~ /^[+-]/ && \
1.1       deraadt   261:        ($3 < 100 || $1 == "ftp" || $1 == "uucp") \
                    262:                { print $1 " " $6 }' /etc/passwd |
                    263: while read uid homedir; do
1.2       deraadt   264:        for j in .rhosts .shosts; do
1.14      millert   265:                # Root owned .rhosts/.shosts files are ok.
1.15      millert   266:                if [ -s ${homedir}/$j -a ! -O ${homedir}/$j ] ; then
1.2       deraadt   267:                        rhost=`ls -ldgT ${homedir}/$j`
                    268:                        printf "$uid: $rhost\n"
                    269:                fi
                    270:        done
1.1       deraadt   271: done > $OUTPUT
                    272: if [ -s $OUTPUT ] ; then
1.2       deraadt   273:        printf "\nChecking for special users with .rhosts/.shosts files.\n"
1.1       deraadt   274:        cat $OUTPUT
                    275: fi
                    276:
1.14      millert   277: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   278: while read uid homedir; do
1.2       deraadt   279:        for j in .rhosts .shosts; do
1.13      millert   280:                if [ -s ${homedir}/$j ] ; then
1.2       deraadt   281:                        awk '{
                    282:                                if ($0 ~ /^+@.*$/ )
                    283:                                        next;
1.4       deraadt   284:                                if ($0 ~ /^\+[  ]*$/ )
1.2       deraadt   285:                                        printf("%s has + sign in it.\n",
1.13      millert   286:                                                FILENAME);
1.2       deraadt   287:                        }' ${homedir}/$j
                    288:                fi
                    289:        done
1.1       deraadt   290: done > $OUTPUT
                    291: if [ -s $OUTPUT ] ; then
1.2       deraadt   292:        printf "\nChecking .rhosts/.shosts files syntax.\n"
1.1       deraadt   293:        cat $OUTPUT
                    294: fi
                    295:
                    296: # Check home directories.  Directories should not be owned by someone else
                    297: # or writeable.
1.14      millert   298: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   299: while read uid homedir; do
                    300:        if [ -d ${homedir}/ ] ; then
                    301:                file=`ls -ldgT ${homedir}`
                    302:                printf "$uid $file\n"
                    303:        fi
                    304: done |
                    305: awk '$1 != $4 && $4 != "root" \
                    306:        { print "user " $1 " home directory is owned by " $4 }
                    307:      $2 ~ /^-....w/ \
                    308:        { print "user " $1 " home directory is group writeable" }
                    309:      $2 ~ /^-.......w/ \
                    310:        { print "user " $1 " home directory is other writeable" }' > $OUTPUT
                    311: if [ -s $OUTPUT ] ; then
                    312:        printf "\nChecking home directories.\n"
                    313:        cat $OUTPUT
                    314: fi
                    315:
                    316: # Files that should not be owned by someone else or readable.
1.2       deraadt   317: list=".netrc .rhosts .shosts"
1.14      millert   318: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   319: while read uid homedir; do
                    320:        for f in $list ; do
                    321:                file=${homedir}/${f}
                    322:                if [ -f $file ] ; then
                    323:                        printf "$uid $f `ls -ldgT $file`\n"
                    324:                fi
                    325:        done
                    326: done |
                    327: awk '$1 != $5 && $5 != "root" \
                    328:        { print "user " $1 " " $2 " file is owned by " $5 }
1.13      millert   329:      $3 ~ /^-...r/ \
                    330:        { print "user " $1 " " $2 " file is group readable" }
1.1       deraadt   331:      $3 ~ /^-......r/ \
                    332:        { print "user " $1 " " $2 " file is other readable" }
                    333:      $3 ~ /^-....w/ \
                    334:        { print "user " $1 " " $2 " file is group writeable" }
                    335:      $3 ~ /^-.......w/ \
                    336:        { print "user " $1 " " $2 " file is other writeable" }' > $OUTPUT
                    337:
                    338: # Files that should not be owned by someone else or writeable.
                    339: list=".bashrc .cshrc .emacs .exrc .forward .klogin .login .logout \
                    340:       .profile .tcshrc"
1.14      millert   341: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   342: while read uid homedir; do
                    343:        for f in $list ; do
                    344:                file=${homedir}/${f}
                    345:                if [ -f $file ] ; then
                    346:                        printf "$uid $f `ls -ldgT $file`\n"
                    347:                fi
                    348:        done
                    349: done |
                    350: awk '$1 != $5 && $5 != "root" \
                    351:        { print "user " $1 " " $2 " file is owned by " $5 }
                    352:      $3 ~ /^-....w/ \
                    353:        { print "user " $1 " " $2 " file is group writeable" }
                    354:      $3 ~ /^-.......w/ \
                    355:        { print "user " $1 " " $2 " file is other writeable" }' >> $OUTPUT
                    356: if [ -s $OUTPUT ] ; then
                    357:        printf "\nChecking dot files.\n"
                    358:        cat $OUTPUT
                    359: fi
                    360:
                    361: # Mailboxes should be owned by user and unreadable.
                    362: ls -l /var/mail | sed 1d | \
                    363: awk '$3 != $9 \
                    364:        { print "user " $9 " mailbox is owned by " $3 }
                    365:      $1 != "-rw-------" \
                    366:        { print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT
                    367: if [ -s $OUTPUT ] ; then
                    368:        printf "\nChecking mailbox ownership.\n"
                    369:        cat $OUTPUT
                    370: fi
                    371:
1.13      millert   372: # File systems should not be globally exported.
                    373: if [ -s /etc/exports ] ; then
                    374:        awk '{
1.19      flipk     375:                if (($1 ~ /^#/) || ($1 ~ /^$/))
1.1       deraadt   376:                        next;
1.13      millert   377:                readonly = 0;
                    378:                for (i = 2; i <= NF; ++i) {
1.19      flipk     379:                        if ($i ~ /^-ro$/)
1.13      millert   380:                                readonly = 1;
                    381:                        else if ($i !~ /^-/)
                    382:                                next;
                    383:                }
                    384:                if (readonly)
                    385:                        print "File system " $1 " globally exported, read-only."
                    386:                else
                    387:                        print "File system " $1 " globally exported, read-write."
                    388:        }' < /etc/exports > $OUTPUT
                    389:        if [ -s $OUTPUT ] ; then
                    390:                printf "\nChecking for globally exported file systems.\n"
                    391:                cat $OUTPUT
                    392:        fi
1.1       deraadt   393: fi
                    394:
1.5       deraadt   395: # Display any changes in setuid/setgid files and devices.
                    396: pending="\nChecking setuid/setgid files and devices:\n"
1.1       deraadt   397: (find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \
1.13      millert   398:        -o -fstype procfs \) -a -prune -o \
                    399:        -type f -a \( -perm -u+s -o -perm -g+s \) -print0 -o \
                    400:        ! -type d -a ! -type f -a ! -type l -a ! -type s -print0 | \
                    401: xargs -0 ls -ldgT | sort +9 > $LIST) 2> $OUTPUT
1.1       deraadt   402:
                    403: # Display any errors that occurred during system file walk.
                    404: if [ -s $OUTPUT ] ; then
1.2       deraadt   405:        printf "${pending}Setuid/device find errors:\n"
                    406:        pending=
1.1       deraadt   407:        cat $OUTPUT
                    408:        printf "\n"
                    409: fi
                    410:
1.12      millert   411: # Display any changes in the setuid/setgid file list.
1.13      millert   412: egrep -v '^[bc]' $LIST > $TMP1
1.1       deraadt   413: if [ -s $TMP1 ] ; then
                    414:        # Check to make sure uudecode isn't setuid.
                    415:        if grep -w uudecode $TMP1 > /dev/null ; then
1.2       deraadt   416:                printf "${pending}\nUudecode is setuid.\n"
                    417:                pending=
1.1       deraadt   418:        fi
                    419:
                    420:        CUR=/var/backups/setuid.current
                    421:        BACK=/var/backups/setuid.backup
                    422:
                    423:        if [ -s $CUR ] ; then
                    424:                if cmp -s $CUR $TMP1 ; then
                    425:                        :
                    426:                else
                    427:                        > $TMP2
1.13      millert   428:                        join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
1.1       deraadt   429:                        if [ -s $OUTPUT ] ; then
1.2       deraadt   430:                                printf "${pending}Setuid additions:\n"
                    431:                                pending=
1.1       deraadt   432:                                tee -a $TMP2 < $OUTPUT
                    433:                                printf "\n"
                    434:                        fi
                    435:
1.13      millert   436:                        join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
1.1       deraadt   437:                        if [ -s $OUTPUT ] ; then
1.2       deraadt   438:                                printf "${pending}Setuid deletions:\n"
                    439:                                pending=
1.1       deraadt   440:                                tee -a $TMP2 < $OUTPUT
                    441:                                printf "\n"
                    442:                        fi
                    443:
1.13      millert   444:                        sort +9 $TMP2 $CUR $TMP1 | \
1.1       deraadt   445:                            sed -e 's/[  ][      ]*/ /g' | uniq -u > $OUTPUT
                    446:                        if [ -s $OUTPUT ] ; then
1.2       deraadt   447:                                printf "${pending}Setuid changes:\n"
                    448:                                pending=
1.1       deraadt   449:                                column -t $OUTPUT
                    450:                                printf "\n"
                    451:                        fi
                    452:
                    453:                        cp $CUR $BACK
                    454:                        cp $TMP1 $CUR
                    455:                fi
                    456:        else
1.2       deraadt   457:                printf "${pending}Setuid additions:\n"
                    458:                pending=
1.1       deraadt   459:                column -t $TMP1
                    460:                printf "\n"
                    461:                cp $TMP1 $CUR
                    462:        fi
                    463: fi
                    464:
                    465: # Check for block and character disk devices that are readable or writeable
                    466: # or not owned by root.operator.
                    467: >$TMP1
1.13      millert   468: DISKLIST="ccd dk fd hd hk hp jb kra ra rb rd rl rx rz sd up vnd wd xd"
1.1       deraadt   469: for i in $DISKLIST; do
1.11      tholo     470:        egrep "^b.*/${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
                    471:        egrep "^c.*/r${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
1.1       deraadt   472: done
                    473:
                    474: awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
                    475:        { printf("Disk %s is user %s, group %s, permissions %s.\n", \
                    476:            $11, $3, $4, $1); }' < $TMP1 > $OUTPUT
                    477: if [ -s $OUTPUT ] ; then
                    478:        printf "\nChecking disk ownership and permissions.\n"
                    479:        cat $OUTPUT
                    480:        printf "\n"
                    481: fi
                    482:
                    483: # Display any changes in the device file list.
                    484: egrep '^[bc]' $LIST | sort +10 > $TMP1
                    485: if [ -s $TMP1 ] ; then
                    486:        CUR=/var/backups/device.current
                    487:        BACK=/var/backups/device.backup
                    488:
                    489:        if [ -s $CUR ] ; then
                    490:                if cmp -s $CUR $TMP1 ; then
                    491:                        :
                    492:                else
                    493:                        > $TMP2
                    494:                        join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
                    495:                        if [ -s $OUTPUT ] ; then
                    496:                                printf "Device additions:\n"
                    497:                                tee -a $TMP2 < $OUTPUT
                    498:                                printf "\n"
                    499:                        fi
                    500:
                    501:                        join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
                    502:                        if [ -s $OUTPUT ] ; then
                    503:                                printf "Device deletions:\n"
                    504:                                tee -a $TMP2 < $OUTPUT
                    505:                                printf "\n"
                    506:                        fi
                    507:
                    508:                        # Report any block device change.  Ignore character
                    509:                        # devices, only the name is significant.
                    510:                        cat $TMP2 $CUR $TMP1 | \
                    511:                        sed -e '/^c/d' | \
                    512:                        sort +10 | \
                    513:                        sed -e 's/[      ][      ]*/ /g' | \
                    514:                        uniq -u > $OUTPUT
                    515:                        if [ -s $OUTPUT ] ; then
                    516:                                printf "Block device changes:\n"
                    517:                                column -t $OUTPUT
                    518:                                printf "\n"
                    519:                        fi
                    520:
                    521:                        cp $CUR $BACK
                    522:                        cp $TMP1 $CUR
                    523:                fi
                    524:        else
                    525:                printf "Device additions:\n"
                    526:                column -t $TMP1
                    527:                printf "\n"
                    528:                cp $TMP1 $CUR
                    529:        fi
                    530: fi
                    531:
                    532: # Check special files.
                    533: # Check system binaries.
                    534: #
                    535: # Create the mtree tree specifications using:
                    536: #
                    537: #      mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure
1.2       deraadt   538: #      chown root.wheel DIR.secure
                    539: #      chmod 600 DIR.secure
1.1       deraadt   540: #
                    541: # Note, this is not complete protection against Trojan horsed binaries, as
                    542: # the hacker can modify the tree specification to match the replaced binary.
                    543: # For details on really protecting yourself against modified binaries, see
                    544: # the mtree(8) manual page.
1.13      millert   545: if [ -d /etc/mtree ] ; then
1.2       deraadt   546:        cd /etc/mtree
1.1       deraadt   547:        mtree -e -p / -f /etc/mtree/special > $OUTPUT
                    548:        if [ -s $OUTPUT ] ; then
                    549:                printf "\nChecking special files and directories.\n"
                    550:                cat $OUTPUT
                    551:        fi
                    552:
                    553:        > $OUTPUT
                    554:        for file in *.secure; do
1.2       deraadt   555:                [ $file = '*.secure' ] && continue
1.1       deraadt   556:                tree=`sed -n -e '3s/.* //p' -e 3q $file`
                    557:                mtree -f $file -p $tree > $TMP1
1.13      millert   558:                if [ -s $TMP1 ] ; then
1.1       deraadt   559:                        printf "\nChecking $tree:\n" >> $OUTPUT
                    560:                        cat $TMP1 >> $OUTPUT
                    561:                fi
                    562:        done
                    563:        if [ -s $OUTPUT ] ; then
                    564:                printf "\nChecking system binaries:\n"
                    565:                cat $OUTPUT
                    566:        fi
1.2       deraadt   567: else
                    568:        echo /etc/mtree is missing
1.1       deraadt   569: fi
                    570:
                    571: # List of files that get backed up and checked for any modifications.  Each
                    572: # file is expected to have two backups, /var/backups/file.{current,backup}.
                    573: # Any changes cause the files to rotate.
                    574: if [ -s /etc/changelist ] ; then
                    575:        for file in `cat /etc/changelist`; do
                    576:                CUR=/var/backups/`basename $file`.current
                    577:                BACK=/var/backups/`basename $file`.backup
1.13      millert   578:                if [ -s $file ] ; then
1.1       deraadt   579:                        if [ -s $CUR ] ; then
                    580:                                diff $CUR $file > $OUTPUT
                    581:                                if [ -s $OUTPUT ] ; then
                    582:                printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file
                    583:                                        cat $OUTPUT
                    584:                                        cp -p $CUR $BACK
                    585:                                        cp -p $file $CUR
                    586:                                        chown root.wheel $CUR $BACK
                    587:                                fi
                    588:                        else
                    589:                                cp -p $file $CUR
                    590:                                chown root.wheel $CUR
                    591:                        fi
                    592:                fi
                    593:        done
                    594: fi