X-Git-Url: https://git.ao2.it/xudo.git/blobdiff_plain/245d24cb8077b4a902055a3e623492ef1e1945fe..refs/heads/master:/xudo.sh?ds=inline diff --git a/xudo.sh b/xudo.sh index 17b488a..2e34bae 100755 --- a/xudo.sh +++ b/xudo.sh @@ -18,9 +18,7 @@ # along with this program. If not, see . -# This is the equivalent of sux[1] but simpler and using sudo, -# since I don't have su installed on some of my systems. -# +# This is the equivalent of sux[1] but simpler and using sudo. # [1] http://fgouget.free.fr/sux/ set -e @@ -72,9 +70,19 @@ id $USERNAME > /dev/null || { echo "Invalid user." 1>&2; exit 1; } [ "x$@" != "x" ] || { usage 1>&2; exit 1; } -# Authorize the user -xauth extract - $DISPLAY | sudo -u "$USERNAME" xauth merge - + +# Get the authorization cookie from the current user. +COOKIE="$(xauth nextract - $DISPLAY)" + +# XAUTHORITY needs to be unset now, so that the default $HOME/.Xauthority will +# be used for the target user and not some locked auth file from the current +# user. +unset XAUTHORITY + +# Authorize the user. +# Use "sudo -H" to cover the case when env_keep+="HOME" is set in /etc/sudoers +echo "$COOKIE" | sudo -H -u "$USERNAME" xauth nmerge - # Execute the command. -# NOTE: -i or -s have to be passed in order to open a shell +# NOTE: -i or -s can be passed in order to open a shell sudo DISPLAY="$DISPLAY" -u "$USERNAME" "$@"