SMJobBless gives error CFErrorDomainLaunchd Code=8

匆匆过客 提交于 2019-12-01 07:26:55

问题


I am trying to install a helper tool via SMJobBless and I am getting the following error,

Error Domain=CFErrorDomainLaunchd Code=8 "The operation couldn’t be completed. (CFErrorDomainLaunchd error 8.)

I verified the code sign, plist of application and helper tool, copied the tool in launchServices and also linked the plists.

Can anyone please help me?

Thank you,


回答1:


Verify Following Things:

1.Code

- (BOOL)blessHelperWithLabel:(NSString *)label
                       error:(NSError **)error {   

    BOOL result = NO;

    AuthorizationItem authItem      = { kSMRightBlessPrivilegedHelper, 0, NULL, 0 };
    AuthorizationRights authRights  = { 1, &authItem };
    AuthorizationFlags flags        =   kAuthorizationFlagDefaults              |
    kAuthorizationFlagInteractionAllowed    |
    kAuthorizationFlagPreAuthorize          |
    kAuthorizationFlagExtendRights;

    AuthorizationRef authRef = NULL;

    /* Obtain the right to install privileged helper tools (kSMRightBlessPrivilegedHelper). */
    OSStatus status = AuthorizationCreate(&authRights, kAuthorizationEmptyEnvironment, flags, &authRef);
    if (status != errAuthorizationSuccess) {
        NSLog(@"%@", [NSString stringWithFormat:@"Failed to create AuthorizationRef. Error code: %d", (int)status]);

    } else {
        /* This does all the work of verifying the helper tool against the application
         * and vice-versa. Once verification has passed, the embedded launchd.plist
         * is extracted and placed in /Library/LaunchDaemons and then loaded. The
         * executable is placed in /Library/PrivilegedHelperTools.
         */
        result = SMJobBless(kSMDomainSystemLaunchd, (CFStringRef)label, authRef, (CFErrorRef *)error);
    }
    return result;
}

2.Tools owned after installation field in info.plist(main app)

helper bundle : identifier <Helper Bundle Identifier> and certificate leaf[subject.CN] = "Developer ID Application: xxxxx (YYXSFDHZ6W)"

3.Clients allowed to add and remove tool field in helper info.plist.

item 0 : identifier <Main App Bundle Identifier> and certificate leaf[subject.CN] = "Developer ID Application: xxxxxx (YYXSFDHZ6W)"

4.Check MachServices filed in xxxxHelperTool-Launchd.plist.it should be

helper tool bundle : YES



回答2:


1、You can use SMJobBlessUtil.py to check your app; maybe it will come to some error decribtion like dump malformed;

2、then you can compare the sample code's project setting, finding the helper target other linker flags ,see if you should set this.




回答3:


Find the tool SMJobBlessUtil.py in the (otherwise superseded sample code) SMJobBless sample code: https://developer.apple.com/library/archive/samplecode/SMJobBless/Introduction/Intro.html

NOTE: SMJobBless IS the correct way to bless jobs. The old way, AuthorizationExecuteWithPrivileges, is deprecated and will be actively shunned in the near future. The "SMJobBless" sample code is deprecated, because the following example code is superior in pretty much every way.

OK, get the tool, and now get the current example code: https://developer.apple.com/library/archive/samplecode/EvenBetterAuthorizationSample/Introduction/Intro.html

Use the SMJobBlessUtil.py script to verify and or set the Info.plist stuff inside your main program and helper.



来源:https://stackoverflow.com/questions/31020919/smjobbless-gives-error-cferrordomainlaunchd-code-8

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