Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems running a shell script as root




27 jul 2007 kl. 22.26 skrev deepak gopal:


Does anyone know what I am doing wrong here?

Not really, but it would help if you posted the return codes you get.
Then look them up here:
http://developer.apple.com/documentation/Security/Reference/ authorization_ref/Reference/reference.html#//apple_ref/doc/uid/ TP30000826-CH4g-CJBEABHG


I put together a simple example from my code that uses AuthorizationExecuteWithPrivileges below.

Also be aware that only the effective user id is changed. Some tools, eg /sbin/SystemStarter, seem to require real user id set to 0 as well.

Mats

Small example:
(compile with 'gcc -framework Security filename.c')

#include <Security/Authorization.h>
#include <stdio.h>

int main() {
AuthorizationRef myAuthRef = NULL;
OSStatus myStatus;
myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, & myAuthRef);
if ( myStatus != errAuthorizationSuccess )
printf("Create error: %i\n", myStatus );
char *myArguments[] = {NULL};
FILE *myCommunicationsPipe;
myStatus = AuthorizationExecuteWithPrivileges(myAuthRef, "/ usr/bin/id", kAuthorizationFlagDefaults, myArguments, &myCommunicationsPipe);
if ( myStatus != errAuthorizationSuccess )
printf("Execute error: %i\n", myStatus );
int c;
while ( (c = fgetc(myCommunicationsPipe) ) != EOF )
printf("%c", c);
fclose(myCommunicationsPipe);
myStatus = AuthorizationFree( myAuthRef, kAuthorizationFlagDefaults);
if ( myStatus != errAuthorizationSuccess )
printf("Free error: %i\n", myStatus );
return 0;
}


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Problems running a shell script as root (From: deepak gopal <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.