[Tutor] Running a python script as root.
Srihari k
srih4ri at gmail.com
Sun Jul 4 20:17:12 CEST 2010
I have a small script that uses python-gammu to read time from my
phone and set the system time:
#!/usr/bin/python
import gammu
sm=gammu.StateMachine()
sm.ReadConfig()
sm.Init()
cell_time=sm.GetDateTime()
import os
os.system('date -s \'%s\''% cell_time)
Now this script works when i run it as root(#)./settime.py or do a
$sudo ./settime.py
When i run it as normal user $./settime.py (as expected) the following
error occurs:
date: cannot set date: Operation not permitted
Sun Jul 4 23:37:37 IST 2010
This is because the normal user is not allowed to set the time using
date -s command.
I did #chmod +s settime.py so that SUID bit be set and all users can
execute the script and set the system time.
now the permissions of file are:
-rwsr-xr-x 1 root root 165 2010-07-04 23:16 settime.py
The script still works as before ..
date: cannot set date: Operation not permitted
Sun Jul 4 23:37:37 IST 2010
I guess this because the python interpreter is still being run by the
normal user and is unprivileged to set the date ? Is it ?
Now how do i make this script work for everyone?
Thanks in advance,
--
Srihari K
More information about the Tutor
mailing list