Active Topics

 


Reply
Thread Tools
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#1
I have been trying to find the proper way how to let a script have root permission. But haven't found an answer. I am trying to make it easier for people using the Awoken-Icon-theme changing the /usr/share/pixmaps/ icons. And am pretty much finish with the gui.

I don't want the user needing to open an terminal and do sudo gainroot. Even better if Rootsh wasn't needed at all. Right now all my solutions ends up in the use/installation of rootsh. Is there a way passed this?

Like the use of a sudoers file in "/etc/sudoers.d/". If i make this file it doesn't seam to recognize it. It still gives be permission denied when doing "/usr/bin/script".

Same goes for if i am putting:
Code:
if [ `id -u` != 0 ]; then
root<<EOF
/usr/bin/python /home/user/.scriptfolder/script.py
EOF
    exit $?
fi
or any other incarnation of this. This works if the user have Rootsh installed though. But what if he don't?

Also what is the proper way of giving "chmod +x"? Does it keep the executable permission through an install/upgrade?

I do not have scratchbox .. am doing all the testing on the n900.
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums
 
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#2
One way to achive that would be:

Make a sudoers file with this inside:
Code:
user ALL = NOPASSWD: /home/user/.scriptfolder/script.py
(Note it would be safer if the script was placed in /opt/somewhere and owned by root with 744 privileges though)

and place it in /etc/sudoers.d/

in the first line of your py code add this to make it execute directly:
Code:
#!/usr/bin/python2.5
from inside you code to execute the script as root:
Code:
os.system('sudo  /home/user/.scriptfolder/script.py')
Should work..
 

The Following 4 Users Say Thank You to Saturn For This Useful Post:
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#3
Have pretty much done that already.. except for the "#!/usr/bin/python2.5" string.

I have mixed PyQT with Bash. Could that cause the problem? Basically i run an gui with python. It has three buttons. The action of the buttons lay in a sh-script. The sh-script contains some for-loops that cp/rm/mv files.

I have not gained enough competence to do that in python yet.. why i do it through a shell-script.

I will go through it again to see if i missed something.. thanks a lot for the reply
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#4
Originally Posted by AlMehdi View Post
I have been trying to find the proper way how to let a script have root permission. But haven't found an answer. I am trying to make it easier for people using the Awoken-Icon-theme changing the /usr/share/pixmaps/ icons. And am pretty much finish with the gui.

I don't want the user needing to open an terminal and do sudo gainroot. Even better if Rootsh wasn't needed at all. Right now all my solutions ends up in the use/installation of rootsh. Is there a way passed this?

Like the use of a sudoers file in "/etc/sudoers.d/". If i make this file it doesn't seam to recognize it. It still gives be permission denied when doing "/usr/bin/script".

Same goes for if i am putting:
Code:
if [ `id -u` != 0 ]; then
root<<EOF
/usr/bin/python /home/user/.scriptfolder/script.py
EOF
    exit $?
fi
or any other incarnation of this. This works if the user have Rootsh installed though. But what if he don't?

Also what is the proper way of giving "chmod +x"? Does it keep the executable permission through an install/upgrade?

I do not have scratchbox .. am doing all the testing on the n900.
How about:

Code:
if [ `id -u` != 0 ]; then
exec root<<EOF
exec /usr/bin/python $0 $*
EOF
    exit $?
fi
Just for your food of thought.
 

The Following User Says Thank You to 9000 For This Useful Post:
Posts: 80 | Thanked: 40 times | Joined on Feb 2010 @ UK
#5
Setuid maybe? Here's an explainiation I pretty much picked at random from a Google search.
 

The Following User Says Thank You to rich c For This Useful Post:
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#6
The GUI should be run as user and the three scripts as root. Otherwise the GUI will not have all graphic elements.

In the sudoers file you can have more than one scripts defined like (there is no line break):
Code:
user ALL = NOPASSWD: /somewhere/script1.sh /somewhere/script2.sh
If you want send me the code and I will have a look for you.
 

The Following User Says Thank You to Saturn For This Useful Post:
mece's Avatar
Posts: 1,111 | Thanked: 1,985 times | Joined on Aug 2009 @ Åbo, Finland
#7
without any modifications to sudoers and whatnot you can use run-standalone.sh like this:

sudo /usr/bin/run-standalone.sh /path/to/runthisscriptasroot.sh

That will run "runthisscriptasroot.sh" as root.

EDIT:
tested it with this script:

#!/bin/sh
whoami > whoami.txt

works
__________________
Class .. : Meddler, Thread watcher, Developer, Helper
Humor .. : [********--] Alignment: Pacifist
Patience : [*****-----] Weapon(s): N900, N950, Metal music
Agro ... : [----------] Relic(s) : N95, NGage, Tamyia Wild One

Try Tweed Suit for your hardcore twittering needs
http://twitter.com/mece66
I like my coffee black, like my metal.
 

The Following 5 Users Say Thank You to mece For This Useful Post:
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#8
Thanks for all of the suggestions

Update:

The run file is /usr/share/application/hildon/awoken.desktop. It uses the gui-file /opt/awoken-extras/awoken.py that uses /opt/awoken-extras/data.sh depending on what button you pressed.

By using the "run-standalone.sh" i am able to run the awoken.py file as root.. but when it want to execute data.sh it get a permission error. I have tried with both user and root permission on the awoken.py file.

So it is: awoken.desktop >> awoken.py >> data.sh

I have tried with and without the awkoen.sudoers in /etc/sudoers.d/

The files are in it's actual folder so if somebody want to try it on the n900 the only need is to unpack it to root. You should comment out the data.sh so no icons are changed.

The file is here: http://dl.dropbox.com/u/3143026/awok...e-1.1-5.tar.gz
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#9
Originally Posted by AlMehdi View Post
I have tried with and without the awkoen.sudoers in /etc/sudoers.d/
Just to check, did you run update-sudoers after adding the file? It won't do anything otherwise.
 
Posts: 1,751 | Thanked: 844 times | Joined on Feb 2010 @ Sweden
#10
Originally Posted by Rob1n View Post
Just to check, did you run update-sudoers after adding the file? It won't do anything otherwise.
Yes, multiple times. But it takes a while before it show up inside /etc/sudoers.

Saturn have looked upon my code and i think he solved it. The install file will contain a postinst file to sett the proper permissions.
__________________
You like what i do? Donate!

Make your desktop look awesome - use the AwOken Theme with the AwOken Icon Theme.

Add me on twitter @almehdin
Visit the swedish maemo/meego community forums

Last edited by AlMehdi; 2011-03-02 at 08:45.
 
Reply


 
Forum Jump


All times are GMT. The time now is 01:04.