Re: Get root privileges with NSTask
Re: Get root privileges with NSTask
- Subject: Re: Get root privileges with NSTask
- From: "Mr. Gecko" <email@hidden>
- Date: Tue, 25 Mar 2008 12:58:57 -0500
how about this code?
NSTask* download = [[NSTask alloc] init];
[download setLaunchPath:@"/usr/bin/curl"];
[download setCurrentDirectoryPath:@"/tmp/"];
[download setArguments: [NSArray arrayWithObjects:@"-O",@"http://www.imagemagick.org/download/binaries/ImageMagick-universal-apple-darwin8.11.0.tar.gz
", nil]];
[download launch];
[download waitUntilExit];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"do
shell script 'cd /; /usr/bin/gnutar -xzf /tmp/ImageMagick-universal-
apple-darwin8.11.0.tar.gz' with administrator privileges"];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
This should do what I need to be done.
If I could install it in to the shared folder than I won't even have
to have root access but I don't know how to make ImageMagick use any
other folder than the root of the hard drive.
On Mar 25, 2008, at 10:23 AM, Jens Alfke wrote:
This is REALLY not the right way to be doing this. I'm not talking
about what auth mechanism to use; I'm talking about what you should
be doing as root. I speak as someone who might download and use your
program someday.
(a) Most of what you're doing can be done in Cocoa without having to
spawn new processes.
(b) Most of it doesn't require root privileges.
* Instead of a 'curl' command, use [NSURLConnection
sendSynchronousRequest:...].
* Please don't download to /. There is no need to put temporary
files at the root of the filesystem! Call NSTemporaryDirectory() to
get a path to download to.
* Extracting the archive does require root privileges, and running
'gnutar' is probably the best way to do it (there is a system
framework that can do this but it's private to Apple.)
* Again, deleting the temporary file doesn't need root privileges if
you put it in a temporary directory. Use NSFileManager to delete it.
* Some error checking wouldn't hurt.
You really, really don't want to call 'rm' as root if you can
possibly avoid it ... remember the poor people who had their disks
erased by an iTunes installer (in 2002?) that had a buggy 'rm'
command in it.
I'm still uncomfortable with this. It would be better if ImageMagick
were packaged as an Installer package; then you could just download
that and call NSWorkspace to open it, and have Apple's Installer app
do the installation. I think most users would feel safer authorizing
Installer to do surgery on their OS.
—Jens
On 25 Mar '08, at 5:47 AM, Mr. Gecko wrote:
I looked around there and found nothing useful.
Here is my code that I am tying to get root privileges with.
NSTask* download = [[NSTask alloc] init];
[download setLaunchPath:@"/usr/bin/curl"];
[download setCurrentDirectoryPath:@"/"];
[download setArguments: [NSArray arrayWithObjects:@"-O",@"http://www.imagemagick.org/download/binaries/ImageMagick-universal-apple-darwin8.11.0.tar.gz
", nil]];
[download launch];
[download waitUntilExit];
NSTask* uncompress = [[NSTask alloc] init];
[uncompress setLaunchPath:@"/usr/bin/gnutar"];
[uncompress setCurrentDirectoryPath:@"/"];
[uncompress setArguments: [NSArray arrayWithObjects:@"-
xzf",@"ImageMagick-universal-apple-darwin8.11.0.tar.gz", nil]];
[uncompress launch];
[uncompress waitUntilExit];
NSTask* delete = [[NSTask alloc] init];
[delete setLaunchPath:@"/bin/rm"];
[delete setCurrentDirectoryPath:@"/"];
[delete setArguments: [NSArray arrayWithObjects:@"ImageMagick-
universal-apple-darwin8.11.0.tar.gz", nil]];
[delete launch];
[delete waitUntilExit];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden