Skip to content

Commit

Permalink
Fix: couldn't run command su in existing ns with an active process.
Browse files Browse the repository at this point in the history
  • Loading branch information
step- committed May 6, 2019
1 parent 03657d5 commit dfabba9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions usr/sbin/orjail
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ printvn() {
VERBOSE=$OLDVERBOSE
}

# run a command as another user
# Note: sudo and su syntax is slightly different and, more importantly, passing
# su arguments with spaces needs escaping quotes and/or possibly spaces; YMMV.
# Ex. orjail ls "/tmp/a\\ b" # systems with su but without sudo
run () {
if [ "$SUDOBIN" ]; then
$SUDOBIN -u "$USERNAME" "$@"
else
su "$USERNAME" -c "$*"
fi
}

# exec no output
eno() {
if [ "$VERBOSE" != y ]; then
Expand Down Expand Up @@ -240,7 +245,7 @@ if [ "$1" = "--inside" ]; then
print G " * Executing..."

run "$@"
exit
exit $?
fi

# The tool
Expand Down Expand Up @@ -637,7 +642,12 @@ if [ $USEFIREJAIL = y ]; then
else #or without
if [ $NAMESPACE_EXIST = y ]; then
pid=$(ip netns pids "$NAME" | tail -1)
nsenter -p -n -i -m -t "$pid" "$SUDOBIN" -u "$USERNAME" "$@"
# This is like function run() - read comments there
if [ "$SUDOBIN" ]; then
nsenter -p -n -i -m -t "$pid" "$SUDOBIN" -u "$USERNAME" "$@"
else
nsenter -p -n -i -m -t "$pid" su "$USERNAME" -c "$*"
fi
else
ip netns exec "$NAME" \
unshare --ipc --fork --pid --mount --mount-proc \
Expand Down

0 comments on commit dfabba9

Please sign in to comment.