Page 1 of 1

Sudo relauncher class (using pkexec)

Posted: Friday 07th August 2020 4:49pm
by BruceSteers
Hi.

I've been writing a class based on something my pkAppMan application does...

As it loads it checks the pkexec policy list to see if '/usr/bin/gbr3' is in it.

if not run as root and gbr3 is not in pkexec list then it displays a message
telling the user to run the application from a shell as root to configure pkexec
to allow gambas apps to ask for root.

Running as root from a terminal will auto-add gbr3 to pkexec list if it's not there and
inform the user via a terminal message that it's been added and now pkexec will work for gambas apps.

now the app can be launched in many ways and still ask for root access via pkexec. (even just double clicking the application.gambas file.)

if gbr3 exists in pkexec list and app has not been run as root it uses the shell command to relaunch itself and quit the current loading app

With the following code...

Code: Select all

' Gambas class file
Public pkp As PkPolicy

Public Sub Form_Open()
pkp = New PkPolicy
pkp.pkLaunch

End
ToDo....
Make it pass any other additional arguments from the initial calling command

Re: Sudo relauncher class (using pkexec)

Posted: Thursday 17th September 2020 12:07pm
by BruceSteers
I did the Todo

It will now pass any additional given arguments to the app being launched.

I've renamed it to PkLaunch.class as it wasn't the pkPolicy.class that's another class i wrote for pkAppMan that fully manages the pkexec policy file. but i used that class and cut it down to the relauncher , forgot to rename it.

Have made it translatable.

So .. add the class to your project.
add this code to the begining of your Form_Open() Event..

Code: Select all

Dim myPk as PkLaunch
myPk = New PkLaunch
myPk.Launch
And you have a root enabled app :)