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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-08-2005, 05:25 AM
|
#1
|
|
Member
Registered: Sep 2003
Posts: 52
Rep:
|
Code runs as root?
I want to write a small program that:
1. Accepts a date string (06/08/2005);
2. Sets system date.
However, setting system date/time requries root privilege.
So I'd like to know if it possible to do it using C code? I do not want su.
|
|
|
|
06-08-2005, 06:00 AM
|
#2
|
|
Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339
Rep:
|
I don't think so. You may, however, give permission to all users to execute /bin/date, but that would severely put your system in jeopardy. For example, every user capable of changing the date, would be able to delay cron jobs, etc (I think cron uses system date, doesn't it?).
Either way, if you are doing it to learn only, then you can do that. Otherwise is just to call "su" within your program or by changing /bin/date to allow execution by user.
I could be mistaken though, as I often am 
Last edited by Mega Man X; 06-08-2005 at 06:01 AM.
|
|
|
|
06-08-2005, 11:46 AM
|
#3
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
Try "sudo" instead. You can tell sudo to let specific user run specific programs as root, without asking the user(s) for a password.
|
|
|
|
06-08-2005, 12:02 PM
|
#4
|
|
Member
Registered: Sep 2003
Posts: 52
Original Poster
Rep:
|
Could not get any idea out the man sudo. I tried to edit /etc/sudoers, but don't know how to.
I am running as user 'neo', if I want this user to run date without typing root password, what should I do?
|
|
|
|
06-08-2005, 05:46 PM
|
#5
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
First, you need to know the full path of the "date" program. It's probably "/bin/date. But to be sure, check with: .
Then to enable user "neo" to run "date" witthout being asked for a password, just put one line in /etc/sudoers
Code:
neo ALL = NOPASSWD: /bin/date
Then, for example, when user "neo" wants to run "date" as "root" to set the date-time to 19 march, 1:00 am:
This will also work when this line is in a script.
Last edited by Hko; 06-08-2005 at 05:48 PM.
|
|
|
|
06-08-2005, 09:38 PM
|
#6
|
|
Member
Registered: Sep 2003
Posts: 52
Original Poster
Rep:
|
That's great! Thanks!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:56 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
|
|