Conditions are the following: MacOSX 10.7 and Cocoa graphical application written in objective-c.
I am faced the following problem. I can't start daemon application from /user/bin folder from my Cocoa application. I know that I should have root privileges to do that.
I have installer, not *.pkg but manually written installer application. I need to start my daemons after installation process is finished. How can I increase my privileges level in objective-c application?
I have this code. But AuthorizationExecuteWithPrivileges call is deprecated.
We should not use it.
AuthorizationItem authItem = { kSMRightModifySystemDaemons, 0, NULL, 0 };
AuthorizationRights authRights = { 1, &authItem };
AuthorizationFlags flags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagPreAuthorize |
kAuthorizationFlagExtendRights;
AuthorizationRef authRef = NULL;
OSStatus status = AuthorizationCreate(&authRights,
kAuthorizationEmptyEnvironment, flags, &authRef);
status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
The second way is to use privileged helper. This way looks very complicated for my case. I just need to start daemons after install.
Of cource I can ask user to restart mac. But i would like to avoid it.
Other possibility is SUID bit on the daemon executable file. But it is not secure i think.
My question is: Is there other simpler way to do it?