running SU commands in an app
Posted: Friday 3rd June 2022 8:59am
Is there ANY possible way to get a gambas program to raise it's su privilages after launch?
I have a program doing some copy/move/delete commands that may or may not be in root only accessible locations.
I don't want to force the app to be run as root but would be handy if it could get su privileges once run if needed.
My currently used option is to gather any commands that need to be run as root into a temporary bash script then run the script via Desktop.RunAsRoot (pkexec) but this will ask for password each time i run a command,
I'm working on this solution... (it's a bit hacky but it works)..
I have a hidden TerminalView object that runs bash through pkexec so a one time password request activates the hidden su bash terminal and then I can run commands through it at will without having to authorize again.
Problems are output text comes with all the terminal escape chars/codes and needs filtering (not a problem if output is not needed) and i'm limited to only using shell commands not gambas internal ones.
anyone ever worked on having a gambas app raise it's privileges?
Ideally i'd like to up the level then use gambas internal copy/move methods rather than shell commands.
Attached is a rough tester for what i have so far. it's simply a textbox with some buttons and a textarea. enter the command you want to run in the textbox and press a button to run it, output goes in the textarea
you can run a command as root and it will ask for password, then running further commands does not as it goes through the hidden TerminalView with superuser bash.
I was getting truncated output. not sure if anyone can improve on my Process_Read() function.
Anyone got a better solution for elevating to SU after program is started?
Respects
I have a program doing some copy/move/delete commands that may or may not be in root only accessible locations.
I don't want to force the app to be run as root but would be handy if it could get su privileges once run if needed.
My currently used option is to gather any commands that need to be run as root into a temporary bash script then run the script via Desktop.RunAsRoot (pkexec) but this will ask for password each time i run a command,
I'm working on this solution... (it's a bit hacky but it works)..
I have a hidden TerminalView object that runs bash through pkexec so a one time password request activates the hidden su bash terminal and then I can run commands through it at will without having to authorize again.
Problems are output text comes with all the terminal escape chars/codes and needs filtering (not a problem if output is not needed) and i'm limited to only using shell commands not gambas internal ones.
anyone ever worked on having a gambas app raise it's privileges?
Ideally i'd like to up the level then use gambas internal copy/move methods rather than shell commands.
Attached is a rough tester for what i have so far. it's simply a textbox with some buttons and a textarea. enter the command you want to run in the textbox and press a button to run it, output goes in the textarea
you can run a command as root and it will ask for password, then running further commands does not as it goes through the hidden TerminalView with superuser bash.
I was getting truncated output. not sure if anyone can improve on my Process_Read() function.
Anyone got a better solution for elevating to SU after program is started?
Respects