Hi,
Any idea why following code always returning errAuthorizationToolExecuteFailure
(-60031). Tried multiple combination of flags, but no luck.
// Create authorization reference
OSStatus status;
AuthorizationRef authorizationRef;
// kAuthorizationRightExecute == "system.privilege.admin"
AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rights = {1, &right};
AuthorizationFlags flags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagExtendRights;
NSString *promptText = @"Custom text displaying in the dialog.\n\n";
AuthorizationItem dialogConfiguration[1] = {
kAuthorizationEnvironmentPrompt, [promptText length], (char *) [promptText
UTF8String], 0 };
AuthorizationEnvironment authorizationEnvironment = { 0 };
authorizationEnvironment.items = dialogConfiguration;
authorizationEnvironment.count = 1;
// Open dialog and prompt user for password
status = AuthorizationCreate(&rights, &authorizationEnvironment, flags,
&authorizationRef);
NSLog(@"Initial Authorization: %d", (int)status);
FILE *pipe = NULL;
if (status == errAuthorizationSuccess)
{
char *cpTool = (char *)[@"cp Rf" UTF8String]; //Running this code
in the sample user. And myApp.app has the Read&write permissions
char *cpToolArgs[] = {(char *)[@"/Users/sample/Desktop/myApp.app"
UTF8String], (char *)[@"/Applications" UTF8String], NULL};
status = AuthorizationExecuteWithPrivileges(authorizationRef,
cpTool,
kAuthorizationFlagDefaults, cpToolArgs, &pipe);
NSLog(@"cpTool:%s Args:%s %s", cpTool, cpToolArgs[0],
cpToolArgs[1]);
if (status != errAuthorizationSuccess)
NSLog(@"Error: %d", (int)status);
}
Regards,
Apparao Mulpuri
This email and any attachments are confidential, and may be legally privileged
and protected by copyright. If you are not the intended recipient dissemination
or copying of this email is prohibited. If you have received this in error,
please notify the sender by replying by email and then delete the email
completely from your system. Any views or opinions are solely those of the
sender. This communication is not intended to form a binding contract unless
expressly indicated to the contrary and properly authorised. Any actions taken
on the basis of this email are at the recipient's own risk.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]