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
relaunchbykendek.tar.gz
Description: application/gzip
------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user