Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > linux user switching

Reply
Thread Tools

linux user switching

 
 
darkchild50@gmail.com
Guest
Posts: n/a
 
      11-12-2005
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

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      11-12-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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) (E-Mail Removed) <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.
 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      11-12-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.


 
Reply With Quote
 
darkchild50@gmail.com
Guest
Posts: n/a
 
      11-12-2005
the system() command dose that run bash script commands or what?

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      11-12-2005
(E-Mail Removed) 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) (E-Mail Removed) <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching user switching and getting current active user from root on linux mpnordland Python 24 12-31-2010 12:59 AM
Re: Is Netscape Leaving Firefox Behind on GNU/Linux? THE LINUX PROPAGANDA MACHINE CONTINUES. FIREFOX IGNORING LINUX............. traci.manicotti@gmail.com Computer Support 2 10-20-2007 02:12 PM
Process Switching vs. Fast/CEF Switching? asdf Cisco 7 05-29-2007 05:26 PM
Linux... yeah linux.. Linux Have a nice cup of pee NZ Computing 19 04-17-2006 10:16 AM
.NET application switching users (user A is shown user B profile) =?Utf-8?B?Qmhhc2thcg==?= ASP .Net 1 12-10-2005 01:29 AM



Advertisments