Yast2
Richard R. Sivernell
res005ru
Wed Nov 3 10:52:34 PST 2004
Alma
Here is the script that I have, enjoy.
#!/bin/bash
#
# /usr/X11R6/bin/sux A shell script to forward X authentication
# and run `su - root [options]'
#
# Usage: sux [-c command] [-s shell] [-|-l] [[user] args]
#
# Copyright 2000 SuSE GmbH
# Author: Werner Fink <werner at suse.de>
#
# 2000/09/13: Avoid su staying around with magic cookie
# in process table due PAM.
export PATH=/usr/X11R6/bin/X11:$PATH
if test "+$(id -u)" = "$1" ; then
#
# Passsive part
#
unset XAUTHORITY || true
if test $# -lt 4 -o ! -e /proc/$$/fd/4 ; then
echo "${0##*/}: Missing id or cookie or DISPLAY" 1>&2
exit 1
fi
export SHELL="$3"
arg0=$2${SHELL##*/}
export DISPLAY="$4"
if test "$(hostname -f)" = "${4%:*}" ; then
displaynum=":${4#*:}"
host="${4%:*}"
unixs="${host%%.*}/unix:${displaynum#*:}"
unixf="${host}/unix:${displaynum#*:}"
tcpip="${host}:${displaynum#*:}"
else
host="${4%:*}"
unixs=""
unixf=""
# Workaround for ssh X11 forwarding/redirecting
if test "$host" = "localhost" ; then
tcpip="$(hostname)/unix:${DISPLAY#*:}"
else
tcpip="${DISPLAY}"
fi
fi
if test -n "$5" ; then
export SESSION_MANAGER="$5"
else
unset SESSION_MANAGER
fi
shift 5
xauth -qif <(exec cat 0<&4) extract >(exec xauth -q merge -) \
${unixs:+"$unixs"} \
${unixf:+"$unixf"} \
${tcpip:+"$tcpip"}
exec 4<&-
if test "$host" != "localhost" ; then
# local names first
for d in $unixs $unixf $tcpip ; do
unset x
x=$(xauth -qi nlist $d 2> /dev/null)
test ${#x} -ne 0 && break
done
unset x
case "$d" in */unix:*) DISPLAY=:${d#*:} ;; esac
unset d
fi
unset unixs unixf tcpip host || true
exec -a $arg0 $SHELL ${1+"$@"}
exit 1
fi
#
# Active part
#
if test -z "$DISPLAY" ; then
echo "${0##*/}: Missing DISPLAY variable" 1>&2
exit 1
fi
user=root
login=
command=
while test -z "${1%%-*}" -a -n "$1" ; do
if test ${#1} -eq 2 -a -n "${2%%-*}" -a "$1" != "-l" ; then
y="${1#-}${2}"; shift 2
else
y="${1#-}" ; shift 1
fi
case "$y" in
c*) command="${y#?}" ;;
s*) shell="${y#?}" ;;
l|"") login=- ;;
*)
echo "Usage: sux [-c command] [-s shell] [-|-l] [[user] args]" 1>&2
exit 1
esac
done
if test -n "$1" ; then
user=$1
shift
fi
id=$(id -u $user)
OIFS="$IFS"; IFS=":"
if type -p ypwhich &> /dev/null && test -n "$(ypwhich 2>/dev/null)" ;
then pwline=($((cat /etc/passwd; ypcat passwd)| grep "^${user}:" |
head -n 1)) else
pwline=($(cat /etc/passwd | grep "^${user}:"))
fi
IFS="$OIFS"
if test -n "$shell" && grep -q $shell /etc/shells &> /dev/null ; then
shell=$shell
else
shell="${pwline[6]}"
fi
if test -n "${DISPLAY%:*}" ; then
host="${DISPLAY%:*}"
else
host="$(hostname -f)"
fi
tcpip="${host}:${DISPLAY#*:}"
unset host
sessmng=""
if test -n "$SESSION_MANAGER" ; then
sessmng="$SESSION_MANAGER"
fi
# Gnome is broken
case "$WINDOWMANAGER" in
*gnome*) sessmng=""
esac
exec 4< ${XAUTHORITY:-$HOME/.Xauthority}
# Get rid of NFS ;^)
cat ${XAUTHORITY:-$HOME/.Xauthority} > /dev/null
exec -a su /bin/su -s /bin/bash $login -- $user \
$0 +$id "$login" "$shell" "$tcpip" "$sessmng" ${command:+-c
"$command"} exit 1
#
# /usr/X11R6/bin/sux ends here
#
--
Rick Sivernell
Dallas, Texas 75287
972 306-2296
res005ru at verizon.net
Registered Linux User
.~.
/ v \
/( _ )\
^ ^
In Linux we trust!
More information about the Linux-users
mailing list