LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2011, 06:36 AM   #1
cruiser
LQ Newbie
 
Registered: Apr 2011
Distribution: Ubuntu, RedHat, Fedora, Customised Linux Kernels
Posts: 23

Rep: Reputation: 1
Unable to change system time as a non-root user


Hi,

I need to edit the system time as a not-root user. I am carrying out the following actions in my program.

1. Read the User Id of the process. User_ID= getuid()
2. Printing Capabilities(Permitted, Efffective, Inheritable)of the process
3. Setting UID = 0, using setuid(0)
4. Calling the prctl(), function to keep capabilities
5.Switching the UID from root to User_ID of the process
6. What we have now is a process with root capabilities as a non root user
7. On printing Permitted, Effective, Inheritable capabilities, I get the following
--> Permitted = 0xfffffeff = Effective
Inheritable = 0x0; with UID = 1001;
8. I then try and set the system time with --> system("date -s 10:00");
9. I get an error: date: cannot set date: Operation not permitted

10. I am unable to understand as to why I cannot set the time even thought the capability bit CAP_SYS_TIME in the Permitted and Effective sets are SET.

Any help will be greatly appreciated.
Thanks and God bless.
 
Old 05-06-2011, 06:59 AM   #2
PhoenixAndThor
Member
 
Registered: Sep 2009
Location: Geogia, USA
Distribution: Ubuntu, Debian, Live CDs
Posts: 213

Rep: Reputation: 39
I think that's a security feature in *nix based systems. To run a program that requires root access, you need to be root, period. The way to execute root commands as a non-root user is with sudo. If you don't want to use sudo, you could try su -c date or su -c hwclock. This Arch Linux Wiki article has some good information: http://wiki.archlinux.org/index.php/Time
 
Old 05-06-2011, 07:30 AM   #3
cruiser
LQ Newbie
 
Registered: Apr 2011
Distribution: Ubuntu, RedHat, Fedora, Customised Linux Kernels
Posts: 23

Original Poster
Rep: Reputation: 1
But why cant we change the Time even though a process,(which is a non-root process in this case) has the CAP_SYS_TIME bit set in the Permitted and Effective sets. If an non root process cannot change the time even though the CAP_SYS_TIME bit is set, wouldnt that defeat the purpose of having capabilities?

I am referring to Question 2 from the below mentioned link.
http://www.kernel.org/pub/linux/libs...capfaq-0.2.txt
 
Old 08-09-2011, 12:47 AM   #4
cruiser
LQ Newbie
 
Registered: Apr 2011
Distribution: Ubuntu, RedHat, Fedora, Customised Linux Kernels
Posts: 23

Original Poster
Rep: Reputation: 1
The problem was that the call system() resets the permissions. Hence instead of using system(), we need to use settimeofday(). That solved the problem
 
  


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
user time, system time, real time .. reg chaitanyajun12 Linux - Newbie 7 03-14-2016 06:43 PM
Log Date/time doesn't change with system time saurabhchokshi Linux - Software 5 07-07-2010 01:27 AM
How to change a process running in root-user to non-root user ???????????????????? narendra1310 Linux - Software 4 10-29-2009 03:11 AM
Unable to change user: *su root* nedimyra Linux - Software 11 09-10-2006 12:14 PM
System time correct for root, wrong for normal user? dx0r515t Slackware 2 07-21-2006 06:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration