【问题标题】:SMJobBless gives error CFErrorDomainLaunchd Code=8SMJobBless 给出错误 CFErrorDomainLaunchd Code=8
【发布时间】:2015-06-24 07:58:23
【问题描述】:

我正在尝试通过 SMJobBless 安装帮助工具,但出现以下错误,

Error Domain=CFErrorDomainLaunchd Code=8 "操作无法完成。(CFErrorDomainLaunchd 错误 8。)

我验证了代码符号、应用程序的 plist 和帮助工具,在 launchServices 中复制了该工具并链接了 plist。

谁能帮帮我?

谢谢,

【问题讨论】:

    标签: macos cocoa smjobbless


    【解决方案1】:

    验证以下内容:

    1.代码

    - (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.info.plist(main app)中安装后拥有的工具字段

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

    3.客户端允许在helper info.plist中添加和删除工具字段。

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

    4.检查xxxxHelperTool-Launchd.plist中归档的MachServices.应该是

    helper tool bundle : YES
    

    【讨论】:

      【解决方案2】:

      在(否则被取代的示例代码)SMJobBless 示例代码中找到工具 SMJobBlessUtil.py:https://developer.apple.com/library/archive/samplecode/SMJobBless/Introduction/Intro.html

      注意:SMJobBless 祝福工作的正确方法。旧方式 AuthorizationExecuteWithPrivileges 已被弃用,将在不久的将来积极回避。 “SMJobBless”示例代码已被弃用,因为以下示例代码在几乎所有方面都更胜一筹。

      好的,获取工具,现在获取当前示例代码: https://developer.apple.com/library/archive/samplecode/EvenBetterAuthorizationSample/Introduction/Intro.html

      使用 SMJobBlessUtil.py 脚本来验证和/或设置主程序和帮助程序中的 Info.plist 内容。

      【讨论】:

        【解决方案3】:

        1、您可以使用 SMJobBlessUtil.py 来检查您的应用程序;也许它会出现一些错误描述,例如dump malformed;

        2、然后你可以比较示例代码的项目设置,找到帮助目标other linker flags,看看是否应该设置。

        【讨论】:

          【解决方案4】:

          基于该错误,我怀疑在您创建了 info 和 launchd 属性列表时,您没有指示链接器将它们嵌入到可执行文件中。

          您可以通过将构建变量OTHER_LDFLAGS 设置为-sectcreate __TEXT __info_plist $(INFOPLIST_FILE) -sectcreate __TEXT __launchd_plist $(LAUNCHDPLIST_FILE) 来做到这一点,其中INFOPLIST_FILELAUNCHDPLIST_FILE 是具有这两个文件路径值的变量。或者,您可以直接在那里指定文件路径,而不是让它们成为自己的构建变量。

          如果您仍然遇到此问题,您可以在辅助工具的主文件中导入 EmbeddedPropertyList framework 并让它打印出嵌入信息和启动属性列表的值。您不需要通过 SMJobBless 安装可执行文件来执行此操作,您可以从终端正常运行可执行文件。在这种情况下,它不会以 root 身份运行,但如果您只是想验证属性列表是否已正确嵌入,那很好。

          【讨论】:

            猜你喜欢
            • 2015-11-19
            • 2018-07-04
            • 2022-07-25
            • 1970-01-01
            • 1970-01-01
            • 2015-10-03
            • 1970-01-01
            • 2014-12-28
            • 2020-07-23
            相关资源
            最近更新 更多