KSHPR: prompt generator for .kshrc

jmm at ecijmm.UUCP jmm at ecijmm.UUCP
Sun Jun 25 14:30:25 AEST 1989


In article <19817 at cup.portal.com> thad at cup.portal.com (Thad P Floryan) writes:
|The following is a l'il qwik'n'dirty you may find useful.  If you know of some
|other method to determine whether one is running su'd or not, please share it.
|This posting is to unix-pc.sources and comp.sys.att since it's of potential use
|to any UNIX user of ksh.
|
|[... shar deleted ...]

Well you asked for it...  I hope there won't be a deluge of similar
postings.  Anyhow, my method of determining whether I'm su'ed to root
or not is a simple test "if [ -w /etc/passwd ]".  If that succeeds,
you're either root or the proud owner of an insecure system.  The
relevant portion of my .kshrc follows (the alias for rn prevents a
time-bombed gotcha - if you run rn as root, then your .newsrc ends
up owned by root, then the next time you run rn as yourself your
.newsrc can't be overwritten properly and ends up truncated, and then
finally the next time you run rn, the .oldnewsrc gets destroyed too):

...
if [ -w /etc/passwd ]
then SUFLAG=' -- ROOT -- '
    alias rn='echo DUMMY -- get out of root first'
else SUFLAG=' '
fi
integer NEST
NEST=${NEST:=0}
if [ $NEST != 0 ]
then NEST=NEST+1; NESTPROMPT=":$NEST "
else NEST=NEST+1; NESTPROMPT=""; stty kill ^X
fi
PS1="$LOGNAME@$SYSNAME$NESTPROMPT("' ${PWD#$HOME/}$SUFLAG) [!] '
PS2="$LOGNAME@$SYSNAME ... "
...



| [ ... later in the shar, he writes ... ]
|X
|XAfter many futile attempts using other approaches, my notes don't indicate
|Xwhether one MUST specify /bin/ksh as the login shell for root or not (in the
|X/etc/passwd file), but it's that way on my systems now and all works fine.
|X

There is a simple way to not care whether root's shell is ksh or not.  I use
the following alias instead of su:

alias sup="su root -c 'exec ksh'"
-- 
John Macdonald


-- 
John Macdonald



More information about the Comp.sys.att mailing list