Communicating over XPC with an app and launch daemon running as root

家住魔仙堡 提交于 2019-12-08 00:01:52

问题


Is it possible to communicate with a launch daemon running as root and an application over XPC? When my daemon is running as my user I can communicate with it fine, when run as root it stops receiving my messages. Is this intended security inside Mac OS X? I need to use low level xpc (for running on Lion as well). I know I can create a priviliged and signed helper tool that is running as root for my app. Will I be able to communicate with it with another process as well over XPC or sockets?

Thanks!

Small extract from my daemon code:

int main()
{
    Logger::Start(Poco::Path::expand("/Users/Shared/Me/Service.log"));
    Logger::LogInfo("Starting xpc_main...");

    void* observer = nullptr;
    CFStringRef observedObject = CFSTR("com.me.service.close");
    CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
    CFNotificationCenterAddObserver(center, observer, notificationCallback, CFSTR("ClientClosing"), observedObject, CFNotificationSuspensionBehaviorDeliverImmediately);

    xpc_connection_t listener = xpc_connection_create_mach_service("com.me.service", NULL, XPC_CONNECTION_MACH_SERVICE_LISTENER);
    xpc_connection_set_event_handler(listener, ^(xpc_object_t event)
    {
        // New connections arrive here. You may safely cast to
        // xpc_connection_t. You will never receive messages here.
        // The semantics of this handler are similar to those of
        // of the one given to xpc_main().
        Logger::LogInfo("Event Handler on listener is called");

        eventHandler((xpc_connection_t)event);
    }); 

    Logger::LogInfo("call xpc_connection_resume...");

    xpc_connection_resume(listener);

    CFRunLoopRun();

    Logger::LogInfo("Main Program is Exiting...");

    return 0;
}

回答1:


The problem is that CFNotificationCenterGetDistributedCenter works only on the same user, root user will not send message to other logged in users..

You'll need to switch to CFNotificationCenterGetDarwinNotifyCenter.

Please note however, that you can't pass any data using this center.



来源:https://stackoverflow.com/questions/23552805/communicating-over-xpc-with-an-app-and-launch-daemon-running-as-root

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!