new cryptsetup, this needs to go upstream when I'm not busy

This commit is contained in:
Zero_Chaos 2009-11-17 05:42:36 +00:00
parent 10e6067019
commit e262566c71
10 changed files with 2093 additions and 0 deletions

View file

@ -0,0 +1 @@
Version bump stolen from 277990

View file

@ -0,0 +1,10 @@
AUX 1.0.5-dm-crypt-stop.sh 1022 RMD160 c74d4fffec325378bb008b28c4225b67577c1d1b SHA1 d7b18d4d4845540baecdde373942cc8966c3d5e3 SHA256 42015047c708aa73eae615559ff76c9c8948a5d01fba68f64c5432e30ec799a4
AUX 1.0.5-dmcrypt.rc 660 RMD160 f1af3b07db2eaf938fd21b8ef4b23068f2fac78a SHA1 c297587c68d84611a8fec444d3a98443105efee7 SHA256 11518d0d26572b07f43e7ad69f638e93546656b9f14b647d9825ab8b4619906d
AUX 1.0.6-dmcrypt.confd 3141 RMD160 64d4d4d7df03d301632851bee5969d11a61d57b1 SHA1 e44c783fd42076c7976cdb9bbf2c5280382ffa31 SHA256 9a962e482ead52e7636c0b99145a420f817c73efb6d506cb8322e555e5515325
AUX 1.0.6-r2-dm-crypt-start.sh 8092 RMD160 d61f1cf13e75c105065f8ca6c6a9afe12eedbcaa SHA1 fc4b6580063cd3758ada2d1ddfced3e005c8fabf SHA256 56004bef91b8fad57fe67fec19427dd7c48e01c8e1ba7ff60f8c370295775fdc
AUX cryptsetup-sha1-gcrypt.patch 44488 RMD160 f61fc5d29a2ffe79e231916590d69a0dfd903bff SHA1 4d747f348fdb896e1d7bd82cdaf9b2ca22244065 SHA256 bb6992ad315625116da944d095815d4d7ea082ed962512f9b097959fe8fe5c71
AUX dm-crypt-start.sh 3939 RMD160 b8e77d42b9f5df01cb04f320d7b983855626b39b SHA1 1af1421b687626dae63781f4d78736522d641984 SHA256 2a6114349008ce7d438dae7adcdcd35fdfafa7d54f73d811812c29938865f651
AUX dm-crypt-stop.sh 1290 RMD160 ccd5c5f25b01a6c80228609c97d4e25136098ff6 SHA1 0f9c13e12b4310a190d5db48d4fd32267b795094 SHA256 944e2227b1125902acfa322373dda67d13998ac2d0af075810986471fcbca5a9
DIST cryptsetup-1.0.7.tar.bz2 417339 RMD160 0b903f14b672dfb74116864886370852c66ec425 SHA1 d955a8149d19bc9f09f20bf89f4a39771e6f5de7 SHA256 829af59ab5bb47e4ff384a927458b4ffbb86380825de5f9ac751a89df599ed99
EBUILD cryptsetup-1.0.7.ebuild 3326 RMD160 3fed6f6d35207ca695b741bd19b258af77a612b7 SHA1 4d01ce83dfe80d6bfcfce73500a4dd8ce442eb90 SHA256 39189f670eaf2f96a5304a0dcde0e628f60356d66f552f96d66a661aa4021ef0
MISC Changelog 32 RMD160 0480dcdda9963f9cdefc2f67239bc4618be598bb SHA1 1781717f3be08f92f930cd753cab68618ca21f76 SHA256 fb1ca9bf1e4741e93a2027612e8091414e54745ce6a0c116f7e74cccfe90e07c

View file

