user account logon from python

Mike Meyer mwm at mired.org
Tue Nov 8 20:06:15 EST 2005


"Philippe C. Martin" <pmartin at snakecard.com> writes:

> Jeff,
>
> 1- I cannot find getpwent in the documentation

getpwent is a Unix library call. For python, you want the pwd
module. The docs are <URL: http://docs.python.org/lib/module-pwd.html >.

> 2- crypt will not work if the system does not have shadow pw

Rubbish. crypt doesn't know anything about passord files. It just
knows how to encrypt a password. It's up to you to get the password
attempt from the user, and the encrypted password from the password
file (or the shadow password file). The pwd module doesn't deal with
shadow passwords. Maybe you meant "system does have shadow pw". But
it's pwd that doesn't work, not crypt - and that depends on the
system. For instance:

bhuda% cat tp.py
#!/usr/bin/env python

import pwd, os

p = pwd.getpwnam(os.environ['USER'])
print p[1]
bhuda% ./tp.py
*

But:

bhuda# ./tp.py
$1$cKJbUtaY$y.e7GRjo8ePxgiBzskyRX0

I.e. - as me, the pwd routines won't return passwords. As root, it
returns the encrypted password.

> 3- Even as root I get "Operation not permitted" using setuid and setgid ...
> but I assume it is because I cannot get 1 and/or 2 to work.

They shouldn't have anything to do with it. Are you sure the process
is running as root? For instance, most modern Unices won't honor the
the setuid bit on script executables. You have to write a setuidj
wrapper that runs the interpreter with the appropriate privileges.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list