security revision 1.112
11.1Scgd#!/bin/sh - 21.1Scgd# 31.112Sagc# $NetBSD: security,v 1.112 2013/05/01 05:36:25 agc 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.112Sagcif [ -s /etc/pkgpath.conf ]; then 251.112Sagc . /etc/pkgpath.conf 261.112Sagcfi 271.15Smrg 281.67Slukem# Set reasonable defaults (if they're not set in security.conf) 291.67Slukem# 301.67Slukembackup_dir=${backup_dir:-/var/backups} 311.67Slukemmax_loginlen=${max_loginlen:-8} 321.67Slukemmax_grouplen=${max_grouplen:-8} 331.104Sadrianppkg_info=${pkg_info:-/usr/sbin/pkg_info} 341.67Slukem 351.67Slukem# Other configurable variables 361.67Slukem# 371.67Slukemspecial_files="/etc/mtree/special /etc/mtree/special.local" 381.67SlukemMP=/etc/master.passwd 391.67SlukemCHANGELIST="" 401.67Slukemwork_dir=$backup_dir/work 411.67Slukem 421.67Slukemif [ ! -d "$work_dir" ]; then 431.67Slukem mkdir -p "$work_dir" 441.67Slukemfi 451.67Slukem 461.102SmarttiSECUREDIR=$(mktemp -d -t _securedir) || exit 1 471.56Slukem 481.67Slukemtrap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE 491.15Smrg 501.56Slukemif ! cd "$SECUREDIR"; then 511.56Slukem echo "Can not cd to $SECUREDIR". 521.15Smrg exit 1 531.15Smrgfi 541.15Smrg 551.91SlukemERR=err.$$ 561.91SlukemTMP1=tmp1.$$ 571.91SlukemTMP2=tmp2.$$ 581.91SlukemMPBYUID=mpbyuid.$$ 591.91SlukemMPBYPATH=mpbypath.$$ 601.91SlukemLIST=list.$$ 611.91SlukemOUTPUT=output.$$ 621.91SlukemLABELS=labels.$$ 631.106ShaadLVM_LABELS=lvm.$$ 641.91SlukemPKGS=pkgs.$$ 651.91SlukemCHANGEFILES=changefiles.$$ 661.91SlukemSPECIALSPEC=specialspec.$$ 671.67Slukem 681.108Sjmmvif [ -n "${pkgdb_dir}" ]; then 691.108Sjmmv echo "WARNING: Setting pkgdb_dir in security.conf(5) is deprecated" 701.108Sjmmv echo "WARNING: Please define PKG_DBDIR in pkg_install.conf(5) instead" 711.108Sjmmv _compat_K_flag="-K ${pkgdb_dir}" 721.108Sjmmvfi 731.108Sjmmv 741.108Sjmmvhave_pkgs() { 751.108Sjmmv $pkg_info ${_compat_K_flag} -q -E '*' 761.108Sjmmv} 771.108Sjmmv 781.67Slukem# migrate_file old new 791.67Slukem# Determine if the "${old}" path name needs to be migrated to the 801.67Slukem# "${new}" path. Also checks if "${old}.current" needs migrating, 811.67Slukem# and if so, migrate it and possibly "${old}.current,v" and 821.67Slukem# "${old}.backup". 831.67Slukem# 841.67Slukemmigrate_file() 851.67Slukem{ 861.67Slukem _old=$1 871.67Slukem _new=$2 881.67Slukem if [ -z "$_old" -o -z "$_new" ]; then 891.67Slukem err 3 "USAGE: migrate_file old new" 901.67Slukem fi 911.67Slukem if [ ! -d "${_new%/*}" ]; then 921.67Slukem mkdir -p "${_new%/*}" 931.67Slukem fi 941.67Slukem if [ -f "${_old}" -a ! -f "${_new}" ]; then 951.67Slukem echo "==> migrating ${_old}" 961.67Slukem echo " to ${_new}" 971.67Slukem mv "${_old}" "${_new}" 981.67Slukem fi 991.67Slukem if [ -f "${_old}.current" -a ! -f "${_new}.current" ]; then 1001.67Slukem echo "==> migrating ${_old}.current" 1011.67Slukem echo " to ${_new}.current" 1021.67Slukem mv "${_old}.current" "${_new}.current" 1031.67Slukem if [ -f "${_old}.current,v" -a ! -f "${_new}.current,v" ]; then 1041.67Slukem echo "==> migrating ${_old}.current,v" 1051.67Slukem echo " to ${_new}.current,v" 1061.67Slukem mv "${_old}.current,v" "${_new}.current,v" 1071.67Slukem fi 1081.67Slukem if [ -f "${_old}.backup" -a ! -f "${_new}.backup" ]; then 1091.67Slukem echo "==> migrating ${_old}.backup" 1101.67Slukem echo " to ${_new}.backup" 1111.67Slukem mv "${_old}.backup" "${_new}.backup" 1121.67Slukem fi 1131.67Slukem fi 1141.67Slukem} 1151.67Slukem 1161.67Slukem 1171.67Slukem# backup_and_diff file printdiff 1181.67Slukem# Determine if file needs backing up, and if so, do it. 1191.67Slukem# If printdiff is yes, display the diffs, otherwise 1201.67Slukem# just print a message saying "[changes omitted]". 1211.67Slukem# 1221.67Slukembackup_and_diff() 1231.67Slukem{ 1241.67Slukem _file=$1 1251.67Slukem _printdiff=$2 1261.67Slukem if [ -z "$_file" -o -z "$_printdiff" ]; then 1271.67Slukem err 3 "USAGE: backup_and_diff file printdiff" 1281.67Slukem fi 1291.67Slukem ! checkyesno _printdiff 1301.67Slukem _printdiff=$? 1311.67Slukem 1321.67Slukem _old=$backup_dir/${_file##*/} 1331.67Slukem case "$_file" in 1341.67Slukem $work_dir/*) 1351.67Slukem _new=$_file 1361.67Slukem migrate_file "$backup_dir/$_old" "$_new" 1371.67Slukem migrate_file "$_old" "$_new" 1381.67Slukem ;; 1391.67Slukem *) 1401.67Slukem _new=$backup_dir/$_file 1411.67Slukem migrate_file "$_old" "$_new" 1421.67Slukem ;; 1431.67Slukem esac 1441.67Slukem CUR=${_new}.current 1451.67Slukem BACK=${_new}.backup 1461.67Slukem if [ -f $_file ]; then 1471.67Slukem if [ -f $CUR ] ; then 1481.67Slukem if [ "$_printdiff" -ne 0 ]; then 1491.83Sjhawk diff ${diff_options} $CUR $_file > $OUTPUT 1501.67Slukem else 1511.67Slukem if ! cmp -s $CUR $_file; then 1521.67Slukem echo "[changes omitted]" 1531.67Slukem fi > $OUTPUT 1541.67Slukem fi 1551.67Slukem if [ -s $OUTPUT ] ; then 1561.67Slukem printf \ 1571.67Slukem "\n======\n%s diffs (OLD < > NEW)\n======\n" $_file 1581.67Slukem cat $OUTPUT 1591.67Slukem backup_file update $_file $CUR $BACK 1601.67Slukem fi 1611.67Slukem else 1621.67Slukem printf "\n======\n%s added\n======\n" $_file 1631.67Slukem if [ "$_printdiff" -ne 0 ]; then 1641.83Sjhawk diff ${diff_options} /dev/null $_file 1651.67Slukem else 1661.67Slukem echo "[changes omitted]" 1671.67Slukem fi 1681.67Slukem backup_file add $_file $CUR $BACK 1691.67Slukem fi 1701.67Slukem else 1711.67Slukem if [ -f $CUR ]; then 1721.67Slukem printf "\n======\n%s removed\n======\n" $_file 1731.67Slukem if [ "$_printdiff" -ne 0 ]; then 1741.83Sjhawk diff ${diff_options} $CUR /dev/null 1751.67Slukem else 1761.67Slukem echo "[changes omitted]" 1771.67Slukem fi 1781.67Slukem backup_file remove $_file $CUR $BACK 1791.67Slukem fi 1801.67Slukem fi 1811.67Slukem} 1821.48Sabs 1831.9Scgd 1841.67Slukem# These are used several times. 1851.67Slukem# 1861.91Slukemawk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID 1871.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH 1881.91Slukemfor file in $special_files; do 1891.91Slukem [ -s $file ] && cat $file 1901.91Slukemdone | mtree -CM -k all > $SPECIALSPEC || exit 1 1911.9Scgd 1921.67Slukem 1931.9Scgd# Check the master password file syntax. 1941.32Slukem# 1951.31Slukemif checkyesno check_passwd; then 1961.85Sjhawk # XXX: the sense of permit_star is reversed; the code works as 1971.85Sjhawk # implemented, but usage needs to be negated. 1981.81Sjhawk checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1 1991.94Sjdolecek checkyesno check_passwd_permit_nonalpha \ 2001.94Sjdolecek && permit_nonalpha=1 || permit_nonalpha=0 2011.94Sjdolecek 2021.81Sjhawk awk -v "len=$max_loginlen" \ 2031.81Sjhawk -v "nowarn_shells_list=$check_passwd_nowarn_shells" \ 2041.81Sjhawk -v "nowarn_users_list=$check_passwd_nowarn_users" \ 2051.94Sjdolecek -v "permit_star=$permit_star" \ 2061.94Sjdolecek -v "permit_nonalpha=$permit_nonalpha" \ 2071.94Sjdolecek ' 2081.25Slukem BEGIN { 2091.25Slukem while ( getline < "/etc/shells" > 0 ) { 2101.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 2111.25Slukem continue; 2121.25Slukem shells[$1]++; 2131.25Slukem } 2141.81Sjhawk split(nowarn_shells_list, a); 2151.81Sjhawk for (i in a) nowarn_shells[a[i]]++; 2161.81Sjhawk split(nowarn_users_list, a); 2171.81Sjhawk for (i in a) nowarn_users[a[i]]++; 2181.81Sjhawk uid0_users_list="root toor" 2191.81Sjhawk split(uid0_users_list, a); 2201.81Sjhawk for (i in a) uid0_users[a[i]]++; 2211.25Slukem FS=":"; 2221.25Slukem } 2231.25Slukem 2241.25Slukem { 2251.15Smrg if ($0 ~ /^[ ]*$/) { 2261.25Slukem printf "Line %d is a blank line.\n", NR; 2271.15Smrg next; 2281.15Smrg } 2291.105Sdholland 2301.105Sdholland # NIS compat entry? 2311.105Sdholland compatline = $1 ~ "^[\\+-]"; 2321.105Sdholland if (compatline) { 2331.105Sdholland if ($1 == "+" && NF == 1) { 2341.105Sdholland next; 2351.105Sdholland } 2361.105Sdholland sub("^.", "", $1); 2371.105Sdholland } 2381.105Sdholland if (NF != 10) 2391.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 2401.105Sdholland if (compatline) { 2411.105Sdholland if ($3 == 0) 2421.81Sjhawk printf "Line %d includes entries with uid 0.\n", 2431.81Sjhawk NR; 2441.105Sdholland if ($1 == "") 2451.105Sdholland next; 2461.34Sabs } 2471.94Sjdolecek if (!permit_nonalpha && 2481.95Speter $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 2491.25Slukem printf "Login %s has non-alphanumeric characters.\n", 2501.25Slukem $1; 2511.34Sabs if (length($1) > len) 2521.81Sjhawk printf "Login %s has more than "len" characters.\n", 2531.81Sjhawk $1; 2541.105Sdholland if ($2 == "" && !compatline && !nowarn_users[$1]) 2551.81Sjhawk printf "Login %s has no password.\n", $1; 2561.81Sjhawk if (!nowarn_shells[$10] && !nowarn_users[$1]) { 2571.81Sjhawk if (length($2) != 13 && 2581.81Sjhawk length($2) != 20 && 2591.81Sjhawk $2 !~ /^\$1/ && 2601.81Sjhawk $2 !~ /^\$2/ && 2611.99Sjmcneill $2 !~ /^\$sha1/ && 2621.81Sjhawk $2 != "" && 2631.81Sjhawk (permit_star || $2 != "*") && 2641.81Sjhawk $2 !~ /^\*[A-z-]+$/ && 2651.81Sjhawk $1 != "toor") { 2661.81Sjhawk if ($10 == "" || shells[$10]) 2671.81Sjhawk printf "Login %s is off but still has "\ 2681.81Sjhawk "a valid shell (%s)\n", $1, $10; 2691.105Sdholland } else if (compatline && $10 == "") { 2701.105Sdholland # nothing 2711.81Sjhawk } else if (! shells[$10]) 2721.81Sjhawk printf "Login %s does not have a valid "\ 2731.81Sjhawk "shell (%s)\n", $1, $10; 2741.81Sjhawk } 2751.81Sjhawk if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1]) 2761.25Slukem printf "Login %s has a user id of 0.\n", $1; 2771.105Sdholland if ($3 != "" && $3 < 0) 2781.25Slukem printf "Login %s has a negative user id.\n", $1; 2791.105Sdholland if ($4 != "" && $4 < 0) 2801.25Slukem printf "Login %s has a negative group id.\n", $1; 2811.15Smrg }' < $MP > $OUTPUT 2821.15Smrg if [ -s $OUTPUT ] ; then 2831.15Smrg printf "\nChecking the $MP file:\n" 2841.15Smrg cat $OUTPUT 2851.15Smrg fi 2861.15Smrg 2871.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 2881.15Smrg if [ -s $OUTPUT ] ; then 2891.15Smrg printf "\n$MP has duplicate user names.\n" 2901.15Smrg column $OUTPUT 2911.15Smrg fi 2921.15Smrg 2931.111Sspz awk -v "permit_dups_list=$check_passwd_permit_dups" \ 2941.111Sspz ' 2951.111Sspz BEGIN { 2961.111Sspz split(permit_dups_list, a); 2971.111Sspz for (i in a) permit_dups[a[i]]++; 2981.111Sspz } 2991.111Sspz { 3001.111Sspz if (!permit_dups[$1]) 3011.111Sspz print $2; 3021.111Sspz }' < $MPBYUID | uniq -d > $TMP2 3031.15Smrg if [ -s $TMP2 ] ; then 3041.111Sspz printf "\n$MP has duplicate user ids.\n" 3051.15Smrg while read uid; do 3061.28Slukem grep -w $uid $MPBYUID 3071.15Smrg done < $TMP2 | column 3081.15Smrg fi 3091.9Scgdfi 3101.9Scgd 3111.9Scgd# Check the group file syntax. 3121.32Slukem# 3131.31Slukemif checkyesno check_group; then 3141.15Smrg GRP=/etc/group 3151.49Sjdolecek awk -F: -v "len=$max_grouplen" '{ 3161.15Smrg if ($0 ~ /^[ ]*$/) { 3171.25Slukem printf "Line %d is a blank line.\n", NR; 3181.15Smrg next; 3191.15Smrg } 3201.34Sabs if (NF != 4 && ($1 != "+" || NF != 1)) 3211.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 3221.34Sabs if ($1 == "+" ) { 3231.34Sabs next; 3241.34Sabs } 3251.95Speter if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 3261.25Slukem printf "Group %s has non-alphanumeric characters.\n", 3271.25Slukem $1; 3281.49Sjdolecek if (length($1) > len) 3291.49Sjdolecek printf "Group %s has more than "len" characters.\n", $1; 3301.15Smrg if ($3 !~ /[0-9]*/) 3311.25Slukem printf "Login %s has a negative group id.\n", $1; 3321.15Smrg }' < $GRP > $OUTPUT 3331.15Smrg if [ -s $OUTPUT ] ; then 3341.15Smrg printf "\nChecking the $GRP file:\n" 3351.15Smrg cat $OUTPUT 3361.15Smrg fi 3371.15Smrg 3381.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 3391.15Smrg if [ -s $OUTPUT ] ; then 3401.15Smrg printf "\n$GRP has duplicate group names.\n" 3411.15Smrg column $OUTPUT 3421.15Smrg fi 3431.9Scgdfi 3441.9Scgd 3451.9Scgd# Check for root paths, umask values in startup files. 3461.9Scgd# The check for the root paths is problematical -- it's likely to fail 3471.9Scgd# in other environments. Once the shells have been modified to warn 3481.9Scgd# of '.' in the path, the path tests should go away. 3491.32Slukem# 3501.31Slukemif checkyesno check_rootdotfiles; then 3511.67Slukem rhome=~root 3521.15Smrg umaskset=no 3531.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 3541.15Smrg for i in $list ; do 3551.15Smrg if [ -f $i ] ; then 3561.67Slukem if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; 3571.67Slukem then 3581.15Smrg umaskset=yes 3591.15Smrg fi 3601.63Slukem # Double check the umask value itself; ensure that 3611.67Slukem # both the group and other write bits are set. 3621.67Slukem # 3631.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 3641.63Slukem awk '{ 3651.67Slukem if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) { 3661.80Swiz print "\tRoot umask is group writable" 3671.63Slukem } 3681.67Slukem if ($2 ~ /[^2367]$/) { 3691.80Swiz print "\tRoot umask is other writable" 3701.63Slukem } 3711.67Slukem }' | sort -u 3721.26Slukem SAVE_PATH=$PATH 3731.26Slukem unset PATH 3741.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 3751.15Smrg source $i 3761.15Smrg /bin/ls -ldgT \$path > $TMP1 3771.9Scgdend-of-csh 3781.76Satatat export PATH=$SAVE_PATH 3791.15Smrg awk '{ 3801.15Smrg if ($10 ~ /^\.$/) { 3811.27Slukem print "\tThe root path includes ."; 3821.15Smrg next; 3831.15Smrg } 3841.15Smrg } 3851.15Smrg $1 ~ /^d....w/ \ 3861.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 3871.15Smrg $1 ~ /^d.......w/ \ 3881.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 3891.67Slukem < $TMP1 3901.15Smrg fi 3911.67Slukem done > $OUTPUT 3921.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 3931.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 3941.15Smrg if [ -s $OUTPUT ]; then 3951.15Smrg cat $OUTPUT 3961.15Smrg fi 3971.15Smrg if [ $umaskset = "no" ] ; then 3981.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 3991.15Smrg fi 4001.9Scgd fi 4011.9Scgd 4021.15Smrg umaskset=no 4031.23Slukem list="/etc/profile ${rhome}/.profile" 4041.15Smrg for i in $list; do 4051.15Smrg if [ -f $i ] ; then 4061.15Smrg if egrep umask $i > /dev/null ; then 4071.15Smrg umaskset=yes 4081.15Smrg fi 4091.15Smrg egrep umask $i | 4101.67Slukem awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \ 4111.80Swiz { print "\tRoot umask is group writable" } \ 4121.67Slukem $2 ~ /[^2367]$/ \ 4131.80Swiz { print "\tRoot umask is other writable" }' 4141.26Slukem SAVE_PATH=$PATH 4151.26Slukem unset PATH 4161.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 4171.15Smrg . $i 4181.110Schristos list=\$(echo \$PATH | /usr/bin/sed -e \ 4191.110Schristos 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g') 4201.15Smrg /bin/ls -ldgT \$list > $TMP1 4211.9Scgdend-of-sh 4221.76Satatat export PATH=$SAVE_PATH 4231.15Smrg awk '{ 4241.15Smrg if ($10 ~ /^\.$/) { 4251.27Slukem print "\tThe root path includes ."; 4261.15Smrg next; 4271.15Smrg } 4281.15Smrg } 4291.15Smrg $1 ~ /^d....w/ \ 4301.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4311.15Smrg $1 ~ /^d.......w/ \ 4321.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4331.67Slukem < $TMP1 4341.9Scgd 4351.15Smrg fi 4361.67Slukem done > $OUTPUT 4371.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 4381.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 4391.15Smrg if [ -s $OUTPUT ]; then 4401.15Smrg cat $OUTPUT 4411.15Smrg fi 4421.15Smrg if [ $umaskset = "no" ] ; then 4431.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 4441.15Smrg fi 4451.9Scgd fi 4461.9Scgdfi 4471.9Scgd 4481.9Scgd# Root and uucp should both be in /etc/ftpusers. 4491.32Slukem# 4501.31Slukemif checkyesno check_ftpusers; then 4511.109Schristos list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID) 4521.27Slukem for i in $list; do 4531.29Slukem if /usr/libexec/ftpd -C $i ; then 4541.67Slukem printf "\t$i is not denied\n" 4551.27Slukem fi 4561.67Slukem done > $OUTPUT 4571.28Slukem if [ -s $OUTPUT ]; then 4581.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 4591.28Slukem cat $OUTPUT 4601.28Slukem fi 4611.9Scgdfi 4621.9Scgd 4631.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 4641.32Slukem# 4651.31Slukemif checkyesno check_aliases; then 4661.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 4671.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 4681.43Sitojun printf "\nEntry for uudecode in $f file.\n" 4691.43Sitojun fi 4701.43Sitojun done 4711.9Scgdfi 4721.9Scgd 4731.9Scgd# Files that should not have + signs. 4741.32Slukem# 4751.31Slukemif checkyesno check_rhosts; then 4761.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 4771.15Smrg for f in $list ; do 4781.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 4791.15Smrg printf "\nPlus sign in $f file.\n" 4801.15Smrg fi 4811.15Smrg done 4821.15Smrg 4831.15Smrg # Check for special users with .rhosts files. Only root and toor should 4841.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 4851.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 4861.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 4871.20Smycroft { print $1 " " $9 }' $MP | 4881.19Smycroft sort -k2 | 4891.15Smrg while read uid homedir; do 4901.15Smrg if [ -f ${homedir}/.rhosts ] ; then 4911.109Schristos rhost=$(ls -ldgT ${homedir}/.rhosts) 4921.46Schristos printf -- "$uid: $rhost\n" 4931.15Smrg fi 4941.15Smrg done > $OUTPUT 4951.15Smrg if [ -s $OUTPUT ] ; then 4961.15Smrg printf "\nChecking for special users with .rhosts files.\n" 4971.15Smrg cat $OUTPUT 4981.15Smrg fi 4991.15Smrg 5001.15Smrg while read uid homedir; do 5011.35Sfair if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \ 5021.41Schristos cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then 5031.46Schristos printf -- "$uid: + in .rhosts file.\n" 5041.15Smrg fi 5051.29Slukem done < $MPBYPATH > $OUTPUT 5061.15Smrg if [ -s $OUTPUT ] ; then 5071.15Smrg printf "\nChecking .rhosts files syntax.\n" 5081.15Smrg cat $OUTPUT 5091.15Smrg fi 5101.9Scgdfi 5111.9Scgd 5121.9Scgd# Check home directories. Directories should not be owned by someone else 5131.80Swiz# or writable. 5141.32Slukem# 5151.31Slukemif checkyesno check_homes; then 5161.85Sjhawk checkyesno check_homes_permit_usergroups && \ 5171.85Sjhawk permit_usergroups=1 || permit_usergroups=0 5181.15Smrg while read uid homedir; do 5191.15Smrg if [ -d ${homedir}/ ] ; then 5201.109Schristos file=$(ls -ldgT ${homedir}) 5211.46Schristos printf -- "$uid $file\n" 5221.9Scgd fi 5231.29Slukem done < $MPBYPATH | 5241.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5251.85Sjhawk $1 != $4 && $4 != "root" \ 5261.15Smrg { print "user " $1 " home directory is owned by " $4 } 5271.101Sjnemeth $2 ~ /^d....w/ && (!usergroups || $5 != $1) \ 5281.80Swiz { print "user " $1 " home directory is group writable" } 5291.101Sjnemeth $2 ~ /^d.......w/ \ 5301.80Swiz { print "user " $1 " home directory is other writable" }' \ 5311.27Slukem > $OUTPUT 5321.15Smrg if [ -s $OUTPUT ] ; then 5331.15Smrg printf "\nChecking home directories.\n" 5341.15Smrg cat $OUTPUT 5351.15Smrg fi 5361.15Smrg 5371.15Smrg # Files that should not be owned by someone else or readable. 5381.67Slukem list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity" 5391.15Smrg while read uid homedir; do 5401.15Smrg for f in $list ; do 5411.15Smrg file=${homedir}/${f} 5421.15Smrg if [ -f $file ] ; then 5431.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5441.15Smrg fi 5451.15Smrg done 5461.29Slukem done < $MPBYPATH | 5471.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5481.85Sjhawk $1 != $5 && $5 != "root" \ 5491.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5501.85Sjhawk $3 ~ /^-...r/ && (!usergroups || $6 != $1) \ 5511.15Smrg { print "user " $1 " " $2 " file is group readable" } 5521.15Smrg $3 ~ /^-......r/ \ 5531.15Smrg { print "user " $1 " " $2 " file is other readable" } 5541.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5551.80Swiz { print "user " $1 " " $2 " file is group writable" } 5561.15Smrg $3 ~ /^-.......w/ \ 5571.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5581.27Slukem > $OUTPUT 5591.15Smrg 5601.80Swiz # Files that should not be owned by someone else or writable. 5611.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 5621.79Selric .cshrc .emacs .exrc .forward .history .k5login .klogin .login \ 5631.79Selric .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \ 5641.79Selric .twmrc .xinitrc .xsession .ssh/authorized_keys \ 5651.79Selric .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \ 5661.79Selric .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \ 5671.79Selric .ssh/known_hosts2" 5681.15Smrg while read uid homedir; do 5691.15Smrg for f in $list ; do 5701.15Smrg file=${homedir}/${f} 5711.15Smrg if [ -f $file ] ; then 5721.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5731.15Smrg fi 5741.15Smrg done 5751.29Slukem done < $MPBYPATH | 5761.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5771.85Sjhawk $1 != $5 && $5 != "root" \ 5781.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5791.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5801.80Swiz { print "user " $1 " " $2 " file is group writable" } 5811.15Smrg $3 ~ /^-.......w/ \ 5821.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5831.27Slukem >> $OUTPUT 5841.15Smrg if [ -s $OUTPUT ] ; then 5851.15Smrg printf "\nChecking dot files.\n" 5861.15Smrg cat $OUTPUT 5871.15Smrg fi 5881.9Scgdfi 5891.9Scgd 5901.9Scgd# Mailboxes should be owned by user and unreadable. 5911.32Slukem# 5921.31Slukemif checkyesno check_varmail; then 5931.86Sjhawk ls -lA /var/mail | \ 5941.63Slukem awk ' NR == 1 { next; } 5951.86Sjhawk $9 ~ /^\./ {next; } 5961.63Slukem $3 != $9 { 5971.63Slukem print "user " $9 " mailbox is owned by " $3 5981.63Slukem } 5991.63Slukem $1 != "-rw-------" { 6001.63Slukem print "user " $9 " mailbox is " $1 ", group " $4 6011.63Slukem }' > $OUTPUT 6021.15Smrg if [ -s $OUTPUT ] ; then 6031.15Smrg printf "\nChecking mailbox ownership.\n" 6041.15Smrg cat $OUTPUT 6051.15Smrg fi 6061.15Smrgfi 6071.15Smrg 6081.32Slukem# NFS exports shouldn't be globally exported 6091.32Slukem# 6101.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 6111.32Slukem awk '{ 6121.22Slukem # ignore comments and blank lines 6131.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 6141.22Slukem next; 6151.100Stron # manage line continuation 6161.100Stron while ($NF ~ /^\\$/) { 6171.100Stron $NF = ""; 6181.100Stron line = $0 ""; 6191.100Stron getline; 6201.100Stron $0 = line $0 ""; 6211.100Stron } 6221.22Slukem 6231.100Stron delete dir; 6241.100Stron readonly = ndir = 0; 6251.100Stron for (i = 1; i <= NF; ++i) { 6261.100Stron if ($i ~ /^\//) dir[ndir++] = $i; 6271.100Stron else if ($i ~ /^-/) { 6281.100Stron if ($i ~ /^-(ro|o)$/) readonly = 1; 6291.100Stron if ($i ~ /^-network/) next; 6301.100Stron } 6311.100Stron else next; 6321.15Smrg } 6331.15Smrg if (readonly) 6341.100Stron for (item in dir) 6351.100Stron rodir[nrodir++] = dir[item]; 6361.15Smrg else 6371.100Stron for (item in dir) 6381.100Stron rwdir[nrwdir++] = dir[item]; 6391.100Stron 6401.100Stron } 6411.100Stron 6421.100Stron END { 6431.100Stron if (nrodir) { 6441.100Stron printf("Globally exported file system%s, read-only:\n", 6451.100Stron nrodir > 1 ? "s" : ""); 6461.100Stron for (item in rodir) 6471.100Stron printf("\t%s\n", rodir[item]); 6481.100Stron } 6491.100Stron if (nrwdir) { 6501.100Stron printf("Globally exported file system%s, read-write:\n", 6511.100Stron nrwdir > 1 ? "s" : ""); 6521.100Stron for (item in rwdir) 6531.100Stron printf("\t%s\n", rwdir[item]); 6541.100Stron } 6551.32Slukem }' < /etc/exports > $OUTPUT 6561.32Slukem if [ -s $OUTPUT ] ; then 6571.15Smrg printf "\nChecking for globally exported file systems.\n" 6581.15Smrg cat $OUTPUT 6591.15Smrg fi 6601.9Scgdfi 6611.9Scgd 6621.9Scgd# Display any changes in setuid files and devices. 6631.32Slukem# 6641.31Slukemif checkyesno check_devices; then 6651.28Slukem > $ERR 6661.92Serh ( 6671.98Slukem 6681.98Slukem # Convert check_devices_ignore_fstypes="foo !bar bax" 6691.98Slukem # into "-fstype foo -o ! -fstype bar -o -fstype bax" 6701.98Slukem # and check_devices_ignore_paths="/foo !/bar /bax" 6711.98Slukem # into " -path /foo -o ! -path /bar -o -path /bax" 6721.98Slukem # 6731.98Slukem ignexpr=$(\ 6741.98Slukem echo $check_devices_ignore_fstypes | \ 6751.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \ 6761.98Slukem echo $check_devices_ignore_paths | \ 6771.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \ 6781.98Slukem ) 6791.98Slukem 6801.98Slukem # Massage the expression into ( $ignexpr ) -a -prune -o 6811.98Slukem if [ -n "${ignexpr}" ]; then 6821.98Slukem ignexpr=$(\ 6831.98Slukem echo $ignexpr | \ 6841.98Slukem sed -e 's/^-o /( /' \ 6851.98Slukem -e 's/$/ ) -a -prune -o/' \ 6861.98Slukem ) 6871.98Slukem fi 6881.98Slukem 6891.98Slukem find / $ignexpr \ 6901.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 6911.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 6921.24Slukem -type b -o -type c \) -print0 | \ 6931.98Slukem xargs -0 ls -ldgTq | sort +9 > $LIST 6941.98Slukem 6951.98Slukem ) 2> $OUTPUT 6961.15Smrg 6971.15Smrg # Display any errors that occurred during system file walk. 6981.15Smrg if [ -s $OUTPUT ] ; then 6991.28Slukem printf "Setuid/device find errors:\n" >> $ERR 7001.28Slukem cat $OUTPUT >> $ERR 7011.28Slukem printf "\n" >> $ERR 7021.15Smrg fi 7031.15Smrg 7041.15Smrg # Display any changes in the setuid file list. 7051.15Smrg egrep -v '^[bc]' $LIST > $TMP1 7061.15Smrg if [ -s $TMP1 ] ; then 7071.15Smrg # Check to make sure uudecode isn't setuid. 7081.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 7091.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 7101.15Smrg fi 7111.15Smrg 7121.67Slukem file=$work_dir/setuid 7131.67Slukem migrate_file "$backup_dir/setuid" "$file" 7141.67Slukem CUR=${file}.current 7151.67Slukem BACK=${file}.backup 7161.15Smrg if [ -s $CUR ] ; then 7171.15Smrg if cmp -s $CUR $TMP1 ; then 7181.15Smrg : 7191.15Smrg else 7201.15Smrg > $TMP2 7211.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 7221.15Smrg if [ -s $OUTPUT ] ; then 7231.28Slukem printf "Setuid additions:\n" >> $ERR 7241.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7251.28Slukem printf "\n" >> $ERR 7261.15Smrg fi 7271.15Smrg 7281.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 7291.15Smrg if [ -s $OUTPUT ] ; then 7301.28Slukem printf "Setuid deletions:\n" >> $ERR 7311.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7321.28Slukem printf "\n" >> $ERR 7331.15Smrg fi 7341.15Smrg 7351.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 7361.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 7371.27Slukem uniq -u > $OUTPUT 7381.15Smrg if [ -s $OUTPUT ] ; then 7391.28Slukem printf "Setuid changes:\n" >> $ERR 7401.28Slukem column -t $OUTPUT >> $ERR 7411.28Slukem printf "\n" >> $ERR 7421.15Smrg fi 7431.9Scgd 7441.52Satatat backup_file update $TMP1 $CUR $BACK 7451.9Scgd fi 7461.15Smrg else 7471.28Slukem printf "Setuid additions:\n" >> $ERR 7481.28Slukem column -t $TMP1 >> $ERR 7491.28Slukem printf "\n" >> $ERR 7501.52Satatat backup_file add $TMP1 $CUR $BACK 7511.9Scgd fi 7521.15Smrg fi 7531.15Smrg 7541.27Slukem # Check for block and character disk devices that are readable or 7551.80Swiz # writable or not owned by root.operator. 7561.15Smrg >$TMP1 7571.61Slukem DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \ 7581.57Ssimonb sd se ss uk up vnd wd xd xy" 7591.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 7601.15Smrg for i in $DISKLIST; do 7611.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7621.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7631.15Smrg done 7641.15Smrg 7651.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 7661.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 7671.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 7681.15Smrg if [ -s $OUTPUT ] ; then 7691.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 7701.28Slukem cat $OUTPUT >> $ERR 7711.28Slukem printf "\n" >> $ERR 7721.9Scgd fi 7731.9Scgd 7741.15Smrg # Display any changes in the device file list. 7751.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 7761.15Smrg if [ -s $TMP1 ] ; then 7771.67Slukem file=$work_dir/device 7781.67Slukem migrate_file "$backup_dir/device" "$file" 7791.67Slukem CUR=${file}.current 7801.67Slukem BACK=${file}.backup 7811.15Smrg 7821.15Smrg if [ -s $CUR ] ; then 7831.15Smrg if cmp -s $CUR $TMP1 ; then 7841.15Smrg : 7851.15Smrg else 7861.15Smrg > $TMP2 7871.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 7881.15Smrg if [ -s $OUTPUT ] ; then 7891.28Slukem printf "Device additions:\n" >> $ERR 7901.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7911.28Slukem printf "\n" >> $ERR 7921.15Smrg fi 7931.15Smrg 7941.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 7951.15Smrg if [ -s $OUTPUT ] ; then 7961.28Slukem printf "Device deletions:\n" >> $ERR 7971.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7981.28Slukem printf "\n" >> $ERR 7991.15Smrg fi 8001.15Smrg 8011.27Slukem # Report any block device change. Ignore 8021.27Slukem # character devices, only the name is 8031.27Slukem # significant. 8041.15Smrg cat $TMP2 $CUR $TMP1 | \ 8051.27Slukem sed -e '/^c/d' | \ 8061.27Slukem sort -k11 | \ 8071.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 8081.27Slukem uniq -u > $OUTPUT 8091.15Smrg if [ -s $OUTPUT ] ; then 8101.28Slukem printf "Block device changes:\n" >> $ERR 8111.28Slukem column -t $OUTPUT >> $ERR 8121.28Slukem printf "\n" >> $ERR 8131.15Smrg fi 8141.9Scgd 8151.52Satatat backup_file update $TMP1 $CUR $BACK 8161.9Scgd fi 8171.15Smrg else 8181.28Slukem printf "Device additions:\n" >> $ERR 8191.28Slukem column -t $TMP1 >> $ERR 8201.28Slukem printf "\n" >> $ERR 8211.52Satatat backup_file add $TMP1 $CUR $BACK >> $ERR 8221.9Scgd fi 8231.28Slukem fi 8241.28Slukem if [ -s $ERR ] ; then 8251.28Slukem printf "\nChecking setuid files and devices:\n" 8261.28Slukem cat $ERR 8271.28Slukem printf "\n" 8281.9Scgd fi 8291.9Scgdfi 8301.9Scgd 8311.9Scgd# Check special files. 8321.9Scgd# Check system binaries. 8331.9Scgd# 8341.9Scgd# Create the mtree tree specifications using: 8351.67Slukem# mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure 8361.38Skleink# chown root:wheel DIR.secure 8371.67Slukem# chmod u+r,go= DIR.secure 8381.9Scgd# 8391.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 8401.9Scgd# the hacker can modify the tree specification to match the replaced binary. 8411.9Scgd# For details on really protecting yourself against modified binaries, see 8421.9Scgd# the mtree(8) manual page. 8431.32Slukem# 8441.31Slukemif checkyesno check_mtree; then 8451.82Sjhawk if checkyesno check_mtree_follow_symlinks; then 8461.82Sjhawk check_mtree_flags="-L" 8471.82Sjhawk else 8481.82Sjhawk check_mtree_flags="" 8491.82Sjhawk fi 8501.91Slukem mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 | 8511.87Sjhawk grep -v '^mtree: dev/tty: Device not configured$' >&2 8521.15Smrg if [ -s $OUTPUT ]; then 8531.9Scgd printf "\nChecking special files and directories.\n" 8541.9Scgd cat $OUTPUT 8551.9Scgd fi 8561.9Scgd 8571.16Smikel for file in /etc/mtree/*.secure; do 8581.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 8591.109Schristos tree=$(sed -n -e '3s/.* //p' -e 3q $file) 8601.82Sjhawk mtree $check_mtree_flags -f $file -p $tree > $TMP1 8611.9Scgd if [ -s $TMP1 ]; then 8621.67Slukem printf "\nChecking $tree:\n" 8631.67Slukem cat $TMP1 8641.9Scgd fi 8651.67Slukem done > $OUTPUT 8661.15Smrg if [ -s $OUTPUT ]; then 8671.9Scgd printf "\nChecking system binaries:\n" 8681.9Scgd cat $OUTPUT 8691.9Scgd fi 8701.9Scgdfi 8711.9Scgd 8721.32Slukem# Backup disklabels of available disks 8731.32Slukem# 8741.32Slukemif checkyesno check_disklabels; then 8751.67Slukem # migrate old disklabels 8761.109Schristos for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \ 8771.109Schristos $backup_dir/disklabel.* 2>/dev/null); do 8781.67Slukem migrate_file "$file" "$work_dir/${file##*/}" 8791.67Slukem done 8801.67Slukem 8811.103Stron # generate list of old disklabels, fdisks & wedges and remove them 8821.103Stron ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null | 8831.52Satatat egrep -v '\.(backup|current)(,v)?$' > $LABELS 8841.32Slukem xargs rm < $LABELS 8851.32Slukem 8861.103Stron # generate disklabels of all disks excluding: cd dk fd md st 8871.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|dk|st|nfs/ { print $1; }') 8881.32Slukem for i in $disks; do 8891.67Slukem disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null 8901.32Slukem done 8911.32Slukem 8921.67Slukem # if fdisk is available, generate fdisks for: ed ld sd wd 8931.67Slukem if [ -x /sbin/fdisk ]; then 8941.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }') 8951.67Slukem for i in $disks; do 8961.67Slukem /sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null 8971.67Slukem done 8981.67Slukem fi 8991.67Slukem 9001.103Stron # if dkctl is available, generate dkctl listwedges for: ed ld sd wd cgd ofdisk ra rl raid 9011.103Stron if [ -x /sbin/dkctl ]; then 9021.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d|cgd|ofdisk|r[al]|raid/ { print $1; }') 9031.103Stron for i in $disks; do 9041.103Stron /sbin/dkctl $i listwedges > "$work_dir/wedges.$i" 2>/dev/null 9051.103Stron done 9061.103Stron fi 9071.103Stron 9081.103Stron # append list of new disklabels, fdisks and wedges 9091.103Stron ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null | 9101.52Satatat egrep -v '\.(backup|current)(,v)?$' >> $LABELS 9111.62Satatat CHANGELIST="$LABELS $CHANGELIST" 9121.62Satatatfi 9131.62Satatat 9141.106Shaadif checkyesno check_lvm; then 9151.106Shaad 9161.106Shaad # generate list of existing LVM elements Physical Volumes, Volume Groups and Logical Volumes. 9171.106Shaadif [ -x /sbin/lvm ]; then 9181.106Shaad lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null 9191.106Shaad lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null 9201.106Shaad lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null 9211.106Shaadfi 9221.106Shaad ls -1d $work_dir/lvm.* 2>/dev/null | 9231.106Shaad egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS 9241.106Shaad CHANGELIST="$CHANGELIST $LVM_LABELS" 9251.106Shaadfi 9261.106Shaad 9271.62Satatat# Check for changes in the list of installed pkgs 9281.62Satatat# 9291.108Sjmmvif checkyesno check_pkgs && have_pkgs; then 9301.67Slukem pkgs=$work_dir/pkgs 9311.67Slukem migrate_file "$backup_dir/pkgs" "$pkgs" 9321.112Sagc pkg_dbdir=$(${pkg_admin} config-var PKG_DBDIR) 9331.108Sjmmv : ${pkg_dbdir:=/var/db/pkg} 9341.108Sjmmv ( cd $pkg_dbdir 9351.104Sadrianp $pkg_info | sort 9361.62Satatat echo "" 9371.62Satatat find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 | 9381.72Slukem xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,' 9391.62Satatat ) > $pkgs 9401.67Slukem echo "$pkgs" > $PKGS 9411.62Satatat CHANGELIST="$PKGS $CHANGELIST" 9421.32Slukemfi 9431.32Slukem 9441.67Slukem# List of files that get backed up and checked for any modifications. 9451.9Scgd# Any changes cause the files to rotate. 9461.32Slukem# 9471.67Slukemif checkyesno check_changelist ; then 9481.91Slukem mtree -D -k type -f $SPECIALSPEC -E exclude | 9491.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES 9501.67Slukem 9511.75Slukem ( 9521.68Slukem # Add other files which might dynamically exist: 9531.67Slukem # /etc/ifconfig.* 9541.67Slukem # /etc/raid*.conf 9551.68Slukem # /etc/rc.d/* 9561.67Slukem # /etc/rc.conf.d/* 9571.68Slukem # 9581.75Slukem echo "/etc/ifconfig.*" 9591.75Slukem echo "/etc/raid*.conf" 9601.75Slukem echo "/etc/rc.d/*" 9611.75Slukem echo "/etc/rc.conf.d/*" 9621.106Shaad echo "/etc/lvm/backup/*" 9631.106Shaad echo "/etc/lvm/archive/*" 9641.67Slukem 9651.68Slukem # Add /etc/changelist 9661.68Slukem # 9671.75Slukem if [ -s /etc/changelist ]; then 9681.75Slukem grep -v '^#' /etc/changelist 9691.75Slukem fi 9701.75Slukem ) | while read file; do 9711.75Slukem case "$file" in 9721.75Slukem *[\*\?\[]*) # If changelist line is a glob ... 9731.75Slukem # ... expand possible backup files 9741.75Slukem # 9751.75Slukem ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \ 9761.75Slukem | sed "s,^$backup_dir/,, ; s,\.current$,," 9771.75Slukem 9781.75Slukem # ... expand possible files 9791.75Slukem # 9801.75Slukem ls -1d $(echo $file) 2>/dev/null 9811.75Slukem ;; 9821.75Slukem *) 9831.75Slukem # Otherwise, just print the filename 9841.75Slukem echo $file 9851.75Slukem ;; 9861.75Slukem esac 9871.75Slukem done >> $CHANGEFILES 9881.67Slukem CHANGELIST="$CHANGEFILES $CHANGELIST" 9891.67Slukemfi 9901.67Slukem 9911.67Slukem# Special case backups, including the master password file and 9921.67Slukem# ssh private host keys. The normal backup mechanisms for 9931.67Slukem# $check_changelist (see below) also print out the actual file 9941.67Slukem# differences and we don't want to do that for these files 9951.67Slukem# 9961.67Slukemecho $MP > $TMP1 # always add /etc/master.passwd 9971.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff | 9981.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1 9991.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2 10001.68Slukem 10011.69Slukemwhile read file; do 10021.67Slukem backup_and_diff "$file" no 10031.69Slukemdone < $TMP2 10041.67Slukem 10051.32Slukem 10061.32Slukemif [ -n "$CHANGELIST" ]; then 10071.73Slukem grep -h -v '^$' $CHANGELIST | sort -u > $TMP1 10081.68Slukem comm -23 $TMP1 $TMP2 | while read file; do 10091.67Slukem backup_and_diff "$file" yes 10101.9Scgd done 10111.44Sadfi 10121.44Sad 10131.108Sjmmvif have_pkgs; then 10141.107Sjmmv if checkyesno check_pkg_vulnerabilities; then 10151.112Sagc ${pkg_admin} ${_compat_K_flag} audit >${OUTPUT} 2>&1 10161.107Sjmmv if [ -s ${OUTPUT} ]; then 10171.107Sjmmv printf "\nInstalled vulnerable packages:\n" 10181.107Sjmmv cat ${OUTPUT} 10191.107Sjmmv fi 10201.107Sjmmv fi 10211.107Sjmmv 10221.107Sjmmv if checkyesno check_pkg_signatures; then 10231.112Sagc ${pkg_admin} ${_compat_K_flag} check >${OUTPUT} 2>&1 10241.107Sjmmv if [ $? -ne 0 ]; then 10251.107Sjmmv printf "\nFiles with invalid signatures:\n" 10261.107Sjmmv cat ${OUTPUT} 10271.107Sjmmv fi 10281.107Sjmmv fi 10291.107Sjmmvfi 10301.107Sjmmv 10311.44Sadif [ -f /etc/security.local ]; then 10321.90Skim . /etc/security.local > $OUTPUT 2>&1 10331.84Sjhawk if [ -s $OUTPUT ] ; then 10341.84Sjhawk printf "\nRunning /etc/security.local:\n" 10351.84Sjhawk cat $OUTPUT 10361.84Sjhawk fi 10371.9Scgdfi 1038