Active Topics

 



Notices


Reply
Thread Tools
Posts: 164 | Thanked: 132 times | Joined on Dec 2007
#1
This is a simple utility for gaining root access. It is similar to (and inspired by) becomeroot, but better in a number of ways:

* sources .bashrc and other startup scripts when turning on root mode
* correctly sets the home directory for user root
* doesn't force the built-in shell onto the user

In addition, there is now a shortcut for entering root mode - "root".

-----
Edit: newer version of easyroot is backward compatible with 'sudo gainroot'. The features above (e.g. sourcing of .bashrc) are only activated by typing 'root'. Thanks to fanoush for this suggestion.
-----

Sample session

[user@nokia ~]$ root
[root@nokia ~]$

Download easyroot here:

http://maemostuff.com

(PS This works for me, but it may not work for you. Backup your files just in case )

Last edited by ag2; 2008-01-30 at 07:50.
 

The Following 4 Users Say Thank You to ag2 For This Useful Post:
Posts: 130 | Thanked: 13 times | Joined on Dec 2007
#2
I'm all for the easy option.
Will try it.

Thanks.

Zuber
 
Posts: 2,152 | Thanked: 1,490 times | Joined on Jan 2006 @ Czech Republic
#3
Originally Posted by ag2 View Post
This is a simple utility for gaining root access. It is similar to (and inspired by) becomeroot, but better in a number of ways
Even if it is better, it should stay 100% compatible with 'sudo gainroot'. Looks like you tried but still I would suggest to drop '-' after su from /usr/sbin/gainroot to make it more compatible with original version. You can add it to your new root script so it is still 'easy'. So root script would become "sudo gainroot -" and in original gainroot use something like "exec su $@". Using exec will avoid one sh process in calling stack (=save some memory). Same could be done in your new root script so together you will save two waiting shells (try it with ps, top or htop from SDK repository).
__________________
Newbies click here before posting. Thanks.

If you really need to PM me with troubleshooting question please consider posting it to the forum instead. It is OK to PM me a link to such post then. Thank you.

Last edited by fanoush; 2008-01-07 at 14:50.
 

The Following User Says Thank You to fanoush For This Useful Post:
Posts: 164 | Thanked: 132 times | Joined on Dec 2007
#4
Originally Posted by fanoush View Post
Even if it is better, it should stay 100% compatible with 'sudo gainroot'. Looks like you tried but still I would suggest to drop '-' after su from /usr/sbin/gainroot to make it more compatible with original version. You can add it to your new root script so it is still 'easy'. So root script would become "sudo gainroot -" and in original gainroot use something like "exec su $@". Using exec will avoid one sh process in calling stack (=save some memory). Same could be done in your new root script so together you will save two waiting shells (try it with ps, top or htop from SDK repository).
Hi fanoush,

I am not sure what you mean by 100% compatible with 'sudo gainroot'. The original 'sudo gainroot' had serious problems, so deviating from it was a design goal. Let me elaborate a bit more on what I think is wrong with the current 'sudo gainroot':

- (this seems to be a bug with busybox) After 'sudo gainroot', "~" still resolves to /home/user instead of /root. Similarly, if you type 'cd' with no arguments, you end up in /home/user.

- with /bin/sh, none of the startup scripts (.bashrc, .profile, etc) are sourced. So if you want to have a custom prompt for root, you can't.

- 'sudo gainroot' always starts in busybox's sorry-*** shell, even if I become root from bash.

- I wasn't very happy with tons of logging (7 lines?) when switching to root. If I need to copy-paste something, the extra logging pushes the interesting stuff above the fold.

'su -' in my version works around all of the above problems.

Also, please note that typing 'sudo gainroot' still works. 'root' is just a convenient shortcut. You can add 'alias root="sudo gainroot"' to your .bashrc to avoid the extra shell instance, though in practice I think the overhead of an extra shell is negligible.

I am not sure about your 'exec' suggestions. I would think a new shell would be started anyway for 'sudo gainroot' regardless of what I put in 'root', because it is 'gainroot' that starts a new shell (with #!/bin/sh). No?

Finally, the original 'sudo gainroot' starts a new shell too, so this script is no worse than the original if you invoke it with 'sudo gainroot'.

Thanks.
 
Posts: 2,152 | Thanked: 1,490 times | Joined on Jan 2006 @ Czech Republic
#5
'sudo gainroot' does not change current directory, does not read .<whatever>rc (and thus does not mess environment variables in unknown way) etc. and is here for more than 2 years. If you want something better/easier/incompatible with this, you (IMO) should put it to your 'root' shortcut so the old way (=running sudo gainroot) still works in same way. Especially if you force people to chose either becomeroot or your package. Design goal of breaking compatibility doesn't look like good goal to me.

One example of compatibility is launching sudo gainroot from scripts to relaunch itself as root like this
Code:
#!/bin/sh
if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
        exec sudo gainroot <<EOF
exec $0 $*
EOF
        exit $?
fi
#real script follows
echo "I am `id`"
echo "current dir is `pwd`"
I am using it a lot in my scripts and over time lot of people may use it too for various quick hacks. It is simple way that allows you to run code as root from scripts without touching /etc/sudoers. Your change of /usr/sbin/gainroot may break such scripts that don't expect things like current working directory or other variables to change.

as for using exec - this is really small thing but as I said try to see with htop what happens when you launch your 'root' script an how many different processes (mainly shells) are spawned, kept in memory and wait for its child to exit. Exec call replaces current process so this does not happen.
__________________
Newbies click here before posting. Thanks.

If you really need to PM me with troubleshooting question please consider posting it to the forum instead. It is OK to PM me a link to such post then. Thank you.

Last edited by fanoush; 2008-01-07 at 21:48.
 

The Following 5 Users Say Thank You to fanoush For This Useful Post:
penguinbait's Avatar
Posts: 3,096 | Thanked: 1,525 times | Joined on Jan 2006 @ Michigan, USA
#6
I just use GNU tar and or add ALL=ALL to user in /etc/sudoers
 
Posts: 164 | Thanked: 132 times | Joined on Dec 2007
#7
fanoush -- I see your point. I will try the suggestions in your original post. If they work, I will update the script. Thanks once again for your feedback.
 
Posts: 2,152 | Thanked: 1,490 times | Joined on Jan 2006 @ Czech Republic
#8
Originally Posted by ag2 View Post
fanoush -- I see your point. I will try the suggestions in your original post. If they work, I will update the script. Thanks once again for your feedback.
Thanks for considering it :-)
__________________
Newbies click here before posting. Thanks.

If you really need to PM me with troubleshooting question please consider posting it to the forum instead. It is OK to PM me a link to such post then. Thank you.
 
BruceL's Avatar
Posts: 305 | Thanked: 154 times | Joined on Aug 2006 @ Colorado
#9
Thanks for your work ag2. I must say that several of my scripts use Fanoush's gainroot trick and it would be a problem if it broke. However, it would be great to have .bashrc working.
 
Posts: 164 | Thanked: 132 times | Joined on Dec 2007
#10
Changing su - to su helps only a little bit:

- .bashrc is still sourced
- the value of ~ changes to /root

The only difference is that the current directory doesn't change

I suppose I can put an if statement in gainroot so that it calls su when called from root and continues to call /bin/sh otherwise. Would this be acceptable? Can you think of other workarounds?
 
Reply


 
Forum Jump


All times are GMT. The time now is 02:10.