Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
- Subject: Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
- From: Brian Hill <email@hidden>
- Date: Thu, 21 Jun 2001 17:01:44 -0500
On Thursday, June 21, 2001, at 01:45 PM, Brendan Younger wrote:
In short, here's what you're looking for:
- (void)execShutdownCountdownAtTime:(NSString *)minutes
{
NSString *prefix = @"+";
char* args[2];
char argumentOne[] = "-h";
OSStatus err = 0;
args[0] = &(argumentOne[0]);
args[1] = [[prefix stringByAppendingString:minutes] cString];
NSLog(@"Parameter passed: %s\nArguments: %s
%s",minutes,args[0],args[1]);
err = AuthorizationExecuteWithPrivileges(authorizationRef,
"/sbin/shutdown",0,args,NULL);
Almost there, but there's one more bug. The 'args' array needs to be
terminated with a NULL entry.
Like this (note that the size of 'args' is now 3, not 2):
- (void)execShutdownCountdownAtTime:(NSString *)minutes
{
NSString *prefix = @"+";
char* args[3];
char argumentOne[] = "-h";
OSStatus err = 0;
args[0] = (char*)argumentOne;
args[1] = [[prefix stringByAppendingString:minutes] cString];
args[2] = NULL;
NSLog(@"Parameter passed: %s\nArguments: %s
%s",minutes,args[0],args[1]);
err = AuthorizationExecuteWithPrivileges(authorizationRef,
"/sbin/shutdown",0,args,NULL);
if(err!=0)
{
NSBeep();
NSLog(@"Error %d in AuthorizationExecuteWithPrivileges",err);
}
}
Brian
email@hidden
http://personalpages.tds.net/~brian_hill
"Why? I came into this game for adventure - go anywhere, travel
light, get in, get out, wherever there's trouble, a man alone.
Now they've got the whole country sectioned off and you can't
move without a form. I'm the last of a breed."
-- Archibald "Harry" Tuttle, Rogue HVAC Repairman