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

Bug#3117: Tob needs whoami



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

Thanks for all the tricks!

Michael Meskes <meskes@informatik.rwth-aachen.de> wrote on debian-devel
    How about setting NEEDROOT to 'no'? In case of a system backup I'm root
    anyway and why not letting a user use tob to backup his own directory?
which I don't really like as the base case. Any sys admin can still change it
locally.

Lars Wirzenius <liw@iki.fi> wrote in private
    Neat is the wrong word.

    > /tmp/tob.$$
    username=`ls -l /tmp/tob.$$ | sed 's/^[^    ]*[     ]*[0-9][0-9]*[  ]*//;s/[        ].*//'`
    rm -f /tmp/tob.$$
    echo $username
which is quite a nice construct and very general.

Lukas Nellen <lukas@teorica0.ifisicacu.unam.mx> wrote
    [...]
    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.
which already indicates where it might fail

Richard Kettlewell <richard@elmail.co.uk> wrote
    You could use `[ -w / ]' or `[ -O / ]' or some such, if you can assume
    that / has sensible ownerships and permissions?  Or (for example)
    /bin/su has to be owned by root to work at all, so `[ -O /bin/su ]'
    perhaps?

    If you can assume bash, $UID will probably be better.
which immediately leads to

Miquel van Smoorenburg <miquels@cistron.nl> proposed
    Well bash sets the UID, EUID, GID and EGID variables by itself.. so
    a test like
    	if [ $UID -ne 0 ]; then
    would do..

So I will now change the first line of tob to
   #!/bin/bash
which is not to restrictive a requirement for a Debian system where bash is
essential and use the UID test Mike and Richard proposed.

--
Dirk Eddelb"uttel                              http://qed.econ.queensu.ca/~edd


Reply to: