• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problems running a shell script as root
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

  • Prev by Date: convertPoint mouseLocationOutsideOfEventStream
  • Next by Date: Re: Changing the app language
  • Previous by thread: Re: Problems running a shell script as root
  • Next by thread: Re: Problems running a shell script as root
  • Index(es):
    • Date
    • Thread