@ -0,0 +1,109 @@
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/cryptsetup/cryptsetup-1.0.6-r2.ebuild,v 1.14 2009/08/31 15:05:29 armin76 Exp $
inherit linux-info eutils flag-o-matic multilib autotools
DESCRIPTION="Tool to setup encrypted devices with dm-crypt"
HOMEPAGE="http://code.google.com/p/cryptsetup/"
SRC_URI="http://cryptsetup.googlecode.com/files/${P}.tar.bz2"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="alpha amd64 arm hppa ia64 ~mips ppc ppc64 s390 sh sparc x86"
IUSE="dynamic nls selinux"
DEPEND="|| (
>=sys-fs/lvm2-2.02.45
>=sys-fs/device-mapper-1.00.07-r1
)
>=dev-libs/libgcrypt-1.1.42
>=dev-libs/libgpg-error-1.0-r1
>=dev-libs/popt-1.7
>=sys-fs/udev-124
|| ( >=sys-libs/e2fsprogs-libs-1.41 <sys-fs/e2fsprogs-1.41 )
selinux? ( sys-libs/libselinux )
!sys-fs/cryptsetup-luks"
dm-crypt_check() {
local CONFIG_CHECK="~DM_CRYPT"
local WARNING_DM_CRYPT="CONFIG_DM_CRYPT:\tis not set (required for cryptsetup)\n"
check_extra_config
}
crypto_check() {
local CONFIG_CHECK="~CRYPTO"
local WARNING_CRYPTO="CONFIG_CRYPTO:\tis not set (required for cryptsetup)\n"
check_extra_config
}
cbc_check() {
local CONFIG_CHECK="~CRYPTO_CBC"
local WARNING_CRYPTO_CBC="CONFIG_CRYPTO_CBC:\tis not set (required for kernel 2.6.19)\n"
check_extra_config
}
pkg_setup() {
dm-crypt_check
crypto_check
cbc_check
if use dynamic ; then
ewarn "If you need cryptsetup for an initrd or initramfs then you"
ewarn "should NOT use the dynamic USE flag"
epause 5
fi
}
src_unpack() {
unpack ${A}
cd "${S}"
# fix for bug #236481, use udevadm instead of udevsettle
# fixed upstream
# epatch "${FILESDIR}"/${PN}-1.0.6-udevsettle.patch
#remove hardcoded sha1 crap from bug #274622
epatch "${FILESDIR}"/cryptsetup-sha1-gcrypt.patch
eautomake
#stricter swap check from bug #248495 may not be needed?
}
src_compile() {
use selinux || export ac_cv_lib_selinux_is_selinux_enabled=no
econf \
--sbindir=/sbin \
$(use_enable !dynamic static) \
--libdir=/usr/$(get_libdir) \
$(use_enable nls) \
|| die
emake || die
}
src_install() {
emake DESTDIR="${D}" install || die "install failed"
rmdir "${D}"/usr/$(get_libdir)/cryptsetup
insinto /$(get_libdir)/rcscripts/addons
newins "${FILESDIR}"/1.0.6-r2-dm-crypt-start.sh dm-crypt-start.sh || die
newins "${FILESDIR}"/1.0.5-dm-crypt-stop.sh dm-crypt-stop.sh || die
newconfd "${FILESDIR}"/1.0.6-dmcrypt.confd dmcrypt || die
newinitd "${FILESDIR}"/1.0.5-dmcrypt.rc dmcrypt || die
}
pkg_postinst() {
ewarn "This ebuild introduces a new set of scripts and configuration"
ewarn "than the last version. If you are currently using /etc/conf.d/cryptfs"
ewarn "then you *MUST* copy your old file to:"
ewarn "/etc/conf.d/dmcrypt"
ewarn "Or your encrypted partitions will *NOT* work."
elog "Please see the example for configuring a LUKS mountpoint"
elog "in /etc/conf.d/dmcrypt"
elog
elog "If you are using baselayout-2 then please do:"
elog "rc-update add dmcrypt boot"
elog "This version introduces a command line arguement 'key_timeout'."
elog "If you want the search for the removable key device to timeout"
elog "after 10 seconds add the following to your bootloader config:"
elog "key_timeout=10"
elog "A timeout of 0 will mean it will wait indefinitely."
}

View file

