security revision 1.129
11.1Scgd#!/bin/sh - 21.1Scgd# 31.129Snia# $NetBSD: security,v 1.129 2021/11/04 12:40:00 nia 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.118Suebayasi echo "WARNING: Setting pkgdb_dir in security.conf(5) is deprecated" 711.118Suebayasi echo "WARNING: Please define PKG_DBDIR in pkg_install.conf(5) instead" 721.118Suebayasi _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.123Skre if [ -z "$_old" ] || [ -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.123Skre if [ -f "${_old}" ] && ! [ -f "${_new}" ]; then 961.67Slukem echo "==> migrating ${_old}" 971.67Slukem echo " to ${_new}" 981.67Slukem mv "${_old}" "${_new}" 991.67Slukem fi 1001.123Skre if [ -f "${_old}.current" ] && ! [ -f "${_new}.current" ]; then 1011.67Slukem echo "==> migrating ${_old}.current" 1021.67Slukem echo " to ${_new}.current" 1031.67Slukem mv "${_old}.current" "${_new}.current" 1041.123Skre if [ -f "${_old}.current,v" ] && 1051.123Skre ! [ -f "${_new}.current,v" ]; then 1061.67Slukem echo "==> migrating ${_old}.current,v" 1071.67Slukem echo " to ${_new}.current,v" 1081.67Slukem mv "${_old}.current,v" "${_new}.current,v" 1091.67Slukem fi 1101.123Skre if [ -f "${_old}.backup" ] && ! [ -f "${_new}.backup" ]; then 1111.67Slukem echo "==> migrating ${_old}.backup" 1121.67Slukem echo " to ${_new}.backup" 1131.67Slukem mv "${_old}.backup" "${_new}.backup" 1141.67Slukem fi 1151.67Slukem fi 1161.67Slukem} 1171.67Slukem 1181.67Slukem 1191.67Slukem# backup_and_diff file printdiff 1201.67Slukem# Determine if file needs backing up, and if so, do it. 1211.118Suebayasi# If printdiff is yes, display the diffs, otherwise 1221.67Slukem# just print a message saying "[changes omitted]". 1231.67Slukem# 1241.67Slukembackup_and_diff() 1251.67Slukem{ 1261.67Slukem _file=$1 1271.67Slukem _printdiff=$2 1281.123Skre if [ -z "$_file" ] || [ -z "$_printdiff" ]; then 1291.67Slukem err 3 "USAGE: backup_and_diff file printdiff" 1301.67Slukem fi 1311.67Slukem ! checkyesno _printdiff 1321.67Slukem _printdiff=$? 1331.67Slukem 1341.67Slukem _old=$backup_dir/${_file##*/} 1351.67Slukem case "$_file" in 1361.67Slukem $work_dir/*) 1371.67Slukem _new=$_file 1381.67Slukem migrate_file "$backup_dir/$_old" "$_new" 1391.67Slukem migrate_file "$_old" "$_new" 1401.67Slukem ;; 1411.67Slukem *) 1421.67Slukem _new=$backup_dir/$_file 1431.67Slukem migrate_file "$_old" "$_new" 1441.67Slukem ;; 1451.67Slukem esac 1461.67Slukem CUR=${_new}.current 1471.67Slukem BACK=${_new}.backup 1481.67Slukem if [ -f $_file ]; then 1491.67Slukem if [ -f $CUR ] ; then 1501.67Slukem if [ "$_printdiff" -ne 0 ]; then 1511.83Sjhawk diff ${diff_options} $CUR $_file > $OUTPUT 1521.67Slukem else 1531.67Slukem if ! cmp -s $CUR $_file; then 1541.67Slukem echo "[changes omitted]" 1551.67Slukem fi > $OUTPUT 1561.67Slukem fi 1571.67Slukem if [ -s $OUTPUT ] ; then 1581.67Slukem printf \ 1591.67Slukem "\n======\n%s diffs (OLD < > NEW)\n======\n" $_file 1601.67Slukem cat $OUTPUT 1611.67Slukem backup_file update $_file $CUR $BACK 1621.67Slukem fi 1631.67Slukem else 1641.67Slukem printf "\n======\n%s added\n======\n" $_file 1651.67Slukem if [ "$_printdiff" -ne 0 ]; then 1661.83Sjhawk diff ${diff_options} /dev/null $_file 1671.67Slukem else 1681.67Slukem echo "[changes omitted]" 1691.67Slukem fi 1701.67Slukem backup_file add $_file $CUR $BACK 1711.67Slukem fi 1721.67Slukem else 1731.67Slukem if [ -f $CUR ]; then 1741.67Slukem printf "\n======\n%s removed\n======\n" $_file 1751.67Slukem if [ "$_printdiff" -ne 0 ]; then 1761.83Sjhawk diff ${diff_options} $CUR /dev/null 1771.67Slukem else 1781.67Slukem echo "[changes omitted]" 1791.67Slukem fi 1801.67Slukem backup_file remove $_file $CUR $BACK 1811.67Slukem fi 1821.67Slukem fi 1831.67Slukem} 1841.48Sabs 1851.9Scgd 1861.67Slukem# These are used several times. 1871.67Slukem# 1881.91Slukemawk -F: '!/^\+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID 1891.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH 1901.91Slukemfor file in $special_files; do 1911.91Slukem [ -s $file ] && cat $file 1921.91Slukemdone | mtree -CM -k all > $SPECIALSPEC || exit 1 1931.9Scgd 1941.67Slukem 1951.128Sriastrad# Check for enough entropy. 1961.128Sriastrad# 1971.128Sriastradif checkyesno check_entropy; then 1981.128Sriastrad if ! dd if=/dev/random iflag=nonblock of=/dev/null bs=1 count=1 \ 1991.128Sriastrad msgfmt=quiet 2>/dev/null; then 2001.128Sriastrad printf '\n' 2011.128Sriastrad printf 'Entropy:\n' 2021.128Sriastrad printf 'System may need more entropy for cryptography.\n' 2031.128Sriastrad printf 'See the entropy(7) man page for details.\n' 2041.128Sriastrad fi 2051.128Sriastradfi 2061.128Sriastrad 2071.128Sriastrad 2081.9Scgd# Check the master password file syntax. 2091.32Slukem# 2101.31Slukemif checkyesno check_passwd; then 2111.118Suebayasi # XXX: the sense of permit_star is reversed; the code works as 2121.118Suebayasi # implemented, but usage needs to be negated. 2131.81Sjhawk checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1 2141.94Sjdolecek checkyesno check_passwd_permit_nonalpha \ 2151.94Sjdolecek && permit_nonalpha=1 || permit_nonalpha=0 2161.94Sjdolecek 2171.81Sjhawk awk -v "len=$max_loginlen" \ 2181.81Sjhawk -v "nowarn_shells_list=$check_passwd_nowarn_shells" \ 2191.81Sjhawk -v "nowarn_users_list=$check_passwd_nowarn_users" \ 2201.94Sjdolecek -v "permit_star=$permit_star" \ 2211.94Sjdolecek -v "permit_nonalpha=$permit_nonalpha" \ 2221.94Sjdolecek ' 2231.25Slukem BEGIN { 2241.25Slukem while ( getline < "/etc/shells" > 0 ) { 2251.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 2261.25Slukem continue; 2271.25Slukem shells[$1]++; 2281.25Slukem } 2291.81Sjhawk split(nowarn_shells_list, a); 2301.81Sjhawk for (i in a) nowarn_shells[a[i]]++; 2311.81Sjhawk split(nowarn_users_list, a); 2321.81Sjhawk for (i in a) nowarn_users[a[i]]++; 2331.81Sjhawk uid0_users_list="root toor" 2341.81Sjhawk split(uid0_users_list, a); 2351.81Sjhawk for (i in a) uid0_users[a[i]]++; 2361.25Slukem FS=":"; 2371.25Slukem } 2381.25Slukem 2391.25Slukem { 2401.15Smrg if ($0 ~ /^[ ]*$/) { 2411.25Slukem printf "Line %d is a blank line.\n", NR; 2421.15Smrg next; 2431.15Smrg } 2441.105Sdholland 2451.105Sdholland # NIS compat entry? 2461.105Sdholland compatline = $1 ~ "^[\\+-]"; 2471.105Sdholland if (compatline) { 2481.105Sdholland if ($1 == "+" && NF == 1) { 2491.105Sdholland next; 2501.105Sdholland } 2511.105Sdholland sub("^.", "", $1); 2521.105Sdholland } 2531.105Sdholland if (NF != 10) 2541.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 2551.105Sdholland if (compatline) { 2561.105Sdholland if ($3 == 0) 2571.81Sjhawk printf "Line %d includes entries with uid 0.\n", 2581.81Sjhawk NR; 2591.105Sdholland if ($1 == "") 2601.105Sdholland next; 2611.34Sabs } 2621.94Sjdolecek if (!permit_nonalpha && 2631.95Speter $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 2641.25Slukem printf "Login %s has non-alphanumeric characters.\n", 2651.25Slukem $1; 2661.34Sabs if (length($1) > len) 2671.81Sjhawk printf "Login %s has more than "len" characters.\n", 2681.81Sjhawk $1; 2691.105Sdholland if ($2 == "" && !compatline && !nowarn_users[$1]) 2701.81Sjhawk printf "Login %s has no password.\n", $1; 2711.81Sjhawk if (!nowarn_shells[$10] && !nowarn_users[$1]) { 2721.81Sjhawk if (length($2) != 13 && 2731.81Sjhawk length($2) != 20 && 2741.81Sjhawk $2 !~ /^\$1/ && 2751.81Sjhawk $2 !~ /^\$2/ && 2761.99Sjmcneill $2 !~ /^\$sha1/ && 2771.129Snia $2 !~ /^\$argon2(i|d|id)/ && 2781.81Sjhawk $2 != "" && 2791.81Sjhawk (permit_star || $2 != "*") && 2801.81Sjhawk $2 !~ /^\*[A-z-]+$/ && 2811.81Sjhawk $1 != "toor") { 2821.81Sjhawk if ($10 == "" || shells[$10]) 2831.81Sjhawk printf "Login %s is off but still has "\ 2841.81Sjhawk "a valid shell (%s)\n", $1, $10; 2851.105Sdholland } else if (compatline && $10 == "") { 2861.105Sdholland # nothing 2871.81Sjhawk } else if (! shells[$10]) 2881.81Sjhawk printf "Login %s does not have a valid "\ 2891.81Sjhawk "shell (%s)\n", $1, $10; 2901.81Sjhawk } 2911.81Sjhawk if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1]) 2921.25Slukem printf "Login %s has a user id of 0.\n", $1; 2931.105Sdholland if ($3 != "" && $3 < 0) 2941.25Slukem printf "Login %s has a negative user id.\n", $1; 2951.105Sdholland if ($4 != "" && $4 < 0) 2961.25Slukem printf "Login %s has a negative group id.\n", $1; 2971.15Smrg }' < $MP > $OUTPUT 2981.15Smrg if [ -s $OUTPUT ] ; then 2991.15Smrg printf "\nChecking the $MP file:\n" 3001.15Smrg cat $OUTPUT 3011.15Smrg fi 3021.15Smrg 3031.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 3041.15Smrg if [ -s $OUTPUT ] ; then 3051.15Smrg printf "\n$MP has duplicate user names.\n" 3061.15Smrg column $OUTPUT 3071.15Smrg fi 3081.15Smrg 3091.111Sspz awk -v "permit_dups_list=$check_passwd_permit_dups" \ 3101.111Sspz ' 3111.111Sspz BEGIN { 3121.111Sspz split(permit_dups_list, a); 3131.111Sspz for (i in a) permit_dups[a[i]]++; 3141.111Sspz } 3151.111Sspz { 3161.111Sspz if (!permit_dups[$1]) 3171.111Sspz print $2; 3181.111Sspz }' < $MPBYUID | uniq -d > $TMP2 3191.15Smrg if [ -s $TMP2 ] ; then 3201.111Sspz printf "\n$MP has duplicate user ids.\n" 3211.15Smrg while read uid; do 3221.28Slukem grep -w $uid $MPBYUID 3231.15Smrg done < $TMP2 | column 3241.15Smrg fi 3251.9Scgdfi 3261.9Scgd 3271.9Scgd# Check the group file syntax. 3281.32Slukem# 3291.31Slukemif checkyesno check_group; then 3301.15Smrg GRP=/etc/group 3311.49Sjdolecek awk -F: -v "len=$max_grouplen" '{ 3321.15Smrg if ($0 ~ /^[ ]*$/) { 3331.25Slukem printf "Line %d is a blank line.\n", NR; 3341.15Smrg next; 3351.15Smrg } 3361.34Sabs if (NF != 4 && ($1 != "+" || NF != 1)) 3371.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 3381.34Sabs if ($1 == "+" ) { 3391.34Sabs next; 3401.34Sabs } 3411.95Speter if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 3421.25Slukem printf "Group %s has non-alphanumeric characters.\n", 3431.25Slukem $1; 3441.49Sjdolecek if (length($1) > len) 3451.49Sjdolecek printf "Group %s has more than "len" characters.\n", $1; 3461.15Smrg if ($3 !~ /[0-9]*/) 3471.25Slukem printf "Login %s has a negative group id.\n", $1; 3481.15Smrg }' < $GRP > $OUTPUT 3491.15Smrg if [ -s $OUTPUT ] ; then 3501.15Smrg printf "\nChecking the $GRP file:\n" 3511.15Smrg cat $OUTPUT 3521.15Smrg fi 3531.15Smrg 3541.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 3551.114Sspz dupgroups="" 3561.114Sspz for group in $(cat $OUTPUT) ; do 3571.116Sapb gcount=$(awk -F: "/$group/ { print \$1,\$3 }" $GRP | 3581.116Sapb sort -u | wc -l) 3591.114Sspz if [ $gcount -gt 1 ]; then 3601.114Sspz dupgroups="$dupgroups $group" 3611.114Sspz fi 3621.114Sspz done 3631.114Sspz if [ ! -z $dupgroups ] ; then 3641.15Smrg printf "\n$GRP has duplicate group names.\n" 3651.114Sspz printf "$dupgroups\n" 3661.15Smrg fi 3671.9Scgdfi 3681.9Scgd 3691.9Scgd# Check for root paths, umask values in startup files. 3701.9Scgd# The check for the root paths is problematical -- it's likely to fail 3711.9Scgd# in other environments. Once the shells have been modified to warn 3721.9Scgd# of '.' in the path, the path tests should go away. 3731.32Slukem# 3741.31Slukemif checkyesno check_rootdotfiles; then 3751.67Slukem rhome=~root 3761.15Smrg umaskset=no 3771.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 3781.15Smrg for i in $list ; do 3791.15Smrg if [ -f $i ] ; then 3801.67Slukem if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; 3811.67Slukem then 3821.15Smrg umaskset=yes 3831.15Smrg fi 3841.63Slukem # Double check the umask value itself; ensure that 3851.67Slukem # both the group and other write bits are set. 3861.67Slukem # 3871.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 3881.63Slukem awk '{ 3891.67Slukem if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) { 3901.80Swiz print "\tRoot umask is group writable" 3911.63Slukem } 3921.67Slukem if ($2 ~ /[^2367]$/) { 3931.80Swiz print "\tRoot umask is other writable" 3941.63Slukem } 3951.67Slukem }' | sort -u 3961.26Slukem SAVE_PATH=$PATH 3971.26Slukem unset PATH 3981.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 3991.15Smrg source $i 4001.15Smrg /bin/ls -ldgT \$path > $TMP1 4011.9Scgdend-of-csh 4021.76Satatat export PATH=$SAVE_PATH 4031.15Smrg awk '{ 4041.15Smrg if ($10 ~ /^\.$/) { 4051.27Slukem print "\tThe root path includes ."; 4061.15Smrg next; 4071.15Smrg } 4081.15Smrg } 4091.15Smrg $1 ~ /^d....w/ \ 4101.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4111.15Smrg $1 ~ /^d.......w/ \ 4121.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4131.67Slukem < $TMP1 4141.15Smrg fi 4151.67Slukem done > $OUTPUT 4161.124Skre if [ $umaskset = no ] || [ -s $OUTPUT ] ; then 4171.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 4181.15Smrg if [ -s $OUTPUT ]; then 4191.15Smrg cat $OUTPUT 4201.15Smrg fi 4211.123Skre if [ $umaskset = no ] ; then 4221.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 4231.15Smrg fi 4241.9Scgd fi 4251.9Scgd 4261.15Smrg umaskset=no 4271.23Slukem list="/etc/profile ${rhome}/.profile" 4281.15Smrg for i in $list; do 4291.15Smrg if [ -f $i ] ; then 4301.15Smrg if egrep umask $i > /dev/null ; then 4311.15Smrg umaskset=yes 4321.15Smrg fi 4331.15Smrg egrep umask $i | 4341.67Slukem awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \ 4351.80Swiz { print "\tRoot umask is group writable" } \ 4361.67Slukem $2 ~ /[^2367]$/ \ 4371.80Swiz { print "\tRoot umask is other writable" }' 4381.26Slukem SAVE_PATH=$PATH 4391.26Slukem unset PATH 4401.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 4411.15Smrg . $i 4421.110Schristos list=\$(echo \$PATH | /usr/bin/sed -e \ 4431.110Schristos 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g') 4441.15Smrg /bin/ls -ldgT \$list > $TMP1 4451.9Scgdend-of-sh 4461.76Satatat export PATH=$SAVE_PATH 4471.15Smrg awk '{ 4481.15Smrg if ($10 ~ /^\.$/) { 4491.27Slukem print "\tThe root path includes ."; 4501.15Smrg next; 4511.15Smrg } 4521.15Smrg } 4531.15Smrg $1 ~ /^d....w/ \ 4541.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4551.15Smrg $1 ~ /^d.......w/ \ 4561.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4571.67Slukem < $TMP1 4581.9Scgd 4591.15Smrg fi 4601.67Slukem done > $OUTPUT 4611.123Skre if [ $umaskset = no ] || [ -s $OUTPUT ] ; then 4621.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 4631.15Smrg if [ -s $OUTPUT ]; then 4641.15Smrg cat $OUTPUT 4651.15Smrg fi 4661.123Skre if [ $umaskset = no ] ; then 4671.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 4681.15Smrg fi 4691.9Scgd fi 4701.9Scgdfi 4711.9Scgd 4721.9Scgd# Root and uucp should both be in /etc/ftpusers. 4731.32Slukem# 4741.31Slukemif checkyesno check_ftpusers; then 4751.109Schristos list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID) 4761.27Slukem for i in $list; do 4771.29Slukem if /usr/libexec/ftpd -C $i ; then 4781.67Slukem printf "\t$i is not denied\n" 4791.27Slukem fi 4801.67Slukem done > $OUTPUT 4811.28Slukem if [ -s $OUTPUT ]; then 4821.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 4831.28Slukem cat $OUTPUT 4841.28Slukem fi 4851.9Scgdfi 4861.9Scgd 4871.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 4881.32Slukem# 4891.31Slukemif checkyesno check_aliases; then 4901.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 4911.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 4921.43Sitojun printf "\nEntry for uudecode in $f file.\n" 4931.43Sitojun fi 4941.43Sitojun done 4951.9Scgdfi 4961.9Scgd 4971.9Scgd# Files that should not have + signs. 4981.32Slukem# 4991.31Slukemif checkyesno check_rhosts; then 5001.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 5011.15Smrg for f in $list ; do 5021.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 5031.15Smrg printf "\nPlus sign in $f file.\n" 5041.15Smrg fi 5051.15Smrg done 5061.15Smrg 5071.15Smrg # Check for special users with .rhosts files. Only root and toor should 5081.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 5091.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 5101.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 5111.20Smycroft { print $1 " " $9 }' $MP | 5121.19Smycroft sort -k2 | 5131.15Smrg while read uid homedir; do 5141.15Smrg if [ -f ${homedir}/.rhosts ] ; then 5151.109Schristos rhost=$(ls -ldgT ${homedir}/.rhosts) 5161.46Schristos printf -- "$uid: $rhost\n" 5171.15Smrg fi 5181.15Smrg done > $OUTPUT 5191.15Smrg if [ -s $OUTPUT ] ; then 5201.15Smrg printf "\nChecking for special users with .rhosts files.\n" 5211.15Smrg cat $OUTPUT 5221.15Smrg fi 5231.15Smrg 5241.15Smrg while read uid homedir; do 5251.123Skre if [ -f ${homedir}/.rhosts ] && 5261.123Skre [ -r ${homedir}/.rhosts ] && 5271.123Skre cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null 5281.123Skre then 5291.46Schristos printf -- "$uid: + in .rhosts file.\n" 5301.15Smrg fi 5311.29Slukem done < $MPBYPATH > $OUTPUT 5321.15Smrg if [ -s $OUTPUT ] ; then 5331.15Smrg printf "\nChecking .rhosts files syntax.\n" 5341.15Smrg cat $OUTPUT 5351.15Smrg fi 5361.9Scgdfi 5371.9Scgd 5381.9Scgd# Check home directories. Directories should not be owned by someone else 5391.80Swiz# or writable. 5401.32Slukem# 5411.31Slukemif checkyesno check_homes; then 5421.85Sjhawk checkyesno check_homes_permit_usergroups && \ 5431.85Sjhawk permit_usergroups=1 || permit_usergroups=0 5441.15Smrg while read uid homedir; do 5451.15Smrg if [ -d ${homedir}/ ] ; then 5461.109Schristos file=$(ls -ldgT ${homedir}) 5471.46Schristos printf -- "$uid $file\n" 5481.9Scgd fi 5491.29Slukem done < $MPBYPATH | 5501.115Sspz awk -v "usergroups=$permit_usergroups" \ 5511.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 5521.115Sspz BEGIN { 5531.115Sspz split(permit_owners_list, a); 5541.115Sspz for (i in a) permit_owners[a[i]]++; 5551.115Sspz } 5561.115Sspz $1 != $4 && $4 != "root" && !permit_owners[$1] \ 5571.15Smrg { print "user " $1 " home directory is owned by " $4 } 5581.101Sjnemeth $2 ~ /^d....w/ && (!usergroups || $5 != $1) \ 5591.80Swiz { print "user " $1 " home directory is group writable" } 5601.101Sjnemeth $2 ~ /^d.......w/ \ 5611.80Swiz { print "user " $1 " home directory is other writable" }' \ 5621.27Slukem > $OUTPUT 5631.15Smrg if [ -s $OUTPUT ] ; then 5641.15Smrg printf "\nChecking home directories.\n" 5651.15Smrg cat $OUTPUT 5661.15Smrg fi 5671.15Smrg 5681.15Smrg # Files that should not be owned by someone else or readable. 5691.67Slukem list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity" 5701.15Smrg while read uid homedir; do 5711.15Smrg for f in $list ; do 5721.15Smrg file=${homedir}/${f} 5731.15Smrg if [ -f $file ] ; then 5741.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5751.15Smrg fi 5761.15Smrg done 5771.29Slukem done < $MPBYPATH | 5781.115Sspz awk -v "usergroups=$permit_usergroups" \ 5791.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 5801.115Sspz BEGIN { 5811.115Sspz split(permit_owners_list, a); 5821.115Sspz for (i in a) permit_owners[a[i]]++; 5831.115Sspz } 5841.115Sspz $1 != $5 && $5 != "root" && !permit_owners[$1] \ 5851.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5861.85Sjhawk $3 ~ /^-...r/ && (!usergroups || $6 != $1) \ 5871.15Smrg { print "user " $1 " " $2 " file is group readable" } 5881.15Smrg $3 ~ /^-......r/ \ 5891.15Smrg { print "user " $1 " " $2 " file is other readable" } 5901.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5911.80Swiz { print "user " $1 " " $2 " file is group writable" } 5921.15Smrg $3 ~ /^-.......w/ \ 5931.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5941.27Slukem > $OUTPUT 5951.15Smrg 5961.80Swiz # Files that should not be owned by someone else or writable. 5971.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 5981.79Selric .cshrc .emacs .exrc .forward .history .k5login .klogin .login \ 5991.79Selric .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \ 6001.79Selric .twmrc .xinitrc .xsession .ssh/authorized_keys \ 6011.79Selric .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \ 6021.79Selric .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \ 6031.79Selric .ssh/known_hosts2" 6041.15Smrg while read uid homedir; do 6051.15Smrg for f in $list ; do 6061.15Smrg file=${homedir}/${f} 6071.15Smrg if [ -f $file ] ; then 6081.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 6091.15Smrg fi 6101.15Smrg done 6111.29Slukem done < $MPBYPATH | 6121.115Sspz awk -v "usergroups=$permit_usergroups" \ 6131.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 6141.115Sspz BEGIN { 6151.115Sspz split(permit_owners_list, a); 6161.115Sspz for (i in a) permit_owners[a[i]]++; 6171.115Sspz } 6181.115Sspz $1 != $5 && $5 != "root" && !permit_owners[$1] \ 6191.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 6201.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 6211.80Swiz { print "user " $1 " " $2 " file is group writable" } 6221.15Smrg $3 ~ /^-.......w/ \ 6231.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 6241.27Slukem >> $OUTPUT 6251.15Smrg if [ -s $OUTPUT ] ; then 6261.15Smrg printf "\nChecking dot files.\n" 6271.15Smrg cat $OUTPUT 6281.15Smrg fi 6291.9Scgdfi 6301.9Scgd 6311.9Scgd# Mailboxes should be owned by user and unreadable. 6321.32Slukem# 6331.31Slukemif checkyesno check_varmail; then 6341.86Sjhawk ls -lA /var/mail | \ 6351.63Slukem awk ' NR == 1 { next; } 6361.86Sjhawk $9 ~ /^\./ {next; } 6371.63Slukem $3 != $9 { 6381.63Slukem print "user " $9 " mailbox is owned by " $3 6391.63Slukem } 6401.63Slukem $1 != "-rw-------" { 6411.63Slukem print "user " $9 " mailbox is " $1 ", group " $4 6421.63Slukem }' > $OUTPUT 6431.15Smrg if [ -s $OUTPUT ] ; then 6441.15Smrg printf "\nChecking mailbox ownership.\n" 6451.15Smrg cat $OUTPUT 6461.15Smrg fi 6471.15Smrgfi 6481.15Smrg 6491.32Slukem# NFS exports shouldn't be globally exported 6501.32Slukem# 6511.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 6521.32Slukem awk '{ 6531.22Slukem # ignore comments and blank lines 6541.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 6551.22Slukem next; 6561.100Stron # manage line continuation 6571.100Stron while ($NF ~ /^\\$/) { 6581.100Stron $NF = ""; 6591.100Stron line = $0 ""; 6601.100Stron getline; 6611.100Stron $0 = line $0 ""; 6621.100Stron } 6631.22Slukem 6641.100Stron delete dir; 6651.100Stron readonly = ndir = 0; 6661.100Stron for (i = 1; i <= NF; ++i) { 6671.100Stron if ($i ~ /^\//) dir[ndir++] = $i; 6681.100Stron else if ($i ~ /^-/) { 6691.100Stron if ($i ~ /^-(ro|o)$/) readonly = 1; 6701.100Stron if ($i ~ /^-network/) next; 6711.100Stron } 6721.100Stron else next; 6731.15Smrg } 6741.15Smrg if (readonly) 6751.100Stron for (item in dir) 6761.100Stron rodir[nrodir++] = dir[item]; 6771.15Smrg else 6781.100Stron for (item in dir) 6791.100Stron rwdir[nrwdir++] = dir[item]; 6801.100Stron 6811.100Stron } 6821.100Stron 6831.100Stron END { 6841.100Stron if (nrodir) { 6851.100Stron printf("Globally exported file system%s, read-only:\n", 6861.100Stron nrodir > 1 ? "s" : ""); 6871.100Stron for (item in rodir) 6881.100Stron printf("\t%s\n", rodir[item]); 6891.100Stron } 6901.100Stron if (nrwdir) { 6911.100Stron printf("Globally exported file system%s, read-write:\n", 6921.100Stron nrwdir > 1 ? "s" : ""); 6931.100Stron for (item in rwdir) 6941.100Stron printf("\t%s\n", rwdir[item]); 6951.100Stron } 6961.32Slukem }' < /etc/exports > $OUTPUT 6971.32Slukem if [ -s $OUTPUT ] ; then 6981.15Smrg printf "\nChecking for globally exported file systems.\n" 6991.15Smrg cat $OUTPUT 7001.15Smrg fi 7011.9Scgdfi 7021.9Scgd 7031.9Scgd# Display any changes in setuid files and devices. 7041.32Slukem# 7051.31Slukemif checkyesno check_devices; then 7061.28Slukem > $ERR 7071.92Serh ( 7081.98Slukem 7091.98Slukem # Convert check_devices_ignore_fstypes="foo !bar bax" 7101.98Slukem # into "-fstype foo -o ! -fstype bar -o -fstype bax" 7111.98Slukem # and check_devices_ignore_paths="/foo !/bar /bax" 7121.98Slukem # into " -path /foo -o ! -path /bar -o -path /bax" 7131.98Slukem # 7141.98Slukem ignexpr=$(\ 7151.98Slukem echo $check_devices_ignore_fstypes | \ 7161.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \ 7171.98Slukem echo $check_devices_ignore_paths | \ 7181.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \ 7191.98Slukem ) 7201.98Slukem 7211.98Slukem # Massage the expression into ( $ignexpr ) -a -prune -o 7221.98Slukem if [ -n "${ignexpr}" ]; then 7231.98Slukem ignexpr=$(\ 7241.98Slukem echo $ignexpr | \ 7251.98Slukem sed -e 's/^-o /( /' \ 7261.98Slukem -e 's/$/ ) -a -prune -o/' \ 7271.98Slukem ) 7281.98Slukem fi 7291.98Slukem 7301.98Slukem find / $ignexpr \ 7311.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 7321.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 7331.24Slukem -type b -o -type c \) -print0 | \ 7341.98Slukem xargs -0 ls -ldgTq | sort +9 > $LIST 7351.98Slukem 7361.98Slukem ) 2> $OUTPUT 7371.15Smrg 7381.15Smrg # Display any errors that occurred during system file walk. 7391.15Smrg if [ -s $OUTPUT ] ; then 7401.28Slukem printf "Setuid/device find errors:\n" >> $ERR 7411.28Slukem cat $OUTPUT >> $ERR 7421.28Slukem printf "\n" >> $ERR 7431.15Smrg fi 7441.15Smrg 7451.15Smrg # Display any changes in the setuid file list. 7461.15Smrg egrep -v '^[bc]' $LIST > $TMP1 7471.15Smrg if [ -s $TMP1 ] ; then 7481.15Smrg # Check to make sure uudecode isn't setuid. 7491.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 7501.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 7511.15Smrg fi 7521.15Smrg 7531.67Slukem file=$work_dir/setuid 7541.67Slukem migrate_file "$backup_dir/setuid" "$file" 7551.67Slukem CUR=${file}.current 7561.67Slukem BACK=${file}.backup 7571.15Smrg if [ -s $CUR ] ; then 7581.15Smrg if cmp -s $CUR $TMP1 ; then 7591.15Smrg : 7601.15Smrg else 7611.15Smrg > $TMP2 7621.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 7631.15Smrg if [ -s $OUTPUT ] ; then 7641.28Slukem printf "Setuid additions:\n" >> $ERR 7651.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7661.28Slukem printf "\n" >> $ERR 7671.15Smrg fi 7681.15Smrg 7691.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 7701.15Smrg if [ -s $OUTPUT ] ; then 7711.28Slukem printf "Setuid deletions:\n" >> $ERR 7721.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7731.28Slukem printf "\n" >> $ERR 7741.15Smrg fi 7751.15Smrg 7761.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 7771.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 7781.27Slukem uniq -u > $OUTPUT 7791.15Smrg if [ -s $OUTPUT ] ; then 7801.28Slukem printf "Setuid changes:\n" >> $ERR 7811.28Slukem column -t $OUTPUT >> $ERR 7821.28Slukem printf "\n" >> $ERR 7831.15Smrg fi 7841.9Scgd 7851.52Satatat backup_file update $TMP1 $CUR $BACK 7861.9Scgd fi 7871.15Smrg else 7881.28Slukem printf "Setuid additions:\n" >> $ERR 7891.28Slukem column -t $TMP1 >> $ERR 7901.28Slukem printf "\n" >> $ERR 7911.52Satatat backup_file add $TMP1 $CUR $BACK 7921.9Scgd fi 7931.15Smrg fi 7941.15Smrg 7951.27Slukem # Check for block and character disk devices that are readable or 7961.80Swiz # writable or not owned by root.operator. 7971.15Smrg >$TMP1 7981.61Slukem DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \ 7991.57Ssimonb sd se ss uk up vnd wd xd xy" 8001.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 8011.15Smrg for i in $DISKLIST; do 8021.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 8031.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 8041.15Smrg done 8051.15Smrg 8061.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 8071.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 8081.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 8091.15Smrg if [ -s $OUTPUT ] ; then 8101.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 8111.28Slukem cat $OUTPUT >> $ERR 8121.28Slukem printf "\n" >> $ERR 8131.9Scgd fi 8141.9Scgd 8151.15Smrg # Display any changes in the device file list. 8161.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 8171.15Smrg if [ -s $TMP1 ] ; then 8181.67Slukem file=$work_dir/device 8191.67Slukem migrate_file "$backup_dir/device" "$file" 8201.67Slukem CUR=${file}.current 8211.67Slukem BACK=${file}.backup 8221.15Smrg 8231.15Smrg if [ -s $CUR ] ; then 8241.15Smrg if cmp -s $CUR $TMP1 ; then 8251.15Smrg : 8261.15Smrg else 8271.15Smrg > $TMP2 8281.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 8291.15Smrg if [ -s $OUTPUT ] ; then 8301.28Slukem printf "Device additions:\n" >> $ERR 8311.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 8321.28Slukem printf "\n" >> $ERR 8331.15Smrg fi 8341.15Smrg 8351.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 8361.15Smrg if [ -s $OUTPUT ] ; then 8371.28Slukem printf "Device deletions:\n" >> $ERR 8381.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 8391.28Slukem printf "\n" >> $ERR 8401.15Smrg fi 8411.15Smrg 8421.27Slukem # Report any block device change. Ignore 8431.27Slukem # character devices, only the name is 8441.27Slukem # significant. 8451.15Smrg cat $TMP2 $CUR $TMP1 | \ 8461.27Slukem sed -e '/^c/d' | \ 8471.27Slukem sort -k11 | \ 8481.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 8491.27Slukem uniq -u > $OUTPUT 8501.15Smrg if [ -s $OUTPUT ] ; then 8511.28Slukem printf "Block device changes:\n" >> $ERR 8521.28Slukem column -t $OUTPUT >> $ERR 8531.28Slukem printf "\n" >> $ERR 8541.15Smrg fi 8551.9Scgd 8561.52Satatat backup_file update $TMP1 $CUR $BACK 8571.9Scgd fi 8581.15Smrg else 8591.28Slukem printf "Device additions:\n" >> $ERR 8601.28Slukem column -t $TMP1 >> $ERR 8611.28Slukem printf "\n" >> $ERR 8621.52Satatat backup_file add $TMP1 $CUR $BACK >> $ERR 8631.9Scgd fi 8641.28Slukem fi 8651.28Slukem if [ -s $ERR ] ; then 8661.28Slukem printf "\nChecking setuid files and devices:\n" 8671.28Slukem cat $ERR 8681.28Slukem printf "\n" 8691.9Scgd fi 8701.9Scgdfi 8711.9Scgd 8721.9Scgd# Check special files. 8731.9Scgd# Check system binaries. 8741.9Scgd# 8751.9Scgd# Create the mtree tree specifications using: 8761.67Slukem# mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure 8771.38Skleink# chown root:wheel DIR.secure 8781.67Slukem# chmod u+r,go= DIR.secure 8791.9Scgd# 8801.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 8811.9Scgd# the hacker can modify the tree specification to match the replaced binary. 8821.9Scgd# For details on really protecting yourself against modified binaries, see 8831.9Scgd# the mtree(8) manual page. 8841.32Slukem# 8851.31Slukemif checkyesno check_mtree; then 8861.82Sjhawk if checkyesno check_mtree_follow_symlinks; then 8871.82Sjhawk check_mtree_flags="-L" 8881.82Sjhawk else 8891.82Sjhawk check_mtree_flags="" 8901.82Sjhawk fi 8911.91Slukem mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 | 8921.87Sjhawk grep -v '^mtree: dev/tty: Device not configured$' >&2 8931.15Smrg if [ -s $OUTPUT ]; then 8941.9Scgd printf "\nChecking special files and directories.\n" 8951.9Scgd cat $OUTPUT 8961.9Scgd fi 8971.9Scgd 8981.16Smikel for file in /etc/mtree/*.secure; do 8991.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 9001.109Schristos tree=$(sed -n -e '3s/.* //p' -e 3q $file) 9011.82Sjhawk mtree $check_mtree_flags -f $file -p $tree > $TMP1 9021.9Scgd if [ -s $TMP1 ]; then 9031.67Slukem printf "\nChecking $tree:\n" 9041.67Slukem cat $TMP1 9051.9Scgd fi 9061.67Slukem done > $OUTPUT 9071.15Smrg if [ -s $OUTPUT ]; then 9081.9Scgd printf "\nChecking system binaries:\n" 9091.9Scgd cat $OUTPUT 9101.9Scgd fi 9111.9Scgdfi 9121.9Scgd 9131.32Slukem# Backup disklabels of available disks 9141.32Slukem# 9151.32Slukemif checkyesno check_disklabels; then 9161.67Slukem # migrate old disklabels 9171.109Schristos for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \ 9181.109Schristos $backup_dir/disklabel.* 2>/dev/null); do 9191.67Slukem migrate_file "$file" "$work_dir/${file##*/}" 9201.67Slukem done 9211.67Slukem 9221.116Sapb # generate list of old disklabels, fdisks & wedges, 9231.116Sapb # and remove them 9241.116Sapb ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* \ 9251.116Sapb 2>/dev/null | 9261.52Satatat egrep -v '\.(backup|current)(,v)?$' > $LABELS 9271.32Slukem xargs rm < $LABELS 9281.32Slukem 9291.122Smlelstv disks="$(/sbin/sysctl -n hw.iostatnames)" 9301.117Schristos 9311.117Schristos # generate disklabels of all disks excluding: cd fd md dk st 9321.117Schristos # nfs and "device" (the header of iostat) 9331.32Slukem for i in $disks; do 9341.117Schristos case $i in 9351.122Smlelstv [cfm]d[0-9]*|dk[0-9]*|st[0-9]*|nfs[0-9]*) 9361.117Schristos ;; 9371.117Schristos *) 9381.120Spgoyette if disklabel $i > /dev/null 2>&1; then 9391.117Schristos disklabel $i > "$work_dir/disklabel.$i" 9401.117Schristos fi 9411.117Schristos ;; 9421.117Schristos esac 9431.32Slukem done 9441.32Slukem 9451.67Slukem # if fdisk is available, generate fdisks for: ed ld sd wd 9461.67Slukem if [ -x /sbin/fdisk ]; then 9471.67Slukem for i in $disks; do 9481.117Schristos case $i in 9491.117Schristos [elsw]d[0-9]*) 9501.117Schristos /sbin/fdisk $i > "$work_dir/fdisk.$i" \ 9511.117Schristos 2>/dev/null 9521.117Schristos ;; 9531.117Schristos esac 9541.67Slukem done 9551.67Slukem fi 9561.67Slukem 9571.116Sapb # if dkctl is available, generate dkctl listwedges 9581.116Sapb # for: ed ld sd wd cgd ofdisk ra rl raid 9591.103Stron if [ -x /sbin/dkctl ]; then 9601.103Stron for i in $disks; do 9611.117Schristos case $i in 9621.117Schristos [elsw]d[0-9]*|cgd[0-9]*|ofdisk[0-9]*|r[al][0-9]*|raid[0-9]*) 9631.122Smlelstv if /sbin/dkctl $i listwedges | 9641.122Smlelstv grep -qe '[0-9] wedges:'; then 9651.117Schristos /sbin/dkctl $i listwedges \ 9661.117Schristos > "$work_dir/wedges.$i" 2>/dev/null 9671.117Schristos fi 9681.117Schristos ;; 9691.117Schristos esac 9701.103Stron done 9711.103Stron fi 9721.103Stron 9731.121Sriastrad # if raidctl is available, generate raidctls for: raid 9741.121Sriastrad if [ -x /sbin/raidctl ]; then 9751.121Sriastrad disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^raid/ { print $1; }') 9761.121Sriastrad for i in $disks; do 9771.121Sriastrad /sbin/raidctl -G $i > "$work_dir/raidconf.$i" \ 9781.121Sriastrad 2>/dev/null 9791.121Sriastrad done 9801.121Sriastrad fi 9811.121Sriastrad 9821.103Stron # append list of new disklabels, fdisks and wedges 9831.116Sapb ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* \ 9841.121Sriastrad $work_dir/raidconf.* 2>/dev/null | 9851.52Satatat egrep -v '\.(backup|current)(,v)?$' >> $LABELS 9861.62Satatat CHANGELIST="$LABELS $CHANGELIST" 9871.62Satatatfi 9881.62Satatat 9891.106Shaadif checkyesno check_lvm; then 9901.118Suebayasi # generate list of existing LVM elements Physical Volumes, 9911.118Suebayasi # Volume Groups and Logical Volumes. 9921.118Suebayasi if [ -x /sbin/lvm ]; then 9931.118Suebayasi lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null 9941.118Suebayasi lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null 9951.118Suebayasi lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null 9961.118Suebayasi fi 9971.118Suebayasi ls -1d $work_dir/lvm.* 2>/dev/null | 9981.118Suebayasi egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS 9991.118Suebayasi CHANGELIST="$CHANGELIST $LVM_LABELS" 10001.106Shaadfi 10011.106Shaad 10021.62Satatat# Check for changes in the list of installed pkgs 10031.62Satatat# 10041.108Sjmmvif checkyesno check_pkgs && have_pkgs; then 10051.67Slukem pkgs=$work_dir/pkgs 10061.67Slukem migrate_file "$backup_dir/pkgs" "$pkgs" 10071.112Sagc pkg_dbdir=$(${pkg_admin} config-var PKG_DBDIR) 10081.127Swiz : ${pkg_dbdir:=/usr/pkg/pkgdb} 10091.108Sjmmv ( cd $pkg_dbdir 10101.104Sadrianp $pkg_info | sort 10111.62Satatat echo "" 10121.62Satatat find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 | 10131.72Slukem xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,' 10141.62Satatat ) > $pkgs 10151.67Slukem echo "$pkgs" > $PKGS 10161.62Satatat CHANGELIST="$PKGS $CHANGELIST" 10171.32Slukemfi 10181.32Slukem 10191.67Slukem# List of files that get backed up and checked for any modifications. 10201.9Scgd# Any changes cause the files to rotate. 10211.32Slukem# 10221.67Slukemif checkyesno check_changelist ; then 10231.91Slukem mtree -D -k type -f $SPECIALSPEC -E exclude | 10241.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES 10251.67Slukem 10261.75Slukem ( 10271.68Slukem # Add other files which might dynamically exist: 10281.67Slukem # /etc/ifconfig.* 10291.67Slukem # /etc/raid*.conf 10301.68Slukem # /etc/rc.d/* 10311.67Slukem # /etc/rc.conf.d/* 10321.68Slukem # 10331.75Slukem echo "/etc/ifconfig.*" 10341.75Slukem echo "/etc/raid*.conf" 10351.75Slukem echo "/etc/rc.d/*" 10361.75Slukem echo "/etc/rc.conf.d/*" 10371.106Shaad echo "/etc/lvm/backup/*" 10381.106Shaad echo "/etc/lvm/archive/*" 10391.67Slukem 10401.68Slukem # Add /etc/changelist 10411.68Slukem # 10421.75Slukem if [ -s /etc/changelist ]; then 10431.75Slukem grep -v '^#' /etc/changelist 10441.75Slukem fi 10451.75Slukem ) | while read file; do 10461.75Slukem case "$file" in 10471.75Slukem *[\*\?\[]*) # If changelist line is a glob ... 10481.75Slukem # ... expand possible backup files 10491.75Slukem # 10501.125Suwe ls -1d $backup_dir/${file}.current 2>/dev/null \ 10511.75Slukem | sed "s,^$backup_dir/,, ; s,\.current$,," 10521.118Suebayasi 10531.75Slukem # ... expand possible files 10541.75Slukem # 10551.125Suwe ls -1d $file 2>/dev/null 10561.75Slukem ;; 10571.75Slukem *) 10581.75Slukem # Otherwise, just print the filename 10591.75Slukem echo $file 10601.75Slukem ;; 10611.75Slukem esac 10621.75Slukem done >> $CHANGEFILES 10631.67Slukem CHANGELIST="$CHANGEFILES $CHANGELIST" 10641.67Slukemfi 10651.67Slukem 10661.126Sriastrad# Save entropy to ${random_file} if defined, like 10671.126Sriastrad# /etc/rc.d/random_seed. 10681.126Sriastrad# 10691.126Sriastradif [ -n "${random_file:-}" ]; then 10701.126Sriastrad rndctl -S "$random_file" 10711.126Sriastradfi 10721.126Sriastrad 10731.67Slukem# Special case backups, including the master password file and 10741.67Slukem# ssh private host keys. The normal backup mechanisms for 10751.67Slukem# $check_changelist (see below) also print out the actual file 10761.67Slukem# differences and we don't want to do that for these files 10771.67Slukem# 10781.67Slukemecho $MP > $TMP1 # always add /etc/master.passwd 10791.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff | 10801.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1 10811.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2 10821.68Slukem 10831.69Slukemwhile read file; do 10841.67Slukem backup_and_diff "$file" no 10851.69Slukemdone < $TMP2 10861.67Slukem 10871.32Slukem 10881.32Slukemif [ -n "$CHANGELIST" ]; then 10891.73Slukem grep -h -v '^$' $CHANGELIST | sort -u > $TMP1 10901.68Slukem comm -23 $TMP1 $TMP2 | while read file; do 10911.67Slukem backup_and_diff "$file" yes 10921.9Scgd done 10931.44Sadfi 10941.44Sad 10951.108Sjmmvif have_pkgs; then 10961.107Sjmmv if checkyesno check_pkg_vulnerabilities; then 10971.112Sagc ${pkg_admin} ${_compat_K_flag} audit >${OUTPUT} 2>&1 10981.107Sjmmv if [ -s ${OUTPUT} ]; then 10991.107Sjmmv printf "\nInstalled vulnerable packages:\n" 11001.107Sjmmv cat ${OUTPUT} 11011.107Sjmmv fi 11021.107Sjmmv fi 11031.107Sjmmv 11041.107Sjmmv if checkyesno check_pkg_signatures; then 11051.112Sagc ${pkg_admin} ${_compat_K_flag} check >${OUTPUT} 2>&1 11061.107Sjmmv if [ $? -ne 0 ]; then 11071.107Sjmmv printf "\nFiles with invalid signatures:\n" 11081.107Sjmmv cat ${OUTPUT} 11091.107Sjmmv fi 11101.107Sjmmv fi 11111.107Sjmmvfi 11121.107Sjmmv 11131.44Sadif [ -f /etc/security.local ]; then 11141.90Skim . /etc/security.local > $OUTPUT 2>&1 11151.84Sjhawk if [ -s $OUTPUT ] ; then 11161.84Sjhawk printf "\nRunning /etc/security.local:\n" 11171.84Sjhawk cat $OUTPUT 11181.84Sjhawk fi 11191.9Scgdfi 1120