LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 06-08-2005, 05:25 AM   #1
neo_in_matrix
Member
 
Registered: Sep 2003
Posts: 52

Rep: Reputation: 15
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.
 
Old 06-08-2005, 06:00 AM   #2
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
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.
 
Old 06-08-2005, 11:46 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
I do not want su.
Try "sudo" instead. You can tell sudo to let specific user run specific programs as root, without asking the user(s) for a password.
 
Old 06-08-2005, 12:02 PM   #4
neo_in_matrix
Member
 
Registered: Sep 2003
Posts: 52

Original Poster
Rep: Reputation: 15
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?
 
Old 06-08-2005, 05:46 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
First, you need to know the full path of the "date" program. It's probably "/bin/date. But to be sure, check with:
Code:
which date
.

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:
Code:
sudo date 03190100
This will also work when this line is in a script.

Last edited by Hko; 06-08-2005 at 05:48 PM.
 
Old 06-08-2005, 09:38 PM   #6
neo_in_matrix
Member
 
Registered: Sep 2003
Posts: 52

Original Poster
Rep: Reputation: 15
That's great! Thanks!
 
  


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
Mozilla (1.7) only runs in root. epheles Linux - Newbie 4 01-09-2005 11:05 AM
program only runs as root mjkramer Linux - Newbie 5 11-22-2004 10:32 AM
x only runs in root Bigfut Red Hat 1 08-19-2004 02:43 AM
evolution only runs for root h2gofast Linux - Software 0 08-16-2004 01:42 PM
Java, code compiles and supposedly runs fine in windows, but not linux exodist Programming 4 03-16-2004 12:47 PM


All times are GMT -5. The time now is 03:33 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration