Issue #73: Ensure to delete mtab in normal user

This commit is contained in:
Filippo Squillace 2015-05-09 16:12:51 +00:00
parent 925730784a
commit 85d8e2ddeb
3 changed files with 31 additions and 3 deletions

View file

@ -123,6 +123,7 @@ of GNU/Linux distributions. The needed executables in the host OS are:
- wget or curl
- tar
- mkdir
- ln
- chown (for root access only)
The minimum recommended linux kernel is 2.6.0+

View file

@ -79,6 +79,7 @@ CLASSIC_CHROOT=${JUJU_HOME}/usr/bin/chroot
TRUE=/usr/bin/true
ID="/usr/bin/id -u"
CHOWN="${JUJU_HOME}/usr/bin/chown"
LN="ln"
################################# MAIN FUNCTIONS ##############################
@ -163,7 +164,9 @@ function run_juju_as_root(){
local cmd="mkdir -p ${JUJU_HOME}/${HOME} && mkdir -p /run/lock && ${main_cmd}"
trap - QUIT EXIT ABRT KILL TERM INT
trap "[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME}" EXIT QUIT ABRT KILL TERM INT
trap "[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME}; rm -r ${JUJU_HOME}/etc/mtab" EXIT QUIT ABRT KILL TERM INT
[ ! -e ${JUJU_HOME}/etc/mtab ] && $LN -s /proc/self/mounts ${JUJU_HOME}/etc/mtab
if ${CHROOT} $JUJU_HOME ${TRUE} 1> /dev/null
then
@ -181,6 +184,8 @@ function run_juju_as_root(){
# The ownership of the files in JuJu is assigned to the real user
[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME}
[ -e ${JUJU_HOME}/etc/mtab ] && rm -r ${JUJU_HOME}/etc/mtab
trap - QUIT EXIT ABRT KILL TERM INT
return $?
}
@ -215,10 +220,12 @@ function _run_juju_with_proot(){
function run_juju_as_fakeroot(){
local proot_args="$1 -b /etc/mtab"
local proot_args="$1"
shift
[ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
die "You cannot access with root privileges. Use --root option instead."
[ ! -e ${JUJU_HOME}/etc/mtab ] && $LN -s /proc/self/mounts ${JUJU_HOME}/etc/mtab
_run_juju_with_proot "-S ${JUJU_HOME} $proot_args" "${@}"
}
@ -228,6 +235,8 @@ function run_juju_as_user(){
shift
[ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
die "You cannot access with root privileges. Use --root option instead."
[ -e ${JUJU_HOME}/etc/mtab ] && rm -f ${JUJU_HOME}/etc/mtab
_run_juju_with_proot "-R ${JUJU_HOME} $proot_args" "${@}"
}
@ -283,7 +292,6 @@ function build_image_juju(){
# yaourt requires sed
# coreutils is needed for chown
sudo pacstrap -G -M -d ${maindir}/root pacman arch-install-scripts coreutils binutils libunistring nano archlinux-keyring sed
sudo rm ${maindir}/root/etc/mtab
sudo bash -c "echo 'Server = $DEFAULT_MIRROR' >> ${maindir}/root/etc/pacman.d/mirrorlist"
info "Generating the locales..."

View file

@ -158,6 +158,25 @@ function test_run_juju_as_user(){
assertTrue "[ -e $JUJU_HOME/newdir ]"
}
function test_run_juju_as_proot_mtab(){
install_mini_juju
$(run_juju_as_fakeroot "-k 3.10" "echo")
assertTrue "[ -e $JUJU_HOME/etc/mtab ]"
$(run_juju_as_user "-k 3.10" "echo")
assertTrue "[ ! -e $JUJU_HOME/etc/mtab ]"
}
function test_run_juju_as_root_mtab(){
[ $SKIP_ROOT_TESTS -eq 1 ] && return
install_mini_juju
CHROOT="sudo $CHROOT"
CLASSIC_CHROOT="sudo $CLASSIC_CHROOT"
CHOWN="sudo $CHOWN"
$(run_juju_as_root "echo")
assertTrue "[ ! -e $JUJU_HOME/etc/mtab ]"
}
function test_run_juju_with_quotes(){
install_mini_juju
local output=$(run_juju_as_user "-k 3.10" "bash" "-c" "/usr/bin/mkdir -v /newdir2" | awk -F: '{print $1}')