execute binary with root privileges
execute binary with root privileges
- Subject: execute binary with root privileges
- From: Lukas Meyer <email@hidden>
- Date: Fri, 1 Apr 2005 20:37:53 +0200
Hi List,
I want to start a binary that needs root privileges with objective C using the Apple Security Framework. I tried out the example from the apple reference starting the binary /usr/bin/id which successfuly shows id 0 for root. Now i changed the binary Path to /sbin/route with some arguments, that adds a specific route. But there the Output of this command sais: route: must be root to alter routing table. So my question is, why it executes the id binary as root and why the other one not?
Attached is my code, that I'm using.
int read (int);
int write (int);
char* args[12];
unsigned int i = 0;
OSStatus myStatus;
AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
AuthorizationRef myAuthorizationRef;
myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
myFlags, &myAuthorizationRef);
if (myStatus != errAuthorizationSuccess)
return myStatus;
do
{
{
AuthorizationItem myItems = {kAuthorizationRightExecute, 0,
NULL, 0};
AuthorizationRights myRights = {1, &myItems};
myFlags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagPreAuthorize |
kAuthorizationFlagExtendRights;
myStatus = AuthorizationCopyRights (myAuthorizationRef, &myRights, NULL, myFlags, NULL );
}
if (myStatus != errAuthorizationSuccess) break;
{
NSArray *arguments = [NSArray arrayWithObjects: @"add", @"-net", @"0.0.0.0", @"10.8.0.41", @"0.0.0.0", nil];
while( i < [arguments count] && i < 50) {
args[i] = (char*)[[arguments objectAtIndex:i] cString];
i++;
}
args[i] = NULL;
char myToolPath[] = "/sbin/route";
char *myArguments[] = { "add", "-net", "0.0.0.0", "10.8.0.41", "0.0.0.0", NULL };
FILE *myCommunicationsPipe = NULL;
char myReadBuffer[128];
myFlags = kAuthorizationFlagDefaults;
myStatus = AuthorizationExecuteWithPrivileges
(myAuthorizationRef, myToolPath, myFlags, 0,
&myCommunicationsPipe);
if (myStatus == errAuthorizationSuccess)
for(;;)
{
int bytesRead = read (fileno (myCommunicationsPipe),
myReadBuffer, sizeof (myReadBuffer));
if (bytesRead < 1) break;
write (fileno (stdout), myReadBuffer, bytesRead);
}
}
} while (0);
AuthorizationFree (myAuthorizationRef, kAuthorizationFlagDefaults);
if (myStatus) printf("Status: %ld\n", myStatus);
return myStatus;
best regards,
LukasAttachment:
PGP.sig
Description: This is a digitally signed message part
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden