permission problem with os.setuid
b.niemann at betternet.de
Fri Sep 17 11:37:41 CEST 2004
Michele Simionato wrote:
> I have a script that sometimes is run by myself (user id 501) and sometimes
> by the mailer program as nobody/nogroup (userid 65534). I would like to change
> the effective uid to 501 in any case, to get the right permissions, but
> os.setuid and os.seteuid give me a OSError No. 1. Is there a way to get what I
> want? My requirement is that the script should work indipendently from the
> mailer program, i.e I would like to avoid configuring the mailer program by
> hand. I am working on linux with postfix on Mandrake and exim4 on Debian.
> Any suggestion?
Once a process is running as nobody (or any other non-root user account), you
cannot simple change the uid - that's a (very important) feature not a bug! To
change the uid you have to be root first, 'sudo' may help you - though I don't
know about the details how this works...
Possible pseudocode (and by pseudo I mean pseudo ;)
if os.getuid() == 0: # I'm root
elif os.getuid() != 501:
os.exec*("sudo", "myscript.py") # script is restarted, now as root
assert os.getuid() == 501
More information about the Python-list