How to use BetterAuthorizationSample? – Cocoa

I am trying to use BetterAuthorizationSample rather then go the so called “malicious” way of using setuid in order to get root privileges.

Currently I am using AuthorizationCreate(); with BLAuthentication to have root access to changing some files, but I am somewhat irritated by the fact that I have to constantly enter my password in every time the app launches.

  • How to gain root privileges for iOS app?
  • NSTask, command line tools and root
  • How to add Root privileges to my OSX application?
  • Once jailbroken, will iOS apps run with root privilege?
  • Swift popToRoot not working
  • Return to root view in IOS
  • So I came across Apple’s method of a HelperTool, and I just can’t figure it out.

    I’ve been working with Cocoa for a couple months now, but this is just out of my reach, yet I still need it. How would I implement this tool to do simple root-privileged tasks?

    Is there a simpler way to use the concept of a HelperTool, so that my users can just enter their password once and it would grant root-privileges forever?

    Solutions Collect From Internet About “How to use BetterAuthorizationSample? – Cocoa”

    The “modern” way to do a helper tool on Mac OS X is to ship it as part of your app, and use the ServiceManagement framework to deploy it. Your users enter their password once, when deploying the tool. That installs it as a launchd job; from then on you use any launchd on-demand mechanism to launch the helper and get it to do work for you.

    Notice that the blog post linked above recommends that you protect subsequent invocations of the helper with an Authorization Services escalation, to avoid having an arbitrary privilege escalation that anyone can use. This seems like it somewhat impacts the “users can just enter their password once” benefit, although you can use AuthorizationRightSet() to create your app’s authorization token in the policy database, so you can actually define whether users need to present passwords on first deployment.

    The sample code from that post is on GitHub, and demonstrates using ServiceManagement to deploy the helper tool and Authorization Services to control access to it.