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

Annotation of src/etc/security, Revision 1.15

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