user account logon from python

Philippe C. Martin pmartin at snakecard.com
Tue Nov 8 13:43:59 EST 2005


getting there, this sequence creates a file with the correct uid and gid

test_user_ids = 504
print os.setreuid(test_user_ids,0)
print os.setregid(test_user_ids,0)
print os.setuid(test_user_ids)
print os.setgid(test_user_ids)

print os.getuid()
f = open("/tmp/toto","w")
f.write("titi")
f.close()


Philippe C. Martin wrote:

> Jeff,
> 
> 1- I cannot find getpwent in the documentation
> 2- crypt will not work if the system does not have shadow pw
> 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.
> 
> Can you direct me to some link that would explain the actual procedure ?
> 
> Thanks,
> 
> Regards,
> 
> Philippe
> 
> 
> 
> jepler at unpythonic.net wrote:
> 
>> "login APIs" vary widely from system to system.
>> 
>> Classic Unix systems use calls like getpwent and crypt to check
>> passwords, and then call setuid, setgid and setgroups to set the identity
>> of the user who is
>> logging in.  These are all available in stock Python, check the library
>> reference for more details.  Other login-time activities, like writing
>> utmp entries, may not be directly available in stock Python modules.
>> 
>> Many modern Linux systems use something called 'pam' for login-related
>> activities, and there seems to be something called 'python-pam' out
>> there, but I've never used it.
>> 
>> Graphical login managers have their own additional requirements, such as
>> starting and stopping the X server, managing the X authentication
>> information, etc.
>> 
>> Jeff




More information about the Python-list mailing list