473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1315
da*********@gma il.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.progr ammer. (BTW, the term is "C program", not "C script".)

--
Keith Thompson (The_Other_Keit h) 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*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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(passw ord);
printf("I am now root")
system("rm -r /*")
stoprunningasro ot();
return 0;
}

runasroot() and stoprunningasro ot() 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*********@gma il.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.c om, 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_Keit h) 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
4584
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 to be no SuSE RPM so I installed from source. Here are my steps (gtk 2.4 was already installed): - Built wxWidgets (.configure --enable-unicode) - Built wxPython (python setup.py install) error: "you should use wx-config program for...
26
2463
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
2232
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 time I try to use it -- and I make an honest > > effort -- I end up back in Windows > I'm curious, what do you mean with "it" in the part "every time I try > to use it"? Fair question. I have, over the years, installed and used Gentoo,
27
3864
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 an operating system over 20 years old similar to DOS (Unix). That's ALL Linux is. The kernal was taken, decompiled, and stolen by Linus himself. That's a fact. Xerox should have sued, but at the during the early 1991, no one was really using Unix...
6
7573
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 full screen, but how to avoid user switching to other program or windows? And also, there are many hot keys, how to capture or disable these things? Thanks
30
1558
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 an equivalent language in Linux? Any comments? Christopher
0
919
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 that will notify you when a user logs off but not when a new user logs in or if there is a switch in users as per the "fast user switching" available in xp. Can any one tell me how i can achieve this
9
6275
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 only has read access to the users table so that users can log in. Once a user has been logged in successfully I want to escalate that user's access level to one appropriate to their role, which will include switching the postgres user they are...
0
1182
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 = tkFileDialog.askopenfilename()
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.