Elevating permissions on OSX
When a file change requires root permissons you can use ‘/usr/libexec/authopen’ which elevates permissions and reads or writes that file for you. But what about executing programs with elevated permissions? On the command line you can of course use ’sudo’ …but what if you don’t want to drag the user to the command line? I thought an ‘authexec’ was missing. So after a little research I’ve modified an example from the Apple documentation that explains how to use
AuthorizationCreate(..)
AuthorizationCopyRights(..)
AuthorizationExecuteWithPrivileges(..)
to elevate permssions. ‘authexec yourapp’ will (just like sudo) ask you to confirm the authentication and then start your application with elevated permissions.
For convenience I’ve put the source and the universal binary online.