summaryrefslogtreecommitdiff
path: root/ezjail.sh
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2006-05-09 00:26:04 +0000
committererdgeist <erdgeist@erdgeist.org>2006-05-09 00:26:04 +0000
commit653bd9e9387ca4e207e3a955af042461c88d7d84 (patch)
treee63a9dc8156e10cb5a1477a0b070ac4316333463 /ezjail.sh
parent56f79ffcec367af0269b5ac646136f76d1405252 (diff)
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
Diffstat (limited to 'ezjail.sh')
-rwxr-xr-xezjail.sh25
1 files changed, 22 insertions, 3 deletions
diff --git a/ezjail.sh b/ezjail.sh
index 313831a..a97129a 100755
--- a/ezjail.sh
+++ b/ezjail.sh
@@ -74,7 +74,9 @@ do_cmd()
74 [ "${action%crypto}" != "${action}" -a -z "${ezjail_blocking}" ] && continue 74 [ "${action%crypto}" != "${action}" -a -z "${ezjail_blocking}" ] && continue
75 75
76 # Try to attach (crypto) devices 76 # Try to attach (crypto) devices
77 [ -n "${ezjail_image}" ] && attach_detach_pre 77 if [ -n "${ezjail_image}" ]; then
78 attach_detach_pre || continue
79 fi
78 80
79 ezjail_pass="${ezjail_pass} ${ezjail}" 81 ezjail_pass="${ezjail_pass} ${ezjail}"
80 done 82 done
@@ -91,10 +93,16 @@ attach_detach_pre ()
91 if [ "${action%crypto}" = "start" ]; then 93 if [ "${action%crypto}" = "start" ]; then
92 # If jail is running, do not mount devices, this is the same check as 94 # If jail is running, do not mount devices, this is the same check as
93 # /etc/rc.d/jail does 95 # /etc/rc.d/jail does
94 [ -e /var/run/jail_${ezjail}.id ] && return 96 [ -e /var/run/jail_${ezjail}.id ] && return 1
97
98 if [ -L "${ezjail_root}.device" ]; then
99 # Fetch destination of soft link
100 ezjail_device=`stat -f "%Y" ${ezjail_root}.device`
101 [ -b "${ezjail_device}" ] && echo "Warning: Jail image file ${ezjail_name} already attached as ${ezjail_device}." && return 1
102 fi
95 103
96 # Create a memory disc from jail image 104 # Create a memory disc from jail image
97 ezjail_device=`mdconfig -a -t vnode -f ${ezjail_image}` 105 ezjail_device=`mdconfig -a -t vnode -f ${ezjail_image}` || return 1
98 106
99 # If this is a crypto jail, try to mount it, remind user, which jail 107 # If this is a crypto jail, try to mount it, remind user, which jail
100 # this is. In this case, the device to mount is 108 # this is. In this case, the device to mount is
@@ -102,17 +110,28 @@ attach_detach_pre ()
102 crypto|bde) 110 crypto|bde)
103 echo "Attaching bde device for image jail ${ezjail}..." 111 echo "Attaching bde device for image jail ${ezjail}..."
104 echo gbde attach /dev/${ezjail_device} ${ezjail_attachparams} | /bin/sh 112 echo gbde attach /dev/${ezjail_device} ${ezjail_attachparams} | /bin/sh
113 if [ $? -eq 0 ]; then
114 mdconfig -d -u ${ezjail_imagedevice} > /dev/null
115 echo "Error: Attaching bde device failed."; return 1
116 fi
105 # Device to mount is not md anymore 117 # Device to mount is not md anymore
106 ezjail_device=${ezjail_device}.bde 118 ezjail_device=${ezjail_device}.bde
107 ;; 119 ;;
108 eli) 120 eli)
109 echo "Attaching eli device for image jail ${ezjail}..." 121 echo "Attaching eli device for image jail ${ezjail}..."
110 echo geli attach ${ezjail_attachparams} /dev/${ezjail_device} | /bin/sh 122 echo geli attach ${ezjail_attachparams} /dev/${ezjail_device} | /bin/sh
123 if [ $? -eq 0 ]; then
124 mdconfig -d -u ${ezjail_imagedevice} > /dev/null
125 echo "Error: Attaching eli device failed."; return 1
126 fi
111 # Device to mount is not md anymore 127 # Device to mount is not md anymore
112 ezjail_device=${ezjail_device}.eli 128 ezjail_device=${ezjail_device}.eli
113 ;; 129 ;;
114 esac 130 esac
115 131
132 # Clean image
133 fsck_ufs -F -p ${ezjail_device}
134
116 # relink image device 135 # relink image device
117 rm -f ${ezjail_root}.device 136 rm -f ${ezjail_root}.device
118 ln -s /dev/${ezjail_device} ${ezjail_root}.device 137 ln -s /dev/${ezjail_device} ${ezjail_root}.device