From: Iain Patterson Date: Thu, 28 Oct 2010 09:52:39 +0000 (+0100) Subject: Don't change directory by default unless becoming root. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=b8a79a95206c8d61754a681c2e8f64b0dc52a907;p=profile.git Don't change directory by default unless becoming root. If the target user is not root require the -c flag to change back to the directory from which become was launched. --- diff --git a/opt/bin/become b/opt/bin/become index 26298cb..e874ae5 100755 --- a/opt/bin/become +++ b/opt/bin/become @@ -1,9 +1,11 @@ #!/bin/bash +chdir=0 kerberos=0 x11=0 while getopts ":kx" opt; do case $opt in + c) chdir=1;; k) kerberos=1;; x) x11=1;; esac @@ -12,8 +14,9 @@ shift $((OPTIND-1)) user="$1"; shift if [ -z "$user" ]; then - echo >&2 "Usage: become [-k] [-x] " - echo >&2 "Options: -k Delegate Kerberos credentials even if target user is not root." + echo >&2 "Usage: become [-c] [-k] [-x] " + echo >&2 "Options: -c Stay in current directory even if target user is not root." + echo >&2 " -k Delegate Kerberos credentials even if target user is not root." echo >&2 " -x Delegate X11 cookie even if target user is not root." exit 1 fi @@ -25,6 +28,7 @@ if [ -z "$uid" ]; then fi if [ $uid = 0 ]; then + chdir=1 kerberos=1 x11=1 fi @@ -69,7 +73,7 @@ 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" -echo >&3 2>/dev/null "cd - &>/dev/null" +[ $chdir = 1 ] && echo >&3 2>/dev/null "cd - &>/dev/null" exec 3>&- dir=$(dirname "$0")