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

Annotation of src/etc/security, Revision 1.111

1.1       cgd         1: #!/bin/sh -
                      2: #
1.111   ! spz         3: #      $NetBSD: security,v 1.110 2011/03/02 17:00:28 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.111   ! spz       290:        awk -v "permit_dups_list=$check_passwd_permit_dups" \
        !           291:        '
        !           292:        BEGIN {
        !           293:                split(permit_dups_list, a);
        !           294:                for (i in a) permit_dups[a[i]]++;
        !           295:        }
        !           296:        {
        !           297:                if (!permit_dups[$1])
        !           298:                        print $2;
        !           299:        }' < $MPBYUID | uniq -d > $TMP2
1.15      mrg       300:        if [ -s $TMP2 ] ; then
1.111   ! spz       301:                printf "\n$MP has duplicate user ids.\n"
1.15      mrg       302:                while read uid; do
1.28      lukem     303:                        grep -w $uid $MPBYUID
1.15      mrg       304:                done < $TMP2 | column
                    305:        fi
1.9       cgd       306: fi
                    307:
                    308: # Check the group file syntax.
1.32      lukem     309: #
1.31      lukem     310: if checkyesno check_group; then
1.15      mrg       311:        GRP=/etc/group
1.49      jdolecek  312:        awk -F: -v "len=$max_grouplen" '{
1.15      mrg       313:                if ($0 ~ /^[     ]*$/) {
1.25      lukem     314:                        printf "Line %d is a blank line.\n", NR;
1.15      mrg       315:                        next;
                    316:                }
1.34      abs       317:                if (NF != 4 && ($1 != "+" || NF != 1))
1.25      lukem     318:                        printf "Line %d has the wrong number of fields.\n", NR;
1.34      abs       319:                if ($1 == "+" )  {
                    320:                        next;
                    321:                }
1.95      peter     322:                if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/)
1.25      lukem     323:                        printf "Group %s has non-alphanumeric characters.\n",
                    324:                            $1;
1.49      jdolecek  325:                if (length($1) > len)
                    326:                        printf "Group %s has more than "len" characters.\n", $1;
1.15      mrg       327:                if ($3 !~ /[0-9]*/)
1.25      lukem     328:                        printf "Login %s has a negative group id.\n", $1;
1.15      mrg       329:        }' < $GRP > $OUTPUT
                    330:        if [ -s $OUTPUT ] ; then
                    331:                printf "\nChecking the $GRP file:\n"
                    332:                cat $OUTPUT
                    333:        fi
                    334:
                    335:        awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
                    336:        if [ -s $OUTPUT ] ; then
                    337:                printf "\n$GRP has duplicate group names.\n"
                    338:                column $OUTPUT
                    339:        fi
1.9       cgd       340: fi
                    341:
                    342: # Check for root paths, umask values in startup files.
                    343: # The check for the root paths is problematical -- it's likely to fail
                    344: # in other environments.  Once the shells have been modified to warn
                    345: # of '.' in the path, the path tests should go away.
1.32      lukem     346: #
1.31      lukem     347: if checkyesno check_rootdotfiles; then
1.67      lukem     348:        rhome=~root
1.15      mrg       349:        umaskset=no
                    350:        list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
                    351:        for i in $list ; do
                    352:                if [ -f $i ] ; then
1.67      lukem     353:                        if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ;
                    354:                        then
1.15      mrg       355:                                umaskset=yes
                    356:                        fi
1.63      lukem     357:                        # Double check the umask value itself; ensure that
1.67      lukem     358:                        # both the group and other write bits are set.
                    359:                        #
1.45      sommerfe  360:                        egrep '^[ \t]*umask[ \t]+[0-7]+' $i |
1.63      lukem     361:                        awk '{
1.67      lukem     362:                                if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) {
1.80      wiz       363:                                        print "\tRoot umask is group writable"
1.63      lukem     364:                                }
1.67      lukem     365:                                if ($2 ~ /[^2367]$/) {
1.80      wiz       366:                                        print "\tRoot umask is other writable"
1.63      lukem     367:                                }
1.67      lukem     368:                            }' | sort -u
1.26      lukem     369:                        SAVE_PATH=$PATH
                    370:                        unset PATH
1.15      mrg       371:                        /bin/csh -f -s << end-of-csh > /dev/null 2>&1
                    372:                                source $i
                    373:                                /bin/ls -ldgT \$path > $TMP1
1.9       cgd       374: end-of-csh
1.76      atatat    375:                        export PATH=$SAVE_PATH
1.15      mrg       376:                        awk '{
                    377:                                if ($10 ~ /^\.$/) {
1.27      lukem     378:                                        print "\tThe root path includes .";
1.15      mrg       379:                                        next;
                    380:                                }
                    381:                             }
                    382:                             $1 ~ /^d....w/ \
1.80      wiz       383:                { print "\tRoot path directory " $10 " is group writable." } \
1.15      mrg       384:                             $1 ~ /^d.......w/ \
1.80      wiz       385:                { print "\tRoot path directory " $10 " is other writable." }' \
1.67      lukem     386:                        < $TMP1
1.15      mrg       387:                fi
1.67      lukem     388:        done > $OUTPUT
1.15      mrg       389:        if [ $umaskset = "no" -o -s $OUTPUT ] ; then
1.27      lukem     390:                printf "\nChecking root csh paths, umask values:\n$list\n\n"
1.15      mrg       391:                if [ -s $OUTPUT ]; then
                    392:                        cat $OUTPUT
                    393:                fi
                    394:                if [ $umaskset = "no" ] ; then
1.27      lukem     395:                    printf "\tRoot csh startup files do not set the umask.\n"
1.15      mrg       396:                fi
1.9       cgd       397:        fi
                    398:
1.15      mrg       399:        umaskset=no
1.23      lukem     400:        list="/etc/profile ${rhome}/.profile"
1.15      mrg       401:        for i in $list; do
                    402:                if [ -f $i ] ; then
                    403:                        if egrep umask $i > /dev/null ; then
                    404:                                umaskset=yes
                    405:                        fi
                    406:                        egrep umask $i |
1.67      lukem     407:                        awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \
1.80      wiz       408:                                { print "\tRoot umask is group writable" } \
1.67      lukem     409:                             $2 ~ /[^2367]$/ \
1.80      wiz       410:                                { print "\tRoot umask is other writable" }'
1.26      lukem     411:                        SAVE_PATH=$PATH
                    412:                        unset PATH
1.15      mrg       413:                        /bin/sh << end-of-sh > /dev/null 2>&1
                    414:                                . $i
1.110     christos  415:                                list=\$(echo \$PATH | /usr/bin/sed -e \
                    416:                                    's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g')
1.15      mrg       417:                                /bin/ls -ldgT \$list > $TMP1
1.9       cgd       418: end-of-sh
1.76      atatat    419:                        export PATH=$SAVE_PATH
1.15      mrg       420:                        awk '{
                    421:                                if ($10 ~ /^\.$/) {
1.27      lukem     422:                                        print "\tThe root path includes .";
1.15      mrg       423:                                        next;
                    424:                                }
                    425:                             }
                    426:                             $1 ~ /^d....w/ \
1.80      wiz       427:                { print "\tRoot path directory " $10 " is group writable." } \
1.15      mrg       428:                             $1 ~ /^d.......w/ \
1.80      wiz       429:                { print "\tRoot path directory " $10 " is other writable." }' \
1.67      lukem     430:                        < $TMP1
1.9       cgd       431:
1.15      mrg       432:                fi
1.67      lukem     433:        done > $OUTPUT
1.15      mrg       434:        if [ $umaskset = "no" -o -s $OUTPUT ] ; then
                    435:                printf "\nChecking root sh paths, umask values:\n$list\n"
                    436:                if [ -s $OUTPUT ]; then
                    437:                        cat $OUTPUT
                    438:                fi
                    439:                if [ $umaskset = "no" ] ; then
1.27      lukem     440:                        printf "\tRoot sh startup files do not set the umask.\n"
1.15      mrg       441:                fi
1.9       cgd       442:        fi
                    443: fi
                    444:
                    445: # Root and uucp should both be in /etc/ftpusers.
1.32      lukem     446: #
1.31      lukem     447: if checkyesno check_ftpusers; then
1.109     christos  448:        list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID)
1.27      lukem     449:        for i in $list; do
1.29      lukem     450:                if /usr/libexec/ftpd -C $i ; then
1.67      lukem     451:                        printf "\t$i is not denied\n"
1.27      lukem     452:                fi
1.67      lukem     453:        done > $OUTPUT
1.28      lukem     454:        if [ -s $OUTPUT ]; then
                    455:                printf "\nChecking the /etc/ftpusers configuration:\n"
                    456:                cat $OUTPUT
                    457:        fi
1.9       cgd       458: fi
                    459:
1.43      itojun    460: # Uudecode should not be in the /etc/mail/aliases file.
1.32      lukem     461: #
1.31      lukem     462: if checkyesno check_aliases; then
1.43      itojun    463:        for f in /etc/mail/aliases /etc/aliases; do
                    464:                if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then
                    465:                        printf "\nEntry for uudecode in $f file.\n"
                    466:                fi
                    467:        done
1.9       cgd       468: fi
                    469:
                    470: # Files that should not have + signs.
1.32      lukem     471: #
1.31      lukem     472: if checkyesno check_rhosts; then
1.15      mrg       473:        list="/etc/hosts.equiv /etc/hosts.lpd"
                    474:        for f in $list ; do
                    475:                if [ -f $f ] && egrep '\+' $f > /dev/null ; then
                    476:                        printf "\nPlus sign in $f file.\n"
                    477:                fi
                    478:        done
                    479:
                    480:        # Check for special users with .rhosts files.  Only root and toor should
1.16      mikel     481:        # have .rhosts files.  Also, .rhosts files should not have plus signs.
1.15      mrg       482:        awk -F: '$1 != "root" && $1 != "toor" && \
                    483:                ($3 < 100 || $1 == "ftp" || $1 == "uucp") \
1.20      mycroft   484:                        { print $1 " " $9 }' $MP |
1.19      mycroft   485:        sort -k2 |
1.15      mrg       486:        while read uid homedir; do
                    487:                if [ -f ${homedir}/.rhosts ] ; then
1.109     christos  488:                        rhost=$(ls -ldgT ${homedir}/.rhosts)
1.46      christos  489:                        printf -- "$uid: $rhost\n"
1.15      mrg       490:                fi
                    491:        done > $OUTPUT
                    492:        if [ -s $OUTPUT ] ; then
                    493:                printf "\nChecking for special users with .rhosts files.\n"
                    494:                cat $OUTPUT
                    495:        fi
                    496:
                    497:        while read uid homedir; do
1.35      fair      498:                if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \
1.41      christos  499:                    cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then
1.46      christos  500:                        printf -- "$uid: + in .rhosts file.\n"
1.15      mrg       501:                fi
1.29      lukem     502:        done < $MPBYPATH > $OUTPUT
1.15      mrg       503:        if [ -s $OUTPUT ] ; then
                    504:                printf "\nChecking .rhosts files syntax.\n"
                    505:                cat $OUTPUT
                    506:        fi
1.9       cgd       507: fi
                    508:
                    509: # Check home directories.  Directories should not be owned by someone else
1.80      wiz       510: # or writable.
1.32      lukem     511: #
1.31      lukem     512: if checkyesno check_homes; then
1.85      jhawk     513:        checkyesno check_homes_permit_usergroups && \
                    514:                permit_usergroups=1 || permit_usergroups=0
1.15      mrg       515:        while read uid homedir; do
                    516:                if [ -d ${homedir}/ ] ; then
1.109     christos  517:                        file=$(ls -ldgT ${homedir})
1.46      christos  518:                        printf -- "$uid $file\n"
1.9       cgd       519:                fi
1.29      lukem     520:        done < $MPBYPATH |
1.85      jhawk     521:        awk -v "usergroups=$permit_usergroups" '
                    522:             $1 != $4 && $4 != "root" \
1.15      mrg       523:                { print "user " $1 " home directory is owned by " $4 }
1.101     jnemeth   524:             $2 ~ /^d....w/ && (!usergroups || $5 != $1) \
1.80      wiz       525:                { print "user " $1 " home directory is group writable" }
1.101     jnemeth   526:             $2 ~ /^d.......w/ \
1.80      wiz       527:                { print "user " $1 " home directory is other writable" }' \
1.27      lukem     528:            > $OUTPUT
1.15      mrg       529:        if [ -s $OUTPUT ] ; then
                    530:                printf "\nChecking home directories.\n"
                    531:                cat $OUTPUT
                    532:        fi
                    533:
                    534:        # Files that should not be owned by someone else or readable.
1.67      lukem     535:        list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity"
1.15      mrg       536:        while read uid homedir; do
                    537:                for f in $list ; do
                    538:                        file=${homedir}/${f}
                    539:                        if [ -f $file ] ; then
1.109     christos  540:                                printf -- "$uid $f $(ls -ldgT $file)\n"
1.15      mrg       541:                        fi
                    542:                done
1.29      lukem     543:        done < $MPBYPATH |
1.85      jhawk     544:        awk  -v "usergroups=$permit_usergroups" '
                    545:             $1 != $5 && $5 != "root" \
1.15      mrg       546:                { print "user " $1 " " $2 " file is owned by " $5 }
1.85      jhawk     547:             $3 ~ /^-...r/ && (!usergroups || $6 != $1) \
1.15      mrg       548:                { print "user " $1 " " $2 " file is group readable" }
                    549:             $3 ~ /^-......r/ \
                    550:                { print "user " $1 " " $2 " file is other readable" }
1.85      jhawk     551:             $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
1.80      wiz       552:                { print "user " $1 " " $2 " file is group writable" }
1.15      mrg       553:             $3 ~ /^-.......w/ \
1.80      wiz       554:                { print "user " $1 " " $2 " file is other writable" }' \
1.27      lukem     555:            > $OUTPUT
1.15      mrg       556:
1.80      wiz       557:        # Files that should not be owned by someone else or writable.
1.19      mycroft   558:        list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \
1.79      elric     559:              .cshrc .emacs .exrc .forward .history .k5login .klogin .login \
                    560:              .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \
                    561:              .twmrc .xinitrc .xsession .ssh/authorized_keys \
                    562:              .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \
                    563:              .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \
                    564:              .ssh/known_hosts2"
1.15      mrg       565:        while read uid homedir; do
                    566:                for f in $list ; do
                    567:                        file=${homedir}/${f}
                    568:                        if [ -f $file ] ; then
1.109     christos  569:                                printf -- "$uid $f $(ls -ldgT $file)\n"
1.15      mrg       570:                        fi
                    571:                done
1.29      lukem     572:        done < $MPBYPATH |
1.85      jhawk     573:        awk -v "usergroups=$permit_usergroups" '
                    574:             $1 != $5 && $5 != "root" \
1.15      mrg       575:                { print "user " $1 " " $2 " file is owned by " $5 }
1.85      jhawk     576:             $3 ~ /^-....w/ && (!usergroups || $6 != $1) \
1.80      wiz       577:                { print "user " $1 " " $2 " file is group writable" }
1.15      mrg       578:             $3 ~ /^-.......w/ \
1.80      wiz       579:                { print "user " $1 " " $2 " file is other writable" }' \
1.27      lukem     580:            >> $OUTPUT
1.15      mrg       581:        if [ -s $OUTPUT ] ; then
                    582:                printf "\nChecking dot files.\n"
                    583:                cat $OUTPUT
                    584:        fi
1.9       cgd       585: fi
                    586:
                    587: # Mailboxes should be owned by user and unreadable.
1.32      lukem     588: #
1.31      lukem     589: if checkyesno check_varmail; then
1.86      jhawk     590:        ls -lA /var/mail | \
1.63      lukem     591:        awk '   NR == 1 { next; }
1.86      jhawk     592:                $9 ~ /^\./ {next; }
1.63      lukem     593:                $3 != $9 {
                    594:                        print "user " $9 " mailbox is owned by " $3
                    595:                }
                    596:                $1 != "-rw-------" {
                    597:                        print "user " $9 " mailbox is " $1 ", group " $4
                    598:                }' > $OUTPUT
1.15      mrg       599:        if [ -s $OUTPUT ] ; then
                    600:                printf "\nChecking mailbox ownership.\n"
                    601:                cat $OUTPUT
                    602:        fi
                    603: fi
                    604:
1.32      lukem     605: # NFS exports shouldn't be globally exported
                    606: #
                    607: if checkyesno check_nfs && [ -f /etc/exports ]; then
                    608:        awk '{
1.22      lukem     609:                # ignore comments and blank lines
1.39      hubertf   610:                if ($0 ~ /^\#/ || $0 ~ /^$/ )
1.22      lukem     611:                        next;
1.100     tron      612:                # manage line continuation
                    613:                while ($NF ~ /^\\$/) {
                    614:                        $NF = "";
                    615:                        line = $0 "";
                    616:                        getline;
                    617:                        $0 = line $0 "";
                    618:                }
1.22      lukem     619:
1.100     tron      620:                delete dir;
                    621:                readonly = ndir = 0;
                    622:                for (i = 1; i <= NF; ++i) {
                    623:                        if ($i ~ /^\//) dir[ndir++] = $i;
                    624:                        else if ($i ~ /^-/) {
                    625:                                if ($i ~ /^-(ro|o)$/) readonly = 1;
                    626:                                if ($i ~ /^-network/) next;
                    627:                        }
                    628:                        else next;
1.15      mrg       629:                }
                    630:                if (readonly)
1.100     tron      631:                        for (item in dir)
                    632:                                rodir[nrodir++] = dir[item];
1.15      mrg       633:                else
1.100     tron      634:                        for (item in dir)
                    635:                                rwdir[nrwdir++] = dir[item];
                    636:
                    637:        }
                    638:
                    639:        END {
                    640:                if (nrodir) {
                    641:                        printf("Globally exported file system%s, read-only:\n",
                    642:                                nrodir > 1 ? "s" : "");
                    643:                        for (item in rodir)
                    644:                                printf("\t%s\n", rodir[item]);
                    645:                }
                    646:                if (nrwdir) {
                    647:                        printf("Globally exported file system%s, read-write:\n",
                    648:                                nrwdir > 1 ? "s" : "");
                    649:                        for (item in rwdir)
                    650:                                printf("\t%s\n", rwdir[item]);
                    651:                }
1.32      lukem     652:        }' < /etc/exports > $OUTPUT
                    653:        if [ -s $OUTPUT ] ; then
1.15      mrg       654:                printf "\nChecking for globally exported file systems.\n"
                    655:                cat $OUTPUT
                    656:        fi
1.9       cgd       657: fi
                    658:
                    659: # Display any changes in setuid files and devices.
1.32      lukem     660: #
1.31      lukem     661: if checkyesno check_devices; then
1.28      lukem     662:        > $ERR
1.92      erh       663:        (
1.98      lukem     664:
                    665:        # Convert check_devices_ignore_fstypes="foo !bar bax"
                    666:        #    into "-fstype foo -o ! -fstype bar -o -fstype bax"
                    667:        # and check_devices_ignore_paths="/foo !/bar /bax"
                    668:        #    into " -path /foo -o ! -path /bar -o -path /bax"
                    669:        #
                    670:        ignexpr=$(\
                    671:            echo $check_devices_ignore_fstypes | \
                    672:                sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \
                    673:            echo $check_devices_ignore_paths | \
                    674:                sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \
                    675:        )
                    676:
                    677:        # Massage the expression into ( $ignexpr ) -a -prune -o
                    678:        if [ -n "${ignexpr}" ]; then
                    679:                ignexpr=$(\
                    680:                        echo $ignexpr | \
                    681:                            sed -e 's/^-o /( /' \
                    682:                                -e 's/$/ ) -a -prune -o/' \
                    683:                )
                    684:        fi
                    685:
                    686:        find / $ignexpr \
1.21      mycroft   687:            \( \( -perm -u+s -a ! -type d \) -o \
                    688:               \( -perm -g+s -a ! -type d \) -o \
1.24      lukem     689:               -type b -o -type c \) -print0 | \
1.98      lukem     690:        xargs -0 ls -ldgTq | sort +9 > $LIST
                    691:
                    692:        ) 2> $OUTPUT
1.15      mrg       693:
                    694:        # Display any errors that occurred during system file walk.
                    695:        if [ -s $OUTPUT ] ; then
1.28      lukem     696:                printf "Setuid/device find errors:\n" >> $ERR
                    697:                cat $OUTPUT >> $ERR
                    698:                printf "\n" >> $ERR
1.15      mrg       699:        fi
                    700:
                    701:        # Display any changes in the setuid file list.
                    702:        egrep -v '^[bc]' $LIST > $TMP1
                    703:        if [ -s $TMP1 ] ; then
                    704:                # Check to make sure uudecode isn't setuid.
                    705:                if grep -w uudecode $TMP1 > /dev/null ; then
1.28      lukem     706:                        printf "\nUudecode is setuid.\n" >> $ERR
1.15      mrg       707:                fi
                    708:
1.67      lukem     709:                file=$work_dir/setuid
                    710:                migrate_file "$backup_dir/setuid" "$file"
                    711:                CUR=${file}.current
                    712:                BACK=${file}.backup
1.15      mrg       713:                if [ -s $CUR ] ; then
                    714:                        if cmp -s $CUR $TMP1 ; then
                    715:                                :
                    716:                        else
                    717:                                > $TMP2
                    718:                                join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
                    719:                                if [ -s $OUTPUT ] ; then
1.28      lukem     720:                                        printf "Setuid additions:\n" >> $ERR
                    721:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    722:                                        printf "\n" >> $ERR
1.15      mrg       723:                                fi
                    724:
                    725:                                join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
                    726:                                if [ -s $OUTPUT ] ; then
1.28      lukem     727:                                        printf "Setuid deletions:\n" >> $ERR
                    728:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    729:                                        printf "\n" >> $ERR
1.15      mrg       730:                                fi
                    731:
1.20      mycroft   732:                                sort -k10 $TMP2 $CUR $TMP1 | \
1.27      lukem     733:                                    sed -e 's/[  ][      ]*/ /g' | \
                    734:                                    uniq -u > $OUTPUT
1.15      mrg       735:                                if [ -s $OUTPUT ] ; then
1.28      lukem     736:                                        printf "Setuid changes:\n" >> $ERR
                    737:                                        column -t $OUTPUT >> $ERR
                    738:                                        printf "\n" >> $ERR
1.15      mrg       739:                                fi
1.9       cgd       740:
1.52      atatat    741:                                backup_file update $TMP1 $CUR $BACK
1.9       cgd       742:                        fi
1.15      mrg       743:                else
1.28      lukem     744:                        printf "Setuid additions:\n" >> $ERR
                    745:                        column -t $TMP1 >> $ERR
                    746:                        printf "\n" >> $ERR
1.52      atatat    747:                        backup_file add $TMP1 $CUR $BACK
1.9       cgd       748:                fi
1.15      mrg       749:        fi
                    750:
1.27      lukem     751:        # Check for block and character disk devices that are readable or
1.80      wiz       752:        # writable or not owned by root.operator.
1.15      mrg       753:        >$TMP1
1.61      lukem     754:        DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \
1.57      simonb    755:            sd se ss uk up vnd wd xd xy"
1.27      lukem     756: #      DISKLIST="$DISKLIST ct mt st wt"
1.15      mrg       757:        for i in $DISKLIST; do
                    758:                egrep "^b.*/${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
                    759:                egrep "^c.*/r${i}[0-9][0-9]*[a-p]$"  $LIST >> $TMP1
                    760:        done
                    761:
                    762:        awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
1.25      lukem     763:                { printf "Disk %s is user %s, group %s, permissions %s.\n", \
                    764:                    $11, $3, $4, $1; }' < $TMP1 > $OUTPUT
1.15      mrg       765:        if [ -s $OUTPUT ] ; then
1.28      lukem     766:                printf "\nChecking disk ownership and permissions.\n" >> $ERR
                    767:                cat $OUTPUT >> $ERR
                    768:                printf "\n" >> $ERR
1.9       cgd       769:        fi
                    770:
1.15      mrg       771:        # Display any changes in the device file list.
1.20      mycroft   772:        egrep '^[bc]' $LIST | sort -k11 > $TMP1
1.15      mrg       773:        if [ -s $TMP1 ] ; then
1.67      lukem     774:                file=$work_dir/device
                    775:                migrate_file "$backup_dir/device" "$file"
                    776:                CUR=${file}.current
                    777:                BACK=${file}.backup
1.15      mrg       778:
                    779:                if [ -s $CUR ] ; then
                    780:                        if cmp -s $CUR $TMP1 ; then
                    781:                                :
                    782:                        else
                    783:                                > $TMP2
                    784:                                join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
                    785:                                if [ -s $OUTPUT ] ; then
1.28      lukem     786:                                        printf "Device additions:\n" >> $ERR
                    787:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    788:                                        printf "\n" >> $ERR
1.15      mrg       789:                                fi
                    790:
                    791:                                join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
                    792:                                if [ -s $OUTPUT ] ; then
1.28      lukem     793:                                        printf "Device deletions:\n" >> $ERR
                    794:                                        tee -a $TMP2 < $OUTPUT >> $ERR
                    795:                                        printf "\n" >> $ERR
1.15      mrg       796:                                fi
                    797:
1.27      lukem     798:                                # Report any block device change. Ignore
                    799:                                # character devices, only the name is
                    800:                                # significant.
1.15      mrg       801:                                cat $TMP2 $CUR $TMP1 | \
1.27      lukem     802:                                    sed -e '/^c/d' | \
                    803:                                    sort -k11 | \
                    804:                                    sed -e 's/[  ][      ]*/ /g' | \
                    805:                                    uniq -u > $OUTPUT
1.15      mrg       806:                                if [ -s $OUTPUT ] ; then
1.28      lukem     807:                                        printf "Block device changes:\n" >> $ERR
                    808:                                        column -t $OUTPUT >> $ERR
                    809:                                        printf "\n" >> $ERR
1.15      mrg       810:                                fi
1.9       cgd       811:
1.52      atatat    812:                                backup_file update $TMP1 $CUR $BACK
1.9       cgd       813:                        fi
1.15      mrg       814:                else
1.28      lukem     815:                        printf "Device additions:\n" >> $ERR
                    816:                        column -t $TMP1 >> $ERR
                    817:                        printf "\n" >> $ERR
1.52      atatat    818:                        backup_file add $TMP1 $CUR $BACK >> $ERR
1.9       cgd       819:                fi
1.28      lukem     820:        fi
                    821:        if [ -s $ERR ] ; then
                    822:                printf "\nChecking setuid files and devices:\n"
                    823:                cat $ERR
                    824:                printf "\n"
1.9       cgd       825:        fi
                    826: fi
                    827:
                    828: # Check special files.
                    829: # Check system binaries.
                    830: #
                    831: # Create the mtree tree specifications using:
1.67      lukem     832: #      mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure
1.38      kleink    833: #      chown root:wheel DIR.secure
1.67      lukem     834: #      chmod u+r,go= DIR.secure
1.9       cgd       835: #
                    836: # Note, this is not complete protection against Trojan horsed binaries, as
                    837: # the hacker can modify the tree specification to match the replaced binary.
                    838: # For details on really protecting yourself against modified binaries, see
                    839: # the mtree(8) manual page.
1.32      lukem     840: #
1.31      lukem     841: if checkyesno check_mtree; then
1.82      jhawk     842:        if checkyesno check_mtree_follow_symlinks; then
                    843:                check_mtree_flags="-L"
                    844:        else
                    845:                check_mtree_flags=""
                    846:        fi
1.91      lukem     847:        mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 |
1.87      jhawk     848:                grep -v '^mtree: dev/tty: Device not configured$' >&2
1.15      mrg       849:        if [ -s $OUTPUT ]; then
1.9       cgd       850:                printf "\nChecking special files and directories.\n"
                    851:                cat $OUTPUT
                    852:        fi
                    853:
1.16      mikel     854:        for file in /etc/mtree/*.secure; do
                    855:                [ $file = '/etc/mtree/*.secure' ] && continue
1.109     christos  856:                tree=$(sed -n -e '3s/.* //p' -e 3q $file)
1.82      jhawk     857:                mtree $check_mtree_flags -f $file -p $tree > $TMP1
1.9       cgd       858:                if [ -s $TMP1 ]; then
1.67      lukem     859:                        printf "\nChecking $tree:\n"
                    860:                        cat $TMP1
1.9       cgd       861:                fi
1.67      lukem     862:        done > $OUTPUT
1.15      mrg       863:        if [ -s $OUTPUT ]; then
1.9       cgd       864:                printf "\nChecking system binaries:\n"
                    865:                cat $OUTPUT
                    866:        fi
                    867: fi
                    868:
1.32      lukem     869: # Backup disklabels of available disks
                    870: #
                    871: if checkyesno check_disklabels; then
1.67      lukem     872:                # migrate old disklabels
1.109     christos  873:        for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \
                    874:            $backup_dir/disklabel.* 2>/dev/null); do
1.67      lukem     875:                migrate_file "$file" "$work_dir/${file##*/}"
                    876:        done
                    877:
1.103     tron      878:                # generate list of old disklabels, fdisks & wedges and remove them
                    879:        ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
1.52      atatat    880:            egrep -v '\.(backup|current)(,v)?$' > $LABELS
1.32      lukem     881:        xargs rm < $LABELS
                    882:
1.103     tron      883:                # generate disklabels of all disks excluding:   cd dk fd md st
1.109     christos  884:        disks=$(iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|dk|st|nfs/ { print $1; }')
1.32      lukem     885:        for i in $disks; do
1.67      lukem     886:                disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null
1.32      lukem     887:        done
                    888:
1.67      lukem     889:                # if fdisk is available, generate fdisks for:   ed ld sd wd
                    890:        if [ -x /sbin/fdisk ]; then
1.109     christos  891:                disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }')
1.67      lukem     892:                for i in $disks; do
                    893:                        /sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null
                    894:                done
                    895:        fi
                    896:
1.103     tron      897:                # if dkctl is available, generate dkctl listwedges for: ed ld sd wd cgd ofdisk ra rl raid
                    898:        if [ -x /sbin/dkctl ]; then
1.109     christos  899:                disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d|cgd|ofdisk|r[al]|raid/ { print $1; }')
1.103     tron      900:                for i in $disks; do
                    901:                        /sbin/dkctl $i listwedges > "$work_dir/wedges.$i" 2>/dev/null
                    902:                done
                    903:        fi
                    904:
                    905:                # append list of new disklabels, fdisks and wedges
                    906:        ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null |
1.52      atatat    907:            egrep -v '\.(backup|current)(,v)?$' >> $LABELS
1.62      atatat    908:        CHANGELIST="$LABELS $CHANGELIST"
                    909: fi
                    910:
1.106     haad      911: if checkyesno check_lvm; then
                    912:
                    913:     # generate list of existing LVM elements Physical Volumes, Volume Groups and Logical Volumes.
                    914: if [ -x /sbin/lvm ]; then
                    915:     lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null
                    916:     lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null
                    917:     lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null
                    918: fi
                    919:     ls -1d $work_dir/lvm.* 2>/dev/null |
                    920:         egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS
                    921:     CHANGELIST="$CHANGELIST $LVM_LABELS"
                    922: fi
                    923:
1.62      atatat    924: # Check for changes in the list of installed pkgs
                    925: #
1.108     jmmv      926: if checkyesno check_pkgs && have_pkgs; then
1.67      lukem     927:        pkgs=$work_dir/pkgs
                    928:        migrate_file "$backup_dir/pkgs" "$pkgs"
1.108     jmmv      929:        pkg_dbdir=$(pkg_admin config-var PKG_DBDIR)
                    930:        : ${pkg_dbdir:=/var/db/pkg}
                    931:        (       cd $pkg_dbdir
1.104     adrianp   932:                $pkg_info | sort
1.62      atatat    933:                echo ""
                    934:                find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 |
1.72      lukem     935:                        xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,'
1.62      atatat    936:         ) > $pkgs
1.67      lukem     937:        echo "$pkgs" > $PKGS
1.62      atatat    938:        CHANGELIST="$PKGS $CHANGELIST"
1.32      lukem     939: fi
                    940:
1.67      lukem     941: # List of files that get backed up and checked for any modifications.
1.9       cgd       942: # Any changes cause the files to rotate.
1.32      lukem     943: #
1.67      lukem     944: if checkyesno check_changelist ; then
1.91      lukem     945:        mtree -D -k type -f $SPECIALSPEC -E exclude |
                    946:            sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES
1.67      lukem     947:
1.75      lukem     948:        (
1.68      lukem     949:                # Add other files which might dynamically exist:
1.67      lukem     950:                #       /etc/ifconfig.*
                    951:                #       /etc/raid*.conf
1.68      lukem     952:                #       /etc/rc.d/*
1.67      lukem     953:                #       /etc/rc.conf.d/*
1.68      lukem     954:                #
1.75      lukem     955:                echo "/etc/ifconfig.*"
                    956:                echo "/etc/raid*.conf"
                    957:                echo "/etc/rc.d/*"
                    958:                echo "/etc/rc.conf.d/*"
1.106     haad      959:                echo "/etc/lvm/backup/*"
                    960:                echo "/etc/lvm/archive/*"
1.67      lukem     961:
1.68      lukem     962:                # Add /etc/changelist
                    963:                #
1.75      lukem     964:                if [ -s /etc/changelist ]; then
                    965:                        grep -v '^#' /etc/changelist
                    966:                fi
                    967:        ) | while read file; do
                    968:                case "$file" in
                    969:                *[\*\?\[]*)     # If changelist line is a glob ...
                    970:                                # ... expand possible backup files
                    971:                                #
                    972:                        ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \
                    973:                            | sed "s,^$backup_dir/,, ; s,\.current$,,"
                    974:
                    975:                                # ... expand possible files
                    976:                                #
                    977:                        ls -1d $(echo $file) 2>/dev/null
                    978:                        ;;
                    979:                *)
                    980:                                # Otherwise, just print the filename
                    981:                        echo $file
                    982:                        ;;
                    983:                esac
                    984:        done >> $CHANGEFILES
1.67      lukem     985:        CHANGELIST="$CHANGEFILES $CHANGELIST"
                    986: fi
                    987:
                    988: # Special case backups, including the master password file and
                    989: # ssh private host keys. The normal backup mechanisms for
                    990: # $check_changelist (see below) also print out the actual file
                    991: # differences and we don't want to do that for these files
                    992: #
                    993: echo $MP > $TMP1                       # always add /etc/master.passwd
1.91      lukem     994: mtree -D -k type -f $SPECIALSPEC -I nodiff |
                    995:     sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1
1.73      lukem     996: grep -v '^$' $TMP1 | sort -u > $TMP2
1.68      lukem     997:
1.69      lukem     998: while read file; do
1.67      lukem     999:        backup_and_diff "$file" no
1.69      lukem    1000: done < $TMP2
1.67      lukem    1001:
1.32      lukem    1002:
                   1003: if [ -n "$CHANGELIST" ]; then
1.73      lukem    1004:        grep -h -v '^$' $CHANGELIST | sort -u > $TMP1
1.68      lukem    1005:        comm -23 $TMP1 $TMP2 | while read file; do
1.67      lukem    1006:                backup_and_diff "$file" yes
1.9       cgd      1007:        done
1.44      ad       1008: fi
                   1009:
1.108     jmmv     1010: if have_pkgs; then
1.107     jmmv     1011:        if checkyesno check_pkg_vulnerabilities; then
1.108     jmmv     1012:                pkg_admin ${_compat_K_flag} audit >${OUTPUT} 2>&1
1.107     jmmv     1013:                if [ -s ${OUTPUT} ]; then
                   1014:                        printf "\nInstalled vulnerable packages:\n"
                   1015:                        cat ${OUTPUT}
                   1016:                fi
                   1017:        fi
                   1018:
                   1019:        if checkyesno check_pkg_signatures; then
1.108     jmmv     1020:                pkg_admin ${_compat_K_flag} check >${OUTPUT} 2>&1
1.107     jmmv     1021:                if [ $? -ne 0 ]; then
                   1022:                        printf "\nFiles with invalid signatures:\n"
                   1023:                        cat ${OUTPUT}
                   1024:                fi
                   1025:        fi
                   1026: fi
                   1027:
1.44      ad       1028: if [ -f /etc/security.local ]; then
1.90      kim      1029:        . /etc/security.local > $OUTPUT 2>&1
1.84      jhawk    1030:        if [ -s $OUTPUT ] ; then
                   1031:                printf "\nRunning /etc/security.local:\n"
                   1032:                cat $OUTPUT
                   1033:        fi
1.9       cgd      1034: fi

CVSweb <webmaster@jp.NetBSD.org>