[Gambas-user] Program to use different group rights

T Lee Davidson t.lee.davidson at gmail.com
Mon Dec 3 00:51:38 CET 2018

As pointed out by Tobi, the solution I suggested previously (quoted below) is insecure.

I have tested another solution that works on openSUSE. Whether or not it will work on Ubuntu, I don't know. Perhaps the use of
"For Input Output" (again, credit to Tobi) will satisfy su's need for a terminal.

' Gambas module file

Public $thePassword As String = "badpass"

Public Sub Main()

  Dim Proc As Process

  Proc = Shell "su -c true $USER" Wait For Input Output As "Proc"
  'Respond based on process exit code
  Print IIf(Proc.Value = 0, "You passed.", "Not authorized: " & Proc.Value)


Public Sub Proc_Read()

  Dim sInput As String

  sInput = Read #Last, -256
  If InStr(sInput, "Password:") Then
    Print "Checking password..."
    Write #Last, $thePassword & "\n"



On 12/2/18 7:37 AM, Rolf-Werner Eilert wrote:
> Me again, now on another system.
> When we discussed this, I tried it on a Suse with KDE. Now I am on Ubuntu Mate, and it doesn't run anymore. I get the error
> message "su: only may be started from a terminal" (or something like that, it's in German).
> Is there a chance to fake a terminal environment in a shell?
> Regards
> Rolf
> Am 26.11.18 um 17:21 schrieb T Lee Davidson:
>> How about this:
>> Public Sub Main()
>>    Dim sPass, sOutput As String
>>    sPass = "wrong"
>>    Shell "echo " & sPass & "|su -c True $USER 2>&1" To sOutput
>>    ' Print sOutput
>>    If InStr(sOutput, "failure") > 0 Then
>>      Print "Fail"
>>    Else
>>      Print "Pass"
>>    Endif
>> End
>> ___
>> Lee

More information about the User mailing list