Getting root access with helper helper and SMJobBless

I am working on the need to periodically install files in a folder in / Library.

I understand that in the past I could use one of the Authenticate methods, but since then they have been deprecated in 10.7.

What I understood from my reading:

I must create an assistant that will authenticate in some way, and so that this assistant performs all the moving tasks. I looked at some code examples, including some related to XPC and one called Lift, but I'm a bit confused.

Many of them seem to be dealing with setting up some kind of client / server model, but I'm not sure how this could lead to the fact that I really installed my files in the correct directories. Most examples simply pass strings.

My question is simple: how can I create my folder in / Library programmatically and periodically write files to it, and only ask for the password for the user once and never? I'm really not sure how to approach this and there seems to be not much documentation.

+7
source share
1 answer

You are right that there is no documentation for this. Basically you will write another application, an auxiliary application, that will be installed using SMJobBless (). Not surprisingly, the hard part here is code signing. The least obvious part for me was that the SMAuthorizedClients and SMPrivilegedExecutables entries in the Info plist files of each application depend on the identity / certificate you used to sign the application. There is also a trick with the compiler / linker to get the Info plist file compiled into a helper tool , which will be a single executable file, not a package.

Once you launch the helper application, you must develop a way to communicate with it, as these are two different processes. XPC is one option, perhaps the easiest. XPC is commonly used with server processes, but what you use here is just the communication side of XPC. It basically transfers dictionaries between two applications. Create a standard format for the dictionary. I used @ "action", @ "source" and @ "destination" with 3 different action values, @ "filemove", @ "filecopy" and @ "makedirectory". These are three things that my helper application can do, and I can easily add more if necessary.

The helper application will basically configure the XPC connection and event handler and wait for the connection and commands. Commands will be just a dictionary, so you check the appropriate keys / values ​​and do whatever.

I can provide more detailed information and a code if you need additional help, but this issue is 9 months, so I do not want to waste time providing you with information that you have already found out.

+4
source

All Articles