Well, here is part of my security abstraction layer. It probably could be cleaner but I don't have the time to fix it up.
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
AuthorizationRef authRef;
- (void)createEnv
{
AuthorizationRights tempRight;
AuthorizationFlags tempFlag;
OSStatus temperr = <font color = blue>0</font>;
tempRight.count=<font color = blue>0</font>;
tempRight.items = NULL;
authRef=NULL;
tempFlag = kAuthorizationFlagDefaults;
temperr = AuthorizationCreate(&tempRight, kAuthorizationEmptyEnvironment, tempFlag, &authRef);
}
- (BOOL)authorizeThis

char *)pathy
{
OSStatus authErr = <font color = blue>0</font>;
AuthorizationRights righty;
AuthorizationFlags flagy;
AuthorizationItem thingy[<font color = blue>1</font>];
thingy[<font color = blue>0</font>].name=kAuthorizationRightExecute;
thingy[<font color = blue>0</font>].value=pathy;
thingy[<font color = blue>0</font>].valueLength=strlen(pathy);
thingy[<font color = blue>0</font>].flags=<font color = blue>0</font>;
righty.count=<font color = blue>1</font>;
righty.items = thingy;
flagy = kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
authErr = AuthorizationCopyRights(authRef,&righty, kAuthorizationEmptyEnvironment, flagy, NULL);
return (errAuthorizationSuccess==authErr); <font color = brown>//this should remove a branch and make the code more efficient</font>
}
- (void)loseSecurity
{
AuthorizationFree(authRef, kAuthorizationFlagDestroyRights);
}
-(int)launchSecure

NSString *)path withArgs

NSArray *)args
<font color = brown>//this is used to create a new secure task with the associated path and argument array.</font>
<font color = brown>//return: an integer that represents the task number</font>
{
OSStatus err =<font color = blue>0</font>;
FILE* pipey;
char *pathy;
char *argt[<font color = blue>4</font>];
int counter;
char *temparg = malloc(sizeof(temparg));
<font color = brown>//first make sure that we are looking at a valied binary (ie: not with trailing '/')</font>
if([[path substringFromIndex

[path length]<font color = blue>-1</font>)] isEqualToString:<font color = orange>@"/"</font>]){
<font color = brown>//we are looking at a directory (most likely another method decided that there are no valid binaries in this bundle)</font>
return <font color = blue>-2</font>; <font color = brown>//this code is different than the usual erro (<font color = blue>-1</font>) since it is slightly different</font>
}
for(counter=<font color = blue>0</font>;counter<[args count];counter++){
[[args objectAtIndex:counter] getCString:temparg];
argt[counter]=temparg;
<font color = brown>// NSLog(<font color = orange>@"Logging number %d: %s"</font>, counter, temparg);</font>
temparg = malloc(sizeof(temparg));
}
argt[counter]=NULL;
<font color = brown>// [path getCString:temparg];//periodic error here</font>
pathy = [path cString];<font color = brown>//temparg; //this line is supposed to create a qualifier warning (???)</font>
output=[NSFileHandle alloc]; <font color = brown>//why is this here when it is never used?</font>
[self createEnv];<font color = brown>//create the environment</font>
if (
athy]){
return <font color = blue>-1</font>;<font color = brown>//error code</font>
}
err = AuthorizationExecuteWithPrivileges(authRef, pathy, <font color = blue>0</font>, argt, &pipey);
if(err){
return <font color = blue>-1</font>;
}
<font color = brown>//I am going to try this without losing the security</font>
<font color = brown>//[self loseSecurity];</font>
<font color = brown>//right before we get out of here lets free up the memory</font>
free(temparg);
for(counter=<font color = blue>0</font>;counter<[args count];counter++){
free(argt[counter]);
}
return <font color = blue>0</font>;<font color = brown>//replace this with something better later</font>
}
</font>[/code]
Given that code, you should be able to just call [self launchSecure

athToTool withArgs:argumentArray]
This is a snippet from "Skeleton Key" which is a rather popular program my company makes. We are planning to release the entire source code soon.
Hope you guys find that useful,
Jeff.