1. Attempt to take one bullet out of the foot-shooting gun by silently

ignoring errors when sourcing rc.conf* files. The most common error
occurs when users put a command of some sort into those files.
(ifconfig is a popular choice)

2. Make the file rotation logic simpler by starting one down from
the "top" of the list, rather than at the top.

3. Try to make file rotation more secure by calling unlink(1) on all
new file names before rotating an old file to the new name, rather than
merely calling 'rm -f' on any files that exceed the number of files
to save.
This commit is contained in:
Doug Barton 2006-08-28 06:41:50 +00:00
parent 6361212beb
commit e8ea7f0260

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2001-2005 Douglas Barton, DougB@FreeBSD.org # Copyright (c) 2001-2006 Douglas Barton, DougB@FreeBSD.org
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -37,9 +37,9 @@ PATH=/bin:/usr/bin
# #
if [ -r /etc/defaults/rc.conf ]; then if [ -r /etc/defaults/rc.conf ]; then
. /etc/defaults/rc.conf . /etc/defaults/rc.conf
source_rc_confs source_rc_confs 2>/dev/null
elif [ -r /etc/rc.conf ]; then elif [ -r /etc/rc.conf ]; then
. /etc/rc.conf . /etc/rc.conf 2>/dev/null
fi fi
case ${entropy_dir} in case ${entropy_dir} in
@ -66,16 +66,16 @@ fi
umask 377 umask 377
for file_num in `jot ${entropy_save_num} ${entropy_save_num} 1`; do esn_m1=$(( ${entropy_save_num} - 1 ))
for file_num in `jot $esn_m1 $esn_m1 1`; do
if [ -e "${entropy_dir}/saved-entropy.${file_num}" ]; then if [ -e "${entropy_dir}/saved-entropy.${file_num}" ]; then
if [ -f "${entropy_dir}/saved-entropy.${file_num}" ]; then if [ -f "${entropy_dir}/saved-entropy.${file_num}" ]; then
new_num=$(($file_num + 1)) new_file=saved-entropy.$(( $file_num + 1 ))
if [ "${new_num}" -gt "${entropy_save_num}" ]; then if [ -e "${entropy_dir}/${new_file}" ]; then
rm -f "${entropy_dir}/saved-entropy.${file_num}" unlink ${entropy_dir}/${new_file}
else
mv "${entropy_dir}/saved-entropy.${file_num}" \
"${entropy_dir}/saved-entropy.${new_num}"
fi fi
mv "${entropy_dir}/saved-entropy.${file_num}" \
"${entropy_dir}/${new_file}"
else else
logger -is -t "$0" \ logger -is -t "$0" \
"${entropy_dir}/saved-entropy.${file_num} is not a regular file, and therefore \ "${entropy_dir}/saved-entropy.${file_num} is not a regular file, and therefore \