473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

linux user switching

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 15 '05 #1
4 1305
da*********@gmail.com 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) ks***@mib.org <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.
Nov 15 '05 #2

<da*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr 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.
Nov 15 '05 #3
the system() command dose that run bash script commands or what?

Nov 15 '05 #4
da*********@gmail.com 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) ks***@mib.org <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.
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Peter Maas | last post by:
Recently I replaced Win2k with Linux on my desktop computer. Using mostly multi-platform software I thought this would be easy. It was not as easy as expected getting wxPython to work. There seemed...
26
by: Simon | last post by:
I'm doing a survey. When do you think GNU/Linux will be ready for the average Joe? What obstacles must it overcome first?
4
by: Tim Golden | last post by:
Tim Golden enlightened us with: > > Well, I'm with you. I'm sure a lot of people will chime in to point > > out just how flexible and useful and productive Linux is as a > > workstation, but every...
27
by: Mike | last post by:
Open source programs in general suck pretty bad also. Here are some loose facts regarding why projects like Linux, PHP, MYSQL, and other open source programs suck: - Linux is simply a clone of...
6
by: Nicky | last post by:
hi,all We are going to develop a program and when it is running, we need it full screen and also, user can not switch to other place before exit our program. I am thinking, we can make a window...
30
by: Christopher Kurtis Koeber | last post by:
Here is the story from Linux.org: http://www.linux.org/news/2004/10/05/0009.html I just want to know what everyone thinks on the issue. What will all of us VB developers do, there isn't much of...
0
by: Erick | last post by:
I want to be able to detect through .net when users change on an xp machine using "fast user switching" method. All i have found so far is the Microsoft.Win32.systemevents clas which has events...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
0
by: Matthias Huening | last post by:
Hi, I have problems using tkFileDialog under Linux (Ubuntu 8.04 in my case, but other Linuxes seem to show the same behaviour). The following works fine: import tkFileDialog f =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.