logging as root using python script

Paul Casteels Paul.Casteels at ua.ac.be
Fri Apr 8 03:21:42 EDT 2005


Raghul wrote:
> Hi
>    Is it possible to login as a root in linux using python script?
> What I need is when I execute a script it should login as root and
> execute my command and logout from root to my existing account. IS is
> possible?
> 
> Thanx in advance.
> 
Hi,

  You can compile the small .c program and setuid it's executable.
  Change the path to your .py script of course.


#include <sys/types.h>
#include <unistd.h>

int main(int argc,char **argv)
{
         char *c1[]={"/tmp/Chg.py\0",'\0'};

         setuid(0);
         seteuid(0);
         execv(c1[0],c1);
         return 1;
}



More information about the Python-list mailing list