Impersonate another user temporarily (Unix and Windows)

billiejoex gnewsg at gmail.com
Wed Aug 22 15:09:58 EDT 2007


Hi there. I'm writing a modification for a FTP server library I'm
maintaining.
Depending on the system I'd want to temporarily impersonate the logged
user to perform actions on filesystem.
Something like:

try:
    change_user('user', 'password')
    os.rmdir('dir')
except:
    print "some error"
finally:
    change_user('old_user', 'password')

On Unix I took at look at os.seteuid() and os.setegid() functions and
I noticed they could be useful for my purpose.
On Windows I have no idea about how could I emulate a similar
behaviour.
Could someone please point me in the right direction?


Thanks in advance




More information about the Python-list mailing list