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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-02-2004, 10:17 AM
|
#1
|
Member
Registered: Feb 2004
Posts: 96
Rep:
|
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?
|
|
|
09-02-2004, 11:03 AM
|
#2
|
Member
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179
Rep:
|
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.
|
|
|
09-02-2004, 09:54 PM
|
#3
|
Member
Registered: Feb 2004
Posts: 96
Original Poster
Rep:
|
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?
|
|
|
09-03-2004, 12:09 AM
|
#4
|
Member
Registered: May 2004
Location: Singapore
Distribution: Debian woody and debian sarge
Posts: 188
Rep:
|
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?
|
|
|
09-03-2004, 02:14 AM
|
#5
|
LQ Newbie
Registered: Apr 2004
Location: New Zealand
Distribution: Slackware 10.0, Gentoo ( no version )
Posts: 21
Rep:
|
or sudo ?
|
|
|
09-03-2004, 11:43 AM
|
#6
|
LQ Newbie
Registered: Aug 2004
Distribution: Fedora Core 2
Posts: 16
Rep:
|
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.
|
|
|
09-04-2004, 11:00 AM
|
#7
|
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:
|
sudo
hi
first you can run in the shell:
you add this line this also as the same as
you can copy the line I think that is
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
in this case your program has root permissons.
Have a time with Linux!,
Mohammad
|
|
|
09-05-2004, 03:03 PM
|
#8
|
Member
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190
Rep:
|
$ chmod u+s yourprogram
|
|
|
09-06-2004, 02:29 AM
|
#9
|
Member
Registered: Apr 2004
Posts: 101
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 10:11 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|