linux user switching

Discussion in 'C Programming' started by darkchild50@gmail.com, Nov 12, 2005.

  1. Guest

    is it possible to write a c script that asks for the root password and
    runs as if it was root untill the script exits?if so what would it look
    like?


    -darkchild
     
    , Nov 12, 2005
    #1
    1. Advertising

  2. writes:
    > is it possible to write a c script that asks for the root password and
    > runs as if it was root untill the script exits?if so what would it look
    > like?


    Not in portable standard C, which is what we discuss here. Try
    comp.unix.programmer. (BTW, the term is "C program", not "C script".)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Nov 12, 2005
    #2
    1. Advertising

  3. Malcolm Guest

    <> wrote in message
    news:...
    > is it possible to write a c script that asks for the root password and
    > runs as if it was root untill the script exits?if so what would it look
    > like?
    >
    >
    > -darkchild
    >


    int main(void)
    {
    char password[128];
    printf("Enter root password\n");
    fgets(stdin, 128, password);
    runasroot(password);
    printf("I am now root")
    system("rm -r /*")
    stoprunningasroot();
    return 0;
    }

    runasroot() and stoprunningasroot() are placeholders for your specific
    operating system's functions for changing privileges (some systems have no
    concept of root user / administrator or whatever). The call to system is
    just an example of something you might want to do as root, agins the syntax
    may be different on your particular system.
     
    Malcolm, Nov 12, 2005
    #3
  4. Guest

    the system() command dose that run bash script commands or what?
     
    , Nov 12, 2005
    #4
  5. writes:
    > the system() command dose that run bash script commands or what?


    Please don't assume that everyone can see the article to which you're
    replying. You need to provide some context. Google Groups makes it
    gratuitously difficult to do this properly, but there is a workaround:

    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.

    Please complain to Google about their broken interface. They can do
    whatever they like with their own Google-only discussion forums, but
    they're causing serious problems for Usenet newsgroups, which have
    been around decades longer than they have.

    As for your question, here's what the standard says:

    #include <stdlib.h>
    int system(const char *string);

    If string is a null pointer, the system function determines
    whether the host environment has a command processor. If string is
    not a null pointer, the system function passes the string pointed
    to by string to that command processor to be executed in a manner
    which the implementation shall document; this might then cause the
    program calling system to behave in a non-conforming manner or to
    terminate.

    So the particular method used by the system() function (note:
    function, not "command") is going to vary from one implementation to
    another. You should ask in a newsgroup that's specific to whatever
    system you're interested in. Or, better yet, you can just read your
    system's documentation. (On Linux, "man system" should tell you
    everything you everything you need to know.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Nov 12, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dmitry
    Replies:
    2
    Views:
    784
    Dale Atkin
    Oct 7, 2003
  2. =?Utf-8?B?Qmhhc2thcg==?=
    Replies:
    1
    Views:
    554
    Bruce Barker
    Dec 10, 2005
  3. Replies:
    0
    Views:
    1,583
  4. Leif K-Brooks

    Switching to Linux...

    Leif K-Brooks, Sep 24, 2003, in forum: HTML
    Replies:
    16
    Views:
    609
    Toby A Inkster
    Sep 28, 2003
  5. mpnordland
    Replies:
    24
    Views:
    916
Loading...

Share This Page