[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#3117: Tob needs whoami



>>>>> "DE" == Dirk Eddelbuettel <edd@ehess.cnrs-mrs.fr> writes:

DE> Good point. If I try to replace the
DE> 	if [ 'whoami' != root ] ; then
DE> by another test for not being root, what should I use? Will _everybody_
DE> have set $USER to their idendity when they either login as, or su to, root,
DE> under every possible shell?

I would never trust the settings of the environment variables. I just
tried su and it cleared USER but it left LOGNAME unchanged. Obviously
not what you want. BTW, I think there was a discussion in some other
context which leads me to believe that USER is a BSDism and that the
posixically correct thing to use is LOGNAME.

DE> Does anybody have another idea or bash trick to this reliably without
DE> requiring /usr/bin/* or /usr/sbin/* stuff?

I have seen scripts that use tests like
	if [ -w /etc/passwd ]; then
i.e., if you can write the password file then you must be
root. However, this might break if the root file system is mounted ro -
something which is quite possible when you are doing an emergency
restore. Maybe there are some other files or devices which have to
exists and which have to have root only access. Trying both /hda and
/sda looks plausible. I would guess that every system on which you
would want to run backups has at least one hard disk.

			Cheers,
				Lukas
-------------------------------------------------------------------------------
   Dr. Lukas Nellen                 | Email: lukas@teorica0.ifisicacu.unam.mx
   Depto. de Fisica Teorica, IFUNAM |
   Apdo. Postal 20-364              | Tel.:  +52 5 622 5014 ext. 218
   01000 Mexico D.F., MEXICO        | Fax:   +52 5 622 5015


Reply to: