Commit 2906f041 authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Desktop.RunAsRoot() now uses 'pkexec' by default. Desktop.RunAs() is a new...

Desktop.RunAsRoot() now uses 'pkexec' by default. Desktop.RunAs() is a new method that allows to specify the username used for running a program.

[GB.DESKTOP]
* NEW: Desktop.RunAsRoot() now takes an optional argument to wait for the program ends, and now uses 'pkexec' by default.
* NEW: Desktop.RunAs() is a method similar as RunAsRoot() that takes the username used for running the program.
parent 4cb88fd5
Pipeline #370708723 passed with stage
in 41 minutes and 14 seconds
......@@ -340,50 +340,61 @@ Static Private Function RootWindow_Read() As Integer
End
Static Public Sub RunAsRoot(Command As String, Optional (Wait) As Boolean, Optional Username As String)
'Main.RunXdgUtil("xdg-su", ["-c", Command])
Static Public Sub RunAs(UserName As String, Command As String, Optional (Wait) As Boolean)
Dim sExec As String = "pkexec"
Dim sCom As String[]
If Not System.Exist(sExec) Then
Select Case Desktop.Type
Case "KDE", "KDE4", "KDE5"
sExec = "kdesudo"
' newer SuSE have no kdesudo, but a kdesu
If Not System.Exist(sExec) Then sExec = "kdesu"
Case "LXDE"
sExec = "lxde-sudo"
Case Else
sExec = "gksudo"
' gksu with an argument raise a gksudo
If Not System.Exist(sExec) Then sExec = "gksu"
End Select
Dim aCmd As String[]
Endif
If Not System.Exist(sExec) Then
Select Case Desktop.Type
Case "KDE", "KDE4", "KDE5"
sExec = "kdesudo"
' newer SuSE have no kdesudo, but a kdesu
If Not System.Exist(sExec) Then sExec = "kdesu"
Case "LXDE"
sExec = "lxde-sudo"
Case Else
sExec = "gksudo"
' gksu with an argument raise a gksudo
If Not System.Exist(sExec) Then sExec = "gksu"
End Select
Endif
If Not System.Exist(sExec) Then Error.Raise("No graphical sudo program found")
sCom = [sExec]
aCmd = [sExec]
If sExec = "pkexec" Then
If Username Then sCom.Insert(["--user", Username])
Dim sPassEnvs As String[] = ["DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "WAYLAND_DISPLAY"]
sCom.Add("env")
For Each sEnv As String In sPassEnvs
If Env[sEnv] Then sCom.Add(sEnv & "=" & Env[sEnv])
Next
sCom.Insert(Split(Command, " ", "\""))
If Username Then aCmd.Insert(["--user", Username])
aCmd.Add("env")
For Each sEnv As String In ["DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "WAYLAND_DISPLAY"]
If Env[sEnv] Then aCmd.Add(sEnv & "=" & Env[sEnv])
Next
aCmd.Insert(Split(Command, " ", "\""))
Else
If Username Then sCom.Insert(["-u", Username])
sCom.Add(Command)
Else
If Username Then aCmd.Insert(["-u", Username])
aCmd.Add(Command)
Endif
If (Wait) Then Exec sCom Wait Else Exec sCom
If (Wait) Then Exec aCmd Wait Else Exec aCmd
End
Static Public Sub RunAsRoot(Command As String, Optional (Wait) As Boolean)
RunAs("", Command, {Wait})
End
Static Public Sub GetFileIcon(Path As String, Size As Integer, Optional Preview As Boolean) As Picture
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment