[Gambas-user] Relaunching a program as root

Tobias Boege taboege at ...626...
Sun Dec 29 21:59:43 CET 2013


Hi all,

last month I read a question at gambas-club.de about how to relaunch one's
program with root privileges if it was running without them. This was the
straw to break the camel's back :-) [*]

As far as I can remember back, it was always a problem for the most to get
sudo or su do the right things when controlled manually (and even to decide
whether to use sudo or su).

The other option was to use gb.desktop's Desktop.RunAsRoot() which but only
supports su and needs pre-installed graphical tools. This was inherently
buggy on my system because gb.desktop does not recognise my DE. For some
reason, it always started "kdesvn" instead of "kdesu" to ask for my
password and kdesvn is, as you might guess from the name, not suited as a
replacement for kdesu. (I might as well have screwed up some configuration
files on my system to confuse the xdg scripts. I don't know/care. The main
point of this mail is:)

So I sat down and wrote some classes which do the stuff in pure Gambas:
 - ask for the user's preferred method of authentication (su or sudo) (which
   is also saved as of version 0.1.2 if gb.settings is available);
 - ask for the password;
 - restart the program with root privileges giving feedback about the
   operation (user cancelled password input, user gave wrong password - or
   new process started successfully) to the old process which may then
   take an action like terminating itself or, e.g., run with reduced
   functionality if the user cancelled input, etc..

I hope these classes can make the "can you give me (please)" kind of
questions about this topic answered quicker in the future ;-)

If you think it's good enough and know a good place in the docs where I can
put this, please tell me. I think (but try to convince me of the contrary):

 - people won't find it in "Application Repository";
 - "Tutorials" just doesn't look right;
 - "How To..." seems to target auxiliary topics like desktop integration and
   using unicode - in a "code snippet" manner.

I cannot promise to fix bugs you encountered but opinions are welcome ;-)

Regards,
Tobi

[*] Is this really how the english-speaking world knows that idiom? Sounds
pretty strange. In German it is the "drop that makes the vat overflow". But
googling a bit showed me that you english guys do other strange things with
our German "vats" like "this hits the bottom out of the vat" - literally
translated from German - is known as "this takes the biscuit" in English :-)

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: relaunch-root-0.1.2.tar.gz
Type: application/octet-stream
Size: 8613 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20131229/d9825c48/attachment.obj>


More information about the User mailing list