FROM : JanakiRam
DATE : Sat Mar 22 17:03:31 2008
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");
}
}*
DATE : Sat Mar 22 17:03:31 2008
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");
}
}*
| Related mails | Author | Date |
|---|---|---|
| JanakiRam | Mar 22, 17:03 | |
| JanakiRam | Mar 23, 15:00 | |
| Jens Alfke | Mar 23, 16:52 | |
| JanakiRam | Mar 23, 18:17 | |
| Chris Hanson | Mar 24, 01:07 |






Cocoa mail archive

