11.1Scgd#!/bin/sh - 21.1Scgd# 31.132She# $NetBSD: security,v 1.132 2024/07/21 14:56:16 he 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.131Smartin if [ "$(sysctl -n kern.entropy.needed)" != 0 ]; then 1991.128Sriastrad printf '\n' 2001.128Sriastrad printf 'Entropy:\n' 2011.128Sriastrad printf 'System may need more entropy for cryptography.\n' 2021.128Sriastrad printf 'See the entropy(7) man page for details.\n' 2031.128Sriastrad fi 2041.128Sriastradfi 2051.128Sriastrad 2061.128Sriastrad 2071.9Scgd# Check the master password file syntax. 2081.32Slukem# 2091.31Slukemif checkyesno check_passwd; then 2101.118Suebayasi # XXX: the sense of permit_star is reversed; the code works as 2111.118Suebayasi # implemented, but usage needs to be negated. 2121.81Sjhawk checkyesno check_passwd_permit_star && permit_star=0 || permit_star=1 2131.94Sjdolecek checkyesno check_passwd_permit_nonalpha \ 2141.94Sjdolecek && permit_nonalpha=1 || permit_nonalpha=0 2151.94Sjdolecek 2161.81Sjhawk awk -v "len=$max_loginlen" \ 2171.81Sjhawk -v "nowarn_shells_list=$check_passwd_nowarn_shells" \ 2181.81Sjhawk -v "nowarn_users_list=$check_passwd_nowarn_users" \ 2191.94Sjdolecek -v "permit_star=$permit_star" \ 2201.94Sjdolecek -v "permit_nonalpha=$permit_nonalpha" \ 2211.94Sjdolecek ' 2221.25Slukem BEGIN { 2231.25Slukem while ( getline < "/etc/shells" > 0 ) { 2241.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 2251.25Slukem continue; 2261.25Slukem shells[$1]++; 2271.25Slukem } 2281.81Sjhawk split(nowarn_shells_list, a); 2291.81Sjhawk for (i in a) nowarn_shells[a[i]]++; 2301.81Sjhawk split(nowarn_users_list, a); 2311.81Sjhawk for (i in a) nowarn_users[a[i]]++; 2321.81Sjhawk uid0_users_list="root toor" 2331.81Sjhawk split(uid0_users_list, a); 2341.81Sjhawk for (i in a) uid0_users[a[i]]++; 2351.25Slukem FS=":"; 2361.25Slukem } 2371.25Slukem 2381.25Slukem { 2391.15Smrg if ($0 ~ /^[ ]*$/) { 2401.25Slukem printf "Line %d is a blank line.\n", NR; 2411.15Smrg next; 2421.15Smrg } 2431.105Sdholland 2441.105Sdholland # NIS compat entry? 2451.105Sdholland compatline = $1 ~ "^[\\+-]"; 2461.105Sdholland if (compatline) { 2471.105Sdholland if ($1 == "+" && NF == 1) { 2481.105Sdholland next; 2491.105Sdholland } 2501.105Sdholland sub("^.", "", $1); 2511.105Sdholland } 2521.105Sdholland if (NF != 10) 2531.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 2541.105Sdholland if (compatline) { 2551.105Sdholland if ($3 == 0) 2561.81Sjhawk printf "Line %d includes entries with uid 0.\n", 2571.81Sjhawk NR; 2581.105Sdholland if ($1 == "") 2591.105Sdholland next; 2601.34Sabs } 2611.94Sjdolecek if (!permit_nonalpha && 2621.95Speter $1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 2631.25Slukem printf "Login %s has non-alphanumeric characters.\n", 2641.25Slukem $1; 2651.34Sabs if (length($1) > len) 2661.81Sjhawk printf "Login %s has more than "len" characters.\n", 2671.81Sjhawk $1; 2681.105Sdholland if ($2 == "" && !compatline && !nowarn_users[$1]) 2691.81Sjhawk printf "Login %s has no password.\n", $1; 2701.81Sjhawk if (!nowarn_shells[$10] && !nowarn_users[$1]) { 2711.81Sjhawk if (length($2) != 13 && 2721.81Sjhawk length($2) != 20 && 2731.81Sjhawk $2 !~ /^\$1/ && 2741.81Sjhawk $2 !~ /^\$2/ && 2751.99Sjmcneill $2 !~ /^\$sha1/ && 2761.129Snia $2 !~ /^\$argon2(i|d|id)/ && 2771.81Sjhawk $2 != "" && 2781.81Sjhawk (permit_star || $2 != "*") && 2791.81Sjhawk $2 !~ /^\*[A-z-]+$/ && 2801.81Sjhawk $1 != "toor") { 2811.81Sjhawk if ($10 == "" || shells[$10]) 2821.81Sjhawk printf "Login %s is off but still has "\ 2831.81Sjhawk "a valid shell (%s)\n", $1, $10; 2841.105Sdholland } else if (compatline && $10 == "") { 2851.105Sdholland # nothing 2861.81Sjhawk } else if (! shells[$10]) 2871.81Sjhawk printf "Login %s does not have a valid "\ 2881.81Sjhawk "shell (%s)\n", $1, $10; 2891.81Sjhawk } 2901.81Sjhawk if ($3 == 0 && !uid0_users[$1] && !nowarn_users[$1]) 2911.25Slukem printf "Login %s has a user id of 0.\n", $1; 2921.105Sdholland if ($3 != "" && $3 < 0) 2931.25Slukem printf "Login %s has a negative user id.\n", $1; 2941.105Sdholland if ($4 != "" && $4 < 0) 2951.25Slukem printf "Login %s has a negative group id.\n", $1; 2961.15Smrg }' < $MP > $OUTPUT 2971.15Smrg if [ -s $OUTPUT ] ; then 2981.15Smrg printf "\nChecking the $MP file:\n" 2991.15Smrg cat $OUTPUT 3001.15Smrg fi 3011.15Smrg 3021.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 3031.15Smrg if [ -s $OUTPUT ] ; then 3041.15Smrg printf "\n$MP has duplicate user names.\n" 3051.15Smrg column $OUTPUT 3061.15Smrg fi 3071.15Smrg 3081.111Sspz awk -v "permit_dups_list=$check_passwd_permit_dups" \ 3091.111Sspz ' 3101.111Sspz BEGIN { 3111.111Sspz split(permit_dups_list, a); 3121.111Sspz for (i in a) permit_dups[a[i]]++; 3131.111Sspz } 3141.111Sspz { 3151.111Sspz if (!permit_dups[$1]) 3161.111Sspz print $2; 3171.111Sspz }' < $MPBYUID | uniq -d > $TMP2 3181.15Smrg if [ -s $TMP2 ] ; then 3191.111Sspz printf "\n$MP has duplicate user ids.\n" 3201.15Smrg while read uid; do 3211.28Slukem grep -w $uid $MPBYUID 3221.15Smrg done < $TMP2 | column 3231.15Smrg fi 3241.9Scgdfi 3251.9Scgd 3261.9Scgd# Check the group file syntax. 3271.32Slukem# 3281.31Slukemif checkyesno check_group; then 3291.15Smrg GRP=/etc/group 3301.49Sjdolecek awk -F: -v "len=$max_grouplen" '{ 3311.15Smrg if ($0 ~ /^[ ]*$/) { 3321.25Slukem printf "Line %d is a blank line.\n", NR; 3331.15Smrg next; 3341.15Smrg } 3351.34Sabs if (NF != 4 && ($1 != "+" || NF != 1)) 3361.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 3371.34Sabs if ($1 == "+" ) { 3381.34Sabs next; 3391.34Sabs } 3401.95Speter if ($1 !~ /^[_A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])*$/) 3411.25Slukem printf "Group %s has non-alphanumeric characters.\n", 3421.25Slukem $1; 3431.49Sjdolecek if (length($1) > len) 3441.49Sjdolecek printf "Group %s has more than "len" characters.\n", $1; 3451.15Smrg if ($3 !~ /[0-9]*/) 3461.25Slukem printf "Login %s has a negative group id.\n", $1; 3471.15Smrg }' < $GRP > $OUTPUT 3481.15Smrg if [ -s $OUTPUT ] ; then 3491.15Smrg printf "\nChecking the $GRP file:\n" 3501.15Smrg cat $OUTPUT 3511.15Smrg fi 3521.15Smrg 3531.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 3541.114Sspz dupgroups="" 3551.114Sspz for group in $(cat $OUTPUT) ; do 3561.116Sapb gcount=$(awk -F: "/$group/ { print \$1,\$3 }" $GRP | 3571.116Sapb sort -u | wc -l) 3581.114Sspz if [ $gcount -gt 1 ]; then 3591.114Sspz dupgroups="$dupgroups $group" 3601.114Sspz fi 3611.114Sspz done 3621.132She if [ ! -z "$dupgroups" ] ; then 3631.15Smrg printf "\n$GRP has duplicate group names.\n" 3641.114Sspz printf "$dupgroups\n" 3651.15Smrg fi 3661.9Scgdfi 3671.9Scgd 3681.9Scgd# Check for root paths, umask values in startup files. 3691.9Scgd# The check for the root paths is problematical -- it's likely to fail 3701.9Scgd# in other environments. Once the shells have been modified to warn 3711.9Scgd# of '.' in the path, the path tests should go away. 3721.32Slukem# 3731.31Slukemif checkyesno check_rootdotfiles; then 3741.67Slukem rhome=~root 3751.15Smrg umaskset=no 3761.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 3771.15Smrg for i in $list ; do 3781.15Smrg if [ -f $i ] ; then 3791.67Slukem if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; 3801.67Slukem then 3811.15Smrg umaskset=yes 3821.15Smrg fi 3831.63Slukem # Double check the umask value itself; ensure that 3841.67Slukem # both the group and other write bits are set. 3851.67Slukem # 3861.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 3871.63Slukem awk '{ 3881.67Slukem if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) { 3891.80Swiz print "\tRoot umask is group writable" 3901.63Slukem } 3911.67Slukem if ($2 ~ /[^2367]$/) { 3921.80Swiz print "\tRoot umask is other writable" 3931.63Slukem } 3941.67Slukem }' | sort -u 3951.26Slukem SAVE_PATH=$PATH 3961.26Slukem unset PATH 3971.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 3981.15Smrg source $i 3991.15Smrg /bin/ls -ldgT \$path > $TMP1 4001.9Scgdend-of-csh 4011.76Satatat export PATH=$SAVE_PATH 4021.15Smrg awk '{ 4031.15Smrg if ($10 ~ /^\.$/) { 4041.27Slukem print "\tThe root path includes ."; 4051.15Smrg next; 4061.15Smrg } 4071.15Smrg } 4081.15Smrg $1 ~ /^d....w/ \ 4091.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4101.15Smrg $1 ~ /^d.......w/ \ 4111.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4121.67Slukem < $TMP1 4131.15Smrg fi 4141.67Slukem done > $OUTPUT 4151.124Skre if [ $umaskset = no ] || [ -s $OUTPUT ] ; then 4161.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 4171.15Smrg if [ -s $OUTPUT ]; then 4181.15Smrg cat $OUTPUT 4191.15Smrg fi 4201.123Skre if [ $umaskset = no ] ; then 4211.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 4221.15Smrg fi 4231.9Scgd fi 4241.9Scgd 4251.15Smrg umaskset=no 4261.23Slukem list="/etc/profile ${rhome}/.profile" 4271.15Smrg for i in $list; do 4281.15Smrg if [ -f $i ] ; then 4291.15Smrg if egrep umask $i > /dev/null ; then 4301.15Smrg umaskset=yes 4311.15Smrg fi 4321.15Smrg egrep umask $i | 4331.67Slukem awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \ 4341.80Swiz { print "\tRoot umask is group writable" } \ 4351.67Slukem $2 ~ /[^2367]$/ \ 4361.80Swiz { print "\tRoot umask is other writable" }' 4371.26Slukem SAVE_PATH=$PATH 4381.26Slukem unset PATH 4391.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 4401.15Smrg . $i 4411.110Schristos list=\$(echo \$PATH | /usr/bin/sed -e \ 4421.110Schristos 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g') 4431.15Smrg /bin/ls -ldgT \$list > $TMP1 4441.9Scgdend-of-sh 4451.76Satatat export PATH=$SAVE_PATH 4461.15Smrg awk '{ 4471.15Smrg if ($10 ~ /^\.$/) { 4481.27Slukem print "\tThe root path includes ."; 4491.15Smrg next; 4501.15Smrg } 4511.15Smrg } 4521.15Smrg $1 ~ /^d....w/ \ 4531.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4541.15Smrg $1 ~ /^d.......w/ \ 4551.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4561.67Slukem < $TMP1 4571.9Scgd 4581.15Smrg fi 4591.67Slukem done > $OUTPUT 4601.123Skre if [ $umaskset = no ] || [ -s $OUTPUT ] ; then 4611.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 4621.15Smrg if [ -s $OUTPUT ]; then 4631.15Smrg cat $OUTPUT 4641.15Smrg fi 4651.123Skre if [ $umaskset = no ] ; then 4661.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 4671.15Smrg fi 4681.9Scgd fi 4691.9Scgdfi 4701.9Scgd 4711.9Scgd# Root and uucp should both be in /etc/ftpusers. 4721.32Slukem# 4731.31Slukemif checkyesno check_ftpusers; then 4741.109Schristos list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID) 4751.27Slukem for i in $list; do 4761.29Slukem if /usr/libexec/ftpd -C $i ; then 4771.67Slukem printf "\t$i is not denied\n" 4781.27Slukem fi 4791.67Slukem done > $OUTPUT 4801.28Slukem if [ -s $OUTPUT ]; then 4811.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 4821.28Slukem cat $OUTPUT 4831.28Slukem fi 4841.9Scgdfi 4851.9Scgd 4861.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 4871.32Slukem# 4881.31Slukemif checkyesno check_aliases; then 4891.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 4901.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 4911.43Sitojun printf "\nEntry for uudecode in $f file.\n" 4921.43Sitojun fi 4931.43Sitojun done 4941.9Scgdfi 4951.9Scgd 4961.9Scgd# Files that should not have + signs. 4971.32Slukem# 4981.31Slukemif checkyesno check_rhosts; then 4991.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 5001.15Smrg for f in $list ; do 5011.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 5021.15Smrg printf "\nPlus sign in $f file.\n" 5031.15Smrg fi 5041.15Smrg done 5051.15Smrg 5061.15Smrg # Check for special users with .rhosts files. Only root and toor should 5071.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 5081.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 5091.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 5101.20Smycroft { print $1 " " $9 }' $MP | 5111.19Smycroft sort -k2 | 5121.15Smrg while read uid homedir; do 5131.15Smrg if [ -f ${homedir}/.rhosts ] ; then 5141.109Schristos rhost=$(ls -ldgT ${homedir}/.rhosts) 5151.46Schristos printf -- "$uid: $rhost\n" 5161.15Smrg fi 5171.15Smrg done > $OUTPUT 5181.15Smrg if [ -s $OUTPUT ] ; then 5191.15Smrg printf "\nChecking for special users with .rhosts files.\n" 5201.15Smrg cat $OUTPUT 5211.15Smrg fi 5221.15Smrg 5231.15Smrg while read uid homedir; do 5241.123Skre if [ -f ${homedir}/.rhosts ] && 5251.123Skre [ -r ${homedir}/.rhosts ] && 5261.123Skre cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null 5271.123Skre then 5281.46Schristos printf -- "$uid: + in .rhosts file.\n" 5291.15Smrg fi 5301.29Slukem done < $MPBYPATH > $OUTPUT 5311.15Smrg if [ -s $OUTPUT ] ; then 5321.15Smrg printf "\nChecking .rhosts files syntax.\n" 5331.15Smrg cat $OUTPUT 5341.15Smrg fi 5351.9Scgdfi 5361.9Scgd 5371.9Scgd# Check home directories. Directories should not be owned by someone else 5381.80Swiz# or writable. 5391.32Slukem# 5401.31Slukemif checkyesno check_homes; then 5411.85Sjhawk checkyesno check_homes_permit_usergroups && \ 5421.85Sjhawk permit_usergroups=1 || permit_usergroups=0 5431.15Smrg while read uid homedir; do 5441.15Smrg if [ -d ${homedir}/ ] ; then 5451.109Schristos file=$(ls -ldgT ${homedir}) 5461.46Schristos printf -- "$uid $file\n" 5471.9Scgd fi 5481.29Slukem done < $MPBYPATH | 5491.115Sspz awk -v "usergroups=$permit_usergroups" \ 5501.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 5511.115Sspz BEGIN { 5521.115Sspz split(permit_owners_list, a); 5531.115Sspz for (i in a) permit_owners[a[i]]++; 5541.115Sspz } 5551.115Sspz $1 != $4 && $4 != "root" && !permit_owners[$1] \ 5561.15Smrg { print "user " $1 " home directory is owned by " $4 } 5571.101Sjnemeth $2 ~ /^d....w/ && (!usergroups || $5 != $1) \ 5581.80Swiz { print "user " $1 " home directory is group writable" } 5591.101Sjnemeth $2 ~ /^d.......w/ \ 5601.80Swiz { print "user " $1 " home directory is other writable" }' \ 5611.27Slukem > $OUTPUT 5621.15Smrg if [ -s $OUTPUT ] ; then 5631.15Smrg printf "\nChecking home directories.\n" 5641.15Smrg cat $OUTPUT 5651.15Smrg fi 5661.15Smrg 5671.15Smrg # Files that should not be owned by someone else or readable. 5681.67Slukem list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity" 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.115Sspz awk -v "usergroups=$permit_usergroups" \ 5781.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 5791.115Sspz BEGIN { 5801.115Sspz split(permit_owners_list, a); 5811.115Sspz for (i in a) permit_owners[a[i]]++; 5821.115Sspz } 5831.115Sspz $1 != $5 && $5 != "root" && !permit_owners[$1] \ 5841.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5851.85Sjhawk $3 ~ /^-...r/ && (!usergroups || $6 != $1) \ 5861.15Smrg { print "user " $1 " " $2 " file is group readable" } 5871.15Smrg $3 ~ /^-......r/ \ 5881.15Smrg { print "user " $1 " " $2 " file is other readable" } 5891.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5901.80Swiz { print "user " $1 " " $2 " file is group writable" } 5911.15Smrg $3 ~ /^-.......w/ \ 5921.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5931.27Slukem > $OUTPUT 5941.15Smrg 5951.80Swiz # Files that should not be owned by someone else or writable. 5961.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 5971.79Selric .cshrc .emacs .exrc .forward .history .k5login .klogin .login \ 5981.79Selric .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \ 5991.79Selric .twmrc .xinitrc .xsession .ssh/authorized_keys \ 6001.79Selric .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \ 6011.79Selric .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \ 6021.79Selric .ssh/known_hosts2" 6031.15Smrg while read uid homedir; do 6041.15Smrg for f in $list ; do 6051.15Smrg file=${homedir}/${f} 6061.15Smrg if [ -f $file ] ; then 6071.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 6081.15Smrg fi 6091.15Smrg done 6101.29Slukem done < $MPBYPATH | 6111.115Sspz awk -v "usergroups=$permit_usergroups" \ 6121.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 6131.115Sspz BEGIN { 6141.115Sspz split(permit_owners_list, a); 6151.115Sspz for (i in a) permit_owners[a[i]]++; 6161.115Sspz } 6171.115Sspz $1 != $5 && $5 != "root" && !permit_owners[$1] \ 6181.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 6191.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 6201.80Swiz { print "user " $1 " " $2 " file is group writable" } 6211.15Smrg $3 ~ /^-.......w/ \ 6221.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 6231.27Slukem >> $OUTPUT 6241.15Smrg if [ -s $OUTPUT ] ; then 6251.15Smrg printf "\nChecking dot files.\n" 6261.15Smrg cat $OUTPUT 6271.15Smrg fi 6281.9Scgdfi 6291.9Scgd 6301.9Scgd# Mailboxes should be owned by user and unreadable. 6311.32Slukem# 6321.31Slukemif checkyesno check_varmail; then 6331.86Sjhawk ls -lA /var/mail | \ 6341.63Slukem awk ' NR == 1 { next; } 6351.86Sjhawk $9 ~ /^\./ {next; } 6361.63Slukem $3 != $9 { 6371.63Slukem print "user " $9 " mailbox is owned by " $3 6381.63Slukem } 6391.63Slukem $1 != "-rw-------" { 6401.63Slukem print "user " $9 " mailbox is " $1 ", group " $4 6411.63Slukem }' > $OUTPUT 6421.15Smrg if [ -s $OUTPUT ] ; then 6431.15Smrg printf "\nChecking mailbox ownership.\n" 6441.15Smrg cat $OUTPUT 6451.15Smrg fi 6461.15Smrgfi 6471.15Smrg 6481.32Slukem# NFS exports shouldn't be globally exported 6491.32Slukem# 6501.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 6511.32Slukem awk '{ 6521.22Slukem # ignore comments and blank lines 6531.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 6541.22Slukem next; 6551.100Stron # manage line continuation 6561.100Stron while ($NF ~ /^\\$/) { 6571.100Stron $NF = ""; 6581.100Stron line = $0 ""; 6591.100Stron getline; 6601.100Stron $0 = line $0 ""; 6611.100Stron } 6621.22Slukem 6631.100Stron delete dir; 6641.100Stron readonly = ndir = 0; 6651.100Stron for (i = 1; i <= NF; ++i) { 6661.100Stron if ($i ~ /^\//) dir[ndir++] = $i; 6671.100Stron else if ($i ~ /^-/) { 6681.100Stron if ($i ~ /^-(ro|o)$/) readonly = 1; 6691.100Stron if ($i ~ /^-network/) next; 6701.100Stron } 6711.100Stron else next; 6721.15Smrg } 6731.15Smrg if (readonly) 6741.100Stron for (item in dir) 6751.100Stron rodir[nrodir++] = dir[item]; 6761.15Smrg else 6771.100Stron for (item in dir) 6781.100Stron rwdir[nrwdir++] = dir[item]; 6791.100Stron 6801.100Stron } 6811.100Stron 6821.100Stron END { 6831.100Stron if (nrodir) { 6841.100Stron printf("Globally exported file system%s, read-only:\n", 6851.100Stron nrodir > 1 ? "s" : ""); 6861.100Stron for (item in rodir) 6871.100Stron printf("\t%s\n", rodir[item]); 6881.100Stron } 6891.100Stron if (nrwdir) { 6901.100Stron printf("Globally exported file system%s, read-write:\n", 6911.100Stron nrwdir > 1 ? "s" : ""); 6921.100Stron for (item in rwdir) 6931.100Stron printf("\t%s\n", rwdir[item]); 6941.100Stron } 6951.32Slukem }' < /etc/exports > $OUTPUT 6961.32Slukem if [ -s $OUTPUT ] ; then 6971.15Smrg printf "\nChecking for globally exported file systems.\n" 6981.15Smrg cat $OUTPUT 6991.15Smrg fi 7001.9Scgdfi 7011.9Scgd 7021.9Scgd# Display any changes in setuid files and devices. 7031.32Slukem# 7041.31Slukemif checkyesno check_devices; then 7051.28Slukem > $ERR 7061.92Serh ( 7071.98Slukem 7081.98Slukem # Convert check_devices_ignore_fstypes="foo !bar bax" 7091.98Slukem # into "-fstype foo -o ! -fstype bar -o -fstype bax" 7101.98Slukem # and check_devices_ignore_paths="/foo !/bar /bax" 7111.98Slukem # into " -path /foo -o ! -path /bar -o -path /bax" 7121.98Slukem # 7131.98Slukem ignexpr=$(\ 7141.98Slukem echo $check_devices_ignore_fstypes | \ 7151.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \ 7161.98Slukem echo $check_devices_ignore_paths | \ 7171.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \ 7181.98Slukem ) 7191.98Slukem 7201.98Slukem # Massage the expression into ( $ignexpr ) -a -prune -o 7211.98Slukem if [ -n "${ignexpr}" ]; then 7221.98Slukem ignexpr=$(\ 7231.98Slukem echo $ignexpr | \ 7241.98Slukem sed -e 's/^-o /( /' \ 7251.98Slukem -e 's/$/ ) -a -prune -o/' \ 7261.98Slukem ) 7271.98Slukem fi 7281.98Slukem 7291.98Slukem find / $ignexpr \ 7301.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 7311.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 7321.24Slukem -type b -o -type c \) -print0 | \ 7331.98Slukem xargs -0 ls -ldgTq | sort +9 > $LIST 7341.98Slukem 7351.98Slukem ) 2> $OUTPUT 7361.15Smrg 7371.15Smrg # Display any errors that occurred during system file walk. 7381.15Smrg if [ -s $OUTPUT ] ; then 7391.28Slukem printf "Setuid/device find errors:\n" >> $ERR 7401.28Slukem cat $OUTPUT >> $ERR 7411.28Slukem printf "\n" >> $ERR 7421.15Smrg fi 7431.15Smrg 7441.15Smrg # Display any changes in the setuid file list. 7451.15Smrg egrep -v '^[bc]' $LIST > $TMP1 7461.15Smrg if [ -s $TMP1 ] ; then 7471.15Smrg # Check to make sure uudecode isn't setuid. 7481.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 7491.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 7501.15Smrg fi 7511.15Smrg 7521.67Slukem file=$work_dir/setuid 7531.67Slukem migrate_file "$backup_dir/setuid" "$file" 7541.67Slukem CUR=${file}.current 7551.67Slukem BACK=${file}.backup 7561.15Smrg if [ -s $CUR ] ; then 7571.15Smrg if cmp -s $CUR $TMP1 ; then 7581.15Smrg : 7591.15Smrg else 7601.15Smrg > $TMP2 7611.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 7621.15Smrg if [ -s $OUTPUT ] ; then 7631.28Slukem printf "Setuid additions:\n" >> $ERR 7641.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7651.28Slukem printf "\n" >> $ERR 7661.15Smrg fi 7671.15Smrg 7681.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 7691.15Smrg if [ -s $OUTPUT ] ; then 7701.28Slukem printf "Setuid deletions:\n" >> $ERR 7711.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7721.28Slukem printf "\n" >> $ERR 7731.15Smrg fi 7741.15Smrg 7751.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 7761.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 7771.27Slukem uniq -u > $OUTPUT 7781.15Smrg if [ -s $OUTPUT ] ; then 7791.28Slukem printf "Setuid changes:\n" >> $ERR 7801.28Slukem column -t $OUTPUT >> $ERR 7811.28Slukem printf "\n" >> $ERR 7821.15Smrg fi 7831.9Scgd 7841.52Satatat backup_file update $TMP1 $CUR $BACK 7851.9Scgd fi 7861.15Smrg else 7871.28Slukem printf "Setuid additions:\n" >> $ERR 7881.28Slukem column -t $TMP1 >> $ERR 7891.28Slukem printf "\n" >> $ERR 7901.52Satatat backup_file add $TMP1 $CUR $BACK 7911.9Scgd fi 7921.15Smrg fi 7931.15Smrg 7941.27Slukem # Check for block and character disk devices that are readable or 7951.80Swiz # writable or not owned by root.operator. 7961.15Smrg >$TMP1 7971.61Slukem DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \ 7981.57Ssimonb sd se ss uk up vnd wd xd xy" 7991.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 8001.15Smrg for i in $DISKLIST; do 8011.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 8021.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 8031.15Smrg done 8041.15Smrg 8051.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 8061.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 8071.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 8081.15Smrg if [ -s $OUTPUT ] ; then 8091.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 8101.28Slukem cat $OUTPUT >> $ERR 8111.28Slukem printf "\n" >> $ERR 8121.9Scgd fi 8131.9Scgd 8141.15Smrg # Display any changes in the device file list. 8151.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 8161.15Smrg if [ -s $TMP1 ] ; then 8171.67Slukem file=$work_dir/device 8181.67Slukem migrate_file "$backup_dir/device" "$file" 8191.67Slukem CUR=${file}.current 8201.67Slukem BACK=${file}.backup 8211.15Smrg 8221.15Smrg if [ -s $CUR ] ; then 8231.15Smrg if cmp -s $CUR $TMP1 ; then 8241.15Smrg : 8251.15Smrg else 8261.15Smrg > $TMP2 8271.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 8281.15Smrg if [ -s $OUTPUT ] ; then 8291.28Slukem printf "Device additions:\n" >> $ERR 8301.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 8311.28Slukem printf "\n" >> $ERR 8321.15Smrg fi 8331.15Smrg 8341.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 8351.15Smrg if [ -s $OUTPUT ] ; then 8361.28Slukem printf "Device deletions:\n" >> $ERR 8371.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 8381.28Slukem printf "\n" >> $ERR 8391.15Smrg fi 8401.15Smrg 8411.27Slukem # Report any block device change. Ignore 8421.27Slukem # character devices, only the name is 8431.27Slukem # significant. 8441.15Smrg cat $TMP2 $CUR $TMP1 | \ 8451.27Slukem sed -e '/^c/d' | \ 8461.27Slukem sort -k11 | \ 8471.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 8481.27Slukem uniq -u > $OUTPUT 8491.15Smrg if [ -s $OUTPUT ] ; then 8501.28Slukem printf "Block device changes:\n" >> $ERR 8511.28Slukem column -t $OUTPUT >> $ERR 8521.28Slukem printf "\n" >> $ERR 8531.15Smrg fi 8541.9Scgd 8551.52Satatat backup_file update $TMP1 $CUR $BACK 8561.9Scgd fi 8571.15Smrg else 8581.28Slukem printf "Device additions:\n" >> $ERR 8591.28Slukem column -t $TMP1 >> $ERR 8601.28Slukem printf "\n" >> $ERR 8611.52Satatat backup_file add $TMP1 $CUR $BACK >> $ERR 8621.9Scgd fi 8631.28Slukem fi 8641.28Slukem if [ -s $ERR ] ; then 8651.28Slukem printf "\nChecking setuid files and devices:\n" 8661.28Slukem cat $ERR 8671.28Slukem printf "\n" 8681.9Scgd fi 8691.9Scgdfi 8701.9Scgd 8711.9Scgd# Check special files. 8721.9Scgd# Check system binaries. 8731.9Scgd# 8741.9Scgd# Create the mtree tree specifications using: 8751.67Slukem# mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure 8761.38Skleink# chown root:wheel DIR.secure 8771.67Slukem# chmod u+r,go= DIR.secure 8781.9Scgd# 8791.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 8801.9Scgd# the hacker can modify the tree specification to match the replaced binary. 8811.9Scgd# For details on really protecting yourself against modified binaries, see 8821.9Scgd# the mtree(8) manual page. 8831.32Slukem# 8841.31Slukemif checkyesno check_mtree; then 8851.82Sjhawk if checkyesno check_mtree_follow_symlinks; then 8861.82Sjhawk check_mtree_flags="-L" 8871.82Sjhawk else 8881.82Sjhawk check_mtree_flags="" 8891.82Sjhawk fi 8901.91Slukem mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 | 8911.87Sjhawk grep -v '^mtree: dev/tty: Device not configured$' >&2 8921.15Smrg if [ -s $OUTPUT ]; then 8931.9Scgd printf "\nChecking special files and directories.\n" 8941.9Scgd cat $OUTPUT 8951.9Scgd fi 8961.9Scgd 8971.16Smikel for file in /etc/mtree/*.secure; do 8981.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 8991.109Schristos tree=$(sed -n -e '3s/.* //p' -e 3q $file) 9001.82Sjhawk mtree $check_mtree_flags -f $file -p $tree > $TMP1 9011.9Scgd if [ -s $TMP1 ]; then 9021.67Slukem printf "\nChecking $tree:\n" 9031.67Slukem cat $TMP1 9041.9Scgd fi 9051.67Slukem done > $OUTPUT 9061.15Smrg if [ -s $OUTPUT ]; then 9071.9Scgd printf "\nChecking system binaries:\n" 9081.9Scgd cat $OUTPUT 9091.9Scgd fi 9101.9Scgdfi 9111.9Scgd 9121.32Slukem# Backup disklabels of available disks 9131.32Slukem# 9141.32Slukemif checkyesno check_disklabels; then 9151.67Slukem # migrate old disklabels 9161.109Schristos for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \ 9171.109Schristos $backup_dir/disklabel.* 2>/dev/null); do 9181.67Slukem migrate_file "$file" "$work_dir/${file##*/}" 9191.67Slukem done 9201.67Slukem 9211.116Sapb # generate list of old disklabels, fdisks & wedges, 9221.116Sapb # and remove them 9231.116Sapb ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* \ 9241.116Sapb 2>/dev/null | 9251.52Satatat egrep -v '\.(backup|current)(,v)?$' > $LABELS 9261.32Slukem xargs rm < $LABELS 9271.32Slukem 9281.122Smlelstv disks="$(/sbin/sysctl -n hw.iostatnames)" 9291.117Schristos 9301.117Schristos # generate disklabels of all disks excluding: cd fd md dk st 9311.117Schristos # nfs and "device" (the header of iostat) 9321.32Slukem for i in $disks; do 9331.117Schristos case $i in 9341.122Smlelstv [cfm]d[0-9]*|dk[0-9]*|st[0-9]*|nfs[0-9]*) 9351.117Schristos ;; 9361.117Schristos *) 9371.120Spgoyette if disklabel $i > /dev/null 2>&1; then 9381.117Schristos disklabel $i > "$work_dir/disklabel.$i" 9391.117Schristos fi 9401.117Schristos ;; 9411.117Schristos esac 9421.32Slukem done 9431.32Slukem 9441.67Slukem # if fdisk is available, generate fdisks for: ed ld sd wd 9451.67Slukem if [ -x /sbin/fdisk ]; then 9461.67Slukem for i in $disks; do 9471.117Schristos case $i in 9481.117Schristos [elsw]d[0-9]*) 9491.117Schristos /sbin/fdisk $i > "$work_dir/fdisk.$i" \ 9501.117Schristos 2>/dev/null 9511.117Schristos ;; 9521.117Schristos esac 9531.67Slukem done 9541.67Slukem fi 9551.67Slukem 9561.116Sapb # if dkctl is available, generate dkctl listwedges 9571.116Sapb # for: ed ld sd wd cgd ofdisk ra rl raid 9581.103Stron if [ -x /sbin/dkctl ]; then 9591.103Stron for i in $disks; do 9601.117Schristos case $i in 9611.117Schristos [elsw]d[0-9]*|cgd[0-9]*|ofdisk[0-9]*|r[al][0-9]*|raid[0-9]*) 9621.122Smlelstv if /sbin/dkctl $i listwedges | 9631.122Smlelstv grep -qe '[0-9] wedges:'; then 9641.117Schristos /sbin/dkctl $i listwedges \ 9651.117Schristos > "$work_dir/wedges.$i" 2>/dev/null 9661.117Schristos fi 9671.117Schristos ;; 9681.117Schristos esac 9691.103Stron done 9701.103Stron fi 9711.103Stron 9721.121Sriastrad # if raidctl is available, generate raidctls for: raid 9731.121Sriastrad if [ -x /sbin/raidctl ]; then 9741.121Sriastrad disks=$(iostat -x | awk 'NR > 1 && $1 ~ /^raid/ { print $1; }') 9751.121Sriastrad for i in $disks; do 9761.121Sriastrad /sbin/raidctl -G $i > "$work_dir/raidconf.$i" \ 9771.121Sriastrad 2>/dev/null 9781.121Sriastrad done 9791.121Sriastrad fi 9801.121Sriastrad 9811.103Stron # append list of new disklabels, fdisks and wedges 9821.116Sapb ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* \ 9831.121Sriastrad $work_dir/raidconf.* 2>/dev/null | 9841.52Satatat egrep -v '\.(backup|current)(,v)?$' >> $LABELS 9851.62Satatat CHANGELIST="$LABELS $CHANGELIST" 9861.62Satatatfi 9871.62Satatat 9881.106Shaadif checkyesno check_lvm; then 9891.118Suebayasi # generate list of existing LVM elements Physical Volumes, 9901.118Suebayasi # Volume Groups and Logical Volumes. 9911.118Suebayasi if [ -x /sbin/lvm ]; then 9921.118Suebayasi lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null 9931.118Suebayasi lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null 9941.118Suebayasi lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null 9951.118Suebayasi fi 9961.118Suebayasi ls -1d $work_dir/lvm.* 2>/dev/null | 9971.118Suebayasi egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS 9981.118Suebayasi CHANGELIST="$CHANGELIST $LVM_LABELS" 9991.106Shaadfi 10001.106Shaad 10011.62Satatat# Check for changes in the list of installed pkgs 10021.62Satatat# 10031.108Sjmmvif checkyesno check_pkgs && have_pkgs; then 10041.67Slukem pkgs=$work_dir/pkgs 10051.67Slukem migrate_file "$backup_dir/pkgs" "$pkgs" 10061.112Sagc pkg_dbdir=$(${pkg_admin} config-var PKG_DBDIR) 10071.127Swiz : ${pkg_dbdir:=/usr/pkg/pkgdb} 10081.108Sjmmv ( cd $pkg_dbdir 10091.104Sadrianp $pkg_info | sort 10101.62Satatat echo "" 10111.62Satatat find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 | 10121.72Slukem xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,' 10131.62Satatat ) > $pkgs 10141.67Slukem echo "$pkgs" > $PKGS 10151.62Satatat CHANGELIST="$PKGS $CHANGELIST" 10161.32Slukemfi 10171.32Slukem 10181.67Slukem# List of files that get backed up and checked for any modifications. 10191.9Scgd# Any changes cause the files to rotate. 10201.32Slukem# 10211.67Slukemif checkyesno check_changelist ; then 10221.91Slukem mtree -D -k type -f $SPECIALSPEC -E exclude | 10231.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES 10241.67Slukem 10251.75Slukem ( 10261.68Slukem # Add other files which might dynamically exist: 10271.67Slukem # /etc/ifconfig.* 10281.67Slukem # /etc/raid*.conf 10291.68Slukem # /etc/rc.d/* 10301.67Slukem # /etc/rc.conf.d/* 10311.68Slukem # 10321.75Slukem echo "/etc/ifconfig.*" 10331.75Slukem echo "/etc/raid*.conf" 10341.75Slukem echo "/etc/rc.d/*" 10351.75Slukem echo "/etc/rc.conf.d/*" 10361.106Shaad echo "/etc/lvm/backup/*" 10371.106Shaad echo "/etc/lvm/archive/*" 10381.67Slukem 10391.68Slukem # Add /etc/changelist 10401.68Slukem # 10411.75Slukem if [ -s /etc/changelist ]; then 10421.75Slukem grep -v '^#' /etc/changelist 10431.75Slukem fi 10441.75Slukem ) | while read file; do 10451.75Slukem case "$file" in 10461.75Slukem *[\*\?\[]*) # If changelist line is a glob ... 10471.75Slukem # ... expand possible backup files 10481.75Slukem # 10491.125Suwe ls -1d $backup_dir/${file}.current 2>/dev/null \ 10501.75Slukem | sed "s,^$backup_dir/,, ; s,\.current$,," 10511.118Suebayasi 10521.75Slukem # ... expand possible files 10531.75Slukem # 10541.125Suwe ls -1d $file 2>/dev/null 10551.75Slukem ;; 10561.75Slukem *) 10571.75Slukem # Otherwise, just print the filename 10581.75Slukem echo $file 10591.75Slukem ;; 10601.75Slukem esac 10611.75Slukem done >> $CHANGEFILES 10621.67Slukem CHANGELIST="$CHANGEFILES $CHANGELIST" 10631.67Slukemfi 10641.67Slukem 10651.126Sriastrad# Save entropy to ${random_file} if defined, like 10661.126Sriastrad# /etc/rc.d/random_seed. 10671.126Sriastrad# 10681.126Sriastradif [ -n "${random_file:-}" ]; then 10691.126Sriastrad rndctl -S "$random_file" 10701.126Sriastradfi 10711.126Sriastrad 10721.67Slukem# Special case backups, including the master password file and 10731.67Slukem# ssh private host keys. The normal backup mechanisms for 10741.67Slukem# $check_changelist (see below) also print out the actual file 10751.67Slukem# differences and we don't want to do that for these files 10761.67Slukem# 10771.67Slukemecho $MP > $TMP1 # always add /etc/master.passwd 10781.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff | 10791.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1 10801.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2 10811.68Slukem 10821.69Slukemwhile read file; do 10831.67Slukem backup_and_diff "$file" no 10841.69Slukemdone < $TMP2 10851.67Slukem 10861.32Slukem 10871.32Slukemif [ -n "$CHANGELIST" ]; then 10881.73Slukem grep -h -v '^$' $CHANGELIST | sort -u > $TMP1 10891.68Slukem comm -23 $TMP1 $TMP2 | while read file; do 10901.67Slukem backup_and_diff "$file" yes 10911.9Scgd done 10921.44Sadfi 10931.44Sad 10941.108Sjmmvif have_pkgs; then 10951.107Sjmmv if checkyesno check_pkg_vulnerabilities; then 10961.112Sagc ${pkg_admin} ${_compat_K_flag} audit >${OUTPUT} 2>&1 10971.107Sjmmv if [ -s ${OUTPUT} ]; then 10981.107Sjmmv printf "\nInstalled vulnerable packages:\n" 10991.107Sjmmv cat ${OUTPUT} 11001.107Sjmmv fi 11011.107Sjmmv fi 11021.107Sjmmv 11031.107Sjmmv if checkyesno check_pkg_signatures; then 11041.112Sagc ${pkg_admin} ${_compat_K_flag} check >${OUTPUT} 2>&1 11051.107Sjmmv if [ $? -ne 0 ]; then 11061.107Sjmmv printf "\nFiles with invalid signatures:\n" 11071.107Sjmmv cat ${OUTPUT} 11081.107Sjmmv fi 11091.107Sjmmv fi 11101.107Sjmmvfi 11111.107Sjmmv 11121.44Sadif [ -f /etc/security.local ]; then 11131.90Skim . /etc/security.local > $OUTPUT 2>&1 11141.84Sjhawk if [ -s $OUTPUT ] ; then 11151.84Sjhawk printf "\nRunning /etc/security.local:\n" 11161.84Sjhawk cat $OUTPUT 11171.84Sjhawk fi 11181.9Scgdfi 1119