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: Mats Mattsson <email@hidden>
- Date: Mon, 30 Jul 2007 18:16:55 +0200
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:
This email sent to email@hidden