The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need to run own scripts as root

Discussion in 'General Discussion' started by metal_cd, Sep 30, 2005.

  1. metal_cd

    metal_cd Member

    Joined:
    Jan 21, 2004
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    I have a need to run my own scripts with root permission but can't seem to make that
    happen. I have tried several ways and the scripts never have full root capability.
    To keep my server stable and secure I have a need to execute some commands as root
    through a browser (when I am not near my main computer).
    I know cPanel does it through their scripting so this is why I ask here.
    How may I set things up so I have an area through a browser (password protected of course)
    that I may execute perl scripts of mine that will have root permissions to do things on the server?
    Any help would be most appreciated.
    Thank you
     
  2. shaun

    shaun Well-Known Member

    Joined:
    Nov 9, 2001
    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    San Clemente, Ca
    If you run your scripts through the WHM they should run as root.

    otherwise you will have to write a wrapper in C and give it suid perms.. Be careful!
     
  3. metal_cd

    metal_cd Member

    Joined:
    Jan 21, 2004
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    If you could be so knid as to explain how to run through WHM. I would not know how to write the c wrapper, I can write only perl.
    Thank you again
     
  4. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Have a look through the existing scripts in /usr/local/cpanel/whostmgr/docroot/cgi/addon_* which should give you enough information.
     
  5. bamasbest

    bamasbest Well-Known Member

    Joined:
    Jan 10, 2004
    Messages:
    531
    Likes Received:
    0
    Trophy Points:
    16
    Chirpy is being a politically correct moderator by not mentioning something.

    Visit his site.

    For a whopping $15 bucks you can purchase a nifty script that allows for file management/shell commands via whm!
     
  6. metal_cd

    metal_cd Member

    Joined:
    Jan 21, 2004
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Well it appears I could run it through whm but for technical reasons I could not run
    it remotely through my limited pocket pc browser (would not access via the non-typical port)
    So, could you possibly give any type of a point towards an explanation of writing
    the c wrapper then setting the suid perms.
    ..or is there any other way of running scripts with full root permmissions through the
    typical http or ssl ports?
    Thank you again
     
  7. shaun

    shaun Well-Known Member

    Joined:
    Nov 9, 2001
    Messages:
    698
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    San Clemente, Ca
    Somthing like this probably work..

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


    main(int argc, char **argv)
    {
    int pid, status;

    if (argc != 2) {
    printf("Usage: %s <command>\n",argv[0]);
    return 1;
    }

    setuid(0);

    pid = fork();
    if(pid == 0) {
    execl(argv[1],argv[1],NULL);
    }
    while (wait(&status) != pid);

    return 0;
    }
     
Loading...

Share This Page