• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



References: 
 >Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie) (From: Brendan Younger <email@hidden>)

  • Prev by Date: Re: WWDC Dev Tools / Software update
  • Next by Date: Re: NSArray init with a path
  • Previous by thread: Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
  • Next by thread: Preferences using NSUserDefaults (newbie)
  • Index(es):
    • Date
    • Thread