I'm trying to write a little C program to run under linux, which must
gain root so it can then shutdown the computer. I can get the code to
execute the su command via system("su"), but once su comes into action,
my program it's halted and su takes over. Because of this, I can't get
my program to write the password su asks. I habe no idea on how to get
C to communicate with other running processes such as su, but I
understand it can be done. Any ideas on how I can achieve this?
Martin Sigwald 5 5663 ms******@gmail. com wrote: I'm trying to write a little C program to run under linux, which must gain root so it can then shutdown the computer. I can get the code to execute the su command via system("su"), but once su comes into action, my program it's halted and su takes over. Because of this, I can't get my program to write the password su asks. I habe no idea on how to get C to communicate with other running processes such as su, but I understand it can be done. Any ideas on how I can achieve this?
Martin Sigwald
Three pieces of advice:
1) This question is off topic for news:comp.lang. c. Although system() is
a function in ISO standard C, its behavior depends on the particular
system upon which it is run.
2) As it's a Linux question, news:comp.os.li nux.development .apps would
be the place to ask. Go there.
3) Even better, considering what you're trying to do, *don't*.
HTH,
--ag
--
Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays
"If you have nothing to hide, you're not trying!"
On Sun, 11 Dec 2005 09:34:52 -0800, ms******@gmail. com wrote: I'm trying to write a little C program to run under linux, which must gain root so it can then shutdown the computer. I can get the code to execute the su command via system("su"), but once su comes into action, my program it's halted and su takes over. Because of this, I can't get my program to write the password su asks. I habe no idea on how to get C to communicate with other running processes such as su, but I understand it can be done. Any ideas on how I can achieve this?
Your question is very linux specific and off topic to this newsgroup.
However, i think you should consider using 'sudo'. Spawning an 'su'
process (if I understand you correctly) will not get you where you want
to be.
Just as an aside, there are perfectly good system tools to shut your
system down ('shutdown -h now' for instance).
Check comp.os.linux.d evelopment.*. You'll get more answers there, i think.
Martin Sigwald ms******@gmail. com wrote: I'm trying to write a little C program to run under linux, which must gain root so it can then shutdown the computer. I can get the code to execute the su command via system("su"), but once su comes into action, my program it's halted and su takes over. Because of this, I can't get my program to write the password su asks. I habe no idea on how to get C to communicate with other running processes such as su, but I understand it can be done. Any ideas on how I can achieve this?
This is highly system specific so you need to ask in a Linux or Unix
group, such as comp.unix.progr ammer, however I'm pretty sure you are
using completely the wrong approach.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
>I'm trying to write a little C program to run under linux, which must gain root so it can then shutdown the computer. I can get the code to execute the su command via system("su"), but once su comes into action, my program it's halted and su takes over.
I don't know of any implementation of system() which *DOESN'T*
suspend the program that called it and run the program it was
directed to, and not unsuspend the program that called it until the
called program finishes or aborts, unless the shell is specifically
asked to put the program in the background, in which case it's not
supposed to take input from stdin.
Because of this, I can't get my program to write the password su asks.
popen() is not standard C, and I doubt it would work in this
case anyway.
Most implementations of su ask for the password from /dev/tty, not
stdin, so there's no place to write such a thing. The user is
supposed to TYPE it. Dictionary attacks are not encouraged.
Gordon L. Burditt
"ms******@gmail .com" <ms******@gmail .com> wrote:
# I'm trying to write a little C program to run under linux, which must
# gain root so it can then shutdown the computer. I can get the code to
# execute the su command via system("su"), but once su comes into action,
If you want to run interactive sub-processes, you might do better
using expect scripting. You can get more information from comp.lang.tcl.
You can run expect from system or popen in C program, if needs must.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Quit killing people. That's high profile. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Luca T. |
last post by:
Hello,
i need some answers...
1) I need to run some linux commands (from inside my app) that require
superuser privileges (mkfs, losetup, etc), how do i do that? (I do not
want to run my app with root privileges, but it will just ask the user
for the root password before proceeding)
2) When i execute the command i need to read its output (especially the
error messages) to know if everything went fine but i do not know how :(
3) How can...
|
by: Yitzhak |
last post by:
I am having "Permission denied" error while calling
LogEvent method of WScript.Shell component.
Basically, ASP page calls Windows Script Host Shell
component to log events to the OS Application Event log.
My environment:
Windows Server 2003, IIS 6, WSH, Classic ASP, Vbscript
Below is the code and the error:
Code:
|
by: YONETANI Tomokazu |
last post by:
Hello.
After upgrading a test database to V8.2 with FixPak7a, too see if
the production servers can be safely upgraded, I noticed that inserts
on an insertable view which consists of multiple underlying tables
stopped working. After playing with it some more, the only failure mode
is when you use CURRENT TIMESTAMP or CURRENT DATE to a column which is
used to determine which underlying table to insert rows to. The following
is a minimum...
|
by: Matt |
last post by:
I want to know what is the purpose of runat="server" attribute??
For example, for a submit button, it just submit the form data to the
server, whats the differences between
<input type="submit" name="submit1">
<input type="submit" name="submit1" runat="server">
Please advise! Thanks!!
|
by: ed |
last post by:
Hi,
Here's my code
'in form
WithEvents formReplace As New Form
Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Clic
formReplace.Show(
| |
by: Martijn Coppoolse |
last post by:
Hello everyone,
I've got two little apps which are able to create a window that displays
something on the desktop, but are not clickable. Instead, when you
click on the window, the item 'behind' or 'under' that window gets clicked.
I'd like to know how to do this, using VB6, VB.Net, Windows Forms, or
API functions.
Any ideas?
|
by: phil campaigne |
last post by:
Thanks Tom,
I originally set installed Postgresql as rpm with the Red Hat 8
installation. I upgraded using source and it put things in different
directories. I think that this is the source of my problem.
However, I think the updated version of Postgresql is not teh one the
system is trying to use:
>That says that when you say "psql", the system is trying to run the psql
|
by: Bruno LIVERNAIS |
last post by:
Hi,
We are currently installing a DB2 V9 ESE on a Linux server
(RHEL4U4-x86_64). Installation runs successfully on each node. Database
user environment is OK and the instance is well created. To be sure,
we've started the database with db2start =successfull. And then shut
it down again successfully too.
The tricks appears when we switch the hp MC/ServiceGuard (A.11.16 for
Linux) package to the other node... the database does not want...
|
by: michael.schmitz |
last post by:
Hello,
my tiny PHP5 test application cannot establish a connection to a
database while I am able to connect to the same database using the DB2
command line tool.
Our server is 64 bit system running SuSE Enterprise Linux 10. The PHP
version installed is v5.1.2.
Product Name = "DB2 Personal Edition"
|
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...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |