How to check whether "user" cancelled Helper SM Job Bless password dialog
Asked Answered
C

0

3

Following is my JobBless code, I need help in finding out the error specifically when user cancels the Helper tool installation password dialog

    var authorization: AuthorizationRef?
    let status: OSStatus = AuthorizationCreate(nil, nil, [], &authorization)

    guard status == errAuthorizationSuccess else {
        return .failure(authFailed)
    }

    var error: Unmanaged<CFError>?
    let blessStatus = SMJobBless(kSMDomainSystemLaunchd, label as CFString, authorization, &error)
    guard blessStatus else {

        //*** CHECK FOR CFERROR TO SEE WHETHER THE FAILURE IS DUE TO USER CANCELLING
        // THE PASSWORD REQUEST**
        print(error)

        return .failure(blessfailed)
    }
    return .success(())

I get the following error printed:

Error Domain=CFErrorDomainLaunchd Code=2

I expected kSMErrorLaunchDeniedByUser (11), but I received kSMErrorInternalFailure(2). I am not sure whether I am looking into the right error enum. Please help.

(lldb) p kSMErrorLaunchDeniedByUser
(Int) $R0 = 11
(lldb) p kSMErrorInternalFailure
(Int) $R1 = 2

The reason I want this error number is to show an error screen if user cancels the dialog instead of entering the password. Please help

Centrosymmetric answered 6/2 at 11:50 Comment(3)
Does it work in the happy case? I suspect you have some other error in your whole setup.Statolatry
Yes, it works well when I give proper password. It is an existing code, just I wanted to add a new error screen to show when the user cancels the password dialogCentrosymmetric
Hmmmm I'm not sure then. I've been using the Blessed framework to wrap a bunch of these shitty APIs. The author has done a pretty thorough job of detecting all the various error conditions and reporting them in a more sensible way. Perhaps you can look into how he handles this case. As a last resort, you could try a Technical Support IncidentStatolatry

© 2022 - 2024 — McMap. All rights reserved.