Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Get admin auth. to run as root?

Get admin auth. to run as root?
Thread Tools
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 5, 2003, 10:33 PM
 
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
Reply With Quote
Mar 6, 2003, 01:28 PM
 
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.
Rick Roe
icons.cx | weblog
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Mar 6, 2003, 02:05 PM
 
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...
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 6, 2003, 03:27 PM
 
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.
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 6, 2003, 03:43 PM
 
Double post.
(Last edited by Brass; Mar 6, 2003 at 05:32 PM. )
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 6, 2003, 05:32 PM
 
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
Reply With Quote
Mar 6, 2003, 06:38 PM
 
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
Reply With Quote
Mar 8, 2003, 11:30 AM
 
Originally posted by Brass:
Where's the code?
Click the Source link, duh.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:51 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2