security revision 1.113
11.1Scgd#!/bin/sh - 21.1Scgd# 31.113Sprlw1# $NetBSD: security,v 1.113 2013/09/08 08:19:40 prlw1 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.113Sprlw1pkg_admin=${pkg_admin:-/usr/sbin/pkg_admin} 341.104Sadrianppkg_info=${pkg_info:-/usr/sbin/pkg_info} 351.67Slukem 361.67Slukem# Other configurable variables 371.67Slukem# 381.67Slukemspecial_files="/etc/mtree/special /etc/mtree/special.local" 391.67SlukemMP=/etc/master.passwd 401.67SlukemCHANGELIST="" 411.67Slukemwork_dir=$backup_dir/work 421.67Slukem 431.67Slukemif [ ! -d "$work_dir" ]; then 441.67Slukem mkdir -p "$work_dir" 451.67Slukemfi 461.67Slukem 471.102SmarttiSECUREDIR=$(mktemp -d -t _securedir) || exit 1 481.56Slukem 491.67Slukemtrap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE 501.15Smrg 511.56Slukemif ! cd "$SECUREDIR"; then 521.56Slukem echo "Can not cd to $SECUREDIR". 531.15Smrg exit 1 541.15Smrgfi 551.15Smrg 561.91SlukemERR=err.$$ 571.91SlukemTMP1=tmp1.$$ 581.91SlukemTMP2=tmp2.$$ 591.91SlukemMPBYUID=mpbyuid.$$ 601.91SlukemMPBYPATH=mpbypath.$$ 611.91SlukemLIST=list.$$ 621.91SlukemOUTPUT=output.$$ 631.91SlukemLABELS=labels.$$ 641.106ShaadLVM_LABELS=lvm.$$ 651.91SlukemPKGS=pkgs.$$ 661.91SlukemCHANGEFILES=changefiles.$$ 671.91SlukemSPECIALSPEC=specialspec.$$ 681.67Slukem 691.108Sjmmvif [ -n "${pkgdb_dir}" ]; then 701.108Sjmmv echo "WARNING: Setting pkgdb_dir in security.conf(5) is deprecated" 711.108Sjmmv echo "WARNING: Please define PKG_DBDIR in pkg_install.conf(5) instead" 721.108Sjmmv _compat_K_flag="-K ${pkgdb_dir}" 731.108Sjmmvfi 741.108Sjmmv 751.108Sjmmvhave_pkgs() { 761.108Sjmmv $pkg_info ${_compat_K_flag} -q -E '*' 771.108Sjmmv} 781.108Sjmmv 791.67Slukem# migrate_file old new 801.67Slukem# Determine if the "${old}" path name needs to be migrated to the 811.67Slukem# "${new}" path. Also checks if "${old}.current" needs migrating, 821.67Slukem# and if so, migrate it and possibly "${old}.current,v" and 831.67Slukem# "${old}.backup". 841.67Slukem# 851.67Slukemmigrate_file() 861.67Slukem{ 871.67Slukem _old=$1 881.67Slukem _new=$2 891.67Slukem if [ -z "$_old" -o -z "$_new" ]; then 901.67Slukem err 3 "USAGE: migrate_file old new" 911.67Slukem fi 921.67Slukem if [ ! -d "${_new%/*}" ]; then 931.67Slukem mkdir -p "${_new%/*}" 941.67Slukem fi 951.67Slukem if [ -f "${_old}" -a ! -f "${_new}" ]; then 961.67Slukem echo "==> migrating ${_old}" 971.67Slukem echo " to ${_new}" 981.67Slukem mv "${_old}" "${_new}" 991.67Slukem fi 1001.67Slukem if [ -f "${_old}.current" -a ! -f "${_new}.current" ]; then 1011.67Slukem echo "==> migrating ${_old}.current" 1021.67Slukem echo " to ${_new}.current" 1031.67Slukem mv "${_old}.current" "${_new}.current" 1041.67Slukem if [ -f "${_old}.current,v" -a ! -f "${_new}.current,v" ]; then 1051.67Slukem echo "==> migrating ${_old}.current,v" 1061.67Slukem echo " to ${_new}.current,v" 1071.67Slukem mv "${_old}.current,v" "${_new}.current,v" 1081.67Slukem fi 1091.67Slukem if [ -f "${_old}.backup" -a ! -f "${_new}.backup" ]; then 1101.67Slukem echo "==> migrating ${_old}.backup" 1111.67Slukem echo " to ${_new}.backup" 1121.67Slukem mv "${_old}.backup" "${_new}.backup" 1131.67Slukem fi 1141.67Slukem fi 1151.67Slukem} 1161.67Slukem 1171.67Slukem 1181.67Slukem# backup_and_diff file printdiff 1191.67Slukem# Determine if file needs backing up, and if so, do it. 1201.67Slukem# If printdiff is yes, display the diffs, otherwise 1211.67Slukem# just print a message saying "[changes omitted]". 1221.67Slukem# 1231.67Slukembackup_and_diff() 1241.67Slukem{ 1251.67Slukem _file=$1 1261.67Slukem _printdiff=$2 1271.67Slukem if [ -z "$_file" -o -z "$_printdiff" ]; then 1281.67Slukem err 3 "USAGE: backup_and_diff file printdiff" 1291.67Slukem fi 1301.67Slukem ! checkyesno _printdiff 1311.67Slukem _printdiff=$? 1321.67Slukem 1331.67Slukem _old=$backup_dir/${_file##*/} 1341.67Slukem case "$_file" in 1351.67Slukem $work_dir/*) 1361.67Slukem _new=$_file 1371.67Slukem migrate_file "$backup_dir/$_old" "$_new" 1381.67Slukem migrate_file "$_old" "$_new" 1391.67Slukem ;; 1401.67Slukem *) 1411.67Slukem _new=$backup_dir/$_file 1421.67Slukem migrate_file "$_old" "$_new" 1431.67Slukem ;; 1441.67Slukem esac 1451.67Slukem CUR=${_new}.current 1461.67Slukem BACK=${_new}.backup 1471.67Slukem if [ -f $_file ]; then 1481.67Slukem if [ -f $CUR ] ; then 1491.67Slukem if [ "$_printdiff" -ne 0 ]; then 1501.83Sjhawk diff ${diff_options} $CUR $_file > $OUTPUT 1511.67Slukem else 1521.67Slukem if ! cmp -s $CUR $_file; then 1531.67Slukem echo "[changes omitted]" 1541.67Slukem fi > $OUTPUT 1551.67Slukem fi 1561.67Slukem if [ -s $OUTPUT ] ; then 1571.67Slukem printf \ 1581.67Slukem "\n======\n%s diffs (OLD < > NEW)\n======\n" $_file 1591.67Slukem cat $OUTPUT 1601.67Slukem backup_file update $_file $CUR $BACK 1611.67Slukem fi 1621.67Slukem else 1631.67Slukem printf "\n======\n%s added\n======\n" $_file 1641.67Slukem if [ "$_printdiff" -ne 0 ]; then 1651.83Sjhawk diff ${diff_options} /dev/null $_file 1661.67Slukem else 1671.67Slukem echo "[changes omitted]" 1681.67Slukem fi 1691.67Slukem backup_file add $_file $CUR $BACK 1701.67Slukem fi 1711.67Slukem else 1721.67Slukem if [ -f $CUR ]; then 1731.67Slukem printf "\n======\n%s removed\n======\n" $_file 1741.67Slukem if [ "$_printdiff" -ne 0 ]; then 1751.83Sjhawk diff ${diff_options} $CUR /dev/null 1761.67Slukem else 1771.67Slukem echo "[changes omitted]" 1781.67Slukem fi 1791.67Slukem backup_file remove $_file $CUR $BACK 1801.67Slukem fi 1811.67Slukem fi 1821.67Slukem} 1831.48Sabs 1841.9Scgd 1851.67Slukem# These are used several times. 1861.67Slukem# 1871.91Slukemawk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID 1881.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH 1891.91Slukemfor file in $special_files; do 1901.91Slukem [ -s $file ] && cat $file 1911.91Slukemdone | mtree -CM -k all > $SPECIALSPEC || exit 1 1921.9Scgd 1931.67Slukem 1941.9Scgd# Check the master password file syntax. 1951.32Slukem# 1961.31Slukemif checkyesno check_passwd; then 1971.85Sjhawk # XXX: the sense of permit_star is reversed; the code works as 1981.85Sjhawk # implemented, but usage needs to be negated. 1991.81Sjhawk checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1 2001.94Sjdolecek checkyesno check_passwd_permit_nonalpha \ 2011.94Sjdolecek && permit_nonalpha=1 || permit_nonalpha=0 2021.94Sjdolecek 2031.81Sjhawk awk -v "len=$max_loginlen" \ 2041.81Sjhawk -v "nowarn_shells_list=$check_passwd_nowarn_shells" \ 2051.81Sjhawk -v "nowarn_users_list=$check_passwd_nowarn_users" \ 2061.94Sjdolecek -v "permit_star=$permit_star" \ 2071.94Sjdolecek -v "permit_nonalpha=$permit_nonalpha" \ 2081.94Sjdolecek ' 2091.25Slukem BEGIN { 2101.25Slukem while ( getline < "/etc/shells" > 0 ) { 2111.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 2121.25Slukem continue; 2131.25Slukem shells[$1]++; 2141.25Slukem } 2151.81Sjhawk split(nowarn_shells_list, a); 2161.81Sjhawk for (i in a) nowarn_shells[a[i]]++; 2171.81Sjhawk split(nowarn_users_list, a); 2181.81Sjhawk for (i in a) nowarn_users[a[i]]++; 2191.81Sjhawk uid0_users_list="root toor" 2201.81Sjhawk split(uid0_users_list, a); 2211.81Sjhawk for (i in a) uid0_users[a[i]]++; 2221.25Slukem FS=":"; 2231.25Slukem } 2241.25Slukem 2251.25Slukem { 2261.15Smrg if ($0 ~ /^[ ]*$/) { 2271.25Slukem printf "Line %d is a blank line.\n", NR; 2281.15Smrg next; 2291.15Smrg } 2301.105Sdholland 2311.105Sdholland # NIS compat entry? 2321.105Sdholland compatline = $1 ~ "^[\\+-]"; 2331.105Sdholland if (compatline) { 2341.105Sdholland if ($1 == "+" && NF == 1) { 2351.105Sdholland next; 2361.105Sdholland } 2371.105Sdholland sub("^.", "", $1); 2381.105Sdholland } 2391.105Sdholland if (NF != 10) 2401.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 2411.105Sdholland if (compatline) { 2421.105Sdholland if ($3 == 0) 2431.81Sjhawk printf "Line %d includes entries with uid 0.\n", 2441.81Sjhawk NR; 2451.105Sdholland if ($1 == "") 2461.105Sdholland next; 2471.34Sabs } 2481.94Sjdolecek if (!permit_nonalpha && 2491.95Speter $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 2501.25Slukem printf "Login %s has non-alphanumeric characters.\n", 2511.25Slukem $1; 2521.34Sabs if (length($1) > len) 2531.81Sjhawk printf "Login %s has more than "len" characters.\n", 2541.81Sjhawk $1; 2551.105Sdholland if ($2 == "" && !compatline && !nowarn_users[$1]) 2561.81Sjhawk printf "Login %s has no password.\n", $1; 2571.81Sjhawk if (!nowarn_shells[$10] && !nowarn_users[$1]) { 2581.81Sjhawk if (length($2) != 13 && 2591.81Sjhawk length($2) != 20 && 2601.81Sjhawk $2 !~ /^\$1/ && 2611.81Sjhawk $2 !~ /^\$2/ && 2621.99Sjmcneill $2 !~ /^\$sha1/ && 2631.81Sjhawk $2 != "" && 2641.81Sjhawk (permit_star || $2 != "*") && 2651.81Sjhawk $2 !~ /^\*[A-z-]+$/ && 2661.81Sjhawk $1 != "toor") { 2671.81Sjhawk if ($10 == "" || shells[$10]) 2681.81Sjhawk printf "Login %s is off but still has "\ 2691.81Sjhawk "a valid shell (%s)\n", $1, $10; 2701.105Sdholland } else if (compatline && $10 == "") { 2711.105Sdholland # nothing 2721.81Sjhawk } else if (! shells[$10]) 2731.81Sjhawk printf "Login %s does not have a valid "\ 2741.81Sjhawk "shell (%s)\n", $1, $10; 2751.81Sjhawk } 2761.81Sjhawk if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1]) 2771.25Slukem printf "Login %s has a user id of 0.\n", $1; 2781.105Sdholland if ($3 != "" && $3 < 0) 2791.25Slukem printf "Login %s has a negative user id.\n", $1; 2801.105Sdholland if ($4 != "" && $4 < 0) 2811.25Slukem printf "Login %s has a negative group id.\n", $1; 2821.15Smrg }' < $MP > $OUTPUT 2831.15Smrg if [ -s $OUTPUT ] ; then 2841.15Smrg printf "\nChecking the $MP file:\n" 2851.15Smrg cat $OUTPUT 2861.15Smrg fi 2871.15Smrg 2881.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 2891.15Smrg if [ -s $OUTPUT ] ; then 2901.15Smrg printf "\n$MP has duplicate user names.\n" 2911.15Smrg column $OUTPUT 2921.15Smrg fi 2931.15Smrg 2941.111Sspz awk -v "permit_dups_list=$check_passwd_permit_dups" \ 2951.111Sspz ' 2961.111Sspz BEGIN { 2971.111Sspz split(permit_dups_list, a); 2981.111Sspz for (i in a) permit_dups[a[i]]++; 2991.111Sspz } 3001.111Sspz { 3011.111Sspz if (!permit_dups[$1]) 3021.111Sspz print $2; 3031.111Sspz }' < $MPBYUID | uniq -d > $TMP2 3041.15Smrg if [ -s $TMP2 ] ; then 3051.111Sspz printf "\n$MP has duplicate user ids.\n" 3061.15Smrg while read uid; do 3071.28Slukem grep -w $uid $MPBYUID 3081.15Smrg done < $TMP2 | column 3091.15Smrg fi 3101.9Scgdfi 3111.9Scgd 3121.9Scgd# Check the group file syntax. 3131.32Slukem# 3141.31Slukemif checkyesno check_group; then 3151.15Smrg GRP=/etc/group 3161.49Sjdolecek awk -F: -v "len=$max_grouplen" '{ 3171.15Smrg if ($0 ~ /^[ ]*$/) { 3181.25Slukem printf "Line %d is a blank line.\n", NR; 3191.15Smrg next; 3201.15Smrg } 3211.34Sabs if (NF != 4 && ($1 != "+" || NF != 1)) 3221.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 3231.34Sabs if ($1 == "+" ) { 3241.34Sabs next; 3251.34Sabs } 3261.95Speter if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 3271.25Slukem printf "Group %s has non-alphanumeric characters.\n", 3281.25Slukem $1; 3291.49Sjdolecek if (length($1) > len) 3301.49Sjdolecek printf "Group %s has more than "len" characters.\n", $1; 3311.15Smrg if ($3 !~ /[0-9]*/) 3321.25Slukem printf "Login %s has a negative group id.\n", $1; 3331.15Smrg }' < $GRP > $OUTPUT 3341.15Smrg if [ -s $OUTPUT ] ; then 3351.15Smrg printf "\nChecking the $GRP file:\n" 3361.15Smrg cat $OUTPUT 3371.15Smrg fi 3381.15Smrg 3391.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 3401.15Smrg if [ -s $OUTPUT ] ; then 3411.15Smrg printf "\n$GRP has duplicate group names.\n" 3421.15Smrg column $OUTPUT 3431.15Smrg fi 3441.9Scgdfi 3451.9Scgd 3461.9Scgd# Check for root paths, umask values in startup files. 3471.9Scgd# The check for the root paths is problematical -- it's likely to fail 3481.9Scgd# in other environments. Once the shells have been modified to warn 3491.9Scgd# of '.' in the path, the path tests should go away. 3501.32Slukem# 3511.31Slukemif checkyesno check_rootdotfiles; then 3521.67Slukem rhome=~root 3531.15Smrg umaskset=no 3541.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 3551.15Smrg for i in $list ; do 3561.15Smrg if [ -f $i ] ; then 3571.67Slukem if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; 3581.67Slukem then 3591.15Smrg umaskset=yes 3601.15Smrg fi 3611.63Slukem # Double check the umask value itself; ensure that 3621.67Slukem # both the group and other write bits are set. 3631.67Slukem # 3641.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 3651.63Slukem awk '{ 3661.67Slukem if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) { 3671.80Swiz print "\tRoot umask is group writable" 3681.63Slukem } 3691.67Slukem if ($2 ~ /[^2367]$/) { 3701.80Swiz print "\tRoot umask is other writable" 3711.63Slukem } 3721.67Slukem }' | sort -u 3731.26Slukem SAVE_PATH=$PATH 3741.26Slukem unset PATH 3751.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 3761.15Smrg source $i 3771.15Smrg /bin/ls -ldgT \$path > $TMP1 3781.9Scgdend-of-csh 3791.76Satatat export PATH=$SAVE_PATH 3801.15Smrg awk '{ 3811.15Smrg if ($10 ~ /^\.$/) { 3821.27Slukem print "\tThe root path includes ."; 3831.15Smrg next; 3841.15Smrg } 3851.15Smrg } 3861.15Smrg $1 ~ /^d....w/ \ 3871.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 3881.15Smrg $1 ~ /^d.......w/ \ 3891.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 3901.67Slukem < $TMP1 3911.15Smrg fi 3921.67Slukem done > $OUTPUT 3931.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 3941.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 3951.15Smrg if [ -s $OUTPUT ]; then 3961.15Smrg cat $OUTPUT 3971.15Smrg fi 3981.15Smrg if [ $umaskset = "no" ] ; then 3991.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 4001.15Smrg fi 4011.9Scgd fi 4021.9Scgd 4031.15Smrg umaskset=no 4041.23Slukem list="/etc/profile ${rhome}/.profile" 4051.15Smrg for i in $list; do 4061.15Smrg if [ -f $i ] ; then 4071.15Smrg if egrep umask $i > /dev/null ; then 4081.15Smrg umaskset=yes 4091.15Smrg fi 4101.15Smrg egrep umask $i | 4111.67Slukem awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \ 4121.80Swiz { print "\tRoot umask is group writable" } \ 4131.67Slukem $2 ~ /[^2367]$/ \ 4141.80Swiz { print "\tRoot umask is other writable" }' 4151.26Slukem SAVE_PATH=$PATH 4161.26Slukem unset PATH 4171.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 4181.15Smrg . $i 4191.110Schristos list=\$(echo \$PATH | /usr/bin/sed -e \ 4201.110Schristos 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g') 4211.15Smrg /bin/ls -ldgT \$list > $TMP1 4221.9Scgdend-of-sh 4231.76Satatat export PATH=$SAVE_PATH 4241.15Smrg awk '{ 4251.15Smrg if ($10 ~ /^\.$/) { 4261.27Slukem print "\tThe root path includes ."; 4271.15Smrg next; 4281.15Smrg } 4291.15Smrg } 4301.15Smrg $1 ~ /^d....w/ \ 4311.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4321.15Smrg $1 ~ /^d.......w/ \ 4331.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4341.67Slukem < $TMP1 4351.9Scgd 4361.15Smrg fi 4371.67Slukem done > $OUTPUT 4381.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 4391.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 4401.15Smrg if [ -s $OUTPUT ]; then 4411.15Smrg cat $OUTPUT 4421.15Smrg fi 4431.15Smrg if [ $umaskset = "no" ] ; then 4441.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 4451.15Smrg fi 4461.9Scgd fi 4471.9Scgdfi 4481.9Scgd 4491.9Scgd# Root and uucp should both be in /etc/ftpusers. 4501.32Slukem# 4511.31Slukemif checkyesno check_ftpusers; then 4521.109Schristos list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID) 4531.27Slukem for i in $list; do 4541.29Slukem if /usr/libexec/ftpd -C $i ; then 4551.67Slukem printf "\t$i is not denied\n" 4561.27Slukem fi 4571.67Slukem done > $OUTPUT 4581.28Slukem if [ -s $OUTPUT ]; then 4591.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 4601.28Slukem cat $OUTPUT 4611.28Slukem fi 4621.9Scgdfi 4631.9Scgd 4641.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 4651.32Slukem# 4661.31Slukemif checkyesno check_aliases; then 4671.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 4681.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 4691.43Sitojun printf "\nEntry for uudecode in $f file.\n" 4701.43Sitojun fi 4711.43Sitojun done 4721.9Scgdfi 4731.9Scgd 4741.9Scgd# Files that should not have + signs. 4751.32Slukem# 4761.31Slukemif checkyesno check_rhosts; then 4771.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 4781.15Smrg for f in $list ; do 4791.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 4801.15Smrg printf "\nPlus sign in $f file.\n" 4811.15Smrg fi 4821.15Smrg done 4831.15Smrg 4841.15Smrg # Check for special users with .rhosts files. Only root and toor should 4851.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 4861.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 4871.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 4881.20Smycroft { print $1 " " $9 }' $MP | 4891.19Smycroft sort -k2 | 4901.15Smrg while read uid homedir; do 4911.15Smrg if [ -f ${homedir}/.rhosts ] ; then 4921.109Schristos rhost=$(ls -ldgT ${homedir}/.rhosts) 4931.46Schristos printf -- "$uid: $rhost\n" 4941.15Smrg fi 4951.15Smrg done > $OUTPUT 4961.15Smrg if [ -s $OUTPUT ] ; then 4971.15Smrg printf "\nChecking for special users with .rhosts files.\n" 4981.15Smrg cat $OUTPUT 4991.15Smrg fi 5001.15Smrg 5011.15Smrg while read uid homedir; do 5021.35Sfair if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \ 5031.41Schristos cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then 5041.46Schristos printf -- "$uid: + in .rhosts file.\n" 5051.15Smrg fi 5061.29Slukem done < $MPBYPATH > $OUTPUT 5071.15Smrg if [ -s $OUTPUT ] ; then 5081.15Smrg printf "\nChecking .rhosts files syntax.\n" 5091.15Smrg cat $OUTPUT 5101.15Smrg fi 5111.9Scgdfi 5121.9Scgd 5131.9Scgd# Check home directories. Directories should not be owned by someone else 5141.80Swiz# or writable. 5151.32Slukem# 5161.31Slukemif checkyesno check_homes; then 5171.85Sjhawk checkyesno check_homes_permit_usergroups && \ 5181.85Sjhawk permit_usergroups=1 || permit_usergroups=0 5191.15Smrg while read uid homedir; do 5201.15Smrg if [ -d ${homedir}/ ] ; then 5211.109Schristos file=$(ls -ldgT ${homedir}) 5221.46Schristos printf -- "$uid $file\n" 5231.9Scgd fi 5241.29Slukem done < $MPBYPATH | 5251.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5261.85Sjhawk $1 != $4 && $4 != "root" \ 5271.15Smrg { print "user " $1 " home directory is owned by " $4 } 5281.101Sjnemeth $2 ~ /^d....w/ && (!usergroups || $5 != $1) \ 5291.80Swiz { print "user " $1 " home directory is group writable" } 5301.101Sjnemeth $2 ~ /^d.......w/ \ 5311.80Swiz { print "user " $1 " home directory is other writable" }' \ 5321.27Slukem > $OUTPUT 5331.15Smrg if [ -s $OUTPUT ] ; then 5341.15Smrg printf "\nChecking home directories.\n" 5351.15Smrg cat $OUTPUT 5361.15Smrg fi 5371.15Smrg 5381.15Smrg # Files that should not be owned by someone else or readable. 5391.67Slukem list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity" 5401.15Smrg while read uid homedir; do 5411.15Smrg for f in $list ; do 5421.15Smrg file=${homedir}/${f} 5431.15Smrg if [ -f $file ] ; then 5441.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5451.15Smrg fi 5461.15Smrg done 5471.29Slukem done < $MPBYPATH | 5481.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5491.85Sjhawk $1 != $5 && $5 != "root" \ 5501.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5511.85Sjhawk $3 ~ /^-...r/ && (!usergroups || $6 != $1) \ 5521.15Smrg { print "user " $1 " " $2 " file is group readable" } 5531.15Smrg $3 ~ /^-......r/ \ 5541.15Smrg { print "user " $1 " " $2 " file is other readable" } 5551.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5561.80Swiz { print "user " $1 " " $2 " file is group writable" } 5571.15Smrg $3 ~ /^-.......w/ \ 5581.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5591.27Slukem > $OUTPUT 5601.15Smrg 5611.80Swiz # Files that should not be owned by someone else or writable. 5621.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 5631.79Selric .cshrc .emacs .exrc .forward .history .k5login .klogin .login \ 5641.79Selric .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \ 5651.79Selric .twmrc .xinitrc .xsession .ssh/authorized_keys \ 5661.79Selric .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \ 5671.79Selric .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \ 5681.79Selric .ssh/known_hosts2" 5691.15Smrg while read uid homedir; do 5701.15Smrg for f in $list ; do 5711.15Smrg file=${homedir}/${f} 5721.15Smrg if [ -f $file ] ; then 5731.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5741.15Smrg fi 5751.15Smrg done 5761.29Slukem done < $MPBYPATH | 5771.85Sjhawk awk -v "usergroups=$permit_usergroups" ' 5781.85Sjhawk $1 != $5 && $5 != "root" \ 5791.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5801.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5811.80Swiz { print "user " $1 " " $2 " file is group writable" } 5821.15Smrg $3 ~ /^-.......w/ \ 5831.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5841.27Slukem >> $OUTPUT 5851.15Smrg if [ -s $OUTPUT ] ; then 5861.15Smrg printf "\nChecking dot files.\n" 5871.15Smrg cat $OUTPUT 5881.15Smrg fi 5891.9Scgdfi 5901.9Scgd 5911.9Scgd# Mailboxes should be owned by user and unreadable. 5921.32Slukem# 5931.31Slukemif checkyesno check_varmail; then 5941.86Sjhawk ls -lA /var/mail | \ 5951.63Slukem awk ' NR == 1 { next; } 5961.86Sjhawk $9 ~ /^\./ {next; } 5971.63Slukem $3 != $9 { 5981.63Slukem print "user " $9 " mailbox is owned by " $3 5991.63Slukem } 6001.63Slukem $1 != "-rw-------" { 6011.63Slukem print "user " $9 " mailbox is " $1 ", group " $4 6021.63Slukem }' > $OUTPUT 6031.15Smrg if [ -s $OUTPUT ] ; then 6041.15Smrg printf "\nChecking mailbox ownership.\n" 6051.15Smrg cat $OUTPUT 6061.15Smrg fi 6071.15Smrgfi 6081.15Smrg 6091.32Slukem# NFS exports shouldn't be globally exported 6101.32Slukem# 6111.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 6121.32Slukem awk '{ 6131.22Slukem # ignore comments and blank lines 6141.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 6151.22Slukem next; 6161.100Stron # manage line continuation 6171.100Stron while ($NF ~ /^\\$/) { 6181.100Stron $NF = ""; 6191.100Stron line = $0 ""; 6201.100Stron getline; 6211.100Stron $0 = line $0 ""; 6221.100Stron } 6231.22Slukem 6241.100Stron delete dir; 6251.100Stron readonly = ndir = 0; 6261.100Stron for (i = 1; i <= NF; ++i) { 6271.100Stron if ($i ~ /^\//) dir[ndir++] = $i; 6281.100Stron else if ($i ~ /^-/) { 6291.100Stron if ($i ~ /^-(ro|o)$/) readonly = 1; 6301.100Stron if ($i ~ /^-network/) next; 6311.100Stron } 6321.100Stron else next; 6331.15Smrg } 6341.15Smrg if (readonly) 6351.100Stron for (item in dir) 6361.100Stron rodir[nrodir++] = dir[item]; 6371.15Smrg else 6381.100Stron for (item in dir) 6391.100Stron rwdir[nrwdir++] = dir[item]; 6401.100Stron 6411.100Stron } 6421.100Stron 6431.100Stron END { 6441.100Stron if (nrodir) { 6451.100Stron printf("Globally exported file system%s, read-only:\n", 6461.100Stron nrodir > 1 ? "s" : ""); 6471.100Stron for (item in rodir) 6481.100Stron printf("\t%s\n", rodir[item]); 6491.100Stron } 6501.100Stron if (nrwdir) { 6511.100Stron printf("Globally exported file system%s, read-write:\n", 6521.100Stron nrwdir > 1 ? "s" : ""); 6531.100Stron for (item in rwdir) 6541.100Stron printf("\t%s\n", rwdir[item]); 6551.100Stron } 6561.32Slukem }' < /etc/exports > $OUTPUT 6571.32Slukem if [ -s $OUTPUT ] ; then 6581.15Smrg printf "\nChecking for globally exported file systems.\n" 6591.15Smrg cat $OUTPUT 6601.15Smrg fi 6611.9Scgdfi 6621.9Scgd 6631.9Scgd# Display any changes in setuid files and devices. 6641.32Slukem# 6651.31Slukemif checkyesno check_devices; then 6661.28Slukem > $ERR 6671.92Serh ( 6681.98Slukem 6691.98Slukem # Convert check_devices_ignore_fstypes="foo !bar bax" 6701.98Slukem # into "-fstype foo -o ! -fstype bar -o -fstype bax" 6711.98Slukem # and check_devices_ignore_paths="/foo !/bar /bax" 6721.98Slukem # into " -path /foo -o ! -path /bar -o -path /bax" 6731.98Slukem # 6741.98Slukem ignexpr=$(\ 6751.98Slukem echo $check_devices_ignore_fstypes | \ 6761.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \ 6771.98Slukem echo $check_devices_ignore_paths | \ 6781.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \ 6791.98Slukem ) 6801.98Slukem 6811.98Slukem # Massage the expression into ( $ignexpr ) -a -prune -o 6821.98Slukem if [ -n "${ignexpr}" ]; then 6831.98Slukem ignexpr=$(\ 6841.98Slukem echo $ignexpr | \ 6851.98Slukem sed -e 's/^-o /( /' \ 6861.98Slukem -e 's/$/ ) -a -prune -o/' \ 6871.98Slukem ) 6881.98Slukem fi 6891.98Slukem 6901.98Slukem find / $ignexpr \ 6911.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 6921.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 6931.24Slukem -type b -o -type c \) -print0 | \ 6941.98Slukem xargs -0 ls -ldgTq | sort +9 > $LIST 6951.98Slukem 6961.98Slukem ) 2> $OUTPUT 6971.15Smrg 6981.15Smrg # Display any errors that occurred during system file walk. 6991.15Smrg if [ -s $OUTPUT ] ; then 7001.28Slukem printf "Setuid/device find errors:\n" >> $ERR 7011.28Slukem cat $OUTPUT >> $ERR 7021.28Slukem printf "\n" >> $ERR 7031.15Smrg fi 7041.15Smrg 7051.15Smrg # Display any changes in the setuid file list. 7061.15Smrg egrep -v '^[bc]' $LIST > $TMP1 7071.15Smrg if [ -s $TMP1 ] ; then 7081.15Smrg # Check to make sure uudecode isn't setuid. 7091.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 7101.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 7111.15Smrg fi 7121.15Smrg 7131.67Slukem file=$work_dir/setuid 7141.67Slukem migrate_file "$backup_dir/setuid" "$file" 7151.67Slukem CUR=${file}.current 7161.67Slukem BACK=${file}.backup 7171.15Smrg if [ -s $CUR ] ; then 7181.15Smrg if cmp -s $CUR $TMP1 ; then 7191.15Smrg : 7201.15Smrg else 7211.15Smrg > $TMP2 7221.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 7231.15Smrg if [ -s $OUTPUT ] ; then 7241.28Slukem printf "Setuid additions:\n" >> $ERR 7251.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7261.28Slukem printf "\n" >> $ERR 7271.15Smrg fi 7281.15Smrg 7291.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 7301.15Smrg if [ -s $OUTPUT ] ; then 7311.28Slukem printf "Setuid deletions:\n" >> $ERR 7321.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7331.28Slukem printf "\n" >> $ERR 7341.15Smrg fi 7351.15Smrg 7361.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 7371.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 7381.27Slukem uniq -u > $OUTPUT 7391.15Smrg if [ -s $OUTPUT ] ; then 7401.28Slukem printf "Setuid changes:\n" >> $ERR 7411.28Slukem column -t $OUTPUT >> $ERR 7421.28Slukem printf "\n" >> $ERR 7431.15Smrg fi 7441.9Scgd 7451.52Satatat backup_file update $TMP1 $CUR $BACK 7461.9Scgd fi 7471.15Smrg else 7481.28Slukem printf "Setuid additions:\n" >> $ERR 7491.28Slukem column -t $TMP1 >> $ERR 7501.28Slukem printf "\n" >> $ERR 7511.52Satatat backup_file add $TMP1 $CUR $BACK 7521.9Scgd fi 7531.15Smrg fi 7541.15Smrg 7551.27Slukem # Check for block and character disk devices that are readable or 7561.80Swiz # writable or not owned by root.operator. 7571.15Smrg >$TMP1 7581.61Slukem DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \ 7591.57Ssimonb sd se ss uk up vnd wd xd xy" 7601.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 7611.15Smrg for i in $DISKLIST; do 7621.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7631.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7641.15Smrg done 7651.15Smrg 7661.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 7671.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 7681.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 7691.15Smrg if [ -s $OUTPUT ] ; then 7701.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 7711.28Slukem cat $OUTPUT >> $ERR 7721.28Slukem printf "\n" >> $ERR 7731.9Scgd fi 7741.9Scgd 7751.15Smrg # Display any changes in the device file list. 7761.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 7771.15Smrg if [ -s $TMP1 ] ; then 7781.67Slukem file=$work_dir/device 7791.67Slukem migrate_file "$backup_dir/device" "$file" 7801.67Slukem CUR=${file}.current 7811.67Slukem BACK=${file}.backup 7821.15Smrg 7831.15Smrg if [ -s $CUR ] ; then 7841.15Smrg if cmp -s $CUR $TMP1 ; then 7851.15Smrg : 7861.15Smrg else 7871.15Smrg > $TMP2 7881.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 7891.15Smrg if [ -s $OUTPUT ] ; then 7901.28Slukem printf "Device additions:\n" >> $ERR 7911.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7921.28Slukem printf "\n" >> $ERR 7931.15Smrg fi 7941.15Smrg 7951.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 7961.15Smrg if [ -s $OUTPUT ] ; then 7971.28Slukem printf "Device deletions:\n" >> $ERR 7981.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7991.28Slukem printf "\n" >> $ERR 8001.15Smrg fi 8011.15Smrg 8021.27Slukem # Report any block device change. Ignore 8031.27Slukem # character devices, only the name is 8041.27Slukem # significant. 8051.15Smrg cat $TMP2 $CUR $TMP1 | \ 8061.27Slukem sed -e '/^c/d' | \ 8071.27Slukem sort -k11 | \ 8081.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 8091.27Slukem uniq -u > $OUTPUT 8101.15Smrg if [ -s $OUTPUT ] ; then 8111.28Slukem printf "Block device changes:\n" >> $ERR 8121.28Slukem column -t $OUTPUT >> $ERR 8131.28Slukem printf "\n" >> $ERR 8141.15Smrg fi 8151.9Scgd 8161.52Satatat backup_file update $TMP1 $CUR $BACK 8171.9Scgd fi 8181.15Smrg else 8191.28Slukem printf "Device additions:\n" >> $ERR 8201.28Slukem column -t $TMP1 >> $ERR 8211.28Slukem printf "\n" >> $ERR 8221.52Satatat backup_file add $TMP1 $CUR $BACK >> $ERR 8231.9Scgd fi 8241.28Slukem fi 8251.28Slukem if [ -s $ERR ] ; then 8261.28Slukem printf "\nChecking setuid files and devices:\n" 8271.28Slukem cat $ERR 8281.28Slukem printf "\n" 8291.9Scgd fi 8301.9Scgdfi 8311.9Scgd 8321.9Scgd# Check special files. 8331.9Scgd# Check system binaries. 8341.9Scgd# 8351.9Scgd# Create the mtree tree specifications using: 8361.67Slukem# mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure 8371.38Skleink# chown root:wheel DIR.secure 8381.67Slukem# chmod u+r,go= DIR.secure 8391.9Scgd# 8401.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 8411.9Scgd# the hacker can modify the tree specification to match the replaced binary. 8421.9Scgd# For details on really protecting yourself against modified binaries, see 8431.9Scgd# the mtree(8) manual page. 8441.32Slukem# 8451.31Slukemif checkyesno check_mtree; then 8461.82Sjhawk if checkyesno check_mtree_follow_symlinks; then 8471.82Sjhawk check_mtree_flags="-L" 8481.82Sjhawk else 8491.82Sjhawk check_mtree_flags="" 8501.82Sjhawk fi 8511.91Slukem mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 | 8521.87Sjhawk grep -v '^mtree: dev/tty: Device not configured$' >&2 8531.15Smrg if [ -s $OUTPUT ]; then 8541.9Scgd printf "\nChecking special files and directories.\n" 8551.9Scgd cat $OUTPUT 8561.9Scgd fi 8571.9Scgd 8581.16Smikel for file in /etc/mtree/*.secure; do 8591.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 8601.109Schristos tree=$(sed -n -e '3s/.* //p' -e 3q $file) 8611.82Sjhawk mtree $check_mtree_flags -f $file -p $tree > $TMP1 8621.9Scgd if [ -s $TMP1 ]; then 8631.67Slukem printf "\nChecking $tree:\n" 8641.67Slukem cat $TMP1 8651.9Scgd fi 8661.67Slukem done > $OUTPUT 8671.15Smrg if [ -s $OUTPUT ]; then 8681.9Scgd printf "\nChecking system binaries:\n" 8691.9Scgd cat $OUTPUT 8701.9Scgd fi 8711.9Scgdfi 8721.9Scgd 8731.32Slukem# Backup disklabels of available disks 8741.32Slukem# 8751.32Slukemif checkyesno check_disklabels; then 8761.67Slukem # migrate old disklabels 8771.109Schristos for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \ 8781.109Schristos $backup_dir/disklabel.* 2>/dev/null); do 8791.67Slukem migrate_file "$file" "$work_dir/${file##*/}" 8801.67Slukem done 8811.67Slukem 8821.103Stron # generate list of old disklabels, fdisks & wedges and remove them 8831.103Stron ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null | 8841.52Satatat egrep -v '\.(backup|current)(,v)?$' > $LABELS 8851.32Slukem xargs rm < $LABELS 8861.32Slukem 8871.103Stron # generate disklabels of all disks excluding: cd dk fd md st 8881.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 !~ /^[cfm]d|dk|st|nfs/ { print $1; }') 8891.32Slukem for i in $disks; do 8901.67Slukem disklabel $i > "$work_dir/disklabel.$i" 2>/dev/null 8911.32Slukem done 8921.32Slukem 8931.67Slukem # if fdisk is available, generate fdisks for: ed ld sd wd 8941.67Slukem if [ -x /sbin/fdisk ]; then 8951.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d/ { print $1; }') 8961.67Slukem for i in $disks; do 8971.67Slukem /sbin/fdisk $i > "$work_dir/fdisk.$i" 2>/dev/null 8981.67Slukem done 8991.67Slukem fi 9001.67Slukem 9011.103Stron # if dkctl is available, generate dkctl listwedges for: ed ld sd wd cgd ofdisk ra rl raid 9021.103Stron if [ -x /sbin/dkctl ]; then 9031.109Schristos disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^[elsw]d|cgd|ofdisk|r[al]|raid/ { print $1; }') 9041.103Stron for i in $disks; do 9051.103Stron /sbin/dkctl $i listwedges > "$work_dir/wedges.$i" 2>/dev/null 9061.103Stron done 9071.103Stron fi 9081.103Stron 9091.103Stron # append list of new disklabels, fdisks and wedges 9101.103Stron ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* 2>/dev/null | 9111.52Satatat egrep -v '\.(backup|current)(,v)?$' >> $LABELS 9121.62Satatat CHANGELIST="$LABELS $CHANGELIST" 9131.62Satatatfi 9141.62Satatat 9151.106Shaadif checkyesno check_lvm; then 9161.106Shaad 9171.106Shaad # generate list of existing LVM elements Physical Volumes, Volume Groups and Logical Volumes. 9181.106Shaadif [ -x /sbin/lvm ]; then 9191.106Shaad lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null 9201.106Shaad lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null 9211.106Shaad lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null 9221.106Shaadfi 9231.106Shaad ls -1d $work_dir/lvm.* 2>/dev/null | 9241.106Shaad egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS 9251.106Shaad CHANGELIST="$CHANGELIST $LVM_LABELS" 9261.106Shaadfi 9271.106Shaad 9281.62Satatat# Check for changes in the list of installed pkgs 9291.62Satatat# 9301.108Sjmmvif checkyesno check_pkgs && have_pkgs; then 9311.67Slukem pkgs=$work_dir/pkgs 9321.67Slukem migrate_file "$backup_dir/pkgs" "$pkgs" 9331.112Sagc pkg_dbdir=$(${pkg_admin} config-var PKG_DBDIR) 9341.108Sjmmv : ${pkg_dbdir:=/var/db/pkg} 9351.108Sjmmv ( cd $pkg_dbdir 9361.104Sadrianp $pkg_info | sort 9371.62Satatat echo "" 9381.62Satatat find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 | 9391.72Slukem xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,' 9401.62Satatat ) > $pkgs 9411.67Slukem echo "$pkgs" > $PKGS 9421.62Satatat CHANGELIST="$PKGS $CHANGELIST" 9431.32Slukemfi 9441.32Slukem 9451.67Slukem# List of files that get backed up and checked for any modifications. 9461.9Scgd# Any changes cause the files to rotate. 9471.32Slukem# 9481.67Slukemif checkyesno check_changelist ; then 9491.91Slukem mtree -D -k type -f $SPECIALSPEC -E exclude | 9501.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES 9511.67Slukem 9521.75Slukem ( 9531.68Slukem # Add other files which might dynamically exist: 9541.67Slukem # /etc/ifconfig.* 9551.67Slukem # /etc/raid*.conf 9561.68Slukem # /etc/rc.d/* 9571.67Slukem # /etc/rc.conf.d/* 9581.68Slukem # 9591.75Slukem echo "/etc/ifconfig.*" 9601.75Slukem echo "/etc/raid*.conf" 9611.75Slukem echo "/etc/rc.d/*" 9621.75Slukem echo "/etc/rc.conf.d/*" 9631.106Shaad echo "/etc/lvm/backup/*" 9641.106Shaad echo "/etc/lvm/archive/*" 9651.67Slukem 9661.68Slukem # Add /etc/changelist 9671.68Slukem # 9681.75Slukem if [ -s /etc/changelist ]; then 9691.75Slukem grep -v '^#' /etc/changelist 9701.75Slukem fi 9711.75Slukem ) | while read file; do 9721.75Slukem case "$file" in 9731.75Slukem *[\*\?\[]*) # If changelist line is a glob ... 9741.75Slukem # ... expand possible backup files 9751.75Slukem # 9761.75Slukem ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \ 9771.75Slukem | sed "s,^$backup_dir/,, ; s,\.current$,," 9781.75Slukem 9791.75Slukem # ... expand possible files 9801.75Slukem # 9811.75Slukem ls -1d $(echo $file) 2>/dev/null 9821.75Slukem ;; 9831.75Slukem *) 9841.75Slukem # Otherwise, just print the filename 9851.75Slukem echo $file 9861.75Slukem ;; 9871.75Slukem esac 9881.75Slukem done >> $CHANGEFILES 9891.67Slukem CHANGELIST="$CHANGEFILES $CHANGELIST" 9901.67Slukemfi 9911.67Slukem 9921.67Slukem# Special case backups, including the master password file and 9931.67Slukem# ssh private host keys. The normal backup mechanisms for 9941.67Slukem# $check_changelist (see below) also print out the actual file 9951.67Slukem# differences and we don't want to do that for these files 9961.67Slukem# 9971.67Slukemecho $MP > $TMP1 # always add /etc/master.passwd 9981.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff | 9991.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1 10001.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2 10011.68Slukem 10021.69Slukemwhile read file; do 10031.67Slukem backup_and_diff "$file" no 10041.69Slukemdone < $TMP2 10051.67Slukem 10061.32Slukem 10071.32Slukemif [ -n "$CHANGELIST" ]; then 10081.73Slukem grep -h -v '^$' $CHANGELIST | sort -u > $TMP1 10091.68Slukem comm -23 $TMP1 $TMP2 | while read file; do 10101.67Slukem backup_and_diff "$file" yes 10111.9Scgd done 10121.44Sadfi 10131.44Sad 10141.108Sjmmvif have_pkgs; then 10151.107Sjmmv if checkyesno check_pkg_vulnerabilities; then 10161.112Sagc ${pkg_admin} ${_compat_K_flag} audit >${OUTPUT} 2>&1 10171.107Sjmmv if [ -s ${OUTPUT} ]; then 10181.107Sjmmv printf "\nInstalled vulnerable packages:\n" 10191.107Sjmmv cat ${OUTPUT} 10201.107Sjmmv fi 10211.107Sjmmv fi 10221.107Sjmmv 10231.107Sjmmv if checkyesno check_pkg_signatures; then 10241.112Sagc ${pkg_admin} ${_compat_K_flag} check >${OUTPUT} 2>&1 10251.107Sjmmv if [ $? -ne 0 ]; then 10261.107Sjmmv printf "\nFiles with invalid signatures:\n" 10271.107Sjmmv cat ${OUTPUT} 10281.107Sjmmv fi 10291.107Sjmmv fi 10301.107Sjmmvfi 10311.107Sjmmv 10321.44Sadif [ -f /etc/security.local ]; then 10331.90Skim . /etc/security.local > $OUTPUT 2>&1 10341.84Sjhawk if [ -s $OUTPUT ] ; then 10351.84Sjhawk printf "\nRunning /etc/security.local:\n" 10361.84Sjhawk cat $OUTPUT 10371.84Sjhawk fi 10381.9Scgdfi 1039