[BACK]Return to security CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc

Annotation of src/etc/security, Revision 1.110

1.1       cgd         1: #!/bin/sh -
                      2: #
1.110   ! christos    3: #      $NetBSD: security,v 1.109 2010/12/27 03:38:52 christos Exp $
1.9       cgd         4: #      from: @(#)security      8.1 (Berkeley) 6/9/93
1.1       cgd         5: #
                      6:
1.9       cgd         7: PATH=/sbin:/usr/sbin:/bin:/usr/bin
1.1       cgd         8:
1.89      jmmv        9: rcvar_manpage='security.conf(5)'
                     10:
1.31      lukem      11: if [ -f /etc/rc.subr ]; then
                     12:        . /etc/rc.subr
                     13: else
                     14:        echo "Can't read /etc/rc.subr; aborting."
                     15:        exit 1;
                     16: fi
                     17:
1.9       cgd        18: umask 077
1.64      cjs        19: TZ=UTC; export TZ
1.1       cgd        20:
1.15      mrg        21: if [ -s /etc/security.conf ]; then
                     22:        . /etc/security.conf
                     23: fi
                     24:
1.67      lukem      25: # Set reasonable defaults (if they're not set in security.conf)
                     26: #
                     27: backup_dir=${backup_dir:-/var/backups}
                     28: max_loginlen=${max_loginlen:-8}
                     29: max_grouplen=${max_grouplen:-8}
1.104     adrianp    30: pkg_info=${pkg_info:-/usr/sbin/pkg_info}
1.67      lukem      31:
                     32: # Other configurable variables
                     33: #
                     34: special_files="/etc/mtree/special /etc/mtree/special.local"
                     35: MP=/etc/master.passwd
                     36: CHANGELIST=""
                     37: work_dir=$backup_dir/work
                     38:
                     39: if [ ! -d "$work_dir" ]; then
                     40:        mkdir -p "$work_dir"
                     41: fi
                     42:
1.102     martti     43: SECUREDIR=$(mktemp -d -t _securedir) || exit 1
1.56      lukem      44:
1.67      lukem      45: trap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE
1.15      mrg        46:
1.56      lukem      47: if ! cd "$SECUREDIR"; then
                     48:        echo "Can not cd to $SECUREDIR".
1.15      mrg        49:        exit 1
                     50: fi
                     51:
1.91      lukem      52: ERR=err.$$
                     53: TMP1=tmp1.$$
                     54: TMP2=tmp2.$$
                     55: MPBYUID=mpbyuid.$$
                     56: MPBYPATH=mpbypath.$$
                     57: LIST=list.$$
                     58: OUTPUT=output.$$
                     59: LABELS=labels.$$
1.106     haad       60: LVM_LABELS=lvm.$$
1.91      lukem      61: PKGS=pkgs.$$
                     62: CHANGEFILES=changefiles.$$
                     63: SPECIALSPEC=specialspec.$$
1.67      lukem      64:
1.108     jmmv       65: if [ -n "${pkgdb_dir}" ]; then
                     66:     echo "WARNING: Setting pkgdb_dir in security.conf(5) is deprecated"
                     67:     echo "WARNING: Please define PKG_DBDIR in pkg_install.conf(5) instead"
                     68:     _compat_K_flag="-K ${pkgdb_dir}"
                     69: fi
                     70:
                     71: have_pkgs() {
                     72:        $pkg_info ${_compat_K_flag} -q -E '*'
                     73: }
                     74:
