Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Setting date/time without being root user?

Posted on 2007-03-21
10
Medium Priority
?
826 Views
Last Modified: 2008-01-09
I need to programmatically set the system date and time on a Linux (RedHat) system without being logged in as the root user. How can I do this, without compromising the security of the system?

I've heard of sudo but that seems a little unsafe to me!

Basically it's a small SIL2 network with a radio clock attached via a serial port; I need to read the time of it, update my local logs, set the system time, then broadcast it around the other systems for them to do likewise. All of this is fine - except setting the system time when not a root user!

Cheers
0
Comment
Question by:gmayo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 6

Expert Comment

by:FrivolousSam
ID: 18766072
This is what the setuid flag is for.  For background, look at http://en.wikipedia.org/wiki/Setuid

You can either log in as root and execute:
chmod ug+s `which date`

Or write a script and chmod your script as root to add the suid bit -- just watch out for injection attacks by your users.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18767514
There's nothing wrong or unsafe with sudo providing you define the commands that need to be run correctly.

Why not just setup NTP?
0
 
LVL 8

Author Comment

by:gmayo
ID: 18769893
The whole network, albeit small, is mostly "black box" machines running in locked equipment rooms. The few users will be on Windows machines, connected via a secure network protocol. All the systems need to perform logging and for that a reliable time source is required - and the fact that the time has changed needs to be logged. Also, as I said before, it's a SIL2 system. All this is why an NTP server cannot be used.

Setuid looks good. One of my programmers says it's potentially unsafe though - but it might be a case of "you said black, so I'll say white" - his only suggested alternative was to use "chroot jail" which, from first glance, seems to be a wide open invitation to abuse.

So, any issues with setuid I ought to be aware of?

Thanks
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 35

Expert Comment

by:Duncan Roe
ID: 18774923
setuid programs should do as little as possible other than the specific task they are written for. For instance, they can fill a filesystem completely full (regular users are subject to a margin). Otherwise, they're fine.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18774991
Writing a good/safe setuid program is a lot harder than defining a sensible sudo rule.
0
 
LVL 6

Expert Comment

by:FrivolousSam
ID: 18779921
I don't see how setting date as setuid is less safe than allowing any user to run date through sudo -- if there is a security flaw in the date program, you are exposed either way.

As far as I can see, there is only one benefit to allowing sudo for this case - you can restrict which users are allowed to set the date.  If you setuid date then any user can exploit a security flaw, but the choice is yours...  Info on editing sudoers using visudo is here: http://www.gratisoft.us/sudo/man/visudo.html
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18786689
Point being is that the code for date (or any other common command) has been around for a very, very long time, so the chance of any exploits in the code are very low compared to writing a setuid program from scratch.

Admittedly, as setting the date is such a simple operation, there's not really that much you can do wrong writing your own program, but it's still possible to write exploitable simple setuid programs.

0
 
LVL 8

Author Comment

by:gmayo
ID: 18806803
Ok, bear in mind this is a small, closed system with controlled access in locked rooms. All we want to do is call the date command to set the system date and time. If there is a way to do it programmatically instead of calling a system command, then so much the better - especially if it avoids all this aggro.
0
 
LVL 6

Accepted Solution

by:
FrivolousSam earned 500 total points
ID: 18826495
All you need to do is log in as root, setuid ug+s date and log out.  Then you can call date from any script and you will be able to set the date.

That is the way to solve your problem.  Where is the aggro?
0
 
LVL 8

Author Comment

by:gmayo
ID: 18834907
Ok, I'll take your word for it. There appear to be two conflicting arguments and I wanted to know the pros and cons of each approach.

Thanks anyway.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question