Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Oct 20, 2018 11:00 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Need Superuser : How to use OS X Standard SU password login
PostPosted: Thu Oct 13, 2005 1:10 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Hi, my App , Showvolumefragmentation need to run an background task as superuser/ADMIN (sudo ....).
I use an non standard workaround (using an editfield an do some shellexec) for password input (and checking), but thats not really good.
Also has problems if the password has some special characters.

When will RB support an Standard SU Login within the app ?

Or any suggestions how to run my sudo shell better ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Need Superuser : How to use OS X Standard SU password lo
PostPosted: Thu Oct 13, 2005 7:27 am 
Offline

Joined: Fri Sep 30, 2005 9:18 am
Posts: 310
mitch_stgt wrote:
Hi, my App , Showvolumefragmentation need to run an background task as superuser/ADMIN (sudo ....).


Have you considered using an AppleScript that calls (for example)

on run
   do shell script "/bin/foo &" with administrator privileges
end run


This will prompt for an admin password and run the "foo" script with admin privileges in the background. If you save the script as an "application" (run-only script), you can drag it into your project and invoke it as if it were a subroutine.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 13, 2005 7:54 am 
Offline
User avatar

Joined: Mon Oct 03, 2005 5:23 am
Posts: 108
Location: Sussex, UK
The MBS plugin has a class to do this (AuthorizationMBS), might be worth a look.


Top
 Profile  
Reply with quote  
 Post subject: Re: Need Superuser : How to use OS X Standard SU password lo
PostPosted: Thu Oct 13, 2005 12:27 pm 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
manutter51 wrote:
mitch_stgt wrote:
Hi, my App , Showvolumefragmentation need to run an background task as superuser/ADMIN (sudo ....).


Have you considered using an AppleScript that calls (for example)

on run
   do shell script "/bin/foo &" with administrator privileges
end run


This will prompt for an admin password and run the "foo" script with admin privileges in the background. If you save the script as an "application" (run-only script), you can drag it into your project and invoke it as if it were a subroutine.



Thanks:
How do i get the result(s) back in my app ?

Code i use now:

here=GetfolderItem("")
app.here_str = here.ShellPath
run_string= "echo " + """"+ app.passwd + """"+" | sudo -S " +app.here_str + "/hfsdebug -h"
sh_exe.Mode = 1
sh_exe.Execute run_string

runs an sudo /hfsdebug -h (if not there there will be an error message as result which i check later

While (sh_exe.IsRunning)
App.DoEvents
Wend
wait for finishing that shell

if instr(sh_exe.Result,"command not found") <> 0 then
....
checks the result text from the sudo call

How do i make this with running appescipt to get the results (textout from the shell call and maybe errorcode) ?

How can i check if the applescript is ended (shell call ended) ?

How can i see if the user A) canceled the admin input window and / or B) has entered an wrong password ?


Later i will have more calls of sudo hfsdebug which gives also data back to the app (checking only errorcode like if sh_exe.ErrorCode = 0 then...)


).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 14, 2005 1:25 am 
Offline

Joined: Mon Oct 03, 2005 11:53 pm
Posts: 670
Location: Loves Park, IL
mitch_stgt wrote:
How do i get the result(s) back in my app ?


With the AppleScript, send it like a function. For example, suppose you have an AS, DHF.scpt, that checks stuff in the Finder to return to your RB app. DHF would look something like this:

On run (x)
tell application "Finder"
//blah-blah-blah - we know code goes here. Let's have it get the number of windows open.
Set monkeys to number of active windows // it probably won't work, but I wanted to show how to get the variable in question.
end tell
Set Monkeys to x
return x
end run


now, in RB, in the action to execute this nifty script, you treat your script as a function:

// we'll use x to get our monkeys.
x = DHF


For more, look in the User Guide. :)

