How do I get my python program to get the root password ?

Brian Allen Vanderburg II BrianVanderburg2 at aim.com
Sat Jan 24 02:55:05 CET 2009


grante at visi.com wrote:
> On 2009-01-24, Linuxguy123 <linuxguy123 at gmail.com> wrote:
>
>   
>> I want to make a python program that I can run as a normal
>> user that changes the permission on some device files.  It
>> will need to ask me for the root password and then run chown
>> as root in order to do this. 
>>
>> How do I accomplish this (easily) ?
>>     
>
> The short answer is: you don't accomplish that easily.
>
> The long answer is: you can accomplishity difficultly by using
> a pty or the pexect module to execute the su or sudo command.
>
>   

Check out libsudo.  It is a simple library that simply calls sudo 
program except it is does all the work of reading/writing the pipes for 
you.  You could then use ctypes to interface to it.  Sudo doesn't use 
the root password but the password of the user executing the command, 
but there may be a way to make it use the password of the user the 
command is executed as instead in /etc/sudoers. I don't really know, I 
just have mine set up for my main user account to be able to execute any 
command.


Brian Vanderburg II



More information about the Python-list mailing list