pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post Reply
BruceSteers
Posts: 17
Joined: Thursday 23rd July 2020 5:20pm

pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post by BruceSteers » Saturday 25th July 2020 10:42pm

From the Readme.txt ....

pkAppMan

What is it?
An application written in gambas basic for linux systems that use the new
policy-kit for running gui applications as root from a non terminal environment.
Ie. from a menu or a desktop launcher
If you have used GKSU in the past before it disappeared
and pkexec became the alternative but don't know how to
configure pkexec then you might want this app.

with GKSU you could just set a launchers command to
gksu /path/appname
and the app would launch fine as root after asking you for your password
pkexec on the other hand is a bit more complicated as you have to set up
a policy file for pkexec and add allowed apps to it before it will work.

That's where this app comes in.
Features.
-- Creates a new pkexec policy file if one does not exist or will
load your existing one if you have one.

-- after first launch (must be run from terminal as root)
it adds the gambas runtime to the pkexec list of apps and
after that if not run as root (ie just double click app) it will
relaunch itself with the pkexec prefix to ask for password
Also. with the gambas runtime added any gambas app that wants
root access can use pkexec prefix.

-- pass a file as an argument, if launched with a file name as
it's argument Ie. 'pkAppMan.gambas "/usr/bin/gedit"' then it will
auto add the app to the list. the means you can right click any app
on your computer and Select "Open with pkAppMan" to load pkAppMan
with said file auto added.

-- Edit description and message.
The description is just so you know what it is in the list
the Message is what is displayed when asked for password.


Requirements:
gambas3-runtime
'sudo apt-get install gambas3-runtime'

Important: on 1st ever running of the application you must run via sudo from a terminal.
ie.
sudo /path/pkAppMan.gambas
Or
sudo gbr3 /path/pkAppMan.gambas

On the first launch it will add gbr3 the gambas runtime exe
to the list of pkexec allowed commands and after that you can just
double click the pkAppMan.gambas file and it will be able to
elevate your privilages.

Instructions..

Simply launch the app and add a rule, then set the full path to the executable file you wish to run
Give a short desription (just so you know what it is) and set a message.
The 'Message' is what is displayed when the gui you want to run asks for password

Then Save.

Now you can make a launcher or menu item using pkexec.
Eg. to make a launcher for pluma text editor as root
add a rule and set it to '/usr/bin/pluma' (it should be there)
Then set the launchers command to 'pkexec pluma'
Or 'pkexec pluma "<path to file>"' to open a file

Adding the balenaEtcher.AppImage with this app also got that working for me on debian.

Screenshot:
pkAppMan.png
pkAppMan.png (68.76 KiB) Viewed 190 times
Download source and app
pkAppMan.zip
bugfix
(32.03 KiB) Downloaded 7 times
(fixed bug below)

Written by Bruce Steers
Last edited by BruceSteers on Tuesday 28th July 2020 8:41am, edited 1 time in total.

User avatar
cogier
Site Admin
Posts: 486
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post by cogier » Monday 27th July 2020 2:05pm

OK I ran the program with Sudo as instructed. I then run without Sudo and I was asked for my password but once I put my password in there was nothing! What did I do wrong?

BruceSteers
Posts: 17
Joined: Thursday 23rd July 2020 5:20pm

Re: pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post by BruceSteers » Tuesday 28th July 2020 8:39am

Oops, sorry cogier

That would be my error.
Making it auto add gbr3 to pkexec list was one of the last features i added but hadn't tested it.
seems i missed out the /usr/bin/ part of the auto adding gbr3 to pkexec :( doh

Have fixed the bug and made it check for the mistake on load so sudo from terminal again and it should be okay :)
pkAppMan.zip
fixed file
(32.03 KiB) Downloaded 10 times

User avatar
cogier
Site Admin
Posts: 486
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post by cogier » Thursday 30th July 2020 4:40pm

I'm sorry I am trying but: -

I got it to work in the IDE by making sure the Debug>Run with...>IDE=True was activated. That could have been explained.

I compiled it to the Desktop and things began to work. I added 'Xed' to the list but with or without the program running 'Xed' did not ask for a password.

What am I doing wrong?

BruceSteers
Posts: 17
Joined: Thursday 23rd July 2020 5:20pm

Re: pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post by BruceSteers » Thursday 30th July 2020 6:35pm

If youve added Xed to the list with full path then you should be set.

using pkexec to launch Xed?
Xed wont launch asking for rights on it's own. It's the policy file for pkexec the program modifies.
You need to create a launcher or menu item using the command "pkexec xed"

The program itself does nothing towards asking you for password except configuring pkexec to do it so it running or not makes no odds. (Changes need to be saved before they will take effect too)

Hope that helps 😎
Last edited by BruceSteers on Thursday 30th July 2020 6:44pm, edited 1 time in total.

BruceSteers
Posts: 17
Joined: Thursday 23rd July 2020 5:20pm

Re: pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post by BruceSteers » Thursday 30th July 2020 6:40pm

I searched fiddled for ages for a way to find if the app
would know if it was being run from the ide.
Then just added the argument ide=true, problem solved 😎

BruceSteers
Posts: 17
Joined: Thursday 23rd July 2020 5:20pm

Re: pkAppMan, manage pkexec policy file to grant gui superuser access (like GKSU)

Post by BruceSteers » Monday 03rd August 2020 11:14am

Update...

Now you can select a file in the list, right click and select to have it create a desktop launcher for you.
Uses the /home/username/Desktop/Appname.desktop protocol.
Will make either a standalone app Launcher for the selected item, like for running the Gambas3 IDE as root, and will try to find the icon for it

Or it can use the selected app as a prefix to launch another app you choose like using gbr3 pkAppMan.gambas and will try to find an icon for the "other" app.
:)
pkAppMan.zip
Compiled : 3/Aug/2020
(38.08 KiB) Downloaded 7 times

Post Reply