1.67      lukem      75: # migrate_file old new
                     76: #      Determine if the "${old}" path name needs to be migrated to the
                     77: #      "${new}" path. Also checks if "${old}.current" needs migrating,
                     78: #      and if so, migrate it and possibly "${old}.current,v" and
                     79: #      "${old}.backup".
                     80: #
                     81: migrate_file()
                     82: {
                     83:        _old=$1
                     84:        _new=$2
                     85:        if [ -z "$_old" -o -z "$_new" ]; then
                     86:                err 3 "USAGE: migrate_file old new"
                     87:        fi
                     88:        if [ ! -d "${_new%/*}" ]; then
                     89:                mkdir -p "${_new%/*}"
                     90:        fi
                     91:        if [ -f "${_old}" -a ! -f "${_new}" ]; then
                     92:                echo "==> migrating ${_old}"
                     93:                echo "           to ${_new}"
                     94:                mv "${_old}" "${_new}"
                     95:        fi
                     96:        if [ -f "${_old}.current" -a ! -f "${_new}.current" ]; then
                     97:                echo "==> migrating ${_old}.current"
                     98:                echo "           to ${_new}.current"
                     99:                mv "${_old}.current" "${_new}.current"
                    100:                if [ -f "${_old}.current,v" -a ! -f "${_new}.current,v" ]; then
                    101:                        echo "==> migrating ${_old}.current,v"
                    102:                        echo "           to ${_new}.current,v"
                    103:                        mv "${_old}.current,v" "${_new}.current,v"
                    104:                fi
                    105:                if [ -f "${_old}.backup" -a ! -f "${_new}.backup" ]; then
                    106:                        echo "==> migrating ${_old}.backup"
                    107:                        echo "           to ${_new}.backup"
                    108:                        mv "${_old}.backup" "${_new}.backup"
                    109:                fi
                    110:        fi
                    111: }
                    112:
                    113:
                    114: # backup_and_diff file printdiff
                    115: #      Determine if file needs backing up, and if so, do it.
                    116: #      If printdiff is yes, display the diffs, otherwise
                    117: #      just print a message saying "[changes omitted]".
                    118: #
                    119: backup_and_diff()
                    120: {
                    121:        _file=$1
                    122:        _printdiff=$2
                    123:        if [ -z "$_file" -o -z "$_printdiff" ]; then
                    124:                err 3 "USAGE: backup_and_diff file printdiff"
                    125:        fi
                    126:        ! checkyesno _printdiff
                    127:        _printdiff=$?
                    128:
                    129:        _old=$backup_dir/${_file##*/}
                    130:        case "$_file" in
                    131:        $work_dir/*)
                    132:                _new=$_file
                    133:                migrate_file "$backup_dir/$_old" "$_new"
                    134:                migrate_file "$_old" "$_new"
                    135:                ;;
                    136:        *)
                    137:                _new=$backup_dir/$_file
                    138:                migrate_file "$_old" "$_new"
                    139:                ;;
                    140:        esac
                    141:        CUR=${_new}.current
                    142:        BACK=${_new}.backup
                    143:        if [ -f $_file ]; then
                    144:                if [ -f $CUR ] ; then
                    145:                        if [ "$_printdiff" -ne 0 ]; then
1.83      jhawk     146:                                diff ${diff_options} $CUR $_file > $OUTPUT
1.67      lukem     147:                        else
                    148:                                if ! cmp -s $CUR $_file; then
                    149:                                        echo "[changes omitted]"
                    150:                                fi > $OUTPUT
                    151:                        fi
                    152:                        if [ -s $OUTPUT ] ; then
                    153:                                printf \
                    154:                        "\n======\n%s diffs (OLD < > NEW)\n======\n" $_file
                    155:                                cat $OUTPUT
                    156:                                backup_file update $_file $CUR $BACK
                    157:                        fi
                    158:                else
                    159:                        printf "\n======\n%s added\n======\n" $_file
                    160:                        if [ "$_printdiff" -ne 0 ]; then
1.83      jhawk     161:                                diff ${diff_options} /dev/null $_file
1.67      lukem     162:                        else
                    163:                                echo "[changes omitted]"
                    164:                        fi
                    165:                        backup_file add $_file $CUR $BACK
                    166:                fi
                    167:        else
                    168:                if [ -f $CUR ]; then
                    169:                        printf "\n======\n%s removed\n======\n" $_file
                    170:                        if [ "$_printdiff" -ne 0 ]; then
1.83      jhawk     171:                                diff ${diff_options} $CUR /dev/null
1.67      lukem     172:                        else
                    173:                                echo "[changes omitted]"
                    174:                        fi
                    175:                        backup_file remove $_file $CUR $BACK
                    176:                fi
                    177:        fi
                    178: }
1.48      abs       179:
1.9       cgd       180:
1.67      lukem     181: # These are used several times.
                    182: #
1.91      lukem     183: awk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID
1.29      lukem     184: awk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH
1.91      lukem     185: for file in $special_files; do
                    186:        [ -s $file ] && cat $file
                    187: done | mtree -CM -k all > $SPECIALSPEC || exit 1
1.9       cgd       188:
1.67      lukem     189:
1.9       cgd       190: # Check the master password file syntax.
1.32      lukem     191: #
1.31      lukem     192: if checkyesno check_passwd; then
1.85      jhawk     193:         # XXX: the sense of permit_star is reversed; the code works as
                    194:         # implemented, but usage needs to be negated.
1.81      jhawk     195:        checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1
1.94      jdolecek  196:        checkyesno check_passwd_permit_nonalpha \
                    197:                 && permit_nonalpha=1 || permit_nonalpha=0
                    198:
1.81      jhawk     199:        awk -v "len=$max_loginlen" \
                    200:            -v "nowarn_shells_list=$check_passwd_nowarn_shells" \
                    201:            -v "nowarn_users_list=$check_passwd_nowarn_users" \
1.94      jdolecek  202:            -v "permit_star=$permit_star" \
                    203:            -v "permit_nonalpha=$permit_nonalpha" \
                    204:        '
1.25      lukem     205:        BEGIN {
                    206:                while ( getline < "/etc/shells" > 0 ) {
1.39      hubertf   207:                        if ($0 ~ /^\#/ || $0 ~ /^$/ )
1.25      lukem     208:                                continue;
                    209:                        shells[$1]++;
                    210:                }
1.81      jhawk     211:                split(nowarn_shells_list, a);
                    212:                for (i in a) nowarn_shells[a[i]]++;
                    213:                split(nowarn_users_list, a);
                    214:                for (i in a) nowarn_users[a[i]]++;
                    215:                uid0_users_list="root toor"
                    216:                split(uid0_users_list, a);
                    217:                for (i in a) uid0_users[a[i]]++;
1.25      lukem     218:                FS=":";
                    219:        }
                    220:
                    221:        {
1.15      mrg       222:                if ($0 ~ /^[     ]*$/) {
1.25      lukem     223:                        printf "Line %d is a blank line.\n", NR;
1.15      mrg       224:                        next;
                    225:                }
1.105     dholland  226:
                    227:                # NIS compat entry?
                    228:                compatline = $1 ~ "^[\\+-]";
                    229:                if (compatline) {
                    230:                        if ($1 == "+" && NF == 1) {
                    231:                                next;
                    232:                        }
                    233:                        sub("^.", "", $1);
                    234:                }
                    235:                if (NF != 10)
1.25      lukem     236:                        printf "Line %d has the wrong number of fields.\n", NR;
1.105     dholland  237:                if (compatline)  {
                    238:                        if ($3 == 0)
1.81      jhawk     239:                            printf "Line %d includes entries with uid 0.\n",
                    240:                                NR;
1.105     dholland  241:                        if ($1 == "")
                    242:                            next;
1.34      abs       243:                }
1.94      jdolecek  244:                if (!permit_nonalpha &&
1.95      peter     245:                    $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
1.25      lukem     246:                        printf "Login %s has non-alphanumeric characters.\n",
                    247:                            $1;
1.34      abs       248:                if (length($1) > len)
1.81      jhawk     249:                        printf "Login %s has more than "len" characters.\n",
                    250:                            $1;
1.105     dholland  251:                if ($2 == "" && !compatline && !nowarn_users[$1])
1.81      jhawk     252:                            printf "Login %s has no password.\n", $1;
                    253:                if (!nowarn_shells[$10] && !nowarn_users[$1]) {
                    254:                    if (length($2) != 13 &&
                    255:                        length($2) != 20 &&
                    256:                        $2 !~ /^\$1/ &&
                    257:                        $2 !~ /^\$2/ &&
1.99      jmcneill  258:                        $2 !~ /^\$sha1/ &&
1.81      jhawk     259:                        $2 != "" &&
                    260:                        (permit_star || $2 != "*") &&
                    261:                        $2 !~ /^\*[A-z-]+$/ &&
                    262:                        $1 != "toor") {
                    263:                            if ($10 == "" || shells[$10])
                    264:                                printf "Login %s is off but still has "\
                    265:                                  "a valid shell (%s)\n", $1, $10;
1.105     dholland  266:                    } else if (compatline && $10 == "") {
                    267:                            # nothing
1.81      jhawk     268:                    } else if (! shells[$10])
                    269:                            printf "Login %s does not have a valid "\
                    270:                            "shell (%s)\n", $1, $10;
                    271:                }
                    272:                if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1])
1.25      lukem     273:                        printf "Login %s has a user id of 0.\n", $1;
1.105     dholland  274:                if ($3 != "" && $3 < 0)
1.25      lukem     275:                        printf "Login %s has a negative user id.\n", $1;
1.105     dholland  276:                if ($4 != "" && $4 < 0)
1.25      lukem     277:                        printf "Login %s has a negative group id.\n", $1;
1.15      mrg       278:        }' < $MP > $OUTPUT
                    279:        if [ -s $OUTPUT ] ; then
                    280:                printf "\nChecking the $MP file:\n"
                    281:                cat $OUTPUT
                    282:        fi
                    283:
                    284:        awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
                    285:        if [ -s $OUTPUT ] ; then
                    286:                printf "\n$MP has duplicate user names.\n"
                    287:                column $OUTPUT
                    288:        fi
                    289:
1.37      wrstuden  290: # To not exclude 'toor', a standard duplicate root account, from the duplicate
                    291: # account test, uncomment the line below (without egrep in it)and comment
                    292: # out the line (with egrep in it) below it.
                    293: #
                    294: #      < $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2
1.36      wrstuden  295:        < $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2
1.15      mrg       296:        if [ -s $TMP2 ] ; then
                    297:                printf "\n$MP has duplicate user id's.\n"
                    298:                while read uid; do
1.28      lukem     299:                        grep -w $uid $MPBYUID
1.15      mrg       300:                done < $TMP2 | column
                    301:        fi
1.9       cgd       302: fi
                    303:
                    304: # Check the group file syntax.
1.32      lukem     305: #
1.31      lukem     306: if checkyesno check_group; then
1.15      mrg       307:        GRP=/etc/group
1.49      jdolecek  308:        awk -F: -v "len=$max_grouplen" '{
1.15      mrg       309:                if ($0 ~ /^[     ]*$/) {
1.25      lukem     310:                        printf "Line %d is a blank line.\n", NR;
1.15      mrg       311:                        next;
                    312:                }
1.34      abs       313:                if (NF != 4 && ($1 != "+" || NF != 1))
1.25      lukem     314:                        printf "Line %d has the wrong number of fields.\n", NR;
1.34      abs       315:                if ($1 == "+" )  {
                    316:                        next;
                    317:                }
1.95      peter     318:                if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
1.25      lukem     319:                        printf "Group %s has non-alphanumeric characters.\n",
                    320:                            $1;
1.49      jdolecek  321:                if (length($1) > len)
                    322:                        printf "Group %s has more than "len" characters.\n", $1;
1.15      mrg       323:                if ($3 !~ /[0-9]*/)
1.25      lukem     324:                        printf "Login %s has a negative group id.\n", $1;
1.15      mrg       325:        }' < $GRP > $OUTPUT
                    326:        if [ -s $OUTPUT ] ; then
                    327:                printf "\nChecking the $GRP file:\n"
                    328:                cat $OUTPUT
                    329:        fi
                    330:
                    331:        awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
                    332:        if [ -s $OUTPUT ] ; then
                    333:                printf "\n$GRP has duplicate group names.\n"
                    334:                column $OUTPUT
                    335:        fi
1.9       cgd       336: fi
                    337:
                    338: # Check for root paths, umask values in startup files.
                    339: # The check for the root paths is problematical -- it's likely to fail
                    340: # in other environments.  Once the shells have been modified to warn
                    341: # of '.' in the path, the path tests should go away.
1.32      lukem     342: #
1.31      lukem     343: if checkyesno check_rootdotfiles; then
1.67      lukem     344:        rhome=~root
1.15      mrg       345:        umaskset=no
                    346:        list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
                    347:        for i in $list ; do
                    348:                if [ -f $i ] ; then
1.67      lukem     349:                        if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ;
                    350:                        then
1.15      mrg       351:                                umaskset=yes
                    352:                        fi
1.63      lukem     353:                        # Double check the umask value itself; ensure that
1.67      lukem     354:                        # both the group and other write bits are set.
                    355:                        #
1.45      sommerfe  356:                        egrep '^[ \t]*umask[ \t]+[0-7]+' $i |
1.63      lukem     357:                        awk '{
1.67      lukem     358:                                if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) {
1.80      wiz       359:                                        print "\tRoot umask is group writable"
1.63      lukem     360:                                }
1.67      lukem     361:                                if ($2 ~ /[^2367]$/) {
1.80      wiz       362:                                        print "\tRoot umask is other writable"
1.63      lukem     363:                                }
1.67      lukem     364:                            }' | sort -u
1.26      lukem     365:                        SAVE_PATH=$PATH
                    366:                        unset PATH
1.15      mrg       367:                        /bin/csh -f -s << end-of-csh > /dev/null 2>&1
                    368:                                source $i
                    369:                                /bin/ls -ldgT \$path > $TMP1
1.9       cgd       370: end-of-csh
1.76      atatat    371:                        export PATH=$SAVE_PATH
1.15      mrg       372:                        awk '{
                    373:                                if ($10 ~ /^\.$/) {
1.27      lukem     374:                                        print "\tThe root path includes .";
1.15      mrg       375:                                        next;
                    376:                                }
                    377:                             }
                    378:                             $1 ~ /^d....w/ \
1.80      wiz       379:                { print "\tRoot path directory " $10 " is group writable." } \
1.15      mrg       380:                             $1 ~ /^d.......w/ \
1.80      wiz       381:                { print "\tRoot path directory " $10 " is other writable." }' \
1.67      lukem     382:                        < $TMP1
1.15      mrg       383:                fi
1.67      lukem     384:        done > $OUTPUT
1.15      mrg       385:        if [ $umaskset = "no" -o -s $OUTPUT ] ; then
1.27      lukem     386:                printf "\nChecking root csh paths, umask values:\n$list\n\n"
1.15      mrg       387:                if [ -s $OUTPUT ]; then
                    388:                        cat $OUTPUT
                    389:                fi
                    390:                if [ $umaskset = "no" ] ; then
1.27      lukem     391:                    printf "\tRoot csh startup files do not set the umask.\n"
1.15      mrg       392:                fi
1.9       cgd       393:        fi
                    394:
