SUGGEST: os.getuser()

Gerrit Holl gerrit.holl at pobox.com
Fri Jan 21 11:04:32 EST 2000


Michael P. Reilly wrote on 948295449:
> : try:
> :     import pwd
> :     return pwd.getpwuid(os.getuid())[0]
> : except ImportError:
> :     import os
> :     for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
> :         user = os.environ.get(name)
> :         if user:
> :             return user
> :     return None
> 
> And this can mislead the program.  getpwuid() usually only stops at the
> first entry matching the given userid.  There are a lot of systems
> which have multiple accounts with the same userid, for legitimate
> reasons.  If the user has changed the environment variable, there is
> usually a reason.  If your program is so paranoid, then you probably
> want your own mechanism.

So getpwuid() is never safe? But in my program, I *also* need the
comment field. So if there are multiple uids the same, I can't get
the full name?

> Not to mention that in some ways, it is far easier to "fake" out
> accounts on a MS box than it is on a UNIX box.  And then there are Mac
> "accounts".

Well, it isn't that bad; my script runs on a Linux box, on a site about
Linux. The chance it will be a MS box in the future should be small <g>.

a-sysop-letting-multiple-identical-uids-be-in-/etc/passwd-
    -is-very-paranoid-anyway-ly yours,
Gerrit.

-- 
Please correct any bad English you encounter in my email message!
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O !M !V PS+ PE?
Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK-----




More information about the Python-list mailing list