source: src-sh/warden/scripts/backend/chrootjail.sh @ 0988d23

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 0988d23 was 0988d23, checked in by Kris Moore <kris@…>, 16 months ago

Add my working directory for the new warden backend changes.

Includes patches from John Hixson (john@…) to change
how warden uses "nicknames" instead of IP addresses for jail
identification.

  • Property mode set to 100755
File size: 1.4 KB
Line 
1#!/bin/sh
2# Chroot into a working jail
3# JAILNAME = $1
4######################################################################
5
6# Source our functions
7PROGDIR="/usr/local/share/warden"
8
9# Source our variables
10. ${PROGDIR}/scripts/backend/functions.sh
11
12JAILNAME="$1"
13
14if [ -z "${JAILNAME}" ]
15then
16  echo "ERROR: No jail specified to chroot into!"
17  exit 5
18fi
19
20if [ -z "${JDIR}" ]
21then
22  echo "ERROR: JDIR is unset!!!!"
23  exit 5
24fi
25
26JAILDIR="${JDIR}/${JAILNAME}"
27
28if [ ! -d "${JAILDIR}" ]
29then
30  echo "ERROR: No jail located at ${JAILDIR}"
31  exit 5
32fi
33
34set_warden_metadir
35
36# Make sure the jail is running
37jls | grep ${JAILDIR}$ >/dev/null 2>/dev/null
38if [ "$?" != "0" ]
39then
40  echo "ERROR: Jail is not running!"
41  exit 6
42fi
43
44# Get the JailID for this jail
45JID="`jls | grep ${JAILDIR}$ | tr -s " " | cut -d " " -f 2`"
46
47# If on an portjail, make display available
48if [ -e "${JMETADIR}/jail-portjail" ] ; then
49  HOST="`cat ${JMETADIR}/host`"
50  xhost + 2>/dev/null >/dev/null
51else
52 if [ "`whoami`" != "root" ] ; then
53   echo "Error: chroot can only be run as root in standard jails"
54   exit 1
55 fi
56fi
57
58# Done with error checking, now lets chroot into the jail
59###################################################################
60
61if [ -z "$2" ] ; then
62  echo "Started shell session on ${JAILNAME}. Type exit when finished."
63  if [ -e "${JMETADIR}/jail-linux" ] ; then
64    jailme ${JID} /bin/bash
65  else
66    jailme ${JID} /bin/csh
67  fi
68  exit $?
69else
70  jailme ${JID} ${2}
71  exit $?
72fi
Note: See TracBrowser for help on using the repository browser.