2002-06-13 22:14:37 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: random
|
2012-08-22 18:43:21 +00:00
|
|
|
# REQUIRE: initrandom var
|
2003-04-18 17:55:05 +00:00
|
|
|
# BEFORE: netif
|
2004-10-07 13:55:26 +00:00
|
|
|
# KEYWORD: nojail shutdown
|
2002-06-13 22:14:37 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="random"
|
|
|
|
start_cmd="random_start"
|
|
|
|
stop_cmd="random_stop"
|
|
|
|
|
2012-08-22 18:43:21 +00:00
|
|
|
extra_commands="saveseed"
|
|
|
|
saveseed_cmd="${name}_stop"
|
|
|
|
|
2002-06-13 22:14:37 +00:00
|
|
|
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}"
|
2007-03-03 06:39:06 +00:00
|
|
|
feed_dev_random /var/db/entropy-file
|
2002-06-13 22:14:37 +00:00
|
|
|
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:'
|
2007-03-03 06:39:06 +00:00
|
|
|
rm -f ${entropy_file} 2> /dev/null
|
2002-06-13 22:14:37 +00:00
|
|
|
oumask=`umask`
|
|
|
|
umask 077
|
2007-03-03 06:39:06 +00:00
|
|
|
if touch ${entropy_file} 2> /dev/null; 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.
|
2007-03-03 06:39:06 +00:00
|
|
|
rm -f /var/db/entropy-file 2> /dev/null
|
|
|
|
if touch /var/db/entropy-file 2> /dev/null; then
|
2005-04-11 02:45:05 +00:00
|
|
|
entropy_file_confirmed=/var/db/entropy-file
|
2002-06-13 22:14:37 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
case ${entropy_file_confirmed} in
|
|
|
|
'')
|
2007-03-03 06:39:06 +00:00
|
|
|
warn 'write failed (read-only fs?)'
|
2002-06-13 22:14:37 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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"
|