Re: Problems running a shell script as root
Re: Problems running a shell script as root
- Subject: Re: Problems running a shell script as root
- From: Claudio Bisegni <email@hidden>
- Date: Sat, 28 Jul 2007 07:54:21 +0200
I'm developing a PreferencePane tat start Openafs by calling script,
and i had the same problem. I was able to get authorization but
script was unable to perform certain operation. Se solution that i
have found, was to make an helper app and let it to perform the
script operation directly coded into helper app. The Helper app was
chowned to "root". So after i get the root privilege with a function
like your getAuthorizationRef it work.
My problem was the unmount of /afs volume.
I hope this can help you.
Anyway the focus is to get an helper tool tat make the root work.
On 27/lug/07, at 20:59, deepak gopal wrote:
Do you mean AuthorizationCreate and AuthorizationCopyRights???
I have done these just didn't include them in the mail. Please
correct me if I am wrong but I dont' see anything other than what I
have already done in the document "Performing Privileged
Operations With Authorization Services"
-----------
//creating AuthorizationRef without privileges.
OSStatus status;
status = AuthorizationCreate(NULL,
kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults,
&authRef_);
- (BOOL)getAuthorizationRef {
AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL,
0};
AuthorizationRights myRights = {1, &myItems};
AuthorizationFlags flags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagPreAuthorize |
kAuthorizationFlagExtendRights;
OSStatus status;
status = AuthorizationCopyRights(authRef_, &myRights,
kAuthorizationEmptyEnvironment, flags, NULL);
if (status != errAuthorizationSuccess) {
return NO;
}
return YES;
}
-----------------------------------------
DG
Brian Smith <email@hidden> wrote:
On Jul 27, 2007, at 11:26 AM, deepak gopal wrote:
I am using AuthorizationExecuteWithPrivileges to run a shell script
which needs root privileges. I can execute the shell scripts as a
local user, but can't run scripts which need root privileges.
I read through many doc's on the net and the guides in
developer.apple.com since yesterday, and haven't found an answer yet.
Please advice.
------------- the code --------------------------
AuthorizationRef authRef_;
NSString *pathToTool = @"/bin/sh";
NSString *filePath3 = @"~/Desktop/AUTOscript/loadApp.sh";
argsArray3[0] = "-p";
argsArray3[1] = (char *)[[filePath3 stringByExpandingTildeInPath]
fileSystemRepresentation];
argsArray3[2] = NULL;
OSStatus status3 = AuthorizationExecuteWithPrivileges(authRef_,
[pathToTool UTF8String], 0, argsArray3 , NULL);
You have created an empty AuthorizationRef structure without getting
any authorization data or actually authorizing the operation. Look at
the "Authorization Services C Reference" or "Performing Privileged
Operations With Authorization Services" documents on how to do this.
Brian
_______________________________________________
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
---------------------------------
DELETE button is history. Unlimited mail storage is just a click
away.
_______________________________________________
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
Claudio Bisegni
email@hidden
Fotografie:
http://picasaweb.google.com/macdevel
http://www.flickr.com/photos/jacod/
_______________________________________________
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