permission problem with os.setuid

Benjamin Niemann pink at odahoda.de
Fri Sep 17 13:19:53 EDT 2004


Michele Simionato wrote:
> Benjamin Niemann <b.niemann at betternet.de> wrote in message news:<cieb24$d6s$1 at online.de>...
> 
>>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
>>   os.setuid(501)
>>elif os.getuid() != 501:
>>   os.exec*("sudo", "myscript.py") # script is restarted, now as root
>>
>>assert os.getuid() == 501
> 
> 
> Uhm ... I wanted somewhat to avoid "sudo". Anyway, at the end I have decided
> to change the design so that the script is always run as nobody.
> This solves as well other issues and I am happy with it.
...and is the best solution. As long as it doesn't need more rights than 
'no'body, there's no point in running it as 'some'body.



More information about the Python-list mailing list