#!/bin/bash
-file="$(mktemp)"
-if [ -n "$file" ]; then
- ( umask 077; cat > "$file"; echo "/bin/rm -f '$file'" >> "$file" )
- exec </dev/tty /bin/bash --rcfile "$file"
-else
+file="${TMPDIR:-/tmp}/$SUDO_USER.became.$USER.$RANDOM.$$"
+( umask 077; cat > "$file"; echo "/bin/rm -f '$file'" >> "$file" )
+exec </dev/tty /bin/bash --rcfile "$file"
# Fall back to the shell.
- exec </dev/tty /bin/bash
-fi
+exec </dev/tty /bin/bash
exit 111
profile="$BECOME/$user"
[ -f "$profile" ] || profile="$BECOME/all"
-file="$(mktemp)"
-if [ -n "$file" ]; then
- exec 3>"$file"
- exec <"$file"
- rm "$file"
-
+file="${TMPDIR:-/tmp}/$USER.become.$user.$RANDOM.$$"
+umask 077
+if exec 3>"$file" && exec <"$file" && rm "$file"; then
echo >&3 "cd"
echo >&3 "PROFILE_HOME='$HOME'"
if [ -n "$PRINCIPAL" ]; then
else
echo >&3 "unset DISPLAY"
fi
-
- echo >&3 2>/dev/null ". $HOME/.bash_profile"
- [ -f "$BECOME/all" ] && cat >&3 2>/dev/null "$BECOME/all"
- [ -f "$BECOME/$user" ] && cat >&3 2>/dev/null "$BECOME/$user"
+else
+ exit 111
fi
+echo >&3 ". $HOME/.bash_profile"
+[ -f "$BECOME/all" ] && cat >&3 2>/dev/null "$BECOME/all"
+[ -f "$BECOME/$user" ] && cat >&3 2>/dev/null "$BECOME/$user"
+
dir=$(dirname "$0")
[ "$dir" = "." ] && dir="$PWD"
exec sudo -H -u "$user" "$dir/became"