[Gambas-user] Relaunching a program as root
Kende Krisztián
nemh at ...2007...
Mon Dec 30 03:20:07 CET 2013
2013-12-29 21:59 keltezéssel, Tobias Boege írta:
> 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
>
>
Jeez, that's complicated code!
I wrote my own version, this is perhaps a little simpler. Check it. ;-)
Otherwise. Your code:
IIf(Application.Path Ends ".gambas", "/usr/bin/gbr3 ", "/usr/bin/gbx3 ")
& Application.Path
isn't correct, because Application.Path is a directory, not file.
And a little bug. If I use sudo method and I write good password, then
opened two window; root and error message (good with su method).
Kendek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: relaunchbykendek.tar.gz
Type: application/gzip
Size: 6197 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20131230/e9dbbdbb/attachment.gz>
More information about the User
mailing list