Index: init.d/checkfs =================================================================== RCS file: /var/cvsroot/gentoo-src/rc-scripts/init.d/checkfs,v retrieving revision 1.39 diff -u -B -r1.39 checkfs --- init.d/checkfs 16 Sep 2004 12:30:13 -0000 1.39 +++ init.d/checkfs 20 Sep 2004 22:38:16 -0000 @@ -179,69 +179,9 @@ eend $? "Failed to setup the LVM" fi - ebegin 'Setting up dm-crypt mappings' - - if [ -f /etc/conf.d/cryptfs ] - then - cryptfs_status=0 - - /bin/egrep '^(mount|swap)' /etc/conf.d/cryptfs | \ - while read mountline - do - mount= - swap= - options= - pre_mount= - - eval ${mountline} - - if [ -n "${mount}" ] - then - target=${mount} - [ -z "${options}" ] && options='-c aes -h sha1' - elif [ -n "${swap}" ] - then - target=${swap} - [ -z "${options}" ] && options='-c aes -h sha1 -d /dev/urandom' - else - ewarn "Invalid line in /etc/conf.d/cryptomount: ${mountline}" - fi - - ! /bin/cryptsetup status ${target}|egrep '\ /dev/null - configured=$? - - if [ ${configured} -eq 0 ] - then - einfo "dm-crypt map ${target}" - if ! /bin/cryptsetup ${options} create ${target} ${source} >/dev/console /dev/null - then - ewarn "Failed to run pre_mount commands on: ${target}" - cryptfs_status=1 - fi - fi - fi - else - ewarn "dm-crypt mapping ${target} is already configured" - cryptfs_status=1 - fi - done - fi - ewend ${cryptfs_status} 'Failed to setup a mapping or swap device.' + dm-crypt-start + ewend $? 'Failed to setup a mapping or swap device' if [ -f /fastboot -o -n "${CDBOOT}" ] then @@ -273,4 +213,83 @@ fi } +# Note: This function is exactly duplicated in localmount. If you change it +# here, make sure to change it there also! +dm-crypt-start() { + local cryptfs_status=0 + local mountline mount swap options pre_mount post_mount source + shopt -s extglob # for +(...) and friends + + if [ -f /etc/conf.d/cryptfs ]; then + while read mountline; do + # skip comments and blank lines, ignoring leading w/s + [[ ${mountline//[ ]/} == +(\#*|) ]] && continue + + # check for the start of a new mount/swap + if [[ ${mountline} == +(mount=*|swap=*) ]]; then + # If we have a mount queued up, then execute it + dm-crypt-execute + + # Prepare for the next mount/swap by setting defaults + unset mount swap options pre_mount post_mount source + eval "${mountline}" + + # Check for an invalid setting + elif [[ ${mountline} != +(options=*|pre_mount=*|post_mount=*|source=*) ]]; then + ewarn "Skipping invalid line in /etc/conf.d/cryptfs: ${mountline}" + continue + elif [[ -z ${mount} && -z ${swap} ]]; then + ewarn "Ignoring setting outside mount/swap section: ${mountline}" + continue + fi + + # Queue this setting for the next call to dmcrypt-execute + eval "${mountline}" + done < /etc/conf.d/cryptfs + + # If we have a mount queued up, then execute it + dmcrypt-execute + fi + + return ${cryptfs_status} +} + +# Setup mappings for an individual mount/swap +# +# Note: This relies on variables localized in dm-crypt-start. This function +# is quite different from the function by the same name in localmount... +dm-crypt-execute() { + local dev target + + if [[ -n ${mount} ]]; then + target=${mount} + : ${options:='-c aes -h sha1'} + 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 '\/dev/console /dev/null + ewend $? || cryptfs_status=1 + fi + fi +} + # vim:ts=4 Index: init.d/localmount =================================================================== RCS file: /var/cvsroot/gentoo-src/rc-scripts/init.d/localmount,v retrieving revision 1.23 diff -u -B -r1.23 localmount --- init.d/localmount 16 Sep 2004 12:30:13 -0000 1.23 +++ init.d/localmount 20 Sep 2004 22:38:16 -0000 @@ -42,48 +42,82 @@ /sbin/swapon -a &>/dev/null eend 0 - # Run any post_mount commands for cryptfs + ebegin 'Running post_mount commands for dm-crypt' + dm-crypt-start + ewend $? 'Failed to run a post_mount command' +} - if [ -f /etc/conf.d/cryptfs ] - then - ebegin "Running post_mount commands for cryptfs" - - /bin/egrep "^mount" /etc/conf.d/cryptfs | \ - while read mountline - do - mount= - mount_point= - post_mount= - - eval ${mountline} - - target=${mount} - - ! /bin/cryptsetup status ${target}|egrep '\ /dev/null - configured=$? - - if [ ${configured} -eq 1 ] - then - mount_point=`/bin/awk "/\/dev\/mapper\/${target}/ { print \\$2 }" /proc/mounts` - if [ -n "${mount_point}" ] - then - if [ -n "${post_mount}" ] - then - if ! eval "${post_mount}" > /dev/null - then - ewarn "Failed to run post_mount commands on: ${target}" - fi - fi - else - ewarn "Failed to find mount point to ${target}. Skipping" - fi - else - ewarn "Target ${target} wasn't mapped, skipping" +# Note: This function is exactly duplicated in localmount. If you change it +# here, make sure to change it there also! +dm-crypt-start() { + local cryptfs_status=0 + local mountline mount swap options pre_mount post_mount source + shopt -s extglob # for +(...) and friends + + if [ -f /etc/conf.d/cryptfs ]; then + while read mountline; do + # skip comments and blank lines, ignoring leading w/s + [[ ${mountline//[ ]/} == +(\#*|) ]] && continue + + # check for the start of a new mount/swap + if [[ ${mountline} == +(mount=*|swap=*) ]]; then + # If we have a mount queued up, then execute it + dm-crypt-execute + + # Prepare for the next mount/swap by setting defaults + unset mount swap options pre_mount post_mount source + eval "${mountline}" + + # Check for an invalid setting + elif [[ ${mountline} != +(options=*|pre_mount=*|post_mount=*|source=*) ]]; then + ewarn "Skipping invalid line in /etc/conf.d/cryptfs: ${mountline}" + continue + elif [[ -z ${mount} && -z ${swap} ]]; then + ewarn "Ignoring setting outside mount/swap section: ${mountline}" + continue fi - done + # Queue this setting for the next call to dmcrypt-execute + eval "${mountline}" + done < /etc/conf.d/cryptfs + + # If we have a mount queued up, then execute it + dmcrypt-execute fi + + return ${cryptfs_status} } +# Run any post_mount commands for an individual mount +# +# Note: This relies on variables localized in dm-crypt-start. This function +# is quite different from the function by the same name in checkfs... +dm-crypt-execute() { + local mount_point target + + if [[ -n ${mount} && -n ${post_mount} ]]; then + target=${mount} + else + return + fi + + if ! /bin/cryptsetup status ${target} | egrep -q '\/dev/null + eend $? || cryptfs_status=1 + fi +} # vim:ts=4