#!/bin/sh # Jens Getreu # This script executes commands # under X11 # in the name of another user. # # usage: sudox -u # example: sudox -u mynobody xeyes # Ideas taken from: # Remote X Apps mini-HOWTO # Vincent Zweije, zweije@xs4all.nl # In order to allow all members of %users to # execute locally every command you will need to # add this line to /etc/sudoers: # %users LOCAL=(mynobody) NOPASSWD:ALL if [ $# -lt 3 ] || [ $1 != "-u" ] then echo "usage: `basename $0` -u " >&2 exit 2 fi shift CLIENTUSER="$1" CLIENTHOME=$(grep "^$CLIENTUSER:" /etc/passwd|cut -d: -f 6) shift # FD 4 becomes stdin too exec 4>&0 xauth nlist "$DISPLAY" | { # FD 3 becomes xauth output # FD 0 becomes stdin again # FD 4 is closed exec 3>&0 0>&4 4>&- exec /usr/bin/sudo -H -u "$CLIENTUSER" \ /usr/X11R6/bin/xauth -f "$CLIENTHOME"/.Xauthority nmerge - <&3 } exec echo "env DISPLAY=$DISPLAY XAUTHORITY=${CLIENTHOME}/.Xauthority $*" | sudo -H -i -u "$CLIENTUSER"