security revision 1.118
11.1Scgd#!/bin/sh - 21.1Scgd# 31.118Suebayasi# $NetBSD: security,v 1.118 2014/12/13 02:17:35 uebayasi 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.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.118Suebayasi# 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.118Suebayasi # XXX: the sense of permit_star is reversed; the code works as 1981.118Suebayasi # 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.114Sspz dupgroups="" 3411.114Sspz for group in $(cat $OUTPUT) ; do 3421.116Sapb gcount=$(awk -F: "/$group/ { print \$1,\$3 }" $GRP | 3431.116Sapb sort -u | wc -l) 3441.114Sspz if [ $gcount -gt 1 ]; then 3451.114Sspz dupgroups="$dupgroups $group" 3461.114Sspz fi 3471.114Sspz done 3481.114Sspz if [ ! -z $dupgroups ] ; then 3491.15Smrg printf "\n$GRP has duplicate group names.\n" 3501.114Sspz printf "$dupgroups\n" 3511.15Smrg fi 3521.9Scgdfi 3531.9Scgd 3541.9Scgd# Check for root paths, umask values in startup files. 3551.9Scgd# The check for the root paths is problematical -- it's likely to fail 3561.9Scgd# in other environments. Once the shells have been modified to warn 3571.9Scgd# of '.' in the path, the path tests should go away. 3581.32Slukem# 3591.31Slukemif checkyesno check_rootdotfiles; then 3601.67Slukem rhome=~root 3611.15Smrg umaskset=no 3621.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 3631.15Smrg for i in $list ; do 3641.15Smrg if [ -f $i ] ; then 3651.67Slukem if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; 3661.67Slukem then 3671.15Smrg umaskset=yes 3681.15Smrg fi 3691.63Slukem # Double check the umask value itself; ensure that 3701.67Slukem # both the group and other write bits are set. 3711.67Slukem # 3721.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 3731.63Slukem awk '{ 3741.67Slukem if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) { 3751.80Swiz print "\tRoot umask is group writable" 3761.63Slukem } 3771.67Slukem if ($2 ~ /[^2367]$/) { 3781.80Swiz print "\tRoot umask is other writable" 3791.63Slukem } 3801.67Slukem }' | sort -u 3811.26Slukem SAVE_PATH=$PATH 3821.26Slukem unset PATH 3831.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 3841.15Smrg source $i 3851.15Smrg /bin/ls -ldgT \$path > $TMP1 3861.9Scgdend-of-csh 3871.76Satatat export PATH=$SAVE_PATH 3881.15Smrg awk '{ 3891.15Smrg if ($10 ~ /^\.$/) { 3901.27Slukem print "\tThe root path includes ."; 3911.15Smrg next; 3921.15Smrg } 3931.15Smrg } 3941.15Smrg $1 ~ /^d....w/ \ 3951.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 3961.15Smrg $1 ~ /^d.......w/ \ 3971.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 3981.67Slukem < $TMP1 3991.15Smrg fi 4001.67Slukem done > $OUTPUT 4011.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 4021.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 4031.15Smrg if [ -s $OUTPUT ]; then 4041.15Smrg cat $OUTPUT 4051.15Smrg fi 4061.15Smrg if [ $umaskset = "no" ] ; then 4071.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 4081.15Smrg fi 4091.9Scgd fi 4101.9Scgd 4111.15Smrg umaskset=no 4121.23Slukem list="/etc/profile ${rhome}/.profile" 4131.15Smrg for i in $list; do 4141.15Smrg if [ -f $i ] ; then 4151.15Smrg if egrep umask $i > /dev/null ; then 4161.15Smrg umaskset=yes 4171.15Smrg fi 4181.15Smrg egrep umask $i | 4191.67Slukem awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \ 4201.80Swiz { print "\tRoot umask is group writable" } \ 4211.67Slukem $2 ~ /[^2367]$/ \ 4221.80Swiz { print "\tRoot umask is other writable" }' 4231.26Slukem SAVE_PATH=$PATH 4241.26Slukem unset PATH 4251.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 4261.15Smrg . $i 4271.110Schristos list=\$(echo \$PATH | /usr/bin/sed -e \ 4281.110Schristos 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g') 4291.15Smrg /bin/ls -ldgT \$list > $TMP1 4301.9Scgdend-of-sh 4311.76Satatat export PATH=$SAVE_PATH 4321.15Smrg awk '{ 4331.15Smrg if ($10 ~ /^\.$/) { 4341.27Slukem print "\tThe root path includes ."; 4351.15Smrg next; 4361.15Smrg } 4371.15Smrg } 4381.15Smrg $1 ~ /^d....w/ \ 4391.80Swiz { print "\tRoot path directory " $10 " is group writable." } \ 4401.15Smrg $1 ~ /^d.......w/ \ 4411.80Swiz { print "\tRoot path directory " $10 " is other writable." }' \ 4421.67Slukem < $TMP1 4431.9Scgd 4441.15Smrg fi 4451.67Slukem done > $OUTPUT 4461.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 4471.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 4481.15Smrg if [ -s $OUTPUT ]; then 4491.15Smrg cat $OUTPUT 4501.15Smrg fi 4511.15Smrg if [ $umaskset = "no" ] ; then 4521.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 4531.15Smrg fi 4541.9Scgd fi 4551.9Scgdfi 4561.9Scgd 4571.9Scgd# Root and uucp should both be in /etc/ftpusers. 4581.32Slukem# 4591.31Slukemif checkyesno check_ftpusers; then 4601.109Schristos list="uucp "$(awk '$2 == 0 { print $1 }' $MPBYUID) 4611.27Slukem for i in $list; do 4621.29Slukem if /usr/libexec/ftpd -C $i ; then 4631.67Slukem printf "\t$i is not denied\n" 4641.27Slukem fi 4651.67Slukem done > $OUTPUT 4661.28Slukem if [ -s $OUTPUT ]; then 4671.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 4681.28Slukem cat $OUTPUT 4691.28Slukem fi 4701.9Scgdfi 4711.9Scgd 4721.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 4731.32Slukem# 4741.31Slukemif checkyesno check_aliases; then 4751.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 4761.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 4771.43Sitojun printf "\nEntry for uudecode in $f file.\n" 4781.43Sitojun fi 4791.43Sitojun done 4801.9Scgdfi 4811.9Scgd 4821.9Scgd# Files that should not have + signs. 4831.32Slukem# 4841.31Slukemif checkyesno check_rhosts; then 4851.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 4861.15Smrg for f in $list ; do 4871.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 4881.15Smrg printf "\nPlus sign in $f file.\n" 4891.15Smrg fi 4901.15Smrg done 4911.15Smrg 4921.15Smrg # Check for special users with .rhosts files. Only root and toor should 4931.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 4941.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 4951.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 4961.20Smycroft { print $1 " " $9 }' $MP | 4971.19Smycroft sort -k2 | 4981.15Smrg while read uid homedir; do 4991.15Smrg if [ -f ${homedir}/.rhosts ] ; then 5001.109Schristos rhost=$(ls -ldgT ${homedir}/.rhosts) 5011.46Schristos printf -- "$uid: $rhost\n" 5021.15Smrg fi 5031.15Smrg done > $OUTPUT 5041.15Smrg if [ -s $OUTPUT ] ; then 5051.15Smrg printf "\nChecking for special users with .rhosts files.\n" 5061.15Smrg cat $OUTPUT 5071.15Smrg fi 5081.15Smrg 5091.15Smrg while read uid homedir; do 5101.35Sfair if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \ 5111.41Schristos cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then 5121.46Schristos printf -- "$uid: + in .rhosts file.\n" 5131.15Smrg fi 5141.29Slukem done < $MPBYPATH > $OUTPUT 5151.15Smrg if [ -s $OUTPUT ] ; then 5161.15Smrg printf "\nChecking .rhosts files syntax.\n" 5171.15Smrg cat $OUTPUT 5181.15Smrg fi 5191.9Scgdfi 5201.9Scgd 5211.9Scgd# Check home directories. Directories should not be owned by someone else 5221.80Swiz# or writable. 5231.32Slukem# 5241.31Slukemif checkyesno check_homes; then 5251.85Sjhawk checkyesno check_homes_permit_usergroups && \ 5261.85Sjhawk permit_usergroups=1 || permit_usergroups=0 5271.15Smrg while read uid homedir; do 5281.15Smrg if [ -d ${homedir}/ ] ; then 5291.109Schristos file=$(ls -ldgT ${homedir}) 5301.46Schristos printf -- "$uid $file\n" 5311.9Scgd fi 5321.29Slukem done < $MPBYPATH | 5331.115Sspz awk -v "usergroups=$permit_usergroups" \ 5341.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 5351.115Sspz BEGIN { 5361.115Sspz split(permit_owners_list, a); 5371.115Sspz for (i in a) permit_owners[a[i]]++; 5381.115Sspz } 5391.115Sspz $1 != $4 && $4 != "root" && !permit_owners[$1] \ 5401.15Smrg { print "user " $1 " home directory is owned by " $4 } 5411.101Sjnemeth $2 ~ /^d....w/ && (!usergroups || $5 != $1) \ 5421.80Swiz { print "user " $1 " home directory is group writable" } 5431.101Sjnemeth $2 ~ /^d.......w/ \ 5441.80Swiz { print "user " $1 " home directory is other writable" }' \ 5451.27Slukem > $OUTPUT 5461.15Smrg if [ -s $OUTPUT ] ; then 5471.15Smrg printf "\nChecking home directories.\n" 5481.15Smrg cat $OUTPUT 5491.15Smrg fi 5501.15Smrg 5511.15Smrg # Files that should not be owned by someone else or readable. 5521.67Slukem list=".Xauthority .netrc .ssh/id_dsa .ssh/id_rsa .ssh/identity" 5531.15Smrg while read uid homedir; do 5541.15Smrg for f in $list ; do 5551.15Smrg file=${homedir}/${f} 5561.15Smrg if [ -f $file ] ; then 5571.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5581.15Smrg fi 5591.15Smrg done 5601.29Slukem done < $MPBYPATH | 5611.115Sspz awk -v "usergroups=$permit_usergroups" \ 5621.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 5631.115Sspz BEGIN { 5641.115Sspz split(permit_owners_list, a); 5651.115Sspz for (i in a) permit_owners[a[i]]++; 5661.115Sspz } 5671.115Sspz $1 != $5 && $5 != "root" && !permit_owners[$1] \ 5681.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 5691.85Sjhawk $3 ~ /^-...r/ && (!usergroups || $6 != $1) \ 5701.15Smrg { print "user " $1 " " $2 " file is group readable" } 5711.15Smrg $3 ~ /^-......r/ \ 5721.15Smrg { print "user " $1 " " $2 " file is other readable" } 5731.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 5741.80Swiz { print "user " $1 " " $2 " file is group writable" } 5751.15Smrg $3 ~ /^-.......w/ \ 5761.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 5771.27Slukem > $OUTPUT 5781.15Smrg 5791.80Swiz # Files that should not be owned by someone else or writable. 5801.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 5811.79Selric .cshrc .emacs .exrc .forward .history .k5login .klogin .login \ 5821.79Selric .logout .profile .qmail .rc_history .rhosts .shosts ssh .tcshrc \ 5831.79Selric .twmrc .xinitrc .xsession .ssh/authorized_keys \ 5841.79Selric .ssh/authorized_keys2 .ssh/config .ssh/id_dsa.pub \ 5851.79Selric .ssh/id_rsa.pub .ssh/identity.pub .ssh/known_hosts \ 5861.79Selric .ssh/known_hosts2" 5871.15Smrg while read uid homedir; do 5881.15Smrg for f in $list ; do 5891.15Smrg file=${homedir}/${f} 5901.15Smrg if [ -f $file ] ; then 5911.109Schristos printf -- "$uid $f $(ls -ldgT $file)\n" 5921.15Smrg fi 5931.15Smrg done 5941.29Slukem done < $MPBYPATH | 5951.115Sspz awk -v "usergroups=$permit_usergroups" \ 5961.118Suebayasi -v "permit_owners_list=$check_homes_permit_other_owner" ' 5971.115Sspz BEGIN { 5981.115Sspz split(permit_owners_list, a); 5991.115Sspz for (i in a) permit_owners[a[i]]++; 6001.115Sspz } 6011.115Sspz $1 != $5 && $5 != "root" && !permit_owners[$1] \ 6021.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 6031.85Sjhawk $3 ~ /^-....w/ && (!usergroups || $6 != $1) \ 6041.80Swiz { print "user " $1 " " $2 " file is group writable" } 6051.15Smrg $3 ~ /^-.......w/ \ 6061.80Swiz { print "user " $1 " " $2 " file is other writable" }' \ 6071.27Slukem >> $OUTPUT 6081.15Smrg if [ -s $OUTPUT ] ; then 6091.15Smrg printf "\nChecking dot files.\n" 6101.15Smrg cat $OUTPUT 6111.15Smrg fi 6121.9Scgdfi 6131.9Scgd 6141.9Scgd# Mailboxes should be owned by user and unreadable. 6151.32Slukem# 6161.31Slukemif checkyesno check_varmail; then 6171.86Sjhawk ls -lA /var/mail | \ 6181.63Slukem awk ' NR == 1 { next; } 6191.86Sjhawk $9 ~ /^\./ {next; } 6201.63Slukem $3 != $9 { 6211.63Slukem print "user " $9 " mailbox is owned by " $3 6221.63Slukem } 6231.63Slukem $1 != "-rw-------" { 6241.63Slukem print "user " $9 " mailbox is " $1 ", group " $4 6251.63Slukem }' > $OUTPUT 6261.15Smrg if [ -s $OUTPUT ] ; then 6271.15Smrg printf "\nChecking mailbox ownership.\n" 6281.15Smrg cat $OUTPUT 6291.15Smrg fi 6301.15Smrgfi 6311.15Smrg 6321.32Slukem# NFS exports shouldn't be globally exported 6331.32Slukem# 6341.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 6351.32Slukem awk '{ 6361.22Slukem # ignore comments and blank lines 6371.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 6381.22Slukem next; 6391.100Stron # manage line continuation 6401.100Stron while ($NF ~ /^\\$/) { 6411.100Stron $NF = ""; 6421.100Stron line = $0 ""; 6431.100Stron getline; 6441.100Stron $0 = line $0 ""; 6451.100Stron } 6461.22Slukem 6471.100Stron delete dir; 6481.100Stron readonly = ndir = 0; 6491.100Stron for (i = 1; i <= NF; ++i) { 6501.100Stron if ($i ~ /^\//) dir[ndir++] = $i; 6511.100Stron else if ($i ~ /^-/) { 6521.100Stron if ($i ~ /^-(ro|o)$/) readonly = 1; 6531.100Stron if ($i ~ /^-network/) next; 6541.100Stron } 6551.100Stron else next; 6561.15Smrg } 6571.15Smrg if (readonly) 6581.100Stron for (item in dir) 6591.100Stron rodir[nrodir++] = dir[item]; 6601.15Smrg else 6611.100Stron for (item in dir) 6621.100Stron rwdir[nrwdir++] = dir[item]; 6631.100Stron 6641.100Stron } 6651.100Stron 6661.100Stron END { 6671.100Stron if (nrodir) { 6681.100Stron printf("Globally exported file system%s, read-only:\n", 6691.100Stron nrodir > 1 ? "s" : ""); 6701.100Stron for (item in rodir) 6711.100Stron printf("\t%s\n", rodir[item]); 6721.100Stron } 6731.100Stron if (nrwdir) { 6741.100Stron printf("Globally exported file system%s, read-write:\n", 6751.100Stron nrwdir > 1 ? "s" : ""); 6761.100Stron for (item in rwdir) 6771.100Stron printf("\t%s\n", rwdir[item]); 6781.100Stron } 6791.32Slukem }' < /etc/exports > $OUTPUT 6801.32Slukem if [ -s $OUTPUT ] ; then 6811.15Smrg printf "\nChecking for globally exported file systems.\n" 6821.15Smrg cat $OUTPUT 6831.15Smrg fi 6841.9Scgdfi 6851.9Scgd 6861.9Scgd# Display any changes in setuid files and devices. 6871.32Slukem# 6881.31Slukemif checkyesno check_devices; then 6891.28Slukem > $ERR 6901.92Serh ( 6911.98Slukem 6921.98Slukem # Convert check_devices_ignore_fstypes="foo !bar bax" 6931.98Slukem # into "-fstype foo -o ! -fstype bar -o -fstype bax" 6941.98Slukem # and check_devices_ignore_paths="/foo !/bar /bax" 6951.98Slukem # into " -path /foo -o ! -path /bar -o -path /bax" 6961.98Slukem # 6971.98Slukem ignexpr=$(\ 6981.98Slukem echo $check_devices_ignore_fstypes | \ 6991.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -fstype \2/g' ; \ 7001.98Slukem echo $check_devices_ignore_paths | \ 7011.98Slukem sed -e's/\(!*\)\([^[:space:]]\{1,\}\)/-o \1 -path \2/g' \ 7021.98Slukem ) 7031.98Slukem 7041.98Slukem # Massage the expression into ( $ignexpr ) -a -prune -o 7051.98Slukem if [ -n "${ignexpr}" ]; then 7061.98Slukem ignexpr=$(\ 7071.98Slukem echo $ignexpr | \ 7081.98Slukem sed -e 's/^-o /( /' \ 7091.98Slukem -e 's/$/ ) -a -prune -o/' \ 7101.98Slukem ) 7111.98Slukem fi 7121.98Slukem 7131.98Slukem find / $ignexpr \ 7141.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 7151.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 7161.24Slukem -type b -o -type c \) -print0 | \ 7171.98Slukem xargs -0 ls -ldgTq | sort +9 > $LIST 7181.98Slukem 7191.98Slukem ) 2> $OUTPUT 7201.15Smrg 7211.15Smrg # Display any errors that occurred during system file walk. 7221.15Smrg if [ -s $OUTPUT ] ; then 7231.28Slukem printf "Setuid/device find errors:\n" >> $ERR 7241.28Slukem cat $OUTPUT >> $ERR 7251.28Slukem printf "\n" >> $ERR 7261.15Smrg fi 7271.15Smrg 7281.15Smrg # Display any changes in the setuid file list. 7291.15Smrg egrep -v '^[bc]' $LIST > $TMP1 7301.15Smrg if [ -s $TMP1 ] ; then 7311.15Smrg # Check to make sure uudecode isn't setuid. 7321.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 7331.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 7341.15Smrg fi 7351.15Smrg 7361.67Slukem file=$work_dir/setuid 7371.67Slukem migrate_file "$backup_dir/setuid" "$file" 7381.67Slukem CUR=${file}.current 7391.67Slukem BACK=${file}.backup 7401.15Smrg if [ -s $CUR ] ; then 7411.15Smrg if cmp -s $CUR $TMP1 ; then 7421.15Smrg : 7431.15Smrg else 7441.15Smrg > $TMP2 7451.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 7461.15Smrg if [ -s $OUTPUT ] ; then 7471.28Slukem printf "Setuid additions:\n" >> $ERR 7481.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7491.28Slukem printf "\n" >> $ERR 7501.15Smrg fi 7511.15Smrg 7521.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 7531.15Smrg if [ -s $OUTPUT ] ; then 7541.28Slukem printf "Setuid deletions:\n" >> $ERR 7551.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 7561.28Slukem printf "\n" >> $ERR 7571.15Smrg fi 7581.15Smrg 7591.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 7601.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 7611.27Slukem uniq -u > $OUTPUT 7621.15Smrg if [ -s $OUTPUT ] ; then 7631.28Slukem printf "Setuid changes:\n" >> $ERR 7641.28Slukem column -t $OUTPUT >> $ERR 7651.28Slukem printf "\n" >> $ERR 7661.15Smrg fi 7671.9Scgd 7681.52Satatat backup_file update $TMP1 $CUR $BACK 7691.9Scgd fi 7701.15Smrg else 7711.28Slukem printf "Setuid additions:\n" >> $ERR 7721.28Slukem column -t $TMP1 >> $ERR 7731.28Slukem printf "\n" >> $ERR 7741.52Satatat backup_file add $TMP1 $CUR $BACK 7751.9Scgd fi 7761.15Smrg fi 7771.15Smrg 7781.27Slukem # Check for block and character disk devices that are readable or 7791.80Swiz # writable or not owned by root.operator. 7801.15Smrg >$TMP1 7811.61Slukem DISKLIST="ccd ch hk hp ld md ra raid rb rd rl rx \ 7821.57Ssimonb sd se ss uk up vnd wd xd xy" 7831.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 7841.15Smrg for i in $DISKLIST; do 7851.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7861.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 7871.15Smrg done 7881.15Smrg 7891.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 7901.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 7911.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 7921.15Smrg if [ -s $OUTPUT ] ; then 7931.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 7941.28Slukem cat $OUTPUT >> $ERR 7951.28Slukem printf "\n" >> $ERR 7961.9Scgd fi 7971.9Scgd 7981.15Smrg # Display any changes in the device file list. 7991.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 8001.15Smrg if [ -s $TMP1 ] ; then 8011.67Slukem file=$work_dir/device 8021.67Slukem migrate_file "$backup_dir/device" "$file" 8031.67Slukem CUR=${file}.current 8041.67Slukem BACK=${file}.backup 8051.15Smrg 8061.15Smrg if [ -s $CUR ] ; then 8071.15Smrg if cmp -s $CUR $TMP1 ; then 8081.15Smrg : 8091.15Smrg else 8101.15Smrg > $TMP2 8111.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 8121.15Smrg if [ -s $OUTPUT ] ; then 8131.28Slukem printf "Device additions:\n" >> $ERR 8141.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 8151.28Slukem printf "\n" >> $ERR 8161.15Smrg fi 8171.15Smrg 8181.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 8191.15Smrg if [ -s $OUTPUT ] ; then 8201.28Slukem printf "Device deletions:\n" >> $ERR 8211.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 8221.28Slukem printf "\n" >> $ERR 8231.15Smrg fi 8241.15Smrg 8251.27Slukem # Report any block device change. Ignore 8261.27Slukem # character devices, only the name is 8271.27Slukem # significant. 8281.15Smrg cat $TMP2 $CUR $TMP1 | \ 8291.27Slukem sed -e '/^c/d' | \ 8301.27Slukem sort -k11 | \ 8311.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 8321.27Slukem uniq -u > $OUTPUT 8331.15Smrg if [ -s $OUTPUT ] ; then 8341.28Slukem printf "Block device changes:\n" >> $ERR 8351.28Slukem column -t $OUTPUT >> $ERR 8361.28Slukem printf "\n" >> $ERR 8371.15Smrg fi 8381.9Scgd 8391.52Satatat backup_file update $TMP1 $CUR $BACK 8401.9Scgd fi 8411.15Smrg else 8421.28Slukem printf "Device additions:\n" >> $ERR 8431.28Slukem column -t $TMP1 >> $ERR 8441.28Slukem printf "\n" >> $ERR 8451.52Satatat backup_file add $TMP1 $CUR $BACK >> $ERR 8461.9Scgd fi 8471.28Slukem fi 8481.28Slukem if [ -s $ERR ] ; then 8491.28Slukem printf "\nChecking setuid files and devices:\n" 8501.28Slukem cat $ERR 8511.28Slukem printf "\n" 8521.9Scgd fi 8531.9Scgdfi 8541.9Scgd 8551.9Scgd# Check special files. 8561.9Scgd# Check system binaries. 8571.9Scgd# 8581.9Scgd# Create the mtree tree specifications using: 8591.67Slukem# mtree -cx -pDIR -kmd5,uid,gid,mode,nlink,size,link,time > DIR.secure 8601.38Skleink# chown root:wheel DIR.secure 8611.67Slukem# chmod u+r,go= DIR.secure 8621.9Scgd# 8631.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 8641.9Scgd# the hacker can modify the tree specification to match the replaced binary. 8651.9Scgd# For details on really protecting yourself against modified binaries, see 8661.9Scgd# the mtree(8) manual page. 8671.32Slukem# 8681.31Slukemif checkyesno check_mtree; then 8691.82Sjhawk if checkyesno check_mtree_follow_symlinks; then 8701.82Sjhawk check_mtree_flags="-L" 8711.82Sjhawk else 8721.82Sjhawk check_mtree_flags="" 8731.82Sjhawk fi 8741.91Slukem mtree -e -l -p / $check_mtree_flags -f $SPECIALSPEC 3>&1 >$OUTPUT 2>&3 | 8751.87Sjhawk grep -v '^mtree: dev/tty: Device not configured$' >&2 8761.15Smrg if [ -s $OUTPUT ]; then 8771.9Scgd printf "\nChecking special files and directories.\n" 8781.9Scgd cat $OUTPUT 8791.9Scgd fi 8801.9Scgd 8811.16Smikel for file in /etc/mtree/*.secure; do 8821.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 8831.109Schristos tree=$(sed -n -e '3s/.* //p' -e 3q $file) 8841.82Sjhawk mtree $check_mtree_flags -f $file -p $tree > $TMP1 8851.9Scgd if [ -s $TMP1 ]; then 8861.67Slukem printf "\nChecking $tree:\n" 8871.67Slukem cat $TMP1 8881.9Scgd fi 8891.67Slukem done > $OUTPUT 8901.15Smrg if [ -s $OUTPUT ]; then 8911.9Scgd printf "\nChecking system binaries:\n" 8921.9Scgd cat $OUTPUT 8931.9Scgd fi 8941.9Scgdfi 8951.9Scgd 8961.32Slukem# Backup disklabels of available disks 8971.32Slukem# 8981.32Slukemif checkyesno check_disklabels; then 8991.67Slukem # migrate old disklabels 9001.109Schristos for file in $(ls -1d $backup_dir/$backup_dir/disklabel.* \ 9011.109Schristos $backup_dir/disklabel.* 2>/dev/null); do 9021.67Slukem migrate_file "$file" "$work_dir/${file##*/}" 9031.67Slukem done 9041.67Slukem 9051.116Sapb # generate list of old disklabels, fdisks & wedges, 9061.116Sapb # and remove them 9071.116Sapb ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* \ 9081.116Sapb 2>/dev/null | 9091.52Satatat egrep -v '\.(backup|current)(,v)?$' > $LABELS 9101.32Slukem xargs rm < $LABELS 9111.32Slukem 9121.117Schristos disks="$(iostat -x | cut -f 1 -d ' ' )" 9131.117Schristos 9141.117Schristos # generate disklabels of all disks excluding: cd fd md dk st 9151.117Schristos # nfs and "device" (the header of iostat) 9161.32Slukem for i in $disks; do 9171.117Schristos case $i in 9181.118Suebayasi [cfm]d[0-9]*|dk[0-9]*|st[0-9]*|nfs|device) 9191.117Schristos ;; 9201.117Schristos *) 9211.117Schristos if disklabel $i > /dev/null 1>&2; then 9221.117Schristos disklabel $i > "$work_dir/disklabel.$i" 9231.117Schristos fi 9241.117Schristos ;; 9251.117Schristos esac 9261.32Slukem done 9271.32Slukem 9281.67Slukem # if fdisk is available, generate fdisks for: ed ld sd wd 9291.67Slukem if [ -x /sbin/fdisk ]; then 9301.67Slukem for i in $disks; do 9311.117Schristos case $i in 9321.117Schristos [elsw]d[0-9]*) 9331.117Schristos /sbin/fdisk $i > "$work_dir/fdisk.$i" \ 9341.117Schristos 2>/dev/null 9351.117Schristos ;; 9361.117Schristos esac 9371.67Slukem done 9381.67Slukem fi 9391.67Slukem 9401.116Sapb # if dkctl is available, generate dkctl listwedges 9411.116Sapb # for: ed ld sd wd cgd ofdisk ra rl raid 9421.103Stron if [ -x /sbin/dkctl ]; then 9431.103Stron for i in $disks; do 9441.117Schristos case $i in 9451.117Schristos [elsw]d[0-9]*|cgd[0-9]*|ofdisk[0-9]*|r[al][0-9]*|raid[0-9]*) 9461.117Schristos if /sbin/dkctl $i listwedges -qe; then 9471.117Schristos /sbin/dkctl $i listwedges \ 9481.117Schristos > "$work_dir/wedges.$i" 2>/dev/null 9491.117Schristos fi 9501.117Schristos ;; 9511.117Schristos esac 9521.103Stron done 9531.103Stron fi 9541.103Stron 9551.103Stron # append list of new disklabels, fdisks and wedges 9561.116Sapb ls -1d $work_dir/disklabel.* $work_dir/fdisk.* $work_dir/wedges.* \ 9571.116Sapb 2>/dev/null | 9581.52Satatat egrep -v '\.(backup|current)(,v)?$' >> $LABELS 9591.62Satatat CHANGELIST="$LABELS $CHANGELIST" 9601.62Satatatfi 9611.62Satatat 9621.106Shaadif checkyesno check_lvm; then 9631.118Suebayasi # generate list of existing LVM elements Physical Volumes, 9641.118Suebayasi # Volume Groups and Logical Volumes. 9651.118Suebayasi if [ -x /sbin/lvm ]; then 9661.118Suebayasi lvm pvdisplay -m >"$work_dir/lvm.pv" 2>/dev/null 9671.118Suebayasi lvm vgdisplay -m >"$work_dir/lvm.vg" 2>/dev/null 9681.118Suebayasi lvm lvdisplay -m >"$work_dir/lvm.lv" 2>/dev/null 9691.118Suebayasi fi 9701.118Suebayasi ls -1d $work_dir/lvm.* 2>/dev/null | 9711.118Suebayasi egrep -v '\.(backup|current)(,v)?$'>> $LVM_LABELS 9721.118Suebayasi CHANGELIST="$CHANGELIST $LVM_LABELS" 9731.106Shaadfi 9741.106Shaad 9751.62Satatat# Check for changes in the list of installed pkgs 9761.62Satatat# 9771.108Sjmmvif checkyesno check_pkgs && have_pkgs; then 9781.67Slukem pkgs=$work_dir/pkgs 9791.67Slukem migrate_file "$backup_dir/pkgs" "$pkgs" 9801.112Sagc pkg_dbdir=$(${pkg_admin} config-var PKG_DBDIR) 9811.108Sjmmv : ${pkg_dbdir:=/var/db/pkg} 9821.108Sjmmv ( cd $pkg_dbdir 9831.104Sadrianp $pkg_info | sort 9841.62Satatat echo "" 9851.62Satatat find . \( -name +REQUIRED_BY -o -name +CONTENTS \) -print0 | 9861.72Slukem xargs -0 ls -ldgTq | sort -t. +1 | sed -e 's, \./, ,' 9871.62Satatat ) > $pkgs 9881.67Slukem echo "$pkgs" > $PKGS 9891.62Satatat CHANGELIST="$PKGS $CHANGELIST" 9901.32Slukemfi 9911.32Slukem 9921.67Slukem# List of files that get backed up and checked for any modifications. 9931.9Scgd# Any changes cause the files to rotate. 9941.32Slukem# 9951.67Slukemif checkyesno check_changelist ; then 9961.91Slukem mtree -D -k type -f $SPECIALSPEC -E exclude | 9971.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis > $CHANGEFILES 9981.67Slukem 9991.75Slukem ( 10001.68Slukem # Add other files which might dynamically exist: 10011.67Slukem # /etc/ifconfig.* 10021.67Slukem # /etc/raid*.conf 10031.68Slukem # /etc/rc.d/* 10041.67Slukem # /etc/rc.conf.d/* 10051.68Slukem # 10061.75Slukem echo "/etc/ifconfig.*" 10071.75Slukem echo "/etc/raid*.conf" 10081.75Slukem echo "/etc/rc.d/*" 10091.75Slukem echo "/etc/rc.conf.d/*" 10101.106Shaad echo "/etc/lvm/backup/*" 10111.106Shaad echo "/etc/lvm/archive/*" 10121.67Slukem 10131.68Slukem # Add /etc/changelist 10141.68Slukem # 10151.75Slukem if [ -s /etc/changelist ]; then 10161.75Slukem grep -v '^#' /etc/changelist 10171.75Slukem fi 10181.75Slukem ) | while read file; do 10191.75Slukem case "$file" in 10201.75Slukem *[\*\?\[]*) # If changelist line is a glob ... 10211.75Slukem # ... expand possible backup files 10221.75Slukem # 10231.75Slukem ls -1d $(echo $backup_dir/${file}.current) 2>/dev/null \ 10241.75Slukem | sed "s,^$backup_dir/,, ; s,\.current$,," 10251.118Suebayasi 10261.75Slukem # ... expand possible files 10271.75Slukem # 10281.75Slukem ls -1d $(echo $file) 2>/dev/null 10291.75Slukem ;; 10301.75Slukem *) 10311.75Slukem # Otherwise, just print the filename 10321.75Slukem echo $file 10331.75Slukem ;; 10341.75Slukem esac 10351.75Slukem done >> $CHANGEFILES 10361.67Slukem CHANGELIST="$CHANGEFILES $CHANGELIST" 10371.67Slukemfi 10381.67Slukem 10391.67Slukem# Special case backups, including the master password file and 10401.67Slukem# ssh private host keys. The normal backup mechanisms for 10411.67Slukem# $check_changelist (see below) also print out the actual file 10421.67Slukem# differences and we don't want to do that for these files 10431.67Slukem# 10441.67Slukemecho $MP > $TMP1 # always add /etc/master.passwd 10451.91Slukemmtree -D -k type -f $SPECIALSPEC -I nodiff | 10461.91Slukem sed '/^type=file/!d ; s/type=file \.//' | unvis >> $TMP1 10471.73Slukemgrep -v '^$' $TMP1 | sort -u > $TMP2 10481.68Slukem 10491.69Slukemwhile read file; do 10501.67Slukem backup_and_diff "$file" no 10511.69Slukemdone < $TMP2 10521.67Slukem 10531.32Slukem 10541.32Slukemif [ -n "$CHANGELIST" ]; then 10551.73Slukem grep -h -v '^$' $CHANGELIST | sort -u > $TMP1 10561.68Slukem comm -23 $TMP1 $TMP2 | while read file; do 10571.67Slukem backup_and_diff "$file" yes 10581.9Scgd done 10591.44Sadfi 10601.44Sad 10611.108Sjmmvif have_pkgs; then 10621.107Sjmmv if checkyesno check_pkg_vulnerabilities; then 10631.112Sagc ${pkg_admin} ${_compat_K_flag} audit >${OUTPUT} 2>&1 10641.107Sjmmv if [ -s ${OUTPUT} ]; then 10651.107Sjmmv printf "\nInstalled vulnerable packages:\n" 10661.107Sjmmv cat ${OUTPUT} 10671.107Sjmmv fi 10681.107Sjmmv fi 10691.107Sjmmv 10701.107Sjmmv if checkyesno check_pkg_signatures; then 10711.112Sagc ${pkg_admin} ${_compat_K_flag} check >${OUTPUT} 2>&1 10721.107Sjmmv if [ $? -ne 0 ]; then 10731.107Sjmmv printf "\nFiles with invalid signatures:\n" 10741.107Sjmmv cat ${OUTPUT} 10751.107Sjmmv fi 10761.107Sjmmv fi 10771.107Sjmmvfi 10781.107Sjmmv 10791.44Sadif [ -f /etc/security.local ]; then 10801.90Skim . /etc/security.local > $OUTPUT 2>&1 10811.84Sjhawk if [ -s $OUTPUT ] ; then 10821.84Sjhawk printf "\nRunning /etc/security.local:\n" 10831.84Sjhawk cat $OUTPUT 10841.84Sjhawk fi 10851.9Scgdfi 1086