security revision 1.58
1#!/bin/sh - 2# 3# $NetBSD: security,v 1.58 2001/09/22 04:06:23 perry Exp $ 4# from: @(#)security 8.1 (Berkeley) 6/9/93 5# 6 7PATH=/sbin:/usr/sbin:/bin:/usr/bin 8 9if [ -f /etc/rc.subr ]; then 10 . /etc/rc.subr 11else 12 echo "Can't read /etc/rc.subr; aborting." 13 exit 1; 14fi 15 16umask 077 17 18if [ -s /etc/security.conf ]; then 19 . /etc/security.conf 20fi 21 22SECUREDIR=`mktemp -d /tmp/_securedir.XXXXXX` || exit 1 23 24trap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT 25 26if ! cd "$SECUREDIR"; then 27 echo "Can not cd to $SECUREDIR". 28 exit 1 29fi 30 31if [ -z "$max_loginlen" ];then 32 max_loginlen=8 33fi 34 35if [ -z "$max_grouplen" ]; then 36 max_grouplen=8 37fi 38 39ERR=secure1.$$ 40TMP1=secure2.$$ 41TMP2=secure3.$$ 42MPBYUID=secure4.$$ 43MPBYPATH=secure5.$$ 44LIST=secure6.$$ 45OUTPUT=secure7.$$ 46LABELS=secure8.$$ 47 48# Handle backup_dir not being set in .conf file 49backup_dir=${backup_dir:-/var/backups} 50 51MP=/etc/master.passwd 52 53# these is used several times. 54awk -F: '!/^+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID 55awk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH 56 57# Check the master password file syntax. 58# 59if checkyesno check_passwd; then 60 awk -v "len=$max_loginlen" ' 61 BEGIN { 62 while ( getline < "/etc/shells" > 0 ) { 63 if ($0 ~ /^\#/ || $0 ~ /^$/ ) 64 continue; 65 shells[$1]++; 66 } 67 FS=":"; 68 } 69 70 { 71 if ($0 ~ /^[ ]*$/) { 72 printf "Line %d is a blank line.\n", NR; 73 next; 74 } 75 if (NF != 10 && ($1 != "+" || NF != 1)) 76 printf "Line %d has the wrong number of fields.\n", NR; 77 if ($1 == "+" ) { 78 if (NF != 1 && $3 == 0) 79 printf "Line %d includes entries with uid 0.\n", NR; 80 next; 81 } 82 if ($1 !~ /^[A-Za-z0-9]([-A-Za-z0-9]*[A-Za-z0-9])*$/) 83 printf "Login %s has non-alphanumeric characters.\n", 84 $1; 85 if (length($1) > len) 86 printf "Login %s has more than "len" characters.\n", $1; 87 if ($2 == "") 88 printf "Login %s has no password.\n", $1; 89 if (length($2) != 13 && length($2) != 20 && length($2) != 34 && $2 != "") { 90 if ($10 == "" || shells[$10]) 91 printf "Login %s is off but still has a valid shell (%s)\n", 92 $1, $10; 93 } else if (! shells[$10]) 94 printf "Login %s does not have a valid shell (%s)\n", 95 $1, $10; 96 if ($3 == 0 && $1 != "root" && $1 != "toor") 97 printf "Login %s has a user id of 0.\n", $1; 98 if ($3 < 0) 99 printf "Login %s has a negative user id.\n", $1; 100 if ($4 < 0) 101 printf "Login %s has a negative group id.\n", $1; 102 }' < $MP > $OUTPUT 103 if [ -s $OUTPUT ] ; then 104 printf "\nChecking the $MP file:\n" 105 cat $OUTPUT 106 fi 107 108 awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 109 if [ -s $OUTPUT ] ; then 110 printf "\n$MP has duplicate user names.\n" 111 column $OUTPUT 112 fi 113 114# To not exclude 'toor', a standard duplicate root account, from the duplicate 115# account test, uncomment the line below (without egrep in it)and comment 116# out the line (with egrep in it) below it. 117# 118# < $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2 119 < $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2 120 if [ -s $TMP2 ] ; then 121 printf "\n$MP has duplicate user id's.\n" 122 while read uid; do 123 grep -w $uid $MPBYUID 124 done < $TMP2 | column 125 fi 126fi 127 128# Backup the master password file; a special case, the normal backup 129# mechanisms also print out file differences and we don't want to do 130# that because this file has encrypted passwords in it. 131# 132CUR=$backup_dir/${MP##*/}.current 133BACK=$backup_dir/${MP##*/}.backup 134if [ -s $CUR ] ; then 135 if cmp -s $CUR $MP; then 136 : 137 else 138 backup_file update $MP $CUR $BACK 139 fi 140else 141 backup_file add $MP $CUR $BACK 142fi 143 144# Check the group file syntax. 145# 146if checkyesno check_group; then 147 GRP=/etc/group 148 awk -F: -v "len=$max_grouplen" '{ 149 if ($0 ~ /^[ ]*$/) { 150 printf "Line %d is a blank line.\n", NR; 151 next; 152 } 153 if (NF != 4 && ($1 != "+" || NF != 1)) 154 printf "Line %d has the wrong number of fields.\n", NR; 155 if ($1 == "+" ) { 156 next; 157 } 158 if ($1 !~ /^[A-Za-z0-9]([-A-Za-z0-9]*[A-Za-z0-9])*$/) 159 printf "Group %s has non-alphanumeric characters.\n", 160 $1; 161 if (length($1) > len) 162 printf "Group %s has more than "len" characters.\n", $1; 163 if ($3 !~ /[0-9]*/) 164 printf "Login %s has a negative group id.\n", $1; 165 }' < $GRP > $OUTPUT 166 if [ -s $OUTPUT ] ; then 167 printf "\nChecking the $GRP file:\n" 168 cat $OUTPUT 169 fi 170 171 awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 172 if [ -s $OUTPUT ] ; then 173 printf "\n$GRP has duplicate group names.\n" 174 column $OUTPUT 175 fi 176fi 177 178# Check for root paths, umask values in startup files. 179# The check for the root paths is problematical -- it's likely to fail 180# in other environments. Once the shells have been modified to warn 181# of '.' in the path, the path tests should go away. 182# 183if checkyesno check_rootdotfiles; then 184 > $OUTPUT 185 rhome=`csh -fc "echo ~root"` 186 umaskset=no 187 list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 188 for i in $list ; do 189 if [ -f $i ] ; then 190 if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; then 191 umaskset=yes 192 fi 193 # double check the umask value itself; ensure that both the 194 # 020 and 002 bits are set. 195 # we handle this in decimal initially to extract the digits, 196 # and then extract the `2' bit of each digit. 197 # this is made especially painful because 198 # bitwise operations were left out of awk. 199 egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 200 awk '{ g= ($2 % 100) - ($2 % 10); 201 g /= 10; 202 g = g % 4; 203 g -= g % 2; 204 if (g != 2) { print "\tRoot umask is group writeable" } 205 o = ($2 % 10); 206 o = o % 4; 207 o -= o % 2; 208 if (o != 2) { print "\tRoot umask is other writeable" } }' | 209 sort -u >> $OUTPUT 210 SAVE_PATH=$PATH 211 unset PATH 212 /bin/csh -f -s << end-of-csh > /dev/null 2>&1 213 source $i 214 /bin/ls -ldgT \$path > $TMP1 215end-of-csh 216 PATH=$SAVE_PATH 217 awk '{ 218 if ($10 ~ /^\.$/) { 219 print "\tThe root path includes ."; 220 next; 221 } 222 } 223 $1 ~ /^d....w/ \ 224 { print "\tRoot path directory " $10 " is group writeable." } \ 225 $1 ~ /^d.......w/ \ 226 { print "\tRoot path directory " $10 " is other writeable." }' \ 227 < $TMP1 >> $OUTPUT 228 fi 229 done 230 if [ $umaskset = "no" -o -s $OUTPUT ] ; then 231 printf "\nChecking root csh paths, umask values:\n$list\n\n" 232 if [ -s $OUTPUT ]; then 233 cat $OUTPUT 234 fi 235 if [ $umaskset = "no" ] ; then 236 printf "\tRoot csh startup files do not set the umask.\n" 237 fi 238 fi 239 240 > $OUTPUT 241 rhome=/root 242 umaskset=no 243 list="/etc/profile ${rhome}/.profile" 244 for i in $list; do 245 if [ -f $i ] ; then 246 if egrep umask $i > /dev/null ; then 247 umaskset=yes 248 fi 249 egrep umask $i | 250 awk '$2 % 100 < 20 \ 251 { print "\tRoot umask is group writeable" } \ 252 $2 % 10 < 2 \ 253 { print "\tRoot umask is other writeable" }' \ 254 >> $OUTPUT 255 SAVE_PATH=$PATH 256 unset PATH 257 /bin/sh << end-of-sh > /dev/null 2>&1 258 . $i 259 list=\`echo \$PATH | /usr/bin/sed -e \ 260 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\` 261 /bin/ls -ldgT \$list > $TMP1 262end-of-sh 263 PATH=$SAVE_PATH 264 awk '{ 265 if ($10 ~ /^\.$/) { 266 print "\tThe root path includes ."; 267 next; 268 } 269 } 270 $1 ~ /^d....w/ \ 271 { print "\tRoot path directory " $10 " is group writeable." } \ 272 $1 ~ /^d.......w/ \ 273 { print "\tRoot path directory " $10 " is other writeable." }' \ 274 < $TMP1 >> $OUTPUT 275 276 fi 277 done 278 if [ $umaskset = "no" -o -s $OUTPUT ] ; then 279 printf "\nChecking root sh paths, umask values:\n$list\n" 280 if [ -s $OUTPUT ]; then 281 cat $OUTPUT 282 fi 283 if [ $umaskset = "no" ] ; then 284 printf "\tRoot sh startup files do not set the umask.\n" 285 fi 286 fi 287fi 288 289# Root and uucp should both be in /etc/ftpusers. 290# 291if checkyesno check_ftpusers; then 292 > $OUTPUT 293 list="uucp "`awk '$2 == 0 { print $1 }' $MPBYUID` 294 for i in $list; do 295 if /usr/libexec/ftpd -C $i ; then 296 printf "\t$i is not denied\n" >> $OUTPUT 297 fi 298 done 299 if [ -s $OUTPUT ]; then 300 printf "\nChecking the /etc/ftpusers configuration:\n" 301 cat $OUTPUT 302 fi 303fi 304 305# Uudecode should not be in the /etc/mail/aliases file. 306# 307if checkyesno check_aliases; then 308 for f in /etc/mail/aliases /etc/aliases; do 309 if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 310 printf "\nEntry for uudecode in $f file.\n" 311 fi 312 done 313fi 314 315# Files that should not have + signs. 316# 317if checkyesno check_rhosts; then 318 list="/etc/hosts.equiv /etc/hosts.lpd" 319 for f in $list ; do 320 if [ -f $f ] && egrep '\+' $f > /dev/null ; then 321 printf "\nPlus sign in $f file.\n" 322 fi 323 done 324 325 # Check for special users with .rhosts files. Only root and toor should 326 # have .rhosts files. Also, .rhosts files should not have plus signs. 327 awk -F: '$1 != "root" && $1 != "toor" && \ 328 ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 329 { print $1 " " $9 }' $MP | 330 sort -k2 | 331 while read uid homedir; do 332 if [ -f ${homedir}/.rhosts ] ; then 333 rhost=`ls -ldgT ${homedir}/.rhosts` 334 printf -- "$uid: $rhost\n" 335 fi 336 done > $OUTPUT 337 if [ -s $OUTPUT ] ; then 338 printf "\nChecking for special users with .rhosts files.\n" 339 cat $OUTPUT 340 fi 341 342 while read uid homedir; do 343 if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \ 344 cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then 345 printf -- "$uid: + in .rhosts file.\n" 346 fi 347 done < $MPBYPATH > $OUTPUT 348 if [ -s $OUTPUT ] ; then 349 printf "\nChecking .rhosts files syntax.\n" 350 cat $OUTPUT 351 fi 352fi 353 354# Check home directories. Directories should not be owned by someone else 355# or writeable. 356# 357if checkyesno check_homes; then 358 while read uid homedir; do 359 if [ -d ${homedir}/ ] ; then 360 file=`ls -ldgT ${homedir}` 361 printf -- "$uid $file\n" 362 fi 363 done < $MPBYPATH | 364 awk '$1 != $4 && $4 != "root" \ 365 { print "user " $1 " home directory is owned by " $4 } 366 $2 ~ /^-....w/ \ 367 { print "user " $1 " home directory is group writeable" } 368 $2 ~ /^-.......w/ \ 369 { print "user " $1 " home directory is other writeable" }' \ 370 > $OUTPUT 371 if [ -s $OUTPUT ] ; then 372 printf "\nChecking home directories.\n" 373 cat $OUTPUT 374 fi 375 376 # Files that should not be owned by someone else or readable. 377 list=".Xauthority .netrc" 378 while read uid homedir; do 379 for f in $list ; do 380 file=${homedir}/${f} 381 if [ -f $file ] ; then 382 printf -- "$uid $f `ls -ldgT $file`\n" 383 fi 384 done 385 done < $MPBYPATH | 386 awk '$1 != $5 && $5 != "root" \ 387 { print "user " $1 " " $2 " file is owned by " $5 } 388 $3 ~ /^-...r/ \ 389 { print "user " $1 " " $2 " file is group readable" } 390 $3 ~ /^-......r/ \ 391 { print "user " $1 " " $2 " file is other readable" } 392 $3 ~ /^-....w/ \ 393 { print "user " $1 " " $2 " file is group writeable" } 394 $3 ~ /^-.......w/ \ 395 { print "user " $1 " " $2 " file is other writeable" }' \ 396 > $OUTPUT 397 398 # Files that should not be owned by someone else or writeable. 399 list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 400 .cshrc .emacs .exrc .forward .history .klogin .login .logout \ 401 .profile .qmail .rc_history .rhosts .tcshrc .twmrc .xinitrc \ 402 .xsession" 403 while read uid homedir; do 404 for f in $list ; do 405 file=${homedir}/${f} 406 if [ -f $file ] ; then 407 printf -- "$uid $f `ls -ldgT $file`\n" 408 fi 409 done 410 done < $MPBYPATH | 411 awk '$1 != $5 && $5 != "root" \ 412 { print "user " $1 " " $2 " file is owned by " $5 } 413 $3 ~ /^-....w/ \ 414 { print "user " $1 " " $2 " file is group writeable" } 415 $3 ~ /^-.......w/ \ 416 { print "user " $1 " " $2 " file is other writeable" }' \ 417 >> $OUTPUT 418 if [ -s $OUTPUT ] ; then 419 printf "\nChecking dot files.\n" 420 cat $OUTPUT 421 fi 422fi 423 424# Mailboxes should be owned by user and unreadable. 425# 426if checkyesno check_varmail; then 427 ls -l /var/mail | sed 1d | \ 428 awk '$3 != $9 \ 429 { print "user " $9 " mailbox is owned by " $3 } 430 $1 != "-rw-------" \ 431 { print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT 432 if [ -s $OUTPUT ] ; then 433 printf "\nChecking mailbox ownership.\n" 434 cat $OUTPUT 435 fi 436fi 437 438# NFS exports shouldn't be globally exported 439# 440if checkyesno check_nfs && [ -f /etc/exports ]; then 441 awk '{ 442 # ignore comments and blank lines 443 if ($0 ~ /^\#/ || $0 ~ /^$/ ) 444 next; 445 446 readonly = 0; 447 for (i = 2; i <= NF; ++i) { 448 if ($i ~ /-ro/) 449 readonly = 1; 450 else if ($i !~ /^-/) 451 next; 452 } 453 if (readonly) 454 print "File system " $1 " globally exported, read-only." 455 else 456 print "File system " $1 " globally exported, read-write." 457 }' < /etc/exports > $OUTPUT 458 if [ -s $OUTPUT ] ; then 459 printf "\nChecking for globally exported file systems.\n" 460 cat $OUTPUT 461 fi 462fi 463 464# Display any changes in setuid files and devices. 465# 466if checkyesno check_devices; then 467 > $ERR 468 (find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \ 469 -o -fstype procfs \) -a -prune -o \ 470 \( \( -perm -u+s -a ! -type d \) -o \ 471 \( -perm -g+s -a ! -type d \) -o \ 472 -type b -o -type c \) -print0 | \ 473 xargs -0 ls -ldgTq | sort +9 > $LIST) 2> $OUTPUT 474 475 # Display any errors that occurred during system file walk. 476 if [ -s $OUTPUT ] ; then 477 printf "Setuid/device find errors:\n" >> $ERR 478 cat $OUTPUT >> $ERR 479 printf "\n" >> $ERR 480 fi 481 482 # Display any changes in the setuid file list. 483 egrep -v '^[bc]' $LIST > $TMP1 484 if [ -s $TMP1 ] ; then 485 # Check to make sure uudecode isn't setuid. 486 if grep -w uudecode $TMP1 > /dev/null ; then 487 printf "\nUudecode is setuid.\n" >> $ERR 488 fi 489 490 CUR=$backup_dir/setuid.current 491 BACK=$backup_dir/setuid.backup 492 493 if [ -s $CUR ] ; then 494 if cmp -s $CUR $TMP1 ; then 495 : 496 else 497 > $TMP2 498 join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 499 if [ -s $OUTPUT ] ; then 500 printf "Setuid additions:\n" >> $ERR 501 tee -a $TMP2 < $OUTPUT >> $ERR 502 printf "\n" >> $ERR 503 fi 504 505 join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 506 if [ -s $OUTPUT ] ; then 507 printf "Setuid deletions:\n" >> $ERR 508 tee -a $TMP2 < $OUTPUT >> $ERR 509 printf "\n" >> $ERR 510 fi 511 512 sort -k10 $TMP2 $CUR $TMP1 | \ 513 sed -e 's/[ ][ ]*/ /g' | \ 514 uniq -u > $OUTPUT 515 if [ -s $OUTPUT ] ; then 516 printf "Setuid changes:\n" >> $ERR 517 column -t $OUTPUT >> $ERR 518 printf "\n" >> $ERR 519 fi 520 521 backup_file update $TMP1 $CUR $BACK 522 fi 523 else 524 printf "Setuid additions:\n" >> $ERR 525 column -t $TMP1 >> $ERR 526 printf "\n" >> $ERR 527 backup_file add $TMP1 $CUR $BACK 528 fi 529 fi 530 531 # Check for block and character disk devices that are readable or 532 # writeable or not owned by root.operator. 533 >$TMP1 534 DISKLIST="acd ccd cd ch fd hk hp mcd md ra rb rd rl rx \ 535 sd se ss uk up vnd wd xd xy" 536# DISKLIST="$DISKLIST ct mt st wt" 537 for i in $DISKLIST; do 538 egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 539 egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 540 done 541 542 awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 543 { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 544 $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 545 if [ -s $OUTPUT ] ; then 546 printf "\nChecking disk ownership and permissions.\n" >> $ERR 547 cat $OUTPUT >> $ERR 548 printf "\n" >> $ERR 549 fi 550 551 # Display any changes in the device file list. 552 egrep '^[bc]' $LIST | sort -k11 > $TMP1 553 if [ -s $TMP1 ] ; then 554 CUR=$backup_dir/device.current 555 BACK=$backup_dir/device.backup 556 557 if [ -s $CUR ] ; then 558 if cmp -s $CUR $TMP1 ; then 559 : 560 else 561 > $TMP2 562 join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 563 if [ -s $OUTPUT ] ; then 564 printf "Device additions:\n" >> $ERR 565 tee -a $TMP2 < $OUTPUT >> $ERR 566 printf "\n" >> $ERR 567 fi 568 569 join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 570 if [ -s $OUTPUT ] ; then 571 printf "Device deletions:\n" >> $ERR 572 tee -a $TMP2 < $OUTPUT >> $ERR 573 printf "\n" >> $ERR 574 fi 575 576 # Report any block device change. Ignore 577 # character devices, only the name is 578 # significant. 579 cat $TMP2 $CUR $TMP1 | \ 580 sed -e '/^c/d' | \ 581 sort -k11 | \ 582 sed -e 's/[ ][ ]*/ /g' | \ 583 uniq -u > $OUTPUT 584 if [ -s $OUTPUT ] ; then 585 printf "Block device changes:\n" >> $ERR 586 column -t $OUTPUT >> $ERR 587 printf "\n" >> $ERR 588 fi 589 590 backup_file update $TMP1 $CUR $BACK 591 fi 592 else 593 printf "Device additions:\n" >> $ERR 594 column -t $TMP1 >> $ERR 595 printf "\n" >> $ERR 596 backup_file add $TMP1 $CUR $BACK >> $ERR 597 fi 598 fi 599 if [ -s $ERR ] ; then 600 printf "\nChecking setuid files and devices:\n" 601 cat $ERR 602 printf "\n" 603 fi 604fi 605 606# Check special files. 607# Check system binaries. 608# 609# Create the mtree tree specifications using: 610# 611# mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure 612# chown root:wheel DIR.secure 613# chmod 600 DIR.secure 614# 615# Note, this is not complete protection against Trojan horsed binaries, as 616# the hacker can modify the tree specification to match the replaced binary. 617# For details on really protecting yourself against modified binaries, see 618# the mtree(8) manual page. 619# 620if checkyesno check_mtree; then 621 mtree -e -l -p / -f /etc/mtree/special > $OUTPUT 622 if [ -s $OUTPUT ]; then 623 printf "\nChecking special files and directories.\n" 624 cat $OUTPUT 625 fi 626 627 > $OUTPUT 628 for file in /etc/mtree/*.secure; do 629 [ $file = '/etc/mtree/*.secure' ] && continue 630 tree=`sed -n -e '3s/.* //p' -e 3q $file` 631 mtree -f $file -p $tree > $TMP1 632 if [ -s $TMP1 ]; then 633 printf "\nChecking $tree:\n" >> $OUTPUT 634 cat $TMP1 >> $OUTPUT 635 fi 636 done 637 if [ -s $OUTPUT ]; then 638 printf "\nChecking system binaries:\n" 639 cat $OUTPUT 640 fi 641fi 642 643CHANGELIST="" 644 645# Backup disklabels of available disks 646# 647if checkyesno check_disklabels; then 648 # generate list of old disklabels and remove them 649 ls -1d $backup_dir/disklabel.* 2>/dev/null | 650 egrep -v '\.(backup|current)(,v)?$' > $LABELS 651 xargs rm < $LABELS 652 653 disks=`iostat -x | sed 1d | awk '$1 !~ /^[cfm]d/ { print $1; }'` 654 for i in $disks; do 655 dlf="$backup_dir/disklabel.$i" 656 disklabel $i > $dlf 2>/dev/null 657 done 658 659 # append list of new disklabels, sort list 660 ls -1d $backup_dir/disklabel.* 2>/dev/null | 661 egrep -v '\.(backup|current)(,v)?$' >> $LABELS 662 sort -u -o $LABELS $LABELS 663 CHANGELIST=$LABELS 664fi 665 666# List of files that get backed up and checked for any modifications. Each 667# file is expected to have two backups, $backup_dir/file.{current,backup}. 668# Any changes cause the files to rotate. 669# 670if checkyesno check_changelist && [ -s /etc/changelist ] ; then 671 CHANGELIST="/etc/changelist $CHANGELIST" 672fi 673 674if [ -n "$CHANGELIST" ]; then 675 for file in `egrep -hv "^#|$MP" $CHANGELIST`; do 676 # old changelist backup names 677 OCUR=$backup_dir/${file##*/}.current 678 OBACK=$backup_dir/${file##*/}.backup 679 # new changelist backup names 680 CUR=$backup_dir$file.current 681 BACK=$backup_dir$file.backup 682 # roll over old backups 683 if [ ! -d ${CUR%/*} ]; then 684 mkdir -p ${CUR%/*} 685 fi 686 if [ -f $OCUR -a ! -f $CUR ]; then 687 mv $OCUR $CUR 688 fi 689 if [ -f $OCUR,v -a ! -f $CUR,v ]; then 690 mv $OCUR,v $CUR,v 691 fi 692 if [ -f $OBACK -a ! -f $BACK ]; then 693 mv $OBACK $BACK 694 fi 695 # and down to work 696 if [ -f $file ]; then 697 if [ -f $CUR ] ; then 698 diff $CUR $file > $OUTPUT 699 if [ -s $OUTPUT ] ; then 700 printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file 701 cat $OUTPUT 702 backup_file update $file $CUR $BACK 703 fi 704 else 705 printf "\n======\n%s added\n======\n" $file 706 diff /dev/null $file 707 backup_file add $file $CUR $BACK 708 fi 709 else 710 if [ -f $CUR ]; then 711 printf "\n======\n%s removed\n======\n" $file 712 diff $CUR /dev/null 713 backup_file remove $file $CUR $BACK 714 fi 715 fi 716 done 717fi 718 719if [ -f /etc/security.local ]; then 720 echo "" 721 echo "Running /etc/security.local:" 722 . /etc/security.local 723fi 724