LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2004, 10:17 AM   #1
icoming
Member
 
Registered: Feb 2004
Posts: 96

Rep: Reputation: 15
how to get root's right in my program


there is the function of system("/sbin/poweroff") in my program.
When i run the program,it tells me i must be 'root' if i execute 'poweroff'.
But i execute 'poweroff' in my xterm,when i am not 'root',it doesn't tell me that i am not root.
why?
 
Old 09-02-2004, 11:03 AM   #2
lone_nut
Member
 
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179

Rep: Reputation: 30
Setuid
It is a special atribut you can set to files, so when executed you can run it as the owner of the file, nearly always root. try
man chmod
for how to turn it on. cant remember.
 
Old 09-02-2004, 09:54 PM   #3
icoming
Member
 
Registered: Feb 2004
Posts: 96

Original Poster
Rep: Reputation: 15
But there are such softwares:when i am not 'root',and run them,they will ask me for the root's password.
how can i do that?
 
Old 09-03-2004, 12:09 AM   #4
mirradric
Member
 
Registered: May 2004
Location: Singapore
Distribution: Debian woody and debian sarge
Posts: 188

Rep: Reputation: 31
Quote:
Originally posted by icoming
But there are such softwares:when i am not 'root',and run them,they will ask me for the root's password.
how can i do that?
are you refering to su?
 
Old 09-03-2004, 02:14 AM   #5
2mcm
LQ Newbie
 
Registered: Apr 2004
Location: New Zealand
Distribution: Slackware 10.0, Gentoo ( no version )
Posts: 21

Rep: Reputation: 15
or sudo ?
 
Old 09-03-2004, 11:43 AM   #6
heluani
LQ Newbie
 
Registered: Aug 2004
Distribution: Fedora Core 2
Posts: 16

Rep: Reputation: 0
The syntax to change the setuid flag is chmod +s /sbin/halt or +s /sbin/poweroff (I assume that poweroff is a link to halt in your system, and both of them call shutdown). Anyways this doesn't answer your original question as to why you can't run them from a program but you can call them from a Console. I believe that the answer lies in that you may have configured permissions to console users. For instance, if you're using Fedora Core/Red Hat, by default you'll have files /etc/security/console.apps/poweroff and so on, if you remove these files then you won't be able to call poweroff from console. Another thing that could be set up in your box is the line

%users localhost=/sbin/shutdown -h now

in your /etc/sudoers file, which grant access also...

Hope this answers your question.

R.
 
Old 09-04-2004, 11:00 AM   #7
phoenix7
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122

Rep: Reputation: 15
sudo

hi
first you can run in the shell:

you add this line
Code:
visudo
this also as the same as
Code:
vim /etc/sudoers
you can copy the line I think that is
Code:
root ALL ALL=(ALL)
and add a line almost seems to this line

Code:
yourusername  ALL ALL=(ALL)
after that your account has root permissons to all resources in the system.
and you can run programs with this syntax


Code:
sudo yourprogram
in this case your program has root permissons.

Have a time with Linux!,
Mohammad
 
Old 09-05-2004, 03:03 PM   #8
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Rep: Reputation: 30
$ chmod u+s yourprogram
 
Old 09-06-2004, 02:29 AM   #9
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
There is a pam module which can be used to get the roots' password
from the user and execute something in roots' permissions.
I think that would be helpful to you.
Try searching for 'pam' in this df i saw a url posted with tutorials..
in this df could be helpful to you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to increase root's partition? snakeo2 Linux - Newbie 5 10-10-2005 11:18 AM
root's .bash_profile xushi Solaris / OpenSolaris 2 05-11-2005 05:28 PM
How to set root's PATH? gepesz Linux - Software 2 08-26-2004 11:10 AM
root's clone karunesh Linux - General 5 06-02-2004 06:20 AM
How to give root's rights Qebex Linux - General 2 09-25-2002 11:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration