1#!/bin/sh 2#
| 1#!/bin/sh 2#
|
3# $FreeBSD: head/etc/rc.d/random 273872 2014-10-30 21:21:53Z markm $
| 3# $FreeBSD: head/etc/rc.d/random 273957 2014-11-02 01:47:27Z des $
|
4# 5 6# PROVIDE: random 7# REQUIRE: FILESYSTEMS 8# BEFORE: netif 9# KEYWORD: nojail shutdown 10 11. /etc/rc.subr 12 13name="random" 14start_cmd="random_start" 15stop_cmd="random_stop" 16 17extra_commands="saveseed" 18saveseed_cmd="${name}_stop" 19
| 4# 5 6# PROVIDE: random 7# REQUIRE: FILESYSTEMS 8# BEFORE: netif 9# KEYWORD: nojail shutdown 10 11. /etc/rc.subr 12 13name="random" 14start_cmd="random_start" 15stop_cmd="random_stop" 16 17extra_commands="saveseed" 18saveseed_cmd="${name}_stop" 19
|
| 20save_dev_random() 21{ 22 for f ; do 23 if :>>"$f" ; then 24 debug "saving entropy to $f" 25 dd if=/dev/random of="$f" bs=4096 count=1 2>/dev/null 26 fi 27 done 28} 29
|
20feed_dev_random() 21{
| 30feed_dev_random() 31{
|
22 if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then 23 cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null 24 fi
| 32 for f ; do 33 if [ -f "$f" -a -r "$f" -a -s "$f" ] ; then 34 if dd if="$f" of=/dev/random bs=4096 2>/dev/null ; then 35 debug "entropy read from $f" 36 rm -f "$f" 37 fi 38 fi 39 done
|
25} 26 27random_start() 28{
| 40} 41 42random_start() 43{
|
| 44 echo -n 'Feeding entropy:' 45 46 if [ ! -w /dev/random ] ; then 47 warn "/dev/random is not writeable" 48 return 1 49 fi 50
|
29 # Reseed /dev/random with previously stored entropy.
| 51 # Reseed /dev/random with previously stored entropy.
|
30 case ${entropy_dir} in
| 52 case ${entropy_dir:=/var/db/entropy} in
|
31 [Nn][Oo]) 32 ;; 33 *)
| 53 [Nn][Oo]) 54 ;; 55 *)
|
34 entropy_dir=${entropy_dir:-/var/db/entropy} 35 if [ -d "${entropy_dir}" ]; then 36 if [ -w /dev/random ]; then 37 for seedfile in ${entropy_dir}/*; do 38 feed_dev_random "${seedfile}" 39 done 40 fi
| 56 if [ -d "${entropy_dir}" ] ; then 57 feed_dev_random "${entropy_dir}"/*
|
41 fi 42 ;; 43 esac 44
| 58 fi 59 ;; 60 esac 61
|
45 case ${entropy_file} in
| 62 case ${entropy_file:=/entropy} in
|
46 [Nn][Oo] | '') 47 ;; 48 *)
| 63 [Nn][Oo] | '') 64 ;; 65 *)
|
49 if [ -w /dev/random ]; then 50 feed_dev_random "${entropy_file}" 51 feed_dev_random /var/db/entropy-file 52 fi
| 66 feed_dev_random "${entropy_file}" /var/db/entropy-file 67 save_dev_random "${entropy_file}"
|
53 ;; 54 esac
| 68 ;; 69 esac
|
| 70 71 echo '.'
|
55} 56 57random_stop() 58{ 59 # Write some entropy so when the machine reboots /dev/random 60 # can be reseeded 61 #
| 72} 73 74random_stop() 75{ 76 # Write some entropy so when the machine reboots /dev/random 77 # can be reseeded 78 #
|
62 case ${entropy_file} in
| 79 case ${entropy_file:=/entropy} in
|
63 [Nn][Oo] | '') 64 ;; 65 *) 66 echo -n 'Writing entropy file:' 67 rm -f ${entropy_file} 2> /dev/null 68 oumask=`umask` 69 umask 077 70 if touch ${entropy_file} 2> /dev/null; then
--- 26 unchanged lines hidden --- | 80 [Nn][Oo] | '') 81 ;; 82 *) 83 echo -n 'Writing entropy file:' 84 rm -f ${entropy_file} 2> /dev/null 85 oumask=`umask` 86 umask 077 87 if touch ${entropy_file} 2> /dev/null; then
--- 26 unchanged lines hidden --- |