Changeset View
Changeset View
Standalone View
Standalone View
head/libexec/rc/rc.d/random
Show All 19 Lines | |||||
save_dev_random() | save_dev_random() | ||||
{ | { | ||||
oumask=`umask` | oumask=`umask` | ||||
umask 077 | umask 077 | ||||
for f ; do | for f ; do | ||||
debug "saving entropy to $f" | debug "saving entropy to $f" | ||||
dd if=/dev/random of="$f" bs=4096 count=1 status=none && | dd if=/dev/random of="$f" bs=4096 count=1 status=none && | ||||
( chflags nodump "$f" 2>/dev/null || : ) && | |||||
chmod 600 "$f" && | chmod 600 "$f" && | ||||
fsync "$f" "$(dirname "$f")" | fsync "$f" "$(dirname "$f")" | ||||
done | done | ||||
umask ${oumask} | umask ${oumask} | ||||
} | } | ||||
feed_dev_random() | feed_dev_random() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
# Write some entropy so when the machine reboots /dev/random | # Write some entropy so when the machine reboots /dev/random | ||||
# can be reseeded | # can be reseeded | ||||
# | # | ||||
case ${entropy_file:=/entropy} in | case ${entropy_file:=/entropy} in | ||||
[Nn][Oo]) | [Nn][Oo]) | ||||
;; | ;; | ||||
*) | *) | ||||
echo -n 'Writing entropy file:' | echo -n 'Writing entropy file: ' | ||||
rm -f ${entropy_file} 2> /dev/null | rm -f ${entropy_file} 2> /dev/null | ||||
oumask=`umask` | oumask=`umask` | ||||
umask 077 | umask 077 | ||||
if touch ${entropy_file} 2> /dev/null; then | if touch ${entropy_file} 2> /dev/null; then | ||||
entropy_file_confirmed="${entropy_file}" | entropy_file_confirmed="${entropy_file}" | ||||
else | else | ||||
# Try this as a reasonable alternative for read-only | # Try this as a reasonable alternative for read-only | ||||
# roots, diskless workstations, etc. | # roots, diskless workstations, etc. | ||||
rm -f /var/db/entropy-file 2> /dev/null | rm -f /var/db/entropy-file 2> /dev/null | ||||
if touch /var/db/entropy-file 2> /dev/null; then | if touch /var/db/entropy-file 2> /dev/null; then | ||||
entropy_file_confirmed=/var/db/entropy-file | entropy_file_confirmed=/var/db/entropy-file | ||||
fi | fi | ||||
fi | fi | ||||
case ${entropy_file_confirmed} in | case ${entropy_file_confirmed} in | ||||
'') | '') | ||||
warn 'write failed (read-only fs?)' | warn 'write failed (read-only fs?)' | ||||
;; | ;; | ||||
*) | *) | ||||
dd if=/dev/random of=${entropy_file_confirmed} \ | save_dev_random "${entropy_file_confirmed}" | ||||
bs=4096 count=1 2> /dev/null || | |||||
warn 'write failed (unwriteable file or full fs?)' | |||||
fsync "${entropy_file_confirmed}" \ | |||||
"$(dirname "${entropy_file_confirmed}")" \ | |||||
2> /dev/null | |||||
echo '.' | echo '.' | ||||
;; | ;; | ||||
esac | esac | ||||
umask ${oumask} | umask ${oumask} | ||||
;; | ;; | ||||
esac | esac | ||||
case ${entropy_boot_file:=/boot/entropy} in | case ${entropy_boot_file:=/boot/entropy} in | ||||
[Nn][Oo]) | [Nn][Oo]) | ||||
;; | ;; | ||||
*) | *) | ||||
echo -n 'Writing early boot entropy file:' | echo -n 'Writing early boot entropy file: ' | ||||
rm -f ${entropy_boot_file} 2> /dev/null | rm -f ${entropy_boot_file} 2> /dev/null | ||||
oumask=`umask` | oumask=`umask` | ||||
umask 077 | umask 077 | ||||
if touch ${entropy_boot_file} 2> /dev/null; then | if touch ${entropy_boot_file} 2> /dev/null; then | ||||
entropy_boot_file_confirmed="${entropy_boot_file}" | entropy_boot_file_confirmed="${entropy_boot_file}" | ||||
fi | fi | ||||
case ${entropy_boot_file_confirmed} in | case ${entropy_boot_file_confirmed} in | ||||
'') | '') | ||||
warn 'write failed (read-only fs?)' | warn 'write failed (read-only fs?)' | ||||
;; | ;; | ||||
*) | *) | ||||
dd if=/dev/random of=${entropy_boot_file_confirmed} \ | save_dev_random "${entropy_boot_file_confirmed}" | ||||
bs=4096 count=1 2> /dev/null || | |||||
warn 'write failed (unwriteable file or full fs?)' | |||||
fsync "${entropy_boot_file_confirmed}" \ | |||||
"$(dirname "${entropy_boot_file_confirmed}")" \ | |||||
2> /dev/null | |||||
echo '.' | echo '.' | ||||
;; | ;; | ||||
esac | esac | ||||
umask ${oumask} | umask ${oumask} | ||||
;; | ;; | ||||
esac | esac | ||||
} | } | ||||
load_rc_config $name | load_rc_config $name | ||||
run_rc_command "$1" | run_rc_command "$1" |