#!/bin/sh # # This script gives the su command on HP/UX and SGI's a little sanity. # To use this, alias su to 'alias su su root -c su-shell' . It looks # up the user in the password database (first checking netinfo root, # netinfo local, /etc/passwd, or NIS) and extracts the login shell. # If it is a valid shell (in /etc/shells) then it extracts the home # directory, exports this as HOME, and runs the user's login shell. # # Eric Myers : 27 October 1995 # Department of Physics, University of Michigan, Ann Arbor, MI # @(#) $Revision: 1.4 $ - $Date: 1997/03/17 23:39:31 $ #======================================================================* PROG=`basename $0` #PSAUX="ps -auxg" # BSD PSAUX="ps -ef" LOGSHELL="" if [ -z "$USER" ]; then echo "$PROG: USER: undefined variable." exit 3 fi # -- NetInfo on a NeXT: look for password entry in / or . maps if [ -x /usr/bin/nidump ]; then PASSWD="/usr/bin/nidump passwd / " LOGSHELL=`$PASSWD | awk -F: "\\\$1 ~ /^$USER$/ {print \\\$7}" ` if [ -z "$LOGSHELL" ]; then PASSWD="/usr/bin/nidump passwd . " LOGSHELL=`$PASSWD | awk -F: "\\\$1 ~ /^$USER$/ {print \\\$7}" ` fi fi # -- If no luck, try /etc/passwd if [ -z "$LOGSHELL" ]; then PASSWD="cat /etc/passwd" LOGSHELL=`$PASSWD | awk -F : "\\\$1 ~ /^$USER$/ {print \\\$7}" ` fi # -- If still nothing, and NIS is running (ypbind) also look in the YP # database if [ -z "$LOGSHELL" ]; then YP=`$PSAUX | grep ypbind | grep -v grep` if [ ! -z "$YP" ]; then PASSWD="ypcat passwd" fi LOGSHELL=`$PASSWD | awk -F : "\\\$1 ~ /^$USER$/ {print \\\$7}" ` fi # -- If nothing by now, give up if [ -z "$LOGSHELL" ]; then echo "$PROG: no shell." exit 1 # no shell, so exit fi # -- For login shell to be valid it must be in /etc/shells if [ -z "`grep $LOGSHELL /etc/shells`" ]; then echo "$PROG: $LOGSHELL: not a valid shell." exit 2 # not a valid shell fi # -- Get the home directory and export it to the subshell HOME=`$PASSWD | awk -F: "\\\$1 ~ /^$USER$/ {print \\\$6}" ` export HOME # -- Run the user's login shell $LOGSHELL exit