Xref: utzoo unix-pc.sources:323 comp.sys.att:6805 Path: utzoo!attcan!lsuc!mnetor!motto!ecijmm!jmm From: jmm@ecijmm.UUCP Newsgroups: unix-pc.sources,comp.sys.att Subject: Re: KSHPR: prompt generator for .kshrc Message-ID: <287@ecijmm.UUCP> Date: 25 Jun 89 04:30:25 GMT References: <19817@cup.portal.com> Reply-To: jmm@ecijmm.UUCP (John Macdonald) Organization: R. H. Lathwell Associates, Elegant Communications, Inc. Lines: 53 In article <19817@cup.portal.com> thad@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