Re: Communicating with Privileged Helper Tool
Re: Communicating with Privileged Helper Tool
- Subject: Re: Communicating with Privileged Helper Tool
- From: Mailing Lists <email@hidden>
- Date: Wed, 23 Dec 2015 18:22:07 +0100
> Unfortunately, this gives me the exact same issue:
>
> CFMessagePortRef remotePort = CFMessagePortCreateRemote(NULL, CFSTR("com.example.app.port.server"));
>
> if (!remotePort) {
> asl_log(asl, aslMsg, ASL_LEVEL_ERR, "no remote port");
> }
How are you creating the other end of the connection? The remote port will just attempt to connect to the local port and not actually register the mach service. If you never registered the mach service name it will fail as you’re seeing.
You can use `CFMessagePortCreateLocal` in you helper tool. This function will take care of registering the service name with the bootstrap server (on top of giving you a port to listen on). If you’re using objc you can register your mach port directly by calling `NSMachBootstrapServer.registerPort:name:`.
If you helper tool is launched by launchd, you can add the MachService name to your job plist and launchd will bootstrap it in the right domain for you.
> On Dec 23, 2015, at 2:25 PM, Mark Allan <email@hidden> wrote:
>
> Hi all,
>
> I've got a an OS X application that needs to perform some privileged operations, so I've written a privileged helper tool (PHT) and it all works fine to call the necessary functions from my user-land application and get the response.
>
> What I'm struggling with is some additional communication between the helper tool and my application during lengthy operations, so the application can provide some visual feedback to the user.
>
> I need to support 10.6, so NSXPCConnection is out of the question. I've tried Distributed Objects as well as CFMessagePort/NSMessagePort but neither seems to work.
>
> For DO, I can successfully vend the object within my GUI application, but I'm unable to connect from my helper tool. When doing the following in the PHT, I always get the log message saying "couldn't connect", and the method in my application doesn't get called.
>
> NSConnection *theConnection = [NSConnection connectionWithRegisteredName: @"uk.co.blahblahconnection" host:nil];
> if (!theConnection) {
> asl_log(logClient, NULL, ASL_LEVEL_ERR, "Couldn't connect");
> }
>
> id myServer = [theConnection rootProxy];
> if (!myServer) {
> asl_log(logClient, NULL, ASL_LEVEL_ERR, "myServer is nil");
> }
> [myServer setProtocolForProxy:@protocol(MyServerProtocol)];
>
> asl_log(logClient, NULL, ASL_LEVEL_ERR, "Function returned %d",[myServer myServerFunction]);
>
> If I use the exact same code in a new project (GUI application), it works absolutely fine!
>
> I assumed that that meant DO isn't permitted from a PHT (despite being permitted over a network, therefore connecting from a different user on a different machine entirely), so dug a bit lower and tried NSMessagePort instead.
>
> Unfortunately, this gives me the exact same issue:
>
> CFMessagePortRef remotePort = CFMessagePortCreateRemote(NULL, CFSTR("com.example.app.port.server"));
>
> if (!remotePort) {
> asl_log(asl, aslMsg, ASL_LEVEL_ERR, "no remote port");
> }
>
> When using the above code in my PHT, I get "no remote port" in the console log, however, trying it from a completely new GUI application project, it works absolutely fine.
>
> Googling/Ducking (DuckDuckGoing?) didn't turn up anything I hadn't already tried, and the search on CocoaBuilder.com isn't working.
>
> Am I missing something? Is there a way to do what I'm looking for, or am I just barking up the wrong tree entirely?
>
> Thanks
> Mark
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden