 |
 |
Get admin auth. to run as root?
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
How do I run a task as root in Cocoa/ObjC? I guess I've got to somehow get some admin authentication and then "sudo" the task, but how do I do that in my ObjC Cocoa application?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Use Authorization Services. Be sure to check out the technotes and sample code there, too -- there are lots of wrong ways to perform root-authorized operations, and your users won't appreciate an app that's a security hole.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Also take a look at ThemeChanger, I went to quite some lengths to make sure it adheres to Apple's recommended way of doing things as much as possible, and some have found it useful sample code...
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Originally posted by Angus_D:
Also take a look at ThemeChanger, I went to quite some lengths to make sure it adheres to Apple's recommended way of doing things as much as possible, and some have found it useful sample code...
Where's the code?
I've almost got it all figured out from the Apple page linked to above (just about to start testing), but some working sample code might help.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
|
(Last edited by Brass; Mar 6, 2003 at 05:32 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Okay, so I've found in the documentation, a function that allows me to execute things as root (which is what I need to chown root and setUID). But I'm not sure exactly how to use it. In fact I actually get a linking error when building (compilation is fine).
The code looks like this, so far:
Code:
#import <Security/Authorization.h>
...
char *chownPath = [@"/usr/sbin/chown" cString];
char *chownArgs[] = { [@"root" cString], [scriptPath cString], NULL };
char *chmodPath = [@"/bin/chmod/" cString];
char *chmodArgs[] = { [@"4555" cString], [scriptPath cString], NULL };
FILE *commPipe = NULL;
AuthorizationRef authRef;
if ( AuthorizationExecuteWithPrivileges(authRef, chownPath, kAuthorizationFlagDefaults, chownArgs, &commPipe)
== errAuthorizationSuccess )
{
NSLog(@"Authorised chown root succeeded");
if ( AuthorizationExecuteWithPrivileges(authRef, chmodPath, kAuthorizationFlagDefaults, chmodArgs, &commPipe)
== errAuthorizationSuccess )
{
NSLog(@"Authorised chmod 4555 succeeded");
}
else
{
NSLog(@"Authorised chmod 4555 failed");
}
}
else
{
NSLog(@"Authorised chown root failed");
}
AuthorizationFree (authRef, kAuthorizationFlagDestroyRights);
Why would I be getting a linking error with this? I'm I on the right track here at all?
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Did you actually link in the Security framework?
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by Brass:
Where's the code?
Click the Source link, duh. 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|