SMJobBless throws error CFErrorDomainLaunchd Code = 8

I try to install a helper tool through SMJobBless and I get the following error:

Domain Error = CFErrorDomainLaunchd Code = 8 "Operation could not be completed. (Error CFErrorDomainLaunchd 8.)

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

Can anybody help me?

Thanks,

+2
source share
3 answers

Confirm the 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 belonging after installation in the info.plist file (main application)

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

3. Clients are allowed to add and remove the tool field in the auxiliary info.plist.

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

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

 helper tool bundle : YES 
+4
source

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

NOTE: SMJobBless is a sure way to bless the work. The old way, AuthorizationExecuteWithPrivileges, is deprecated and will be actively avoided in the near future. The sample code "SMJobBless" is deprecated because the following code example is superior in every way.

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

Use the SMJobBlessUtil.py script to check and / or customize the Info.plist material inside your main program and helper.

+1
source

1 、 You can use SMJobBlessUtil.py to test your application; perhaps this will lead to some error description, for example, dump malformed output;

2 、 then you can compare the settings of the sample code project by finding the auxiliary targets of other linker flags , see if you should set this.

+1
source

Source: https://habr.com/ru/post/1241191/