View | Details | Raw Unified | Return to bug 134225
Collapse All | Expand All

(-)save-entropy.sh (-19 / +27 lines)
Lines 64-92 Link Here
64
	chmod 0700 "${entropy_dir}"
64
	chmod 0700 "${entropy_dir}"
65
fi
65
fi
66
66
67
umask 377
67
# Scan files 1..$entropy_save_num picking a non-existent file or
68
68
# the oldest existing file
69
esn_m1=$(( ${entropy_save_num} - 1 ))
69
save_file="${entropy_dir}/saved-entropy.1"
70
for file_num in `jot $esn_m1 $esn_m1 1`; do
70
if [ -e "${save_file}" ] ; then
71
	if [ -e "${entropy_dir}/saved-entropy.${file_num}" ]; then
71
	if [ ! -f "${save_file}" ] ; then
72
		if [ -f "${entropy_dir}/saved-entropy.${file_num}" ]; then
72
		logger -is -t "$0" \
73
			new_file=saved-entropy.$(( $file_num + 1 ))
73
"${save_file} is not a regular file, and therefore \
74
			if [ -e "${entropy_dir}/${new_file}" ]; then
74
it will not be rotated. Entropy file harvesting is aborted."
75
				unlink ${entropy_dir}/${new_file}
75
		exit 1
76
			fi
76
	fi
77
			mv "${entropy_dir}/saved-entropy.${file_num}" \
77
	next_try=2
78
			    "${entropy_dir}/${new_file}"
78
	while [ ${next_try} -le ${entropy_save_num} ]; do
79
		else
79
		next="${entropy_dir}/saved-entropy.${next_try}"
80
		if [ ! -e "${next}" ] ; then
81
			save_file="${next}"
82
			break
83
		elif [ ! -f "${next}" ] ; then
80
			logger -is -t "$0" \
84
			logger -is -t "$0" \
81
"${entropy_dir}/saved-entropy.${file_num} is not a regular file, and therefore \
85
"${next} is not a regular file, and therefore \
82
it will not be rotated. Entropy file harvesting is aborted."
86
it will not be rotated. Entropy file harvesting is aborted."
83
			exit 1
87
			exit 1
88
		elif [ "${next}" -ot "${save_file}" ] ; then
89
			save_file="${next}"
84
		fi
90
		fi
85
	fi
91
		next_try=$(( ${next_try} + 1 ))
86
done
92
	done
93
fi
87
94
88
dd if=/dev/random of="${entropy_dir}/saved-entropy.1" \
95
[ -e "${save_file}" ] && chmod 600 "${save_file}"
89
    bs="$entropy_save_sz" count=1 2> /dev/null
90
96
91
exit 0
97
dd if=/dev/random of="${save_file}" bs="$entropy_save_sz" count=1 2> /dev/null
98
chmod 400 "${save_file}"
92
99
100
exit 0

Return to bug 134225