freebsd-dev/etc/rc.d/encswap
Dag-Erling Smørgrav 607b5a9109 Add support for initializing swap devices with random one-shot keys. Note
that the keys are currently generated by computing the MD5 checksum of 512
bytes read from /dev/random, and are passed to gbde on the command line.

Sponsored by:	Teleplan AS
2004-02-03 11:26:08 +00:00

55 lines
937 B
Bash

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: disks
# REQUIRE: random
# KEYWORD: FreeBSD
. /etc/rc.subr
name="gbde_swap"
start_cmd="gbde_swap_attach"
stop_cmd="gbde_swap_detach"
gbde_swap_attach()
{
cat /etc/fstab |
while read device mountpoint type options rest ; do
case "${device}:${type}:${options}" in
*.bde:swap:sw)
;;
*)
continue
;;
esac
passphrase=`dd if=/dev/random count=1 2>/dev/null | md5 -q`
device="${device%.bde}"
lockfile="/var/run/${device##*/}.lock"
gbde init "${device}" -L "${lockfile}" -P "${passphrase}" ||
return 1
gbde attach "${device}" -l "${lockfile}" -p "${passphrase}" ||
return 1
done
}
gbde_swap_detach()
{
cat /etc/fstab |
while read device mountpoint type options rest ; do
case "${device}:${type}:${options}" in
*.bde:swap:sw)
;;
*)
continue
;;
esac
device="${device%.bde}"
gbde detach "${device}"
done
}
load_rc_config $name
run_rc_command "$1"