Authorization Services error when invoking tool from Cocoa framework
Authorization Services error when invoking tool from Cocoa framework
- Subject: Authorization Services error when invoking tool from Cocoa framework
- From: David Reed <email@hidden>
- Date: Thu, 2 Dec 2004 14:24:08 -0500
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@hidden | AIM/iChat: parmadil01
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden