security revision 1.111
11.1Scgd#!/bin/sh - 21.1Scgd# 31.111Sspz# $NetBSD: security,v 1.111 2012/04/05 09:09:27 spz Exp $ 41.9Scgd# from: @(#)security 8.1 (Berkeley) 6/9/93 51.1Scgd# 61.1Scgd 71.9ScgdPATH=/sbin:/usr/sbin:/bin:/usr/bin 81.1Scgd 91.89Sjmmvrcvar_manpage='security.conf(5)' 101.89Sjmmv 111.31Slukemif [ -f /etc/rc.subr ]; then 121.31Slukem . /etc/rc.subr 131.31Slukemelse 141.31Slukem echo "Can't read /etc/rc.subr; aborting." 151.31Slukem exit 1; 161.31Slukemfi 171.31Slukem 181.9Scgdumask 077 191.64ScjsTZ=UTC; export TZ 201.1Scgd 211.15Smrgif [ -s /etc/security.conf ]; then 221.15Smrg . /etc/security.conf 231.15Smrgfi 241.15Smrg 251.67Slukem# Set reasonable defaults (if they're not set in security.conf) 261.67Slukem# 271.67Slukembackup_dir=${backup_dir:-/var/backups} 281.67Slukemmax_loginlen=${max_loginlen:-8} 291.67Slukemmax_grouplen=${max_grouplen:-8} 301.104Sadrianppkg_info=${pkg_info:-/usr/sbin/pkg_info} 311.67Slukem 321.67Slukem# Other configurable variables 331.67Slukem# 341.67Slukemspecial_files="/etc/mtree/special /etc/mtree/special.local" 351.67SlukemMP=/etc/master.passwd 361.67SlukemCHANGELIST="" 371.67Slukemwork_dir=$backup_dir/work 381.67Slukem 391.67Slukemif [ ! -d "$work_dir" ]; then 401.67Slukem mkdir -p "$work_dir" 411.67Slukemfi 421.67Slukem 431.102SmarttiSECUREDIR=$(mktemp -d -t _securedir) || exit 1 441.56Slukem 451.67Slukemtrap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE 461.15Smrg 471.56Slukemif ! cd "$SECUREDIR"; then 481.56Slukem echo "Can not cd to $SECUREDIR". 491.15Smrg exit 1 501.15Smrgfi 511.15Smrg 521.91SlukemERR=err.$$ 531.91SlukemTMP1=tmp1.$$ 541.91SlukemTMP2=tmp2.$$ 551.91SlukemMPBYUID=mpbyuid.$$ 561.91SlukemMPBYPATH=mpbypath.$$ 571.91SlukemLIST=list.$$ 581.91SlukemOUTPUT=output.$$ 591.91SlukemLABELS=labels.$$ 601.106ShaadLVM_LABELS=lvm.$$ 611.91SlukemPKGS=pkgs.$$ 621.91SlukemCHANGEFILES=changefiles.$$ 631.91SlukemSPECIALSPEC=specialspec.$$ 641.67Slukem 651.108Sjmmvif [ -n "${pkgdb_dir}" ]; then 661.108Sjmmv echo "WARNING: Setting pkgdb_dir in security.conf(5) is deprecated" 671.108Sjmmv echo "WARNING: Please define PKG_DBDIR in pkg_install.conf(5) instead" 681.108Sjmmv _compat_K_flag="-K ${pkgdb_dir}" 691.108Sjmmvfi 701.108Sjmmv 711.108Sjmmvhave_pkgs() { 721.108Sjmmv $pkg_info ${_compat_K_flag} -q -E '*' 731.108Sjmmv} 741.108Sjmmv 751.67Slukem# migrate_file old new 761.67Slukem# Determine if the "${old}" path name needs to be migrated to the 771.67Slukem# "${new}" path. Also checks if "${old}.current" needs migrating, 781.67Slukem# and if so, migrate it and possibly "${old}.current,v" and 791.67Slukem# "${old}.backup". 801.67Slukem# 811.67Slukemmigrate_file() 821.67Slukem{ 831.67Slukem _old=$1 841.67Slukem _new=$2 851.67Slukem if [ -z "$_old" -o -z "$_new" ]; then 861.67Slukem err 3 "USAGE: migrate_file old new" 871.67Slukem fi 881.67Slukem if [ ! -d "${_new%/*}" ]; then 891.67Slukem mkdir -p "${_new%/*}" 901.67Slukem fi 911.67Slukem if [ -f "${_old}" -a ! -f "${_new}" ]; then 921.67Slukem echo "==> migrating ${_old}" 931.67Slukem echo " to ${_new}" 941.67Slukem mv "${_old}" "${_new}" 951.67Slukem fi 961.67Slukem if [ -f "${_old}.current" -a ! -f "${_new}.current" ]; then 971.67Slukem echo "==> migrating ${_old}.current" 981.67Slukem echo " to ${_new}.current" 991.67Slukem mv "${_old}.current" "${_new}.current" 1001.67Slukem if [ -f "${_old}.current,v" -a ! -f "${_new}.current,v" ]; then 1011.67Slukem echo "==> migrating ${_old}.current,v" 1021.67Slukem echo " to ${_new}.current,v" 1031.67Slukem mv "${_old}.current,v" "${_new}.current,v" 1041.67Slukem fi 1051.67Slukem if [ -f "${_old}.backup" -a ! -f "${_new}.backup" ]; then 1061.67Slukem echo "==> migrating ${_old}.backup" 1071.67Slukem echo " to ${_new}.backup" 1081.67Slukem mv "${_old}.backup" "${_new}.backup" 1091.67Slukem fi 1101.67Slukem fi 1111.67Slukem} 1121.67Slukem 1131.67Slukem 1141.67Slukem# backup_and_diff file printdiff 1151.67Slukem# Determine if file needs backing up, and if so, do it. 1161.67Slukem# If printdiff is yes, display the diffs, otherwise 1171.67Slukem# just print a message saying "[changes omitted]". 1181.67Slukem# 1191.67Slukembackup_and_diff() 1201.67Slukem{ 1211.67Slukem _file=$1 1221.67Slukem _printdiff=$2 1231.67Slukem if [ -z "$_file" -o -z "$_printdiff" ]; then 1241.67Slukem err 3 "USAGE: backup_and_diff file printdiff" 1251.67Slukem fi 1261.67Slukem ! checkyesno _printdiff 1271.67Slukem _printdiff=$? 1281.67Slukem 1291.67Slukem _old=$backup_dir/${_file##*/} 1301.67Slukem case "$_file" in 1311.67Slukem $work_dir/*) 1321.67Slukem _new=$_file 1331.67Slukem migrate_file "$backup_dir/$_old" "$_new" 1341.67Slukem migrate_file "$_old" "$_new" 1351.67Slukem ;; 1361.67Slukem *) 1371.67Slukem _new=$backup_dir/$_file 1381.67Slukem migrate_file "$_old" "$_new" 1391.67Slukem ;; 1401.67Slukem esac 1411.67Slukem CUR=${_new}.current 1421.67Slukem BACK=${_new}.backup 1431.67Slukem if [ -f $_file ]; then 1441.67Slukem if [ -f $CUR ] ; then 1451.67Slukem if [ "$_printdiff" -ne 0 ]; then 1461.83Sjhawk diff ${diff_options} $CUR $_file > $OUTPUT 1471.67Slukem else 1481.67Slukem if ! cmp -s $CUR $_file; then 1491.67Slukem echo "[changes omitted]" 1501.67Slukem fi > $OUTPUT 1511.67Slukem fi 1521.67Slukem if [ -s $OUTPUT ] ; then 1531.67Slukem printf \ 1541.67Slukem "\n======\n%s diffs (OLD < > NEW)\n======\n" $_file 1551.67Slukem cat $OUTPUT 1561.67Slukem backup_file update $_file $CUR $BACK 1571.67Slukem fi 1581.67Slukem else 1591.67Slukem printf "\n======\n%s added\n======\n" $_file 1601.67Slukem if [ "$_printdiff" -ne 0 ]; then 1611.83Sjhawk diff ${diff_options} /dev/null $_file 1621.67Slukem else 1631.67Slukem echo "[changes omitted]" 1641.67Slukem fi 1651.67Slukem backup_file add $_file $CUR $BACK 1661.67Slukem fi 1671.67Slukem else 1681.67Slukem if [ -f $CUR ]; then 1691.67Slukem printf "\n======\n%s removed\n======\n" $_file 1701.67Slukem if [ "$_printdiff" -ne 0 ]; then 1711.83Sjhawk diff ${diff_options} $CUR /dev/null 1721.67Slukem else 1731.67Slukem echo "[changes omitted]" 1741.67Slukem fi 1751.67Slukem backup_file remove $_file $CUR $BACK 1761.67Slukem fi 1771.67Slukem fi 1781.67Slukem} 1791.48Sabs 1801.9Scgd 1811.67Slukem# These are used several times. 1821.67Slukem# 1831.91Slukemawk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID 1841.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH 1851.91Slukemfor file in $special_files; do 1861.91Slukem [ -s $file ] && cat $file 1871.91Slukemdone | mtree -CM -k all > $SPECIALSPEC || exit 1 1881.9Scgd 1891.67Slukem 1901.9Scgd# Check the master password file syntax. 1911.32Slukem# 1921.31Slukemif checkyesno check_passwd; then 1931.85Sjhawk # XXX: the sense of permit_star is reversed; the code works as 1941.85Sjhawk # implemented, but usage needs to be negated. 1951.81Sjhawk checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1 1961.94Sjdolecek checkyesno check_passwd_permit_nonalpha \ 1971.94Sjdolecek && permit_nonalpha=1 || permit_nonalpha=0 1981.94Sjdolecek 1991.81Sjhawk awk -v "len=$max_loginlen" \ 2001.81Sjhawk -v "nowarn_shells_list=$check_passwd_nowarn_shells" \ 2011.81Sjhawk -v "nowarn_users_list=$check_passwd_nowarn_users" \ 2021.94Sjdolecek -v "permit_star=$permit_star" \ 2031.94Sjdolecek -v "permit_nonalpha=$permit_nonalpha" \ 2041.94Sjdolecek ' 2051.25Slukem BEGIN { 2061.25Slukem while ( getline < "/etc/shells" > 0 ) { 2071.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 2081.25Slukem continue; 2091.25Slukem shells[$1]++; 2101.25Slukem } 2111.81Sjhawk split(nowarn_shells_list, a); 2121.81Sjhawk for (i in a) nowarn_shells[a[i]]++; 2131.81Sjhawk split(nowarn_users_list, a); 2141.81Sjhawk for (i in a) nowarn_users[a[i]]++; 2151.81Sjhawk uid0_users_list="root toor" 2161.81Sjhawk split(uid0_users_list, a); 2171.81Sjhawk for (i in a) uid0_users[a[i]]++; 2181.25Slukem FS=":"; 2191.25Slukem } 2201.25Slukem 2211.25Slukem { 2221.15Smrg if ($0 ~ /^[ ]*$/) { 2231.25Slukem printf "Line %d is a blank line.\n", NR; 2241.15Smrg next; 2251.15Smrg } 2261.105Sdholland 2271.105Sdholland # NIS compat entry? 2281.105Sdholland compatline = $1 ~ "^[\\+-]"; 2291.105Sdholland if (compatline) { 2301.105Sdholland if ($1 == "+" && NF == 1) { 2311.105Sdholland next; 2321.105Sdholland } 2331.105Sdholland sub("^.", "", $1); 2341.105Sdholland } 2351.105Sdholland if (NF != 10) 2361.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 2371.105Sdholland if (compatline) { 2381.105Sdholland if ($3 == 0) 2391.81Sjhawk printf "Line %d includes entries with uid 0.\n", 2401.81Sjhawk NR; 2411.105Sdholland if ($1 == "") 2421.105Sdholland next; 2431.34Sabs } 2441.94Sjdolecek if (!permit_nonalpha && 2451.95Speter $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 2461.25Slukem printf "Login %s has non-alphanumeric characters.\n", 2471.25Slukem $1; 2481.34Sabs if (length($1) > len) 2491.81Sjhawk printf "Login %s has more than "len" characters.\n", 2501.81Sjhawk $1; 2511.105Sdholland if ($2 == "" && !compatline && !nowarn_users[$1]) 2521.81Sjhawk printf "Login %s has no password.\n", $1; 2531.81Sjhawk if (!nowarn_shells[$10] && !nowarn_users[$1]) { 2541.81Sjhawk if (length($2) != 13 && 2551.81Sjhawk length($2) != 20 && 2561.81Sjhawk $2 !~ /^\$1/ && 2571.81Sjhawk $2 !~ /^\$2/ && 2581.99Sjmcneill $2 !~ /^\$sha1/ && 2591.81Sjhawk $2 != "" && 2601.81Sjhawk (permit_star || $2 != "*") && 2611.81Sjhawk $2 !~ /^\*[A-z-]+$/ && 2621.81Sjhawk $1 != "toor") { 2631.81Sjhawk if ($10 == "" || shells[$10]) 2641.81Sjhawk printf "Login %s is off but still has "\ 2651.81Sjhawk "a valid shell (%s)\n", $1, $10; 2661.105Sdholland } else if (compatline && $10 == "") { 2671.105Sdholland # nothing 2681.81Sjhawk } else if (! shells[$10]) 2691.81Sjhawk printf "Login %s does not have a valid "\ 2701.81Sjhawk "shell (%s)\n", $1, $10; 2711.81Sjhawk } 2721.81Sjhawk if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1]) 2731.25Slukem printf "Login %s has a user id of 0.\n", $1; 2741.105Sdholland if ($3 != "" && $3 < 0) 2751.25Slukem printf "Login %s has a negative user id.\n", $1; 2761.105Sdholland if ($4 != "" && $4 < 0) 2771.25Slukem printf "Login %s has a negative group id.\n", $1; 2781.15Smrg }' < $MP > $OUTPUT 2791.15Smrg if [ -s $OUTPUT ] ; then 2801.15Smrg printf "\nChecking the $MP file:\n" 2811.15Smrg cat $OUTPUT 2821.15Smrg fi 2831.15Smrg 2841.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 2851.15Smrg if [ -s $OUTPUT ] ; then 2861.15Smrg printf "\n$MP has duplicate user names.\n" 2871.15Smrg column $OUTPUT 2881.15Smrg fi 2891.15Smrg 2901.111Sspz awk -v "permit_dups_list=$check_passwd_permit_dups" \ 2911.111Sspz ' 2921.111Sspz BEGIN { 2931.111Sspz split(permit_dups_list, a); 2941.111Sspz for (i in a) permit_dups[a[i]]++; 2951.111Sspz } 2961.111Sspz { 2971.111Sspz if (!permit_dups[$1]) 2981.111Sspz print $2; 2991.111Sspz }' < $MPBYUID | uniq -d > $TMP2 3001.15Smrg if [ -s $TMP2 ] ; then 3011.111Sspz printf "\n$MP has duplicate user ids.\n" 3021.15Smrg while read uid; do 3031.28Slukem grep -w $uid $MPBYUID 3041.15Smrg done < $TMP2 | column 3051.15Smrg fi 3061.9Scgdfi 3071.9Scgd 3081.9Scgd# Check the group file syntax. 3091.32Slukem# 3101.31Slukemif checkyesno check_group; then 3111.15Smrg GRP=/etc/group 3121.49Sjdolecek awk -F: -v "len=$max_grouplen" '{ 3131.15Smrg if ($0 ~ /^[ ]*$/) { 3141.25Slukem printf "Line %d is a blank line.\n", NR; 3151.15Smrg next; 3161.15Smrg } 3171.34Sabs if (NF != 4 && ($1 != "+" || NF != 1)) 3181.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 3191.34Sabs if ($1 == "+" ) { 3201.34Sabs next; 3211.34Sabs } 3221.95Speter if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 3231.25Slukem printf "Group %s has non-alphanumeric characters.\n", 3241.25Slukem $1; 3251.49Sjdolecek if (length($1) > len) 3261.49Sjdolecek printf "Group %s has more than "len" characters.\n", $1; 3271.15Smrg if ($3 !~ /[0-9]*/) 3281.25Slukem printf "Login %s has a negative group id.\n", $1; 3291.15Smrg }' < $GRP > $OUTPUT 3301.15Smrg if [ -s $OUTPUT ] ; then 3311.15Smrg printf "\nChecking the $GRP file:\n" 3321.15Smrg cat $OUTPUT 3331.15Smrg fi 3341.15Smrg 3351.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 3361.15Smrg if [ -s $OUTPUT ] ; then 3371.15Smrg printf "\n$GRP has duplicate group names.\n" 3381.15Smrg column $OUTPUT 3391.15Smrg fi 3401.9Scgdfi 3411.9Scgd 3421.9Scgd# Check for root paths, umask values in startup files. 3431.9Scgd# The check for the root paths is problematical -- it's likely to fail 3441.9Scgd# in other environments. Once the shells have been modified to warn 3451.9Scgd# of '.' in the path, the path tests should go away. 3461.32Slukem# 3471.31Slukemif checkyesno check_rootdotfiles; then 3481.67Slukem rhome=~root 3491.15Smrg umaskset=no 3501.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 3511.15Smrg for i in $list ; do 3521.15Smrg if [ -f $i ] ; then 3531.67Slukem if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; 3541.67Slukem then 3551.15Smrg umaskset=yes 3561.15Smrg fi 3571.63Slukem # Double check the umask value itself; ensure that 3581.67Slukem # both the group and other write bits are set. 3591.67Slukem # 3601.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 3611.63Slukem awk '{ 3621.67Slukem if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) { 3631.80Swiz print "\tRoot umask is group writable" 3641.63Slukem } 3651.67Slukem if ($2 ~ /[^2367]$/) { 3661.80Swiz print "\tRoot umask is other writable" 3671.63Slukem } 3681.67Slukem }' | sort -u 3691.26Slukem SAVE_PATH=$PATH 3701.26Slukem unset PATH 3711.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 3721.15Smrg source $i 3731.15Smrg /bin/ls -ldgT \$path > $TMP1 3741.9Scgdend-of-csh 3751.76Satatat export PATH=$SAVE_PATH 3761.15Smrg awk '{ 3771.15Smrg if ($10 ~ /^\.$/) { 3781.27Slukem print "\tThe root path includes ."; 3791.15Smrg next; 3801.15Smrg } 3811.15Smrg } 3821.15Smrg $1 ~ /^d....w/ \ 3831.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 3841.15Smrg $1 ~ /^d.......w/ \ 3851.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 3861.67Slukem < $TMP1 3871.15Smrg fi 3881.67Slukem done > $OUTPUT 3891.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 3901.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 3911.15Smrg if [ -s $OUTPUT ]; then 3921.15Smrg cat $OUTPUT 3931.15Smrg fi 3941.15Smrg if [ $umaskset = "no" ] ; then 3951.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 3961.15Smrg fi 3971.9Scgd fi 3981.9Scgd 3991.15Smrg umaskset=no 4001.23Slukem list="/etc/profile ${rhome}/.profile" 4011.15Smrg for i in $list; do 4021.15Smrg if [ -f $i ] ; then 4031.15Smrg if egrep umask $i > /dev/null ; then 4041.15Smrg umaskset=yes 4051.15Smrg fi 4061.15Smrg egrep umask $i | 4071.67Slukem awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \ 4081.80Swiz { print "\tRoot umask is group writable" } \ 4091.67Slukem $2 ~ /[^2367]$/ \ 4101.80Swiz { print "\tRoot umask is other writable" }' 4111.26Slukem SAVE_PATH=$PATH 4121.26Slukem unset PATH 4131.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 4141.15Smrg . $i 4151.110Schristos list=\$(echo \$PATH | /usr/bin/sed -e \ 4161.110Schristos 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g') 4171.15Smrg /bin/ls -ldgT \$list > $TMP1 4181.9Scgdend-of-sh 4191.76Satatat export PATH=$SAVE_PATH 4201.15Smrg awk '{ 4211.15Smrg if ($10 ~ /^\.$/) { 4221.27Slukem print "\tThe root path includes ."; 4231.15Smrg next; 4241.15Smrg } 4251.15Smrg } 4261.15Smrg $1 ~ /^d....w/ \ 4271.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4281.15Smrg $1 ~ /^d.......w/ \ 4291.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4301.67Slukem < $TMP1 4311.9Scgd 4321.15Smrg fi 4331.67Slukem done > $OUTPUT 4341.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 4351.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 4361.15Smrg if [ -s $OUTPUT ]; then 4371.15Smrg cat $OUTPUT 4381.15Smrg fi 4391.15Smrg if [ $umaskset = "no" ] ; then 4401.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 4411.15Smrg fi 4421.9Scgd fi 4431.9Scgdfi 4441.9Scgd 4451.9Scgd# Root and uucp should both be in /etc/ftpusers. 4461.32Slukem# 4471.31Slukemif checkyesno check_ftpusers; then 4481.109Schristos list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID) 4491.27Slukem for i in $list; do 4501.29Slukem if /usr/libexec/ftpd -C $i ; then 4511.67Slukem printf "\t$i is not denied\n" 4521.27Slukem fi 4531.67Slukem done > $OUTPUT 4541.28Slukem if [ -s $OUTPUT ]; then 4551.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 4561.28Slukem cat $OUTPUT 4571.28Slukem fi 4581.9Scgdfi 4591.9Scgd 4601.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 4611.32Slukem# 4621.31Slukemif checkyesno check_aliases; then 4631.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 4641.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 4651.43Sitojun printf "\nEntry for uudecode in $f file.\n" 4661.43Sitojun fi 4671.43Sitojun done 4681.9Scgdfi 4691.9Scgd 4701.9Scgd# Files that should not have + signs. 4711.32Slukem# 4721.31Slukemif checkyesno check_rhosts; then 4731.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 4741.15Smrg for f in $list ; do 4751.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 4761.15Smrg printf "\nPlus sign in $f file.\n" 4771.15Smrg fi 4781.15Smrg done 4791.15Smrg 4801.15Smrg # Check for special users with .rhosts files. Only root and toor should 4811.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 4821.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 4831.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 4841.20Smycroft { print $1 " " $9 }' $MP | 4851.19Smycroft sort -k2 | 4861.15Smrg while read uid homedir; do 4871.15Smrg if [ -f ${homedir}/.rhosts ] ; then 4881.109Schristos rhost=$(ls -ldgT ${homedir}/.rhosts) 4891.46Schristos printf -- "$uid: $rhost\n" 4901.15Smrg fi 4911.15Smrg done > $OUTPUT 4921.15Smrg if [ -s $OUTPUT ] ; then 4931.15Smrg printf "\nChecking for special users with .rhosts files.\n" 4941.15Smrg cat $OUTPUT 4951.15Smrg fi 4961.15Smrg 4971.15Smrg while read uid homedir; do 4981.35Sfair if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \ 4991.41Schristos cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then 5001.46Schristos printf -- "$uid: + in .rhosts file.\n" 5011.15Smrg fi 5021.29Slukem done < $MPBYPATH > $OUTPUT 5031.15Smrg if [ -s $OUTPUT ] ; then 5041.15Smrg printf "\nChecking .rhosts files syntax.\n" 5051.15Smrg cat $OUTPUT 5061.15Smrg fi 5071.9Scgdfi 5081.9Scgd 5091.9Scgd# Check home directories. Directories should not be owned by someone else 5101.80Swiz# or writable. 5111.32Slukem# 5121.31Slukemif checkyesno check_homes; then 5131.85Sjhawk checkyesno check_homes_permit_usergroups && \ 5141.85Sjhawk permit_usergroups=1 || permit_usergroups=0 5151.15Smrg while read uid homedir; do 5161.15Smrg if [ -d ${homedir}/ ] ; then 5171.109Schristos file=$(ls -ldgT ${homedir}) 5181.46Schristos printf -- "$uid $file\n" 5191.9Scgd fi 5201.29Slukem done < $MPBYPATH | 5211.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5221.85Sjhawk $1 != $4 && $4 != "root" \ 5231.15Smrg { print "user " $1 " home directory is owned by " $4 } 5241.101Sjnemeth $2 ~ /^d....w/ && (!usergroups || $5 != $1) \ 5251.80Swiz { print "user " $1 " home directory is group writable" } 5261.101Sjnemeth $2 ~ /^d.......w/ \ 5271.80Swiz { print "user " $1 " home directory is other writable" }' \ 5281.27Slukem > $OUTPUT 5291.15Smrg if [ -s $OUTPUT ] ; then 5301.15Smrg printf "\nChecking home directories.\n" 5311.15Smrg cat $OUTPUT 5321.15Smrg fi 5331.15Smrg 5341.15Smrg # Files that should not be owned by someone else or readable. 5351.67Slukem list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity" 5361.15Smrg while read uid homedir; do 5371.15Smrg for f in $list ; do 5381.15Smrg file=${homedir}/${f} 5391.15Smrg if [ -f $file ] ; then 5401.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5411.15Smrg fi 5421.15Smrg done 5431.29Slukem done < $MPBYPATH | 5441.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5451.85Sjhawk $1 != $5 && $5 != "root" \ 5461.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5471.85Sjhawk $3 ~ /^-...r/ && (!usergroups || $6 != $1) \ 5481.15Smrg { print "user " $1 " " $2 " file is group readable" } 5491.15Smrg $3 ~ /^-......r/ \ 5501.15Smrg { print "user " $1 " " $2 " file is other readable" } 5511.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5521.80Swiz { print "user " $1 " " $2 " file is group writable" } 5531.15Smrg $3 ~ /^-.......w/ \ 5541.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5551.27Slukem > $OUTPUT 5561.15Smrg 5571.80Swiz # Files that should not be owned by someone else or writable. 5581.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 5591.79Selric .cshrc .emacs .exrc .forward .history .k5login .klogin .login \ 5601.79Selric .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \ 5611.79Selric .twmrc .xinitrc .xsession .ssh/authorized_keys \ 5621.79Selric .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \ 5631.79Selric .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \ 5641.79Selric .ssh/known_hosts2" 5651.15Smrg while read uid homedir; do 5661.15Smrg for f in $list ; do 5671.15Smrg file=${homedir}/${f} 5681.15Smrg if [ -f $file ] ; then 5691.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5701.15Smrg fi 5711.15Smrg done 5721.29Slukem done < $MPBYPATH | 5731.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5741.85Sjhawk $1 != $5 && $5 != "root" \ 5751.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5761.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5771.80Swiz { print "user " $1 " " $2 " file is group writable" } 5781.15Smrg $3 ~ /^-.......w/ \ 5791.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5801.27Slukem >> $OUTPUT 5811.15Smrg if [ -s $OUTPUT ] ; then 5821.15Smrg printf "\nChecking dot files.\n" 5831.15Smrg cat $OUTPUT 5841.15Smrg fi 5851.9Scgdfi 5861.9Scgd 5871.9Scgd# Mailboxes should be owned by user and unreadable. 5881.32Slukem# 5891.31Slukemif checkyesno check_varmail; then 5901.86Sjhawk ls -lA /var/mail | \ 5911.63Slukem awk ' NR == 1 { next; } 5921.86Sjhawk $9 ~ /^\./ {next; } 5931.63Slukem $3 != $9 { 5941.63Slukem print "user " $9 " mailbox is owned by " $3 5951.63Slukem } 5961.63Slukem $1 != "-rw-------" { 5971.63Slukem print "user " $9 " mailbox is " $1 ", group " $4 5981.63Slukem }' > $OUTPUT 5991.15Smrg if [ -s $OUTPUT ] ; then 6001.15Smrg printf "\nChecking mailbox ownership.\n" 6011.15Smrg cat $OUTPUT 6021.15Smrg fi 6031.15Smrgfi 6041.15Smrg 6051.32Slukem# NFS exports shouldn't be globally exported 6061.32Slukem# 6071.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 6081.32Slukem awk '{ 6091.22Slukem # ignore comments and blank lines 6101.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 6111.22Slukem next; 6121.100Stron # manage line continuation 6131.100Stron while ($NF ~ /^\\$/) { 6141.100Stron $NF = ""; 6151.100Stron line = $0 ""; 6161.100Stron getline; 6171.100Stron $0 = line $0 ""; 6181.100Stron } 6191.22Slukem 6201.100Stron delete dir; 6211.100Stron readonly = ndir = 0; 6221.100Stron for (i = 1; i <= NF; ++i) { 6231.100Stron if ($i ~ /^\//) dir[ndir++] = $i; 6241.100Stron else if ($i ~ /^-/) { 6251.100Stron if ($i ~ /^-(ro|o)$/) readonly = 1; 6261.100Stron if ($i ~ /^-network/) next; 6271.100Stron } 6281.100Stron else next; 6291.15Smrg } 6301.15Smrg if (readonly) 6311.100Stron for (item in dir) 6321.100Stron rodir[nrodir++] = dir[item]; 6331.15Smrg else 6341.100Stron for (item in dir) 6351.100Stron rwdir[nrwdir++] = dir[item]; 6361.100Stron 6371.100Stron } 6381.100Stron 6391.100Stron END { 6401.100Stron if (nrodir) { 6411.100Stron printf("Globally exported file system%s, read-only:\n", 6421.100Stron nrodir > 1 ? "s" : ""); 6431.100Stron for (item in rodir) 6441.100Stron printf("\t%s\n", rodir[item]); 6451.100Stron } 6461.100Stron if (nrwdir) { 6471.100Stron printf("Globally exported file system%s, read-write:\n", 6481.100Stron nrwdir > 1 ? "s" : ""); 6491.100Stron for (item in rwdir) 6501.100Stron printf("\t%s\n", rwdir[item]); 6511.100Stron } 6521.32Slukem }' < /etc/exports > $OUTPUT 6531.32Slukem if [ -s $OUTPUT ] ; then 6541.15Smrg printf "\nChecking for globally exported file systems.\n" 6551.15Smrg cat $OUTPUT 6561.15Smrg fi 6571.9Scgdfi 6581.9Scgd 6591.9Scgd# Display any changes in setuid files and devices. 6601.32Slukem# 6611.31Slukemif checkyesno check_devices; then 6621.28Slukem > $ERR 6631.92Serh ( 6641.98Slukem 6651.98Slukem # Convert check_devices_ignore_fstypes="foo !bar bax" 6661.98Slukem # into "-fstype foo -o ! -fstype bar -o -fstype bax" 6671.98Slukem # and check_devices_ignore_paths="/foo !/bar /bax" 6681.98Slukem # into " -path /foo -o ! -path /bar -o -path /bax" 6691.98Slukem # 6701.98Slukem ignexpr=$(\ 6711.98Slukem echo $check_devices_ignore_fstypes | \ 6721.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \ 6731.98Slukem echo $check_devices_ignore_paths | \ 6741.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \ 6751.98Slukem ) 6761.98Slukem 6771.98Slukem # Massage the expression into ( $ignexpr ) -a -prune -o 6781.98Slukem if [ -n "${ignexpr}" ]; then 6791.98Slukem ignexpr=$(\ 6801.98Slukem echo $ignexpr | \ 6811.98Slukem sed -e 's/^-o /( /' \ 6821.98Slukem -e 's/$/ ) -a -prune -o/' \ 6831.98Slukem ) 6841.98Slukem fi 6851.98Slukem 6861.98Slukem find / $ignexpr \ 6871.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 6881.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 6891.24Slukem -type b -o -type c \) -print0 | \ 6901.98Slukem xargs -0 ls -ldgTq | sort +9 > $LIST 6911.98Slukem 6921.98Slukem ) 2> $OUTPUT 6931.15Smrg 6941.15Smrg # Display any errors that occurred during system file walk. 6951.15Smrg if [ -s $OUTPUT ] ; then 6961.28Slukem printf "Setuid/device find errors:\n" >> $ERR 6971.28Slukem cat $OUTPUT >> $ERR 6981.28Slukem printf "\n" >> $ERR 6991.15Smrg fi 7001.15Smrg 7011.15Smrg # Display any changes in the setuid file list. 7021.15Smrg egrep -v '^[bc]' $LIST > $TMP1 7031.15Smrg if [ -s $TMP1 ] ; then 7041.15Smrg # Check to make sure uudecode isn't setuid. 7051.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 7061.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 7071.15Smrg fi 7081.15Smrg 7091.67Slukem file=$work_dir/setuid 7101.67Slukem migrate_file "$backup_dir/setuid" "$file" 7111.67Slukem CUR=${file}.current 7121.67Slukem BACK=${file}.backup 7131.15Smrg if [ -s $CUR ] ; then 7141.15Smrg if cmp -s $CUR $TMP1 ; then 7151.15Smrg : 7161.15Smrg else 7171.15Smrg > $TMP2 7181.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 7191.15Smrg if [ -s $OUTPUT ] ; then 7201.28Slukem printf "Setuid additions:\n" >> $ERR 7211.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7221.28Slukem printf "\n" >> $ERR 7231.15Smrg fi 7241.15Smrg 7251.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 7261.15Smrg if [ -s $OUTPUT ] ; then 7271.28Slukem printf "Setuid deletions:\n" >> $ERR 7281.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7291.28Slukem printf "\n" >> $ERR 7301.15Smrg fi 7311.15Smrg 7321.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 7331.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 7341.27Slukem uniq -u > $OUTPUT 7351.15Smrg if [ -s $OUTPUT ] ; then 7361.28Slukem printf "Setuid changes:\n" >> $ERR 7371.28Slukem column -t $OUTPUT >> $ERR 7381.28Slukem printf "\n" >> $ERR 7391.15Smrg fi 7401.9Scgd 7411.52Satatat backup_file update $TMP1 $CUR $BACK 7421.9Scgd fi 7431.15Smrg else 7441.28Slukem printf "Setuid additions:\n" >> $ERR 7451.28Slukem column -t $TMP1 >> $ERR 7461.28Slukem printf "\n" >> $ERR 7471.52Satatat backup_file add $TMP1 $CUR $BACK 7481.9Scgd fi 7491.15Smrg fi 7501.15Smrg 7511.27Slukem # Check for block and character disk devices that are readable or 7521.80Swiz # writable or not owned by root.operator. 7531.15Smrg >$TMP1 7541.61Slukem DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \ 7551.57Ssimonb sd se ss uk up vnd wd xd xy" 7561.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 7571.15Smrg for i in $DISKLIST; do 7581.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7591.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7601.15Smrg done 7611.15Smrg 7621.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 7631.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 7641.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 7651.15Smrg if [ -s $OUTPUT ] ; then 7661.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 7671.28Slukem cat $OUTPUT >> $ERR 7681.28Slukem printf "\n" >> $ERR 7691.9Scgd fi 7701.9Scgd 7711.15Smrg # Display any changes in the device file list. 7721.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 7731.15Smrg if [ -s $TMP1 ] ; then 7741.67Slukem file=$work_dir/device 7751.67Slukem migrate_file "$backup_dir/device" "$file" 7761.67Slukem CUR=${file}.current 7771.67Slukem BACK=${file}.backup 7781.15Smrg 7791.15Smrg if [ -s $CUR ] ; then 7801.15Smrg if cmp -s $CUR $TMP1 ; then 7811.15Smrg : 7821.15Smrg else 7831.15Smrg > $TMP2 7841.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 7851.15Smrg if [ -s $OUTPUT ] ; then 7861.28Slukem printf "Device additions:\n" >> $ERR 7871.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7881.28Slukem printf "\n" >> $ERR 7891.15Smrg fi 7901.15Smrg 7911.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 7921.15Smrg if [ -s $OUTPUT ] ; then 7931.28Slukem printf "Device deletions:\n" >> $ERR 7941.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7951.28Slukem printf "\n" >> $ERR 7961.15Smrg fi 7971.15Smrg 7981.27Slukem # Report any block device change. Ignore 7991.27Slukem # character devices, only the name is 8001.27Slukem # significant. 8011.15Smrg cat $TMP2 $CUR $TMP1 | \ 8021.27Slukem sed -e '/^c/d' | \ 8031.27Slukem sort -k11 | \ 8041.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 8051.27Slukem uniq -u > $OUTPUT 8061.15Smrg if [ -s $OUTPUT ] ; then 8071.28Slukem printf "Block device changes:\n" >> $ERR 8081.28Slukem column -t $OUTPUT >> $ERR 8091.28Slukem printf "\n" >> $ERR 8101.15Smrg fi 8111.9Scgd 8121.52Satatat backup_file update $TMP1 $CUR $BACK 8131.9Scgd fi 8141.15Smrg else 8151.28Slukem printf "Device additions:\n" >> $ERR 8161.28Slukem column -t $TMP1 >> $ERR 8171.28Slukem printf "\n" >> $ERR 8181.52Satatat backup_file add $TMP1 $CUR $BACK >> $ERR 8191.9Scgd fi 8201.28Slukem fi 8211.28Slukem if [ -s $ERR ] ; then 8221.28Slukem printf "\nChecking setuid files and devices:\n" 8231.28Slukem cat $ERR 8241.28Slukem printf "\n" 8251.9Scgd fi 8261.9Scgdfi 8271.9Scgd 8281.9Scgd# Check special files. 8291.9Scgd# Check system binaries. 8301.9Scgd# 8311.9Scgd# Create the mtree tree specifications using: 8321.67Slukem# mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure 8331.38Skleink# chown root:wheel DIR.secure 8341.67Slukem# chmod u+r,go= DIR.secure 8351.9Scgd# 8361.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 8371.9Scgd# the hacker can modify the tree specification to match the replaced binary. 8381.9Scgd# For details on really protecting yourself against modified binaries, see 8391.9Scgd# the mtree(8) manual page. 8401.32Slukem# 8411.31Slukemif checkyesno check_mtree; then 8421.82Sjhawk if checkyesno check_mtree_follow_symlinks; then 8431.82Sjhawk check_mtree_flags="-L" 8441.82Sjhawk else 8451.82Sjhawk check_mtree_flags="" 8461.82Sjhawk fi 8471.91Slukem mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 | 8481.87Sjhawk grep -v '^mtree: dev/tty: Device not configured$' >&2 8491.15Smrg if [ -s $OUTPUT ]; then 8501.9Scgd printf "\nChecking special files and directories.\n" 8511.9Scgd cat $OUTPUT 8521.9Scgd fi 8531.9Scgd 8541.16Smikel for file in /etc/mtree/*.secure; do 8551.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 8561.109Schristos tree=$(sed -n -e '3s/.* //p' -e 3q $file) 8571.82Sjhawk mtree $check_mtree_flags -f $file -p $tree > $TMP1 8581.9Scgd if [ -s $TMP1 ]; then 8591.67Slukem printf "\nChecking $tree:\n" 8601.67Slukem cat $TMP1 8611.9Scgd fi 8621.67Slukem done > $OUTPUT 8631.15Smrg if [ -s $OUTPUT ]; then 8641.9Scgd printf "\nChecking system binaries:\n" 8651.9Scgd cat $OUTPUT 8661.9Scgd fi 8671.9Scgdfi 8681.9Scgd 8691.32Slukem# Backup disklabels of available disks 8701.32Slukem# 8711.32Slukemif checkyesno check_disklabels; then 8721.67Slukem # migrate old disklabels 8731.109Schristos for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \ 8741.109Schristos $backup_dir/disklabel.* 2>/dev/null); do 8751.67Slukem migrate_file "$file" "$work_dir/${file##*/}" 8761.67Slukem done 8771.67Slukem 8781.103Stron # generate list of old disklabels, fdisks & wedges and remove them 8791.103Stron ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null | 8801.52Satatat egrep -v '\.(backup|current)(,v)?$' > $LABELS 8811.32Slukem xargs rm < $LABELS 8821.32Slukem 8831.103Stron # generate disklabels of all disks excluding: cd dk fd md st 8841.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|dk|st|nfs/ { print $1; }') 8851.32Slukem for i in $disks; do 8861.67Slukem disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null 8871.32Slukem done 8881.32Slukem 8891.67Slukem # if fdisk is available, generate fdisks for: ed ld sd wd 8901.67Slukem if [ -x /sbin/fdisk ]; then 8911.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }') 8921.67Slukem for i in $disks; do 8931.67Slukem /sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null 8941.67Slukem done 8951.67Slukem fi 8961.67Slukem 8971.103Stron # if dkctl is available, generate dkctl listwedges for: ed ld sd wd cgd ofdisk ra rl raid 8981.103Stron if [ -x /sbin/dkctl ]; then 8991.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d|cgd|ofdisk|r[al]|raid/ { print $1; }') 9001.103Stron for i in $disks; do 9011.103Stron /sbin/dkctl $i listwedges > "$work_dir/wedges.$i" 2>/dev/null 9021.103Stron done 9031.103Stron fi 9041.103Stron 9051.103Stron # append list of new disklabels, fdisks and wedges 9061.103Stron ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null | 9071.52Satatat egrep -v '\.(backup|current)(,v)?$' >> $LABELS 9081.62Satatat CHANGELIST="$LABELS $CHANGELIST" 9091.62Satatatfi 9101.62Satatat 9111.106Shaadif checkyesno check_lvm; then 9121.106Shaad 9131.106Shaad # generate list of existing LVM elements Physical Volumes, Volume Groups and Logical Volumes. 9141.106Shaadif [ -x /sbin/lvm ]; then 9151.106Shaad lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null 9161.106Shaad lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null 9171.106Shaad lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null 9181.106Shaadfi 9191.106Shaad ls -1d $work_dir/lvm.* 2>/dev/null | 9201.106Shaad egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS 9211.106Shaad CHANGELIST="$CHANGELIST $LVM_LABELS" 9221.106Shaadfi 9231.106Shaad 9241.62Satatat# Check for changes in the list of installed pkgs 9251.62Satatat# 9261.108Sjmmvif checkyesno check_pkgs && have_pkgs; then 9271.67Slukem pkgs=$work_dir/pkgs 9281.67Slukem migrate_file "$backup_dir/pkgs" "$pkgs" 9291.108Sjmmv pkg_dbdir=$(pkg_admin config-var PKG_DBDIR) 9301.108Sjmmv : ${pkg_dbdir:=/var/db/pkg} 9311.108Sjmmv ( cd $pkg_dbdir 9321.104Sadrianp $pkg_info | sort 9331.62Satatat echo "" 9341.62Satatat find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 | 9351.72Slukem xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,' 9361.62Satatat ) > $pkgs 9371.67Slukem echo "$pkgs" > $PKGS 9381.62Satatat CHANGELIST="$PKGS $CHANGELIST" 9391.32Slukemfi 9401.32Slukem 9411.67Slukem# List of files that get backed up and checked for any modifications. 9421.9Scgd# Any changes cause the files to rotate. 9431.32Slukem# 9441.67Slukemif checkyesno check_changelist ; then 9451.91Slukem mtree -D -k type -f $SPECIALSPEC -E exclude | 9461.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES 9471.67Slukem 9481.75Slukem ( 9491.68Slukem # Add other files which might dynamically exist: 9501.67Slukem # /etc/ifconfig.* 9511.67Slukem # /etc/raid*.conf 9521.68Slukem # /etc/rc.d/* 9531.67Slukem # /etc/rc.conf.d/* 9541.68Slukem # 9551.75Slukem echo "/etc/ifconfig.*" 9561.75Slukem echo "/etc/raid*.conf" 9571.75Slukem echo "/etc/rc.d/*" 9581.75Slukem echo "/etc/rc.conf.d/*" 9591.106Shaad echo "/etc/lvm/backup/*" 9601.106Shaad echo "/etc/lvm/archive/*" 9611.67Slukem 9621.68Slukem # Add /etc/changelist 9631.68Slukem # 9641.75Slukem if [ -s /etc/changelist ]; then 9651.75Slukem grep -v '^#' /etc/changelist 9661.75Slukem fi 9671.75Slukem ) | while read file; do 9681.75Slukem case "$file" in 9691.75Slukem *[\*\?\[]*) # If changelist line is a glob ... 9701.75Slukem # ... expand possible backup files 9711.75Slukem # 9721.75Slukem ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \ 9731.75Slukem | sed "s,^$backup_dir/,, ; s,\.current$,," 9741.75Slukem 9751.75Slukem # ... expand possible files 9761.75Slukem # 9771.75Slukem ls -1d $(echo $file) 2>/dev/null 9781.75Slukem ;; 9791.75Slukem *) 9801.75Slukem # Otherwise, just print the filename 9811.75Slukem echo $file 9821.75Slukem ;; 9831.75Slukem esac 9841.75Slukem done >> $CHANGEFILES 9851.67Slukem CHANGELIST="$CHANGEFILES $CHANGELIST" 9861.67Slukemfi 9871.67Slukem 9881.67Slukem# Special case backups, including the master password file and 9891.67Slukem# ssh private host keys. The normal backup mechanisms for 9901.67Slukem# $check_changelist (see below) also print out the actual file 9911.67Slukem# differences and we don't want to do that for these files 9921.67Slukem# 9931.67Slukemecho $MP > $TMP1 # always add /etc/master.passwd 9941.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff | 9951.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1 9961.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2 9971.68Slukem 9981.69Slukemwhile read file; do 9991.67Slukem backup_and_diff "$file" no 10001.69Slukemdone < $TMP2 10011.67Slukem 10021.32Slukem 10031.32Slukemif [ -n "$CHANGELIST" ]; then 10041.73Slukem grep -h -v '^$' $CHANGELIST | sort -u > $TMP1 10051.68Slukem comm -23 $TMP1 $TMP2 | while read file; do 10061.67Slukem backup_and_diff "$file" yes 10071.9Scgd done 10081.44Sadfi 10091.44Sad 10101.108Sjmmvif have_pkgs; then 10111.107Sjmmv if checkyesno check_pkg_vulnerabilities; then 10121.108Sjmmv pkg_admin ${_compat_K_flag} audit >${OUTPUT} 2>&1 10131.107Sjmmv if [ -s ${OUTPUT} ]; then 10141.107Sjmmv printf "\nInstalled vulnerable packages:\n" 10151.107Sjmmv cat ${OUTPUT} 10161.107Sjmmv fi 10171.107Sjmmv fi 10181.107Sjmmv 10191.107Sjmmv if checkyesno check_pkg_signatures; then 10201.108Sjmmv pkg_admin ${_compat_K_flag} check >${OUTPUT} 2>&1 10211.107Sjmmv if [ $? -ne 0 ]; then 10221.107Sjmmv printf "\nFiles with invalid signatures:\n" 10231.107Sjmmv cat ${OUTPUT} 10241.107Sjmmv fi 10251.107Sjmmv fi 10261.107Sjmmvfi 10271.107Sjmmv 10281.44Sadif [ -f /etc/security.local ]; then 10291.90Skim . /etc/security.local > $OUTPUT 2>&1 10301.84Sjhawk if [ -s $OUTPUT ] ; then 10311.84Sjhawk printf "\nRunning /etc/security.local:\n" 10321.84Sjhawk cat $OUTPUT 10331.84Sjhawk fi 10341.9Scgdfi 1035