From 653bd9e9387ca4e207e3a955af042461c88d7d84 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Tue, 9 May 2006 00:26:04 +0000 Subject: Added attach/detach subsubcommands to config Added more error checking when attaching image jails Woke up this morning when the streets where full of cars --- ezjail.sh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'ezjail.sh') diff --git a/ezjail.sh b/ezjail.sh index 313831a..a97129a 100755 --- a/ezjail.sh +++ b/ezjail.sh @@ -74,7 +74,9 @@ do_cmd() [ "${action%crypto}" != "${action}" -a -z "${ezjail_blocking}" ] && continue # Try to attach (crypto) devices - [ -n "${ezjail_image}" ] && attach_detach_pre + if [ -n "${ezjail_image}" ]; then + attach_detach_pre || continue + fi ezjail_pass="${ezjail_pass} ${ezjail}" done @@ -91,10 +93,16 @@ attach_detach_pre () if [ "${action%crypto}" = "start" ]; then # If jail is running, do not mount devices, this is the same check as # /etc/rc.d/jail does - [ -e /var/run/jail_${ezjail}.id ] && return + [ -e /var/run/jail_${ezjail}.id ] && return 1 + + if [ -L "${ezjail_root}.device" ]; then + # Fetch destination of soft link + ezjail_device=`stat -f "%Y" ${ezjail_root}.device` + [ -b "${ezjail_device}" ] && echo "Warning: Jail image file ${ezjail_name} already attached as ${ezjail_device}." && return 1 + fi # Create a memory disc from jail image - ezjail_device=`mdconfig -a -t vnode -f ${ezjail_image}` + ezjail_device=`mdconfig -a -t vnode -f ${ezjail_image}` || return 1 # If this is a crypto jail, try to mount it, remind user, which jail # this is. In this case, the device to mount is @@ -102,17 +110,28 @@ attach_detach_pre () crypto|bde) echo "Attaching bde device for image jail ${ezjail}..." echo gbde attach /dev/${ezjail_device} ${ezjail_attachparams} | /bin/sh + if [ $? -eq 0 ]; then + mdconfig -d -u ${ezjail_imagedevice} > /dev/null + echo "Error: Attaching bde device failed."; return 1 + fi # Device to mount is not md anymore ezjail_device=${ezjail_device}.bde ;; eli) echo "Attaching eli device for image jail ${ezjail}..." echo geli attach ${ezjail_attachparams} /dev/${ezjail_device} | /bin/sh + if [ $? -eq 0 ]; then + mdconfig -d -u ${ezjail_imagedevice} > /dev/null + echo "Error: Attaching eli device failed."; return 1 + fi # Device to mount is not md anymore ezjail_device=${ezjail_device}.eli ;; esac + # Clean image + fsck_ufs -F -p ${ezjail_device} + # relink image device rm -f ${ezjail_root}.device ln -s /dev/${ezjail_device} ${ezjail_root}.device -- cgit v1.2.3