[Gambas-user] Gambas app run as root

EA7DFH ea7dfh at ...2382...
Sun Oct 3 20:20:27 CEST 2010


El 03/10/10 19:21, Jussi Lahtinen escribió:
> It is attached to first mail from Stefano.
> 
> Jussi
> 
> 
> 2010/10/3 Benoît Minisini <gambas at ...1...>
> 
>>> Il domenica 3 ottobre 2010 18:46:38 Jussi Lahtinen ha scritto:
>>>> No, with Ubuntu 10.04 it does not work.
>>>> Textbox.Text is "", because shell is executed before textbox is even
>>>> shown.
>>>>
>>>> Your original code gives result:
>>>> *Password:
>>>> Password:
>>>> su: Authentication failure*
>>>> Then form appears, and after that when write password and click
>>>> "confirm", you will get error message from gambas "System error. Bad
>>>> file descriptor". Error is given from line:
>>>> *PRINT #hProcess, TextBox1.Text*
>>>>
>>>> Jussi
>>>
>>> Well, I'm on Slackware 32 bit. I switch the code to gb.gtk and still
>> works
>>> here. I don't know. Maybe a Ubuntu 64 bit issue?
>>>
>>>> Then form appears, and after that when write password and click
>> "confirm",
>>>>
>>>> you will get error message from gambas "System error. Bad file
>>>> descriptor".
>>>
>>> I get this error when I try a second time, because after the first try
>>> the code inside Form_Open is not run again. It was an example on the fly
>>> to show howto su.
>>>
>>> Change the Button_Click code to:
>>>
>>> PUBLIC SUB Button1_Click()
>>>
>>>   PRINT #hProcess, TextBox1.Text
>>>   WAIT
>>>   TRY hProcess.Kill
>>>   hProcess = SHELL "su -c 'ls /root'" FOR INPUT OUTPUT
>>>
>>> END
>>>
>>> This should fix the Bad descriptor error. For the first error I suppose
>> is
>>> something with 64 bit. don't know.
>>>
>>
>> Can I see the project?
>>
>> --
>> Benoît Minisini


Please, try the following code and tell us if it works for you:


PRIVATE $hprocess AS Process

PUBLIC SUB Form_Open()
DIM pwd AS String

pwd = InputBox("Type your root password", "Root privileges needed")
  IF pwd THEN
    $hprocess = SHELL Subst("echo &1 | sudo -S ls /root", pwd) FOR READ
  ELSE
    RETURN
  ENDIF
END

PUBLIC SUB Process_Read()
DIM outstr AS String

  WHILE NOT Eof($hprocess)
    LINE INPUT #$hprocess, outstr
    PRINT outstr
  WEND

END

The only drawback is that passwords in the inputbox are not hidden.

Regards,


-- 
Jesus, EA7DFH




More information about the User mailing list