Re: Unable to unload Launch Daemon using Cocoa Application.
Re: Unable to unload Launch Daemon using Cocoa Application.
- Subject: Re: Unable to unload Launch Daemon using Cocoa Application.
- From: JanakiRam <email@hidden>
- Date: Sun, 23 Mar 2008 19:30:51 +0530
It seems no one had came across such a situation. Can any one from apple
help me ?
Please help me to solve this problem. Thanks in Advance.
-JanakiRam.
On 3/22/08, JanakiRam <email@hidden> wrote:
>
> Hi All,
>
> I'm developing a cocoa application which needs to unload my Launch
> Daemon for one particular requirement. I've used Authorization Services to
> perform unload of Launch Daemon ( previlaged action ). But couldn't succeed
> in this. I'm getting the following error on executed my code.
>
> *Output :*
> **
> *lauchctl : Error in unloading mydaemon*
> **
> *Note :* Attaching my code snippet for your reference.
>
> Please help me to solve this problem. Thanks in Advance.
>
> -JanakiRam
>
> *Code Snippet :*
> **
> *- (void) UnloadDaemon
> {
> // setup our authorization environment.
> AuthorizationItem authItems[1]; // we only want to get authorization
> for one command
> BOOL authorized = NO; // are we authorized?
> char *args[4];
>
> char *command = "/bin/launchctl";
>
> authItems[0].name = kAuthorizationRightExecute; // we want the right
> to execute
> authItems[0].value = command; // the path to the startup script
> authItems[0].valueLength = strlen(command); // length of the command
> authItems[0].flags = 0; // no extra flags
>
> authRights.count = 1; // we have one item
> authRights.items = authItems; // here is the values for our item
>
> authFlags = kAuthorizationFlagInteractionAllowed |
> kAuthorizationFlagExtendRights;
>
> // lets find out if we are authorized
>
> ourStatus = AuthorizationCopyRights(authorizationRef,&authRights,
> kAuthorizationEmptyEnvironment, authFlags, NULL);
>
> authorized = (errAuthorizationSuccess==ourStatus);
>
> if (authorized)
> {
> // we are authorized, so let's tell the security framework to
> execute
> // our command as root
> args[0] = "unload";
> args[1] = "-w";
> args[2] = "/Library/LaunchDaemons/org.mycompany.launchdaemon.plist";
> args[3] = NULL;
>
> ourStatus = AuthorizationExecuteWithPrivileges(authorizationRef,
> command,
> kAuthorizationFlagDefaults,
> args, NULL);
>
> if(ourStatus != errAuthorizationSuccess)
> {
> NSLog(@"unload has failed");
> }
> }
> else
> {
> NSLog(@"error in authentication");
> }
> }*
>
_______________________________________________
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