[Gllug] cuserid?

Peter Grandi pg_gllug at gllug.for.sabi.co.UK
Mon Oct 17 14:51:38 UTC 2005


>>> On Mon, 17 Oct 2005 15:21:54 +0100,
>>> pg_gllug at gllug.for.sabi.co.UK (Peter Grandi) said:

>>> On Mon, 17 Oct 2005 15:10:16 +0100, Peter Childs
>>> <peterachilds at gmail.com> said:

peterachilds> How do I find out who the current user is as
peterachilds> returned by whoami in c [ ... ]

pg_gllug> Well in the general case this is impossible; what a
pg_gllug> process really knows is the current numeric id [ ... ]
pg_gllug> The best bet is severalfold: check both '$USER' and
pg_gllug> '$LOGNAME' first, then if that fails find out which
pg_gllug> one is the current tty, and use 'wtmp'(5)

Oops, that should have been 'utmp'(5), but fortunately it is the
same 'man' page for both :-); also, in particular consider the
prominent warning in it.

pg_gllug> [ ... ] As a shortcut you can look at the output of
pg_gllug> 'id -a' for example. [ ... ]

Or even better, 'strace' or even 'ltrace' an invocation of
'whoami' or 'id'. That should be quite entertaining.

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list