[PC-BSD Commits] r15660 - in pcbsd/current/src-qt4/warden: bin scripts/backend

svn at pcbsd.org svn at pcbsd.org
Wed Feb 29 13:15:30 PST 2012


Author: kris
Date: 2012-02-29 21:15:29 +0000 (Wed, 29 Feb 2012)
New Revision: 15660

Modified:
   pcbsd/current/src-qt4/warden/bin/warden
   pcbsd/current/src-qt4/warden/scripts/backend/chrootjail.sh
Log:

Add functionality to run command inside a jail via "warden chroot" command



Modified: pcbsd/current/src-qt4/warden/bin/warden
===================================================================
--- pcbsd/current/src-qt4/warden/bin/warden	2012-02-29 20:41:20 UTC (rev 15659)
+++ pcbsd/current/src-qt4/warden/bin/warden	2012-02-29 21:15:29 UTC (rev 15660)
@@ -48,9 +48,9 @@
     list - Lists the installed jails
 mkinmate - Creates a inmate file from the specified directory
     pkgs - Lists the installed packages / inmates in a jail
-    type - Set the jail type (portjail/normal)
    start - Start a jail
     stop - Stops a jail
+    type - Set the jail type (portjail/normal)
 "
 };
 
@@ -237,11 +237,11 @@
  title
  echo "Help chroot
 
-Logs into a jail using chroot
+Logs into a jail using chroot, or runs the supplied command. 
 
 Usage:
 
-  warden chroot <IP>
+  warden chroot <IP> <optional cmd>
 
 Example:
 
@@ -346,6 +346,7 @@
            inload) help_inload ;;
            indel) help_indel ;;
            mkinmate) help_mkinmate ;;
+           type) help_type ;;
            *) help_main ;;
          esac  ;;
 
@@ -495,7 +496,7 @@
             exit 1
           fi
 
-          ${PROGDIR}/scripts/backend/chrootjail.sh "${IP}"
+          ${PROGDIR}/scripts/backend/chrootjail.sh "${IP}" "${3}"
           ;;
  mkinmate) # The user wants to create an inmate package, do it
          IDIR="${2}"

Modified: pcbsd/current/src-qt4/warden/scripts/backend/chrootjail.sh
===================================================================
--- pcbsd/current/src-qt4/warden/scripts/backend/chrootjail.sh	2012-02-29 20:41:20 UTC (rev 15659)
+++ pcbsd/current/src-qt4/warden/scripts/backend/chrootjail.sh	2012-02-29 21:15:29 UTC (rev 15660)
@@ -29,17 +29,24 @@
   exit 5
 fi
 
+# Make sure the jail is running
+jls | grep ${IP} >/dev/null 2>/dev/null
+if [ "$?" != "0" ]
+then
+  echo "ERROR: Jail is not running!"
+  exit 6
+fi
+
+# Get the JailID for this jail
+JID="`jls | grep ${IP} | tr -s " " ":" | cut -d ":" -f 2`"
+
+
 # Done with error checking, now lets chroot into the jail
 ###################################################################
 
-# Create our chroot script
-
-echo "#!/bin/csh
-clear
-echo 'Started chroot session on ${IP}. Type exit when finished.'
-/bin/csh
-" > "${JDIR}/${IP}/.chroot.sh"
-chmod 755 ${JDIR}/${IP}/.chroot.sh
-chroot "${JDIR}/${IP}" /.chroot.sh
-rm ${JDIR}/${IP}/.chroot.sh
-
+if [ -z "$2" ] ; then
+  echo 'Started shell session on ${IP}. Type exit when finished.'
+  jailme ${JID} /bin/csh
+else
+  jailme ${JID} "${2}"
+fi



More information about the Commits mailing list