Re: Authorization.h
Re: Authorization.h
- Subject: Re: Authorization.h
- From: Julien Jalon <email@hidden>
- Date: Tue, 6 Nov 2001 15:31:03 +0100
Le mardi 6 novembre 2001, ` 11:54 AM, Stiphane Sudre a icrit :
On mardi, novembre 6, 2001, at 10:20 , Josh M. Hurd wrote:
[...]
My main app needs to be able to operate on a list of files as root.
It already does this with non-root files so all the code and data
structures are in place. My data is in an NSArray and I would like to
send it to my root privileged tool as such to avoid code changes. I
have read through tons of doc pages and pieced together snippets of
sample code but can't get it to work. Neither one is willing to
respond to the other. I am attempting to make connections with
NSConnection and communicate through a proxy using NSProxy. Is this
even close?
[...]
Does anyone know of a good tutorial or some sample code that
illustrates how to so this? I've checked various site, including
Apple but haven't found any that helped.
You can do what Julien is explaining to you: use NSNotification and
more precisely its userInfo NSDictionary data to transmit your NSArray.
Another solution is to use a CFMessagePort to communicate between both
applications. You may need to convert your array before sending it
through a CFDataRef but it's not that complex.
Another solution is to write your array to a file in /tmp/user_id/ and
send a notification to your privileged tool that the data is available.
You can do this via a NSNotification again.
A good example is available in /Developer/Examples/CoreFoundation :
Notification Observer / Poster .
Hmm... I think the best way is th one Josh propose: Distributed Object.
It's easy and elegant.
The idea is to develop the application with no DO and with an object
doing all the important stuff. Then develop just a little tool vending
the same object. The application then has just to connect to the tool
and replaces his local important object with the vended object. The rest
of the application code remains unchanged... it will not even know that
the important object does not operate in his space. DO are very
powerful... and with ObjC/FoundationKit it's very elegant.
If you want sample code, you can look at DNSUpdate code on my homepage
(
http://mapage.noos.fr/jalon), you can look at it and ask me whatever
you want on the code.
From my code:
// Server side (tool)
[...]
NSConnection *theServer=[NSConnection defaultConnection];
[...]
_sharedGuardian=[[DUGuardian alloc] init];
if(theServer) {
/* _sharedGuardian is the vended object */
[theServer setRootObject:_sharedGuardian];
[theServer registerName:DNSUPDATE];
[...]
}
[...]
/* run waiting for connections */
[[NSRunLoop currentRunLoop] run];
[...]
// Client side (application)
[...]
theServer=[NSConnection connectionWithRegisteredName:DNSUPDATE
host:nil];
[...]
/* guardian is the _sharedGuardian vended above */
guardian=[theServer rootProxy];
[guardian setProtocolForProxy:@protocol(DUGuardian)];
/* now, you can use guardian as if it was a local object */
[..]
For security issues, the tool has to authenticate the one who is
connecting. You can use whatever you want. My solution here : the
guardian here is not the real important object... it's just an object
giving the real important object if you give it a key ([guardian
getProxyWithKey:]).
--Julien