Re: sudo in NSTask
Re: sudo in NSTask
- Subject: Re: sudo in NSTask
- From: Chris Hanson <email@hidden>
- Date: Thu, 25 Sep 2003 11:57:54 -0500
On Thursday, September 25, 2003, at 10:50 AM, April Gendill wrote:
Is it possible to launch a task using NSTask in super user mode.
obviously make the path: sudo <some commandline app> does not work
since it actually wants a path and not a command line command.
There are two issues here that I'll address separately.
(1) You need to know the path to the tool you want to run to use
NSTask. In this case, you want to run sudo, so you need to know its
path. You also should pass a full path to sudo for the tool *it* runs.
Finally, you'll need to use the -S argument to sudo to have it read
the password from stdin, and use an NSPipe to pass that to sudo.
(2) You should, in general, *not* use this as a way to run tools with
superuser privileges (i.e. as root). There is another, more flexible
and standardized mechanism on Mac OS X called Authorization Services.
When something like Installer.app or System Preferences.app asks you
for your password, it's not using sudo, it's using Authorization
Services. Apple has two samples called AuthSample and MoreAuthSample
that demonstrate exactly how they recommend developers accomplish this.
To sum up, (1) says "learn the Unix process and execution model" and
(2) says "don't use it directly to run things with elevated privileges,
use the framework Apple provides for doing so."
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.