1.15      mrg       395:        umaskset=no
1.23      lukem     396:        list="/etc/profile ${rhome}/.profile"
1.15      mrg       397:        for i in $list; do
                    398:                if [ -f $i ] ; then
                    399:                        if egrep umask $i > /dev/null ; then
                    400:                                umaskset=yes
                    401:                        fi
                    402:                        egrep umask $i |
1.67      lukem     403:                        awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \
1.80      wiz       404:                                { print "\tRoot umask is group writable" } \
1.67      lukem     405:                             $2 ~ /[^2367]$/ \
1.80      wiz       406:                                { print "\tRoot umask is other writable" }'
1.26      lukem     407:                        SAVE_PATH=$PATH
                    408:                        unset PATH
1.15      mrg       409:                        /bin/sh << end-of-sh > /dev/null 2>&1
                    410:                                . $i
1.110   ! christos  411:                                list=\$(echo \$PATH | /usr/bin/sed -e \
        !           412:                                    's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g')
1.15      mrg       413:                                /bin/ls -ldgT \$list > $TMP1
1.9       cgd       414: end-of-sh
1.76      atatat    415:                        export PATH=$SAVE_PATH
1.15      mrg       416:                        awk '{
                    417:                                if ($10 ~ /^\.$/) {
1.27      lukem     418:                                        print "\tThe root path includes .";
1.15      mrg       419:                                        next;
                    420:                                }
                    421:                             }
                    422:                             $1 ~ /^d....w/ \
1.80      wiz       423:                { print "\tRoot path directory " $10 " is group writable." } \
1.15      mrg       424:                             $1 ~ /^d.......w/ \
1.80      wiz       425:                { print "\tRoot path directory " $10 " is other writable." }' \
1.67      lukem     426:                        < $TMP1
1.9       cgd       427:
1.15      mrg       428:                fi
1.67      lukem     429:        done > $OUTPUT
1.15      mrg       430:        if [ $umaskset = "no" -o -s $OUTPUT ] ; then
                    431:                printf "\nChecking root sh paths, umask values:\n$list\n"
                    432:                if [ -s $OUTPUT ]; then
                    433:                        cat $OUTPUT
                    434:                fi
                    435:                if [ $umaskset = "no" ] ; then
1.27      lukem     436:                        printf "\tRoot sh startup files do not set the umask.\n"
1.15      mrg       437:                fi
1.9       cgd       438:        fi
                    439: fi
                    440:
                    441: # Root and uucp should both be in /etc/ftpusers.
1.32      lukem     442: #
1.31      lukem     443: if checkyesno check_ftpusers; then
1.109     christos  444:        list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID)
1.27      lukem     445:        for i in $list; do
1.29      lukem     446:                if /usr/libexec/ftpd -C $i ; then
1.67      lukem     447:                        printf "\t$i is not denied\n"
1.27      lukem     448:                fi
1.67      lukem     449:        done > $OUTPUT
1.28      lukem     450:        if [ -s $OUTPUT ]; then
                    451:                printf "\nChecking the /etc/ftpusers configuration:\n"
                    452:                cat $OUTPUT
                    453:        fi
1.9       cgd       454: fi
                    455:
1.43      itojun    456: # Uudecode should not be in the /etc/mail/aliases file.
1.32      lukem     457: #
1.31      lukem     458: if checkyesno check_aliases; then
1.43      itojun    459:        for f in /etc/mail/aliases /etc/aliases; do
                    460:                if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then
                    461:                        printf "\nEntry for uudecode in $f file.\n"
                    462:                fi
                    463:        done
1.9       cgd       464: fi
                    465:
                    466: # Files that should not have + signs.
1.32      lukem     467: #
1.31      lukem     468: if checkyesno check_rhosts; then
1.15      mrg       469:        list="/etc/hosts.equiv /etc/hosts.lpd"
                    470:        for f in $list ; do
                    471:                if [ -f $f ] && egrep '\+' $f > /dev/null ; then
                    472:                        printf "\nPlus sign in $f file.\n"
                    473:                fi
                    474:        done
                    475:
                    476:        # Check for special users with .rhosts files.  Only root and toor should
1.16      mikel     477:        # have .rhosts files.  Also, .rhosts files should not have plus signs.
1.15      mrg       478:        awk -F: '$1 != "root" && $1 != "toor" && \
                    479:                ($3 < 100 || $1 == "ftp" || $1 == "uucp") \
1.20      mycroft   480:                        { print $1 " " $9 }' $MP |
1.19      mycroft   481:        sort -k2 |
1.15      mrg       482:        while read uid homedir; do
                    483:                if [ -f ${homedir}/.rhosts ] ; then
1.109     christos  484:                        rhost=$(ls -ldgT ${homedir}/.rhosts)
1.46      christos  485:                        printf -- "$uid: $rhost\n"
1.15      mrg       486:                fi
                    487:        done > $OUTPUT
                    488:        if [ -s $OUTPUT ] ; then
                    489:                printf "\nChecking for special users with .rhosts files.\n"
                    490:                cat $OUTPUT
                    491:        fi
                    492:
                    493:        while read uid homedir; do
1.35      fair      494:                if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \
1.41      christos  495:                    cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then
1.46      christos  496:                        printf -- "$uid: + in .rhosts file.\n"
1.15      mrg       497:                fi
1.29      lukem     498:        done < $MPBYPATH > $OUTPUT
1.15      mrg       499:        if [ -s $OUTPUT ] ; then
                    500:                printf "\nChecking .rhosts files syntax.\n"
                    501:                cat $OUTPUT
                    502:        fi
1.9       cgd       503: fi
                    504:
                    505: # Check home directories.  Directories should not be owned by someone else
1.80      wiz       506: # or writable.
1.32      lukem     507: #
1.31      lukem     508: if checkyesno check_homes; then
1.85      jhawk     509:        checkyesno check_homes_permit_usergroups && \
                    510:                permit_usergroups=1 || permit_usergroups=0
1.15      mrg       511:        while read uid homedir; do
                    512:                if [ -d ${homedir}/ ] ; then
1.109     christos  513:                        file=$(ls -ldgT ${homedir})
1.46      christos  514:                        printf -- "$uid $file\n"
1.9       cgd       515:                fi
1.29      lukem     516:        done < $MPBYPATH |
1.85      jhawk     517:        awk -v "usergroups=$permit_usergroups" '
                    518:             $1 != $4 && $4 != "root" \
1.15      mrg       519:                { print "user " $1 " home directory is owned by " $4 }
1.101     jnemeth   520:             $2 ~ /^d....w/ && (!usergroups || $5 != $1) \
1.80      wiz       521:                { print "user " $1 " home directory is group writable" }
1.101     jnemeth   522:             $2 ~ /^d.......w/ \
1.80      wiz       523:                { print "user " $1 " home directory is other writable" }' \
1.27      lukem     524:            > $OUTPUT
1.15      mrg       525:        if [ -s $OUTPUT ] ; then
                    526:                printf "\nChecking home directories.\n"
                    527:                cat $OUTPUT
                    528:        fi
                    529:
                    530:        # Files that should not be owned by someone else or readable.
1.67      lukem     531:        list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity"
1.15      mrg       532:        while read uid homedir; do
                    533:                for f in $list ; do
                    534:                        file=${homedir}/${f}
                    535:                        if [ -f $file ] ; then
1.109     christos  536:                                printf -- "$uid $f $(ls -ldgT $file)\n"
1.15      mrg       537:                        fi
                    538:                done
1.29      lukem     539:        done < $MPBYPATH |
1.85      jhawk     540:        awk  -v "usergroups=$permit_usergroups" '
                    541:             $1 != $5 && $5 != "root" \
1.15      mrg       542:                { print "user " $1 " " $2 " file is owned by " $5 }
1.85      jhawk     543:             $3 ~ /^-...r/ && (!usergroups || $6 != $1) \
1.15      mrg       544:                { print "user " $1 " " $2 " file is group readable" }
                    545:             $3 ~ /^-......r/ \
                    546:                { print "user " $1 " " $2 " file is other readable" }
1.85      jhawk     547:             $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
1.80      wiz       548:                { print "user " $1 " " $2 " file is group writable" }
1.15      mrg       549:             $3 ~ /^-.......w/ \
1.80      wiz       550:                { print "user " $1 " " $2 " file is other writable" }' \
1.27      lukem     551:            > $OUTPUT
1.15      mrg       552:
1.80      wiz       553:        # Files that should not be owned by someone else or writable.
1.19      mycroft   554:        list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \
1.79      elric     555:              .cshrc .emacs .exrc .forward .history .k5login .klogin .login \
                    556:              .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \
                    557:              .twmrc .xinitrc .xsession .ssh/authorized_keys \
                    558:              .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \
                    559:              .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \
                    560:              .ssh/known_hosts2"
1.15      mrg       561:        while read uid homedir; do
                    562:                for f in $list ; do
                    563:                        file=${homedir}/${f}
                    564:                        if [ -f $file ] ; then
1.109     christos  565:                                printf -- "$uid $f $(ls -ldgT $file)\n"
1.15      mrg       566:                        fi
                    567:                done
1.29      lukem     568:        done < $MPBYPATH |
1.85      jhawk     569:        awk -v "usergroups=$permit_usergroups" '
                    570:             $1 != $5 && $5 != "root" \
1.15      mrg       571:                { print "user " $1 " " $2 " file is owned by " $5 }
1.85      jhawk     572:             $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
1.80      wiz       573:                { print "user " $1 " " $2 " file is group writable" }
1.15      mrg       574:             $3 ~ /^-.......w/ \
1.80      wiz       575:                { print "user " $1 " " $2 " file is other writable" }' \
1.27      lukem     576:            >> $OUTPUT
1.15      mrg       577:        if [ -s $OUTPUT ] ; then
                    578:                printf "\nChecking dot files.\n"
                    579:                cat $OUTPUT
                    580:        fi
1.9       cgd       581: fi
                    582:
                    583: # Mailboxes should be owned by user and unreadable.
1.32      lukem     584: #
1.31      lukem     585: if checkyesno check_varmail; then
1.86      jhawk     586:        ls -lA /var/mail | \
1.63      lukem     587:        awk '   NR == 1 { next; }
1.86      jhawk     588:                $9 ~ /^\./ {next; }
1.63      lukem     589:                $3 != $9 {
                    590:                        print "user " $9 " mailbox is owned by " $3
                    591:                }
                    592:                $1 != "-rw-------" {
                    593:                        print "user " $9 " mailbox is " $1 ", group " $4
                    594:                }' > $OUTPUT
1.15      mrg       595:        if [ -s $OUTPUT ] ; then
                    596:                printf "\nChecking mailbox ownership.\n"
                    597:                cat $OUTPUT
                    598:        fi
                    599: fi
                    600:
1.32      lukem     601: # NFS exports shouldn't be globally exported
                    602: #
                    603: if checkyesno check_nfs && [ -f /etc/exports ]; then
                    604:        awk '{
1.22      lukem     605:                # ignore comments and blank lines
1.39      hubertf   606:                if ($0 ~ /^\#/ || $0 ~ /^$/ )
1.22      lukem     607:                        next;
1.100     tron      608:                # manage line continuation
                    609:                while ($NF ~ /^\\$/) {
                    610:                        $NF = "";
                    611:                        line = $0 "";
                    612:                        getline;
                    613:                        $0 = line $0 "";
                    614:                }
1.22      lukem     615:
1.100     tron      616:                delete dir;
                    617:                readonly = ndir = 0;
                    618:                for (i = 1; i <= NF; ++i) {
                    619:                        if ($i ~ /^\//) dir[ndir++] = $i;
                    620:                        else if ($i ~ /^-/) {
                    621:                                if ($i ~ /^-(ro|o)$/) readonly = 1;
                    622:                                if ($i ~ /^-network/) next;
                    623:                        }
                    624:                        else next;
1.15      mrg       625:                }
                    626:                if (readonly)
1.100     tron      627:                        for (item in dir)
                    628:                                rodir[nrodir++] = dir[item];
1.15      mrg       629:                else
1.100     tron      630:                        for (item in dir)
                    631:                                rwdir[nrwdir++] = dir[item];
                    632:
                    633:        }
                    634:
                    635:        END {
                    636:                if (nrodir) {
                    637:                        printf("Globally exported file system%s, read-only:\n",
                    638:                                nrodir > 1 ? "s" : "");
                    639:                        for (item in rodir)
                    640:                                printf("\t%s\n", rodir[item]);
                    641:                }
                    642:                if (nrwdir) {
                    643:                        printf("Globally exported file system%s, read-write:\n",
                    644:                                nrwdir > 1 ? "s" : "");
                    645:                        for (item in rwdir)
                    646:                                printf("\t%s\n", rwdir[item]);
                    647:                }
1.32      lukem     648:        }' < /etc/exports > $OUTPUT
                    649:        if [ -s $OUTPUT ] ; then
1.15      mrg       650:                printf "\nChecking for globally exported file systems.\n"
                    651:                cat $OUTPUT
                    652:        fi
1.9       cgd       653: fi
                    654:
                    655: # Display any changes in setuid files and devices.
1.32      lukem     656: #
1.31      lukem     657: if checkyesno check_devices; then
1.28      lukem     658:        > $ERR
1.92      erh       659:        (
1.98      lukem     660:
                    661:        # Convert check_devices_ignore_fstypes="foo !bar bax"
                    662:        #    into "-fstype foo -o ! -fstype bar -o -fstype bax"
                    663:        # and check_devices_ignore_paths="/foo !/bar /bax"
                    664:        #    into " -path /foo -o ! -path /bar -o -path /bax"
                    665:        #
                    666:        ignexpr=$(\
                    667:            echo $check_devices_ignore_fstypes | \
                    668:                sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \
                    669:            echo $check_devices_ignore_paths | \
                    670:                sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \
                    671:        )
                    672:
                    673:        # Massage the expression into ( $ignexpr ) -a -prune -o
                    674:        if [ -n "${ignexpr}" ]; then
                    675:                ignexpr=$(\
                    676:                        echo $ignexpr | \
                    677:                            sed -e 's/^-o /( /' \
                    678:                                -e 's/$/ ) -a -prune -o/' \
                    679:                )
                    680:        fi
                    681:
                    682:        find / $ignexpr \
1.21      mycroft   683:            \( \( -perm -u+s -a ! -type d \) -o \
                    684:               \( -perm -g+s -a ! -type d \) -o \
1.24      lukem     685:               -type b -o -type c \) -print0 | \
1.98      lukem     686:        xargs -0 ls -ldgTq | sort +9 > $LIST
                    687:
                    688:        ) 2> $OUTPUT
1.15      mrg       689:
                    690:        # Display any errors that occurred during system file walk.
                    691:        if [ -s $OUTPUT ] ; then
1.28      lukem     692:                printf "Setuid/device find errors:\n" >> $ERR
                    693:                cat $OUTPUT >> $ERR
                    694:                printf "\n" >> $ERR
1.15      mrg       695:        fi
                    696:
                    697:        # Display any changes in the setuid file list.
                    698:        egrep -v '^[bc]' $LIST > $TMP1
                    699:        if [ -s $TMP1 ] ; then
                    700:                # Check to make sure uudecode isn't setuid.
                    701:                if grep -w uudecode $TMP1 > /dev/null ; then
1.28      lukem     702:                        printf "\nUudecode is setuid.\n" >> $ERR
1.15      mrg       703:                fi
                    704:
1.67      lukem     705:                file=$work_dir/setuid
                    706:                migrate_file "$backup_dir/setuid" "$file"
                    707:                CUR=${file}.current
                    708:                BACK=${file}.backup
1.15      mrg       709:                if [ -s $CUR ] ; then
                    710:                        if cmp -s $CUR $TMP1 ; then
                    711:                                :
                    712:                        else
                    713:                                > $TMP2
                    714:                                join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
                    715:                                if [ -s $OUTPUT ] ; then
1.28      lukem     716:                                        printf "Setuid additions:\n" >> $ERR
                    717:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    718:                                        printf "\n" >> $ERR
1.15      mrg       719:                                fi
                    720:
                    721:                                join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
                    722:                                if [ -s $OUTPUT ] ; then
1.28      lukem     723:                                        printf "Setuid deletions:\n" >> $ERR
                    724:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    725:                                        printf "\n" >> $ERR
1.15      mrg       726:                                fi
                    727:
1.20      mycroft   728:                                sort -k10 $TMP2 $CUR $TMP1 | \
1.27      lukem     729:                                    sed -e 's/[  ][      ]*/ /g' | \
                    730:                                    uniq -u > $OUTPUT
1.15      mrg       731:                                if [ -s $OUTPUT ] ; then
1.28      lukem     732:                                        printf "Setuid changes:\n" >> $ERR
                    733:                                        column -t $OUTPUT >> $ERR
                    734:                                        printf "\n" >> $ERR
1.15      mrg       735:                                fi
1.9       cgd       736:
1.52      atatat    737:                                backup_file update $TMP1 $CUR $BACK
1.9       cgd       738:                        fi
1.15      mrg       739:                else
1.28      lukem     740:                        printf "Setuid additions:\n" >> $ERR
                    741:                        column -t $TMP1 >> $ERR
                    742:                        printf "\n" >> $ERR
1.52      atatat    743:                        backup_file add $TMP1 $CUR $BACK
1.9       cgd       744:                fi
1.15      mrg       745:        fi
                    746:
1.27      lukem     747:        # Check for block and character disk devices that are readable or
1.80      wiz       748:        # writable or not owned by root.operator.
1.15      mrg       749:        >$TMP1
1.61      lukem     750:        DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \
1.57      simonb    751:            sd se ss uk up vnd wd xd xy"
1.27      lukem     752: #      DISKLIST="$DISKLIST ct mt st wt"
1.15      mrg       753:        for i in $DISKLIST; do
                    754:                egrep "^b.*/${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
                    755:                egrep "^c.*/r${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
                    756:        done
                    757:
                    758:        awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
1.25      lukem     759:                { printf "Disk %s is user %s, group %s, permissions %s.\n", \
                    760:                    $11, $3, $4, $1; }' < $TMP1 > $OUTPUT
1.15      mrg       761:        if [ -s $OUTPUT ] ; then
1.28      lukem     762:                printf "\nChecking disk ownership and permissions.\n" >> $ERR
                    763:                cat $OUTPUT >> $ERR
                    764:                printf "\n" >> $ERR
1.9       cgd       765:        fi
                    766:
1.15      mrg       767:        # Display any changes in the device file list.
1.20      mycroft   768:        egrep '^[bc]' $LIST | sort -k11 > $TMP1
1.15      mrg       769:        if [ -s $TMP1 ] ; then
1.67      lukem     770:                file=$work_dir/device
                    771:                migrate_file "$backup_dir/device" "$file"
                    772:                CUR=${file}.current
                    773:                BACK=${file}.backup
1.15      mrg       774:
                    775:                if [ -s $CUR ] ; then
                    776:                        if cmp -s $CUR $TMP1 ; then
                    777:                                :
                    778:                        else
                    779:                                > $TMP2
                    780:                                join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
                    781:                                if [ -s $OUTPUT ] ; then
1.28      lukem     782:                                        printf "Device additions:\n" >> $ERR
                    783:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    784:                                        printf "\n" >> $ERR
1.15      mrg       785:                                fi
                    786:
                    787:                                join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
                    788:                                if [ -s $OUTPUT ] ; then
1.28      lukem     789:                                        printf "Device deletions:\n" >> $ERR
                    790:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    791:                                        printf "\n" >> $ERR
1.15      mrg       792:                                fi
                    793:
1.27      lukem     794:                                # Report any block device change. Ignore
                    795:                                # character devices, only the name is
                    796:                                # significant.
1.15      mrg       797:                                cat $TMP2 $CUR $TMP1 | \
1.27      lukem     798:                                    sed -e '/^c/d' | \
                    799:                                    sort -k11 | \
                    800:                                    sed -e 's/[  ][      ]*/ /g' | \
                    801:                                    uniq -u > $OUTPUT
1.15      mrg       802:                                if [ -s $OUTPUT ] ; then
1.28      lukem     803:                                        printf "Block device changes:\n" >> $ERR
                    804:                                        column -t $OUTPUT >> $ERR
                    805:                                        printf "\n" >> $ERR
1.15      mrg       806:                                fi
1.9       cgd       807:
1.52      atatat    808:                                backup_file update $TMP1 $CUR $BACK
1.9       cgd       809:                        fi
1.15      mrg       810:                else
1.28      lukem     811:                        printf "Device additions:\n" >> $ERR
                    812:                        column -t $TMP1 >> $ERR
                    813:                        printf "\n" >> $ERR
1.52      atatat    814:                        backup_file add $TMP1 $CUR $BACK >> $ERR
1.9       cgd       815:                fi
1.28      lukem     816:        fi
                    817:        if [ -s $ERR ] ; then
                    818:                printf "\nChecking setuid files and devices:\n"
                    819:                cat $ERR
                    820:                printf "\n"
1.9       cgd       821:        fi
                    822: fi
                    823:
                    824: # Check special files.
                    825: # Check system binaries.
                    826: #
                    827: # Create the mtree tree specifications using:
1.67      lukem     828: #      mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure
1.38      kleink    829: #      chown root:wheel DIR.secure
1.67      lukem     830: #      chmod u+r,go= DIR.secure
1.9       cgd       831: #
                    832: # Note, this is not complete protection against Trojan horsed binaries, as
                    833: # the hacker can modify the tree specification to match the replaced binary.
                    834: # For details on really protecting yourself against modified binaries, see
                    835: # the mtree(8) manual page.
1.32      lukem     836: #
1.31      lukem     837: if checkyesno check_mtree; then
1.82      jhawk     838:        if checkyesno check_mtree_follow_symlinks; then
                    839:                check_mtree_flags="-L"
                    840:        else
                    841:                check_mtree_flags=""
                    842:        fi
1.91      lukem     843:        mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 |
1.87      jhawk     844:                grep -v '^mtree: dev/tty: Device not configured$' >&2
1.15      mrg       845:        if [ -s $OUTPUT ]; then
1.9       cgd       846:                printf "\nChecking special files and directories.\n"
                    847:                cat $OUTPUT
                    848:        fi
                    849:
1.16      mikel     850:        for file in /etc/mtree/*.secure; do
                    851:                [ $file = '/etc/mtree/*.secure' ] && continue
1.109     christos  852:                tree=$(sed -n -e '3s/.* //p' -e 3q $file)
1.82      jhawk     853:                mtree $check_mtree_flags -f $file -p $tree > $TMP1
1.9       cgd       854:                if [ -s $TMP1 ]; then
1.67      lukem     855:                        printf "\nChecking $tree:\n"
                    856:                        cat $TMP1
1.9       cgd       857:                fi
1.67      lukem     858:        done > $OUTPUT
1.15      mrg       859:        if [ -s $OUTPUT ]; then
1.9       cgd       860:                printf "\nChecking system binaries:\n"
                    861:                cat $OUTPUT
                    862:        fi
                    863: fi
                    864:
1.32      lukem     865: # Backup disklabels of available disks
                    866: #
                    867: if checkyesno check_disklabels; then
1.67      lukem     868:                # migrate old disklabels
1.109     christos  869:        for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \
                    870:            $backup_dir/disklabel.* 2>/dev/null); do
1.67      lukem     871:                migrate_file "$file" "$work_dir/${file##*/}"
                    872:        done
                    873:
1.103     tron      874:                # generate list of old disklabels, fdisks & wedges and remove them
                    875:        ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
1.52      atatat    876:            egrep -v '\.(backup|current)(,v)?$' > $LABELS
1.32      lukem     877:        xargs rm < $LABELS
                    878:
1.103     tron      879:                # generate disklabels of all disks excluding:   cd dk fd md st
1.109     christos  880:        disks=$(iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|dk|st|nfs/ { print $1; }')
1.32      lukem     881:        for i in $disks; do
1.67      lukem     882:                disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null
1.32      lukem     883:        done
                    884:
1.67      lukem     885:                # if fdisk is available, generate fdisks for:   ed ld sd wd
                    886:        if [ -x /sbin/fdisk ]; then
1.109     christos  887:                disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }')
1.67      lukem     888:                for i in $disks; do
                    889:                        /sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null
                    890:                done
                    891:        fi
                    892:
1.103     tron      893:                # if dkctl is available, generate dkctl listwedges for: ed ld sd wd cgd ofdisk ra rl raid
                    894:        if [ -x /sbin/dkctl ]; then
1.109     christos  895:                disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d|cgd|ofdisk|r[al]|raid/ { print $1; }')
1.103     tron      896:                for i in $disks; do
                    897:                        /sbin/dkctl $i listwedges > "$work_dir/wedges.$i" 2>/dev/null
                    898:                done
                    899:        fi
                    900:
                    901:                # append list of new disklabels, fdisks and wedges
                    902:        ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
1.52      atatat    903:            egrep -v '\.(backup|current)(,v)?$' >> $LABELS
1.62      atatat    904:        CHANGELIST="$LABELS $CHANGELIST"
                    905: fi
                    906:
1.106     haad      907: if checkyesno check_lvm; then
                    908:
                    909:     # generate list of existing LVM elements Physical Volumes, Volume Groups and Logical Volumes.
                    910: if [ -x /sbin/lvm ]; then
                    911:     lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null
                    912:     lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null
                    913:     lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null
                    914: fi
                    915:     ls -1d $work_dir/lvm.* 2>/dev/null |
                    916:         egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS
                    917:     CHANGELIST="$CHANGELIST $LVM_LABELS"
                    918: fi
                    919:
1.62      atatat    920: # Check for changes in the list of installed pkgs
                    921: #
1.108     jmmv      922: if checkyesno check_pkgs && have_pkgs; then
1.67      lukem     923:        pkgs=$work_dir/pkgs
                    924:        migrate_file "$backup_dir/pkgs" "$pkgs"
1.108     jmmv      925:        pkg_dbdir=$(pkg_admin config-var PKG_DBDIR)
                    926:        : ${pkg_dbdir:=/var/db/pkg}
                    927:        (       cd $pkg_dbdir
1.104     adrianp   928:                $pkg_info | sort
1.62      atatat    929:                echo ""
                    930:                find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 |
1.72      lukem     931:                        xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,'
1.62      atatat    932:         ) > $pkgs
1.67      lukem     933:        echo "$pkgs" > $PKGS
1.62      atatat    934:        CHANGELIST="$PKGS $CHANGELIST"
1.32      lukem     935: fi
                    936:
1.67      lukem     937: # List of files that get backed up and checked for any modifications.
1.9       cgd       938: # Any changes cause the files to rotate.
1.32      lukem     939: #
1.67      lukem     940: if checkyesno check_changelist ; then
1.91      lukem     941:        mtree -D -k type -f $SPECIALSPEC -E exclude |
                    942:            sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES
1.67      lukem     943:
1.75      lukem     944:        (
1.68      lukem     945:                # Add other files which might dynamically exist:
1.67      lukem     946:                #       /etc/ifconfig.*
                    947:                #       /etc/raid*.conf
1.68      lukem     948:                #       /etc/rc.d/*
1.67      lukem     949:                #       /etc/rc.conf.d/*
1.68      lukem     950:                #
1.75      lukem     951:                echo "/etc/ifconfig.*"
                    952:                echo "/etc/raid*.conf"
                    953:                echo "/etc/rc.d/*"
                    954:                echo "/etc/rc.conf.d/*"
1.106     haad      955:                echo "/etc/lvm/backup/*"
                    956:                echo "/etc/lvm/archive/*"
1.67      lukem     957:
1.68      lukem     958:                # Add /etc/changelist
                    959:                #
1.75      lukem     960:                if [ -s /etc/changelist ]; then
                    961:                        grep -v '^#' /etc/changelist
                    962:                fi
                    963:        ) | while read file; do
                    964:                case "$file" in
                    965:                *[\*\?\[]*)     # If changelist line is a glob ...
                    966:                                # ... expand possible backup files
                    967:                                #
                    968:                        ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \
                    969:                            | sed "s,^$backup_dir/,, ; s,\.current$,,"
                    970:
                    971:                                # ... expand possible files
                    972:                                #
                    973:                        ls -1d $(echo $file) 2>/dev/null
                    974:                        ;;
                    975:                *)
                    976:                                # Otherwise, just print the filename
                    977:                        echo $file
                    978:                        ;;
                    979:                esac
                    980:        done >> $CHANGEFILES
1.67      lukem     981:        CHANGELIST="$CHANGEFILES $CHANGELIST"
                    982: fi
                    983:
                    984: # Special case backups, including the master password file and
                    985: # ssh private host keys. The normal backup mechanisms for
                    986: # $check_changelist (see below) also print out the actual file
                    987: # differences and we don't want to do that for these files
                    988: #
                    989: echo $MP > $TMP1                       # always add /etc/master.passwd
1.91      lukem     990: mtree -D -k type -f $SPECIALSPEC -I nodiff |
                    991:     sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1
1.73      lukem     992: grep -v '^$' $TMP1 | sort -u > $TMP2
1.68      lukem     993:
1.69      lukem     994: while read file; do
1.67      lukem     995:        backup_and_diff "$file" no
1.69      lukem     996: done < $TMP2
1.67      lukem     997:
1.32      lukem     998:
                    999: if [ -n "$CHANGELIST" ]; then
1.73      lukem    1000:        grep -h -v '^$' $CHANGELIST | sort -u > $TMP1
1.68      lukem    1001:        comm -23 $TMP1 $TMP2 | while read file; do
1.67      lukem    1002:                backup_and_diff "$file" yes
1.9       cgd      1003:        done
1.44      ad       1004: fi
                   1005:
1.108     jmmv     1006: if have_pkgs; then
1.107     jmmv     1007:        if checkyesno check_pkg_vulnerabilities; then
1.108     jmmv     1008:                pkg_admin ${_compat_K_flag} audit >${OUTPUT} 2>&1
1.107     jmmv     1009:                if [ -s ${OUTPUT} ]; then
                   1010:                        printf "\nInstalled vulnerable packages:\n"
                   1011:                        cat ${OUTPUT}
                   1012:                fi
                   1013:        fi
                   1014:
                   1015:        if checkyesno check_pkg_signatures; then
1.108     jmmv     1016:                pkg_admin ${_compat_K_flag} check >${OUTPUT} 2>&1
1.107     jmmv     1017:                if [ $? -ne 0 ]; then
                   1018:                        printf "\nFiles with invalid signatures:\n"
                   1019:                        cat ${OUTPUT}
                   1020:                fi
                   1021:        fi
                   1022: fi
                   1023:
1.44      ad       1024: if [ -f /etc/security.local ]; then
1.90      kim      1025:        . /etc/security.local > $OUTPUT 2>&1
1.84      jhawk    1026:        if [ -s $OUTPUT ] ; then
                   1027:                printf "\nRunning /etc/security.local:\n"
                   1028:                cat $OUTPUT
                   1029:        fi
1.9       cgd      1030: fi

CVSweb <webmaster@jp.NetBSD.org>