Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Nov 19, 2017 11:10 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Shelling out a sudo command.
PostPosted: Fri Apr 19, 2013 10:33 pm 
Offline
User avatar

Joined: Wed Jul 07, 2010 2:55 pm
Posts: 720
Location: University Of Calgary, Faculty Of Medicine
I'm trying to run a unix command that requires root permission.
eg
sudo dd if=x.img of=/dev/rdisk1

But of course the shell doesn't have a method of asking admin's password so this fails.

What do I do?

_________________
If at first you don't succeed... Try REALBasic and if that doesn't work try Xojo.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Sat Apr 20, 2013 4:35 am 
Offline

Joined: Wed Dec 14, 2011 4:20 am
Posts: 84
BrianOBrien wrote:
I'm trying to run a unix command that requires root permission.
eg
sudo dd if=x.img of=/dev/rdisk1

But of course the shell doesn't have a method of asking admin's password so this fails.

What do I do?



Have you tried this:
echo  YourSudoPassword  | sudo -S "dd if=x.img of=/dev/rdisk1"



Info: http://developer.apple.com/library/mac/ ... udo.8.html


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Sat Apr 20, 2013 1:10 pm 
Offline
User avatar

Joined: Wed Jul 07, 2010 2:55 pm
Posts: 720
Location: University Of Calgary, Faculty Of Medicine
yes and it works! :) If I use an async shell.
however dd isn't very verbose....
So there is no concept of time to completion...
The user just waits...

_________________
If at first you don't succeed... Try REALBasic and if that doesn't work try Xojo.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Sat Apr 20, 2013 1:20 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
I use dcfldd instead has several options including verbose output etc..

http://dcfldd.sourceforge.net/

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Sat Apr 20, 2013 1:48 pm 
Offline
User avatar

Joined: Wed Jul 07, 2010 2:55 pm
Posts: 720
Location: University Of Calgary, Faculty Of Medicine
Correct me if I'm wrong but can I not just open the raw unix device and write to it in binary mode?
/dev/rdisk1

_________________
If at first you don't succeed... Try REALBasic and if that doesn't work try Xojo.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Mon Apr 22, 2013 5:53 pm 
Offline
User avatar

Joined: Wed Jul 07, 2010 2:55 pm
Posts: 720
Location: University Of Calgary, Faculty Of Medicine
p0wn3d wrote:
I use dcfldd instead has several options including verbose output etc..

http://dcfldd.sourceforge.net/


Who would you package that application with your own application for distribution?
MAC? Linux, Windows?

_________________
If at first you don't succeed... Try REALBasic and if that doesn't work try Xojo.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Mon Apr 22, 2013 8:15 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Am I missing something here?

DD is a command line file copy function of OSX (ie. Unix)

why not just use normal RealStudio File copy commands?

FolderItem.CopyFileTo ( Destination as FolderItem )
If Destination is a folder, then the FolderItem is copied into Destination.
If Destination is a file and the file already exists, the copy is aborted. You need to delete the existing file first. If there is an error, the LastErrorCode property contains an error code.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Wed May 01, 2013 2:35 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
You can do this however you want, but it is normally considered bad form to pipe the password in cleartext.

RealBasic does not provide access to the security framework for elevated privileges directly, but that does not mean you cannot work around this.

You might consider prompting the user to authenticate with a work around. The easiest way I've found to do this in RealBasic is to use an AppleScript via a Shell by calling an osascript that calls another shell. Confused yet ? :lol:

Example
dim myshell as new Shell
myshell.Execute "osascript -e 'do shell script ""/bin/ls -la"" with administrator privileges'"
MsgBox myshell.Result

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Wed May 01, 2013 11:22 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
pony wrote:
You can do this however you want, but it is normally considered bad form to pipe the password in cleartext.


Amen to that. I strongly advise against using cleartext passwords.

pony wrote:
RealBasic does not provide access to the security framework for elevated privileges directly, but that does not mean you cannot work around this.

You might consider prompting the user to authenticate with a work around. The easiest way I've found to do this in RealBasic is to use an AppleScript via a Shell by calling an osascript that calls another shell. Confused yet ? :lol:

Example
dim myshell as new Shell
myshell.Execute "osascript -e 'do shell script ""/bin/ls -la"" with administrator privileges'"
MsgBox myshell.Result


Hey Pony, thanks for this.
It seems to work but also throw some errors.
No big deal I guess since you parse out the desired response but does it normally throw errors for you?

What do you parse for success?


2013-05-01 22:14:39.785 osascript[76500:607] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
   /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
/



Alternatively for those that have MBS there is MBSauthorize.

If I remember correctly I think you can also elevate your app to admin or root privs a single time -probably a permission requiring admin pwd then never have to bother the user again. But this is generally frowned upon unless you have a very good reason to do it, which is rare.


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Thu May 02, 2013 7:18 am 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
Thats not a problem with my example, its actually a problem with an old 32 bit AppleScript scripting addition you have installed, whilst running in 64 bit.
It would manifest itself when running other AppleScripts.
Here is the fix
http://kb2.adobe.com/cps/516/cpsid_51615.html

J.Sh3ppard wrote:
Hey Pony, thanks for this.
It seems to work but also throw some errors.
No big deal I guess since you parse out the desired response but does it normally throw errors for you?

What do you parse for success?


2013-05-01 22:14:39.785 osascript[76500:607] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types:  dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.  Did find:
   /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
/



Alternatively for those that have MBS there is MBSauthorize.

If I remember correctly I think you can also elevate your app to admin or root privs a single time -probably a permission requiring admin pwd then never have to bother the user again. But this is generally frowned upon unless you have a very good reason to do it, which is rare.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Fri May 03, 2013 12:01 am 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
pony wrote:
Thats not a problem with my example, its actually a problem with an old 32 bit AppleScript scripting addition you have installed, whilst running in 64 bit.
It would manifest itself when running other AppleScripts.
Here is the fix
http://kb2.adobe.com/cps/516/cpsid_51615.html


Cool, thanks much :)

Is there a way to test for the old 32bit AppleScript scripting addition you mentioned before executing the shell using the alternative parameter (shown below)?


myshell.Execute "arch -i386 osascript -e 'do shell script ""/bin/ls -la"" with administrator privileges'"


Or would you not even bother?

Also what are you parsing to check for success that would be reliable regardless of the user's shell verbosity setting?


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Fri May 03, 2013 2:15 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
OK. I just read something about xojo in another thread? No idea if Real was bought out or what is going on. I also read these forums are closing, that is a real shame.

I have no intention of signing up for a new account with another forum, where previous posts are not ported across.

Just wanted to check in for the last time. I enjoyed helping, being helped, and even sparring with some of you.

So long, and thanks for all the fish.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Shelling out a sudo command.
PostPosted: Fri May 03, 2013 2:24 pm 
Offline

Joined: Tue Mar 23, 2010 8:44 pm
Posts: 673
pony wrote:
OK. I just read something about xojo in another thread? No idea if Real was bought out or what is going on.


Mostly just another name change.

pony wrote:
I also read these forums are closing, that is a real shame.

I have no intention of signing up for a new account with another forum, where previous posts are not ported across.

Just wanted to check in for the last time. I enjoyed helping, being helped, and even sparring with some of you.

So long, and thanks for all the fish.



Well that's a big bummer. I'm sure the community is going to miss you since you've been a very helpful contributor.

What other products are you using then?

Xcode and Corona?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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