Skip navigation.
 
mlAuthorization Services error when invoking tool from Cocoa framework
FROM : David Reed
DATE : Thu Dec 02 20:24:08 2004

Hi all,

  I'm writing a man page viewer in Cocoa ('iMan', iman-macosx.sf.net).
One of the features I am working on for the next version is the ability
to create/update the whatis.db file, which the apropos and whatis
commands use to perform a search of the man pages.

This database is stored in files called whatis.db in the man page
directories, which aren't user-writable without authorization. What I
need to do, essentially, is just run the command 'sudo
/usr/libexec/makewhatis $MANPATH' (with a possibly user-specified
manpath) and get notification when the command terminates.

Following Apple's sample code and Authorization docs, I have factored
my application to produce a helper tool which runs as root, invokes
makewhatis and waits for it to terminate, and then notifies the main
app via Distributed Notifications. All fine and dandy, except for one
problem. I send the AuthorizationRef created in the main app (actually,
the engine framework that does the work) to the helper tool via
AuthorizationMakeExternalForm. However, the function
AuthorizationCreateFromExternalForm, called in the helper, always
returns error -60002, errAuthorizationInvalidRef. This does not make
sense to me, based on the documentation of this constant, and I can't
work out what I am doing wrong.

The code is as follows:

// In engine framework. Note: I've tried with and without PreAuthorize
without success.
if (AuthorizationCreate(NULL,
                   kAuthorizationEmptyEnvironment,
                   kAuthorizationFlagDefaults,
                   &authRef) == errAuthorizationSuccess) {
       AuthorizationExternalForm externalForm;
       
       if (AuthorizationMakeExternalForm(authRef, &externalForm) ==
errAuthorizationSuccess) {

           //... create and launch NSTask with 'input', an NSPipe, as standard
input
       
           write([[input fileHandleForWriting] fileDescriptor], &externalForm,
sizeof(externalForm));

Then, in the helper tool:
       AuthorizationRef authRef;
       AuthorizationExternalForm extForm;
       OSStatus err;

       if (read(STDIN_FILENO, &extForm, sizeof(extForm)) != sizeof(extForm))
{
           HelperToolSendResultNotification(-2);
           return -1;
       }
       // FIXME: this is returning -60002, errAuthorizationInvalidRef.
       if ((err = AuthorizationCreateFromExternalForm(&extForm, &authRef))
!= errAuthorizationSuccess) {
           HelperToolSendResultNotification(err);
           return -1;
       }

Hence, my question is: what is causing this error? I've tried comparing
the bytes in helper tool and framework; they're the same. My code, as
far as I can tell, works in the same way as Apple's MoreAuthSample,
except that is doesn't actually work! My
Googling/list-archive-searching has not turned up any answers, leading
me to believe something obvious is wrong that I can't see.

Any assistance, comments, links, RTFM's are welcomed -- I'm at my wits
end.

Thanks for reading this long message,
David.

--
David Reed | <email_removed> | AIM/iChat: parmadil01

Related mailsAuthorDate
mlAuthorization Services error when invoking tool from Cocoa framework David Reed Dec 2, 20:24
mlRe: Authorization Services error when invoking tool from Cocoa framework Fritz Anderson Dec 3, 03:23