@ -0,0 +1,40 @@
# /lib/rcscripts/addons/dm-crypt-stop.sh
# Try to remove any dm-crypt mappings
csetup=/sbin/cryptsetup
if [ -f /etc/conf.d/dmcrypt ] && [ -x "$csetup" ]
then
einfo "Removing dm-crypt mappings"
/bin/egrep "^(target|swap)" /etc/conf.d/dmcrypt | \
while read targetline
do
target=
swap=
eval ${targetline}
[ -n "${swap}" ] && target=${swap}
[ -z "${target}" ] && ewarn "Invalid line in /etc/conf.d/dmcrypt: ${targetline}"
ebegin "Removing dm-crypt mapping for: ${target}"
${csetup} remove ${target}
eend $? "Failed to remove dm-crypt mapping for: ${target}"
done
if [[ -n $(/bin/egrep -e "^(source=)./dev/loop*" /etc/conf.d/dmcrypt) ]] ; then
einfo "Taking down any dm-crypt loop devices"
/bin/egrep -e "^(source)" /etc/conf.d/dmcrypt | while read sourceline
do
source=
eval ${sourceline}
if [[ -n $(echo ${source} | grep /dev/loop) ]] ; then
ebegin " Taking down ${source}"
/sbin/losetup -d ${source}
eend $? " Failed to remove loop"
fi
done
fi
fi
# vim:ts=4

View file

@ -0,0 +1,30 @@
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/cryptsetup/files/1.0.5-dmcrypt.rc,v 1.3 2008/02/01 12:38:44 flameeyes Exp $
depend() {
before checkfs fsck
if [ -e /lib/librc.so ]; then
need device-mapper
fi
}
start() {
if [ ! -e /lib/librc.so ]; then
eerror "The ${myservice} init script is written for baselayout-2"
eerror "Please do not use it with baselayout-1"
return 1
fi
. /lib/rcscripts/addons/dm-crypt-start.sh
}
stop() {
if [ ! -e /lib/librc.so ]; then
return 0
fi
. /lib/rcscripts/addons/dm-crypt-stop.sh
}

View file

@ -0,0 +1,94 @@
# /etc/conf.d/cryptfs
#--------------------
# Instructions
#--------------------
# Note regarding the syntax of this file. This file is *almost* bash,
# but each line is evaluated separately. Separate swaps/targets can be
# specified. The init-script which reads this file assumes that a
# swap= or target= line starts a new section, similar to lilo or grub
# configuration.
# Note when using gpg keys and /usr on a separate partition, you will
# have to copy /usr/bin/gpg to /bin/gpg so that it will work properly
# and ensure that gpg has been compiled statically.
# See http://bugs.gentoo.org/90482 for more information.
# Note that the init-script which reads this file detects whether your
# partition is LUKS or not. No mkfs is run unless you specify a makefs
# option.
# Global options:
#----------------
# Max number of checks to perform (1 per second)
#dmcrypt_max_timeout=120
# Arguments:
#-----------
# target=<name> == Mapping name for partition.
# swap=<name> == Mapping name for swap partition.
# source='<dev>' == Real device for partition.
# key='</path/to/keyfile>[:<mode>]' == Fullpath from / or from inside removable media.
# remdev='<dev>' == Device that will be assigned to removable media.
# gpg_options='<opts>' == Default are --quiet --decrypt
# options='<opts>' == cryptsetup, for LUKS you can only use --readonly
# loop_file='<file>' == Loopback file.
# pre_mount='cmds' == commands to execute before mounting partition.
# post_mount='cmds' == commands to execute after mounting partition.
#-----------
# Supported Modes
# gpg == decrypt and pipe key into cryptsetup.
# Note: new-line character must not be part of key.
# Command to erase \n char: 'cat key | tr -d '\n' > cleanKey'
#--------------------
# dm-crypt examples
#--------------------
## swap
# Swap partitions. These should come first so that no keys make their
# way into unencrypted swap.
# If no options are given, they will default to: -c aes -h sha1 -d /dev/urandom
# If no makefs is given then mkswap will be assumed
#swap=crypt-swap
#source='/dev/hda2'
## /home with passphrase
#target=crypt-home
#source='/dev/hda5'
## /home with regular keyfile
#target=crypt-home
#source='/dev/hda5'
#key='/full/path/to/homekey'
## /home with gpg protected key
#target=crypt-home
#source='/dev/hda5'
#key='/full/path/to/homekey:gpg'
## /home with regular keyfile on removable media(such as usb-stick)
#target=crypt-home
#source='/dev/hda5'
#key='/full/path/to/homekey'
#remdev='/dev/sda1'
##/home with gpg protected key on removable media(such as usb-stick)
#target=crypt-home
#source='/dev/hda5'
#key='/full/path/to/homekey:gpg'
#remdev='/dev/sda1'
##/tmp with regular keyfile
#target=crypt-tmp
#source='/dev/hda6'
#key='/full/path/to/tmpkey'
#pre_mount='/sbin/mkreiserfs -f -f ${dev}'
#post_mount='chown root:root ${mount_point}; chmod 1777 ${mount_point}'
## Loopback file example
#mount='crypt-loop-home'
#source='/dev/loop0'
#loop_file='/mnt/crypt/home'

View file

@ -0,0 +1,294 @@
# /lib/rcscripts/addons/dm-crypt-start.sh
# For backwards compatability with baselayout < 1.13.0
dm_crypt_execute_checkfs() {
dm_crypt_execute_dmcrypt
}
dm_crypt_execute_volumes() {
dm_crypt_execute_dmcrypt
}
# Setup mappings for an individual target/swap
# Note: This relies on variables localized in the main body below.
dm_crypt_execute_dmcrypt() {
local dev ret mode foo
# some colors
local red='\x1b[31;01m' green='\x1b[32;01m' off='\x1b[0;0m'
if [ -n "$target" ]; then
# let user set options, otherwise leave empty
: ${options:=' '}
elif [ -n "$swap" ]; then
einfo "Checking swap is not LUKS"
cryptsetup isLuks ${source} 2>/dev/null
foo="$?"
if [ "${foo}" -eq 0 ]; then
ewarn "The swap you have defined is a LUKS partition. Aborting crypt-swap setup."
return
fi
target=${swap}
# swap contents do not need to be preserved between boots, luks not required.
# suspend2 users should have initramfs's init handling their swap partition either way.
: ${options:='-c aes -h sha1 -d /dev/urandom'}
: ${pre_mount:='mkswap ${dev}'}
else
return
fi
if [ -z "$source" ] && [ ! -e "$source" ]; then
ewarn "source \"${source}\" for ${target} missing, skipping..."
return
fi
if [[ -n ${loop_file} ]] ; then
dev="/dev/mapper/${target}"
ebegin " Setting up loop device ${source}"
/sbin/losetup ${source} ${loop_file}
fi
# cryptsetup:
# luksOpen <device> <name> # <device> is $source
# create <name> <device> # <name> is $target
local arg1="create" arg2="$target" arg3="$source" luks=0
cryptsetup isLuks ${source} 2>/dev/null && { arg1="luksOpen"; arg2="$source"; arg3="$target"; luks=1; }
if /sbin/cryptsetup status ${target} | egrep -q '\<active:' ; then
einfo "dm-crypt mapping ${target} is already configured"
return
fi
splash svc_input_begin ${SVCNAME} >/dev/null 2>&1
# Handle keys
if [ -n "$key" ]; then
read_abort() {
local ans
local prompt=" ${green}*${off} $1? (${red}yes${off}/${green}No${off}) "
shift
echo -n -e "${prompt}"
if ! read -n 1 $* ans ; then
local back=${prompt//?/\\b}
echo -n -e "${back}"
else
echo
fi
case $ans in
[yY]|[yY][eE][sS]) return 0;;
*) return 1;;
esac
}
# Notes: sed not used to avoid case where /usr partition is encrypted.
mode=${key/*:/} && ( [ "$mode" == "$key" ] || [ -z "$mode" ] ) && mode=reg
key=${key/:*/}
case "$mode" in
gpg|reg)
# handle key on removable device
if [ -n "$remdev" ]; then
# temp directory to mount removable device
local mntrem="${RC_SVCDIR}/dm-crypt-remdev.$$"
if [ ! -d "${mntrem}" ] ; then
if ! mkdir -p "${mntrem}" ; then
ewarn "${source} will not be decrypted ..."
einfo "Reason: Unable to create temporary mount point '${mntrem}'"
return
fi
fi
i=0
einfo "Please insert removable device for ${target}"
while [ ${i} -lt ${dmcrypt_max_timeout:-120} ] ; do
foo=""
if mount -n -o ro "${remdev}" "${mntrem}" 2>/dev/null >/dev/null ; then
# keyfile exists?
if [ ! -e "${mntrem}${key}" ]; then
umount -n "${mntrem}"
rmdir "${mntrem}"
einfo "Cannot find ${key} on removable media."
read_abort "Abort" ${read_timeout:--t 1} && return
else
key="${mntrem}${key}"
break
fi
else
[ -e "${remdev}" ] \
&& foo="mount failed" \
|| foo="mount source not found"
fi
((++i))
read_abort "Stop waiting after $i attempts (${foo})" -t 1 && return
done
else # keyfile ! on removable device
if [ ! -e "$key" ]; then
ewarn "${source} will not be decrypted ..."
einfo "Reason: keyfile ${key} does not exist."
return
fi
fi
;;
*)
ewarn "${source} will not be decrypted ..."
einfo "Reason: mode ${mode} is invalid."
return
;;
esac
else
mode=none
fi
ebegin "dm-crypt map ${target}"
einfo "cryptsetup will be called with : ${options} ${arg1} ${arg2} ${arg3}"
if [ "$mode" == "gpg" ]; then
: ${gpg_options:='-q -d'}
# gpg available ?
if type -p gpg >/dev/null ; then
for (( i = 0 ; i < 3 ; i++ ))
do
# paranoid, don't store key in a variable, pipe it so it stays very little in ram unprotected.
# save stdin stdout stderr "values"
gpg ${gpg_options} ${key} 2>/dev/null | cryptsetup ${options} ${arg1} ${arg2} ${arg3}
ret="$?"
[ "$ret" -eq 0 ] && break
done
eend "${ret}" "failure running cryptsetup"
else
ewarn "${source} will not be decrypted ..."
einfo "Reason: cannot find gpg application."
einfo "You have to install app-crypt/gnupg first."
einfo "If you have /usr on its own partition, try copying gpg to /bin ."
fi
else
if [ "$mode" == "reg" ]; then
cryptsetup ${options} -d ${key} ${arg1} ${arg2} ${arg3}
ret="$?"
eend "${ret}" "failure running cryptsetup"
else
cryptsetup ${options} ${arg1} ${arg2} ${arg3}
ret="$?"
eend "${ret}" "failure running cryptsetup"
fi
fi
if [ -d "$mntrem" ]; then
umount -n ${mntrem} 2>/dev/null >/dev/null
rmdir ${mntrem} 2>/dev/null >/dev/null
fi
splash svc_input_end ${SVCNAME} >/dev/null 2>&1
if [[ ${ret} != 0 ]] ; then
cryptfs_status=1
else
if [[ -n ${pre_mount} ]] ; then
dev="/dev/mapper/${target}"
ebegin " Running pre_mount commands for ${target}"
eval "${pre_mount}" > /dev/null
ewend $? || cryptfs_status=1
fi
fi
}
# Run any post_mount commands for an individual mount
#
# Note: This relies on variables localized in the main body below.
dm_crypt_execute_localmount() {
local mount_point
[ -z "$target" ] && [ -z "$post_mount" ] && return
if ! /sbin/cryptsetup status ${target} | egrep -q '\<active:' ; then
ewarn "Skipping unmapped target ${target}"
cryptfs_status=1
return
fi
mount_point=$(grep "/dev/mapper/${target}" /proc/mounts | cut -d' ' -f2)
if [[ -z ${mount_point} ]] ; then
ewarn "Failed to find mount point for ${target}, skipping"
cryptfs_status=1
fi
if [[ -n ${post_mount} ]] ; then
ebegin "Running post_mount commands for target ${target}"
eval "${post_mount}" >/dev/null
eend $? || cryptfs_status=1
fi
}
# Determine string lengths
strlen() {
if [ -z "$1" ]
then
echo "usage: strlen <variable_name>"
die
fi
eval echo "\${#${1}}"
}
# Lookup optional bootparams
parse_opt() {
case "$1" in
*\=*)
local key_name="`echo "$1" | cut -f1 -d=`"
local key_len=`strlen key_name`
local value_start=$((key_len+2))
echo "$1" | cut -c ${value_start}-
;;
esac
}
local cryptfs_status=0
local gpg_options key loop_file target targetline options pre_mount post_mount source swap remdev
CMDLINE="`cat /proc/cmdline`"
for x in ${CMDLINE}
do
case "${x}" in
key_timeout\=*)
KEY_TIMEOUT=`parse_opt "${x}"`
if [ ${KEY_TIMEOUT} -gt 0 ]; then
read_timeout="-t ${KEY_TIMEOUT}"
fi
;;
esac
done
if [[ -f /etc/conf.d/dmcrypt ]] && [[ -x /sbin/cryptsetup ]] ; then
ebegin "Setting up dm-crypt mappings"
# Fix for baselayout-1.12.10 (bug 174256)
[ -z ${SVCNAME} ] && SVCNAME="${myservice}"
while read -u 3 targetline ; do
# skip comments and blank lines
[[ ${targetline}\# == \#* ]] && continue
# check for the start of a new target/swap
case ${targetline} in
target=*|swap=*)
# If we have a target queued up, then execute it
dm_crypt_execute_${SVCNAME}
# Prepare for the next target/swap by resetting variables
unset gpg_options key loop_file target options pre_mount post_mount source swap remdev
;;
gpg_options=*|remdev=*|key=*|loop_file=*|options=*|pre_mount=*|post_mount=*|source=*)
if [[ -z ${target} && -z ${swap} ]] ; then
ewarn "Ignoring setting outside target/swap section: ${targetline}"
continue
fi
;;
*)
ewarn "Skipping invalid line in /etc/conf.d/dmcrypt: ${targetline}"
;;
esac
# Queue this setting for the next call to dm_crypt_execute_${SVCNAME}
eval "${targetline}"
done 3< /etc/conf.d/dmcrypt
# If we have a target queued up, then execute it
dm_crypt_execute_${SVCNAME}
ewend ${cryptfs_status} "Failed to setup dm-crypt devices"
fi
# vim:ts=4

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,146 @@
# /lib/rcscripts/addons/dm-crypt-start.sh
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/cryptsetup/files/dm-crypt-start.sh,v 1.6 2006/04/12 02:52:43 vapier Exp $
# Setup mappings for an individual mount/swap
#
# Note: This relies on variables localized in the main body below.
dm-crypt-execute-checkfs() {
local dev target ret
if [[ -n ${loop_file} ]] ; then
dev="/dev/mapper/${target}"
ebegin " Setting up loop device ${source}"
/sbin/losetup ${source} ${loop_file}
fi
if [[ -n ${mount} ]] ; then
target=${mount}
: ${options:='-c aes -h sha1'}
[[ -n ${key} ]] && : ${gpg_options:='-q -d'}
elif [[ -n ${swap} ]] ; then
target=${swap}
: ${options:='-c aes -h sha1 -d /dev/urandom'}
: ${pre_mount:='mkswap ${dev}'}
else
return
fi
if /bin/cryptsetup status ${target} | egrep -q '\<active:' ; then
einfo "dm-crypt mapping ${target} is already configured"
return
fi
splash svc_input_begin checkfs
ebegin "dm-crypt map ${target}"
if [[ -z ${key} ]] ; then
/bin/cryptsetup ${options} create ${target} ${source} >/dev/console </dev/console
ret=$?
eend ${ret} "failure running cryptsetup"
else
if type -p gpg >/dev/null ; then
ret=1
while [[ ${ret} -gt 0 ]] ; do
keystring=$(gpg ${gpg_options} ${key} 2>/dev/null </dev/console)
if [[ -z ${keystring} ]] ; then
ret=5
else
echo ${keystring} | /bin/cryptsetup ${options} create ${target} ${source}
ret=$?
fi
done
eend ${ret}
else
einfo "You have to install app-crypt/gnupg first"
fi
fi
splash svc_input_end checkfs
if [[ ${ret} != 0 ]] ; then
cryptfs_status=1
else
if [[ -n ${pre_mount} ]] ; then
dev="/dev/mapper/${target}"
ebegin " Running pre_mount commands for ${target}"
eval "${pre_mount}" > /dev/null
ewend $? || cryptfs_status=1
fi
fi
}
# Run any post_mount commands for an individual mount
#
# Note: This relies on variables localized in the main body below.
dm-crypt-execute-localmount() {
local mount_point target
if [[ -n ${mount} && -n ${post_mount} ]] ; then
target=${mount}
else
return
fi
if ! /bin/cryptsetup status ${target} | egrep -q '\<active:' ; then
ewarn "Skipping unmapped target ${target}"
cryptfs_status=1
return
fi
mount_point=$(grep "/dev/mapper/${target}" /proc/mounts | cut -d' ' -f2)
if [[ -z ${mount_point} ]] ; then
ewarn "Failed to find mount point for ${target}, skipping"
cryptfs_status=1
fi
if [[ -n ${post_mount} ]] ; then
ebegin "Running post_mount commands for target ${target}"
eval "${post_mount}" >/dev/null
eend $? || cryptfs_status=1
fi
}
local cryptfs_status=0
local gpg_options key loop_file mount mountline options pre_mount post_mount source swap
if [[ -f /etc/conf.d/cryptfs ]] && [[ -x /bin/cryptsetup ]] ; then
ebegin "Setting up dm-crypt mappings"
while read mountline ; do
# skip comments and blank lines
[[ ${mountline}\# == \#* ]] && continue
# check for the start of a new mount/swap
case ${mountline} in
mount=*|swap=*)
# If we have a mount queued up, then execute it
dm-crypt-execute-${myservice}
# Prepare for the next mount/swap by resetting variables
unset gpg_options key loop_file mount options pre_mount post_mount source swap
;;
gpg_options=*|key=*|loop_file=*|options=*|pre_mount=*|post_mount=*|source=*)
if [[ -z ${mount} && -z ${swap} ]] ; then
ewarn "Ignoring setting outside mount/swap section: ${mountline}"
continue
fi
;;
*)
ewarn "Skipping invalid line in /etc/conf.d/cryptfs: ${mountline}"
;;
esac
# Queue this setting for the next call to dm-crypt-execute-${myservice}
eval "${mountline}"
done < /etc/conf.d/cryptfs
# If we have a mount queued up, then execute it
dm-crypt-execute-${myservice}
ewend ${cryptfs_status} "Failed to setup dm-crypt devices"
fi
# vim:ts=4

View file

@ -0,0 +1,51 @@
# /lib/rcscripts/addons/dm-crypt-stop.sh
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-fs/cryptsetup/files/dm-crypt-stop.sh,v 1.2 2005/03/02 15:16:39 vapier Exp $
# Try to remove any dm-crypt mappings
if [ -f /etc/conf.d/cryptfs ] && [ -x /bin/cryptsetup ]
then
einfo "Removing dm-crypt mappings"
/bin/egrep "^(mount|swap)" /etc/conf.d/cryptfs | \
while read mountline
do
mount=
swap=
target=
eval ${mountline}
if [ -n "${mount}" ]
then
target=${mount}
elif [ -n "${swap}" ]
then
target=${swap}
else
ewarn "Invalid line in /etc/conf.d/cryptfs: ${mountline}"
fi
ebegin "Removing dm-crypt mapping for: ${target}"
/bin/cryptsetup remove ${target}
eend $? "Failed to remove dm-crypt mapping for: ${target}"
done
if [[ -n $(/bin/egrep -e "^(source=)./dev/loop*" /etc/conf.d/cryptfs) ]] ; then
einfo "Taking down any dm-crypt loop devices"
/bin/egrep -e "^(source)" /etc/conf.d/cryptfs | while read sourceline
do
source=
eval ${sourceline}
if [[ -n $(echo ${source} | grep /dev/loop) ]] ; then
ebegin " Taking down ${source}"
/sbin/losetup -d ${source}
eend $? " Failed to remove loop"
fi
done
fi
fi
# vim:ts=4