One last thing: The characters outside of the x in "On run" should be the characters you get holding down the shift key and the brackets, not 9 and 0. (Damnit, Jim, I'm a geek, not a... :P)

Wayne C. Winquist

_________________
Wayne C. Winquist

Not Wayne's World Wordpress
Not Wayne's World MySpace!
Not Wayne's World Yahoo! 360


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 14, 2005 9:10 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
THanks

Your example run an App (Finder) which supports Applescript.
I run an commandline code, which is not supported (no variables are shared)

How do i use a code like this ?
???? i dont know to code.


run (restult_string)

do shell script "/bin/ls &" with administrator privileges ??examle of ls, sure needs no admin password????

set result_string to ????text output of shell above (ls output) ????

return (result_String)


"
now, in RB, in the action to execute this nifty script, you treat your script as a function:

Code:
// we'll use x to get our monkeys.
x = DHF
"

What kind of datatype is the varibale x in the RB app ?


String (would be good because the shell gives back text) ?

I think i must deklare it also (i would do it as an global variable)

is OK ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Need Superuser : How to use OS X Standard SU password lo
PostPosted: Fri Oct 14, 2005 10:10 am 
Offline

Joined: Fri Sep 30, 2005 9:18 am
Posts: 310
mitch_stgt wrote:
Thanks:
How do i get the result(s) back in my app ?

Code i use now:

here=GetfolderItem("")
app.here_str = here.ShellPath
run_string= "echo " + """"+ app.passwd + """"+" | sudo -S " +app.here_str + "/hfsdebug -h"
sh_exe.Mode = 1
sh_exe.Execute run_string



Hmm, that could be a problem. If you use an AppleScript, the script won't return any result at all until the entire script concludes, so assuming the /hfsdebug process is time-consuming, you're not going to want to wait around for it. Since you're checking for disk fragmentation, I assume this will be time consuming.

You could stick with what you've got, on the grounds that you've got kind of a special application here, but there is a bit of a risk that someone could snoop the password while you're passing it through to the shell, or if you don't mind a bit of a more complicated solution, take a 3-part approach:

Part One: launch the background task.

Write an AppleScript with the following code, and save it as an Application called StartHFSDebug

on run (shellPath, logFile)
do script shellPath & "/hfsdebug -h >" & logFile & " 2>&1 &" with administrator privileges
return result
end run


(Everything between "do script" and "administrator privileges" should be on one line, by the way.) Save the script as an Application in the folder with your RB code, and drag it into your RB project. You now have an RB function called

StartHFSDebug(shellPath As String, logFile As String) As String

that you can call in your code, that will start your /hfsdebug routine running in the background, and that will start logging its output into the file whose shell path you pass in as the logFile argument. It will return immediately with a string result, which I expect will be (or will contain) either the process ID of the background process, or the error message of the command could not be completed.

So to start Part One, just call StartHFSDebug with your original ShellPath plus the shell path of a temporary file. For Part 2, start a thread and read the temporary file. (You might want to use an interactive shell and "tail -f" for this). Then for Part 3, you have to manually detect when /hfsdebug is finished -- hopefully it puts out an "all done" message of some sort -- and delete the temporary file.

It's a bit more complicated, but it's more secure, and it's really not too bad, I hope? :wink: I'm having to guess just a bit here because I don't quite understand what your code is doing when it calls "sudo -S " + password + shell path + "/hfsdebug -h". That doesn't seem to be a built-in command, so I'm assuming you're locating some app you have that has a defrag command you access via an /hfsdebug flag. Anyway, hope this helps.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 14, 2005 11:27 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Thanks a lot.
I tried it without file generation.
It works , but there is no result.
So, i would have to use temp files for communikation between RB and the shell script.

I will wait for an:
sh_exe.Execute_withAdminprivileges "/hfsdebug" diekt RB call.

That sh_exe works very good any easy.

sh_exe.Result gives back that text, the shell writes to standard out.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 14, 2005 7:56 pm 
Offline

Joined: Mon Oct 03, 2005 11:53 pm
Posts: 670
Location: Loves Park, IL
mitch_stgt wrote:
now, in RB, in the action to execute this nifty script, you treat your script as a function:

Code:
// we'll use x to get our monkeys.
x = DHF
"

What kind of datatype is the varibale x in the RB app ?


String (would be good because the shell gives back text) ?

I think i must deklare it also (i would do it as an global variable)

is OK ?


It's in the user manual; there is no declaring an applescript in RB. x can be any type of variable, though since you'd be working with the terminal, most likely it would have to be either a text (string) or numeric (integer, single, double).

Last time I checked, the terminal was applescriptable, as there are quite a few scripts floating around. (The one I like Resexcellence has one for running screensavers as a desktop picture, something that would have to be done from the terminal.

RB treats Applescript as a method or function; as a result, running and passing information to a script is the same as you would a script, and returning values from a script is the same as a function.

Hope that helps. :) (I try)

Wayne C. Winquist

_________________
Wayne C. Winquist

Not Wayne's World Wordpress
Not Wayne's World MySpace!
Not Wayne's World Yahoo! 360


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 15, 2005 2:41 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
The problem from my first tests is:
The admin privileges works.

But the output of the shell (example /bin/ls, which not really need admin privileges ) goes into "nirvana".
IN RB there is no result

result = Applescript

result is an empty string, the output of the command ls didnt get into result.


would be fine if, like after the sh.execute "/bin/ls" an sh.result works also with running applescript.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Oct 15, 2005 3:14 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
ONE STEP AHEAD !"

I found out that this gives back the result (in Applescript editor work now, not testet in RB)

on run {}
set myString to do shell script "/Volumes/Programme_Tools_X/Programme_X/sonstiges/hfsdebug -h 2>&1 &" with administrator privileges
return myString
end run

The solution was to use the set variable to do shell ... , and give that variable back as result.

Found that by googling !

Solution here:
http://www.osxfaq.com/Tutorials/as_unix/index.ws
Also there, and usefull for me, beacue i will execute that hfsdung serveal time:
if you use with administrator privileges and password, the password will only asked oncem not every shellcall.



Also found good examples for do shell .. (not RB spezific) here

http://developer.apple.com/technotes/tn2002/tn2065.html


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 19, 2005 2:28 pm 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
My hint works in Applesciptedit, not in RB.

Needs some changes (without you get no result back):

on run{return_str}

set return_str to (do shell script "/Volumes/Programme_Tools_X/Programme_X/sonstiges/hfsdebug -h 2>&1 &" as string with administrator privileges)
return return_str
end run


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group