2002-06-13 22:14:37 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: random
|
2004-04-12 18:11:00 +00:00
|
|
|
# REQUIRE: var initrandom
|
2003-04-18 17:55:05 +00:00
|
|
|
# BEFORE: netif
|
2004-03-08 12:25:05 +00:00
|
|
|
# KEYWORD: FreeBSD nojail shutdown
|
2002-06-13 22:14:37 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="random"
|
|
|
|
start_cmd="random_start"
|
|
|
|
stop_cmd="random_stop"
|
|
|
|
|
|
|
|
feed_dev_random()
|
|
|
|
{
|
|
|
|
if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then
|
|
|
|
cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
random_start()
|
|
|
|
{
|
|
|
|
# Reseed /dev/random with previously stored entropy.
|
|
|
|
case ${entropy_dir} in
|
|
|
|
[Nn][Oo])
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
entropy_dir=${entropy_dir:-/var/db/entropy}
|
|
|
|
if [ -d "${entropy_dir}" ]; then
|
|
|
|
if [ -w /dev/random ]; then
|
|
|
|
for seedfile in ${entropy_dir}/*; do
|
|
|
|
feed_dev_random "${seedfile}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case ${entropy_file} in
|
|
|
|
[Nn][Oo] | '')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -w /dev/random ]; then
|
|
|
|
feed_dev_random "${entropy_file}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
random_stop()
|
|
|
|
{
|
2004-02-07 23:13:28 +00:00
|
|
|
# Write some entropy so when the machine reboots /dev/random
|
2002-06-13 22:14:37 +00:00
|
|
|
# can be reseeded
|
|
|
|
#
|
|
|
|
case ${entropy_file} in
|
|
|
|
[Nn][Oo] | '')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo -n 'Writing entropy file:'
|
|
|
|
rm -f ${entropy_file}
|
|
|
|
oumask=`umask`
|
|
|
|
umask 077
|
2002-10-12 10:31:31 +00:00
|
|
|
if touch ${entropy_file}; then
|
2002-06-13 22:14:37 +00:00
|
|
|
entropy_file_confirmed="${entropy_file}"
|
|
|
|
else
|
|
|
|
# Try this as a reasonable alternative for read-only
|
|
|
|
# roots, diskless workstations, etc.
|
|
|
|
rm -f /var/db/entropy
|
2002-10-12 10:31:31 +00:00
|
|
|
if touch /var/db/entropy; then
|
2002-06-13 22:14:37 +00:00
|
|
|
entropy_file_confirmed=/var/db/entropy
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
case ${entropy_file_confirmed} in
|
|
|
|
'')
|
|
|
|
err 1 '${entropy_file_confirmed}:' \
|
|
|
|
' entropy file write failed.'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
dd if=/dev/random of=${entropy_file_confirmed} \
|
|
|
|
bs=4096 count=1 2> /dev/null
|
|
|
|
echo '.'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
umask ${oumask}
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|