0

I launch my application with an apple droplet asking for privileges to make the application work as root. Also I need it to read/write settings, so I use NSUserDefaults. I call setuid (because NSUserDefaults initWithUser doesn't work) to set the current user and then read and write his settings.

The problem is that I need to set privileges back to the root for some operations.

setuid(0);

fails. Any suggestions?

Update: This is MacOs app, not IOS. OS: 10.8

// to set the current user when the app is run with root privileges
CFStringRef temp = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
NSString* usrname = (NSString*)temp;
passwd* passwdStruct = getpwnam([usrname UTF8String]);
[NSUserDefaults resetStandardUserDefaults];
setuid(passwdStruct->pw_uid);
amplifier
  • 1,793
  • 1
  • 21
  • 55

0 Answers0