Re: NSUsersDefault and users
Re: NSUsersDefault and users
- Subject: Re: NSUsersDefault and users
- From: Chris Parker <email@hidden>
- Date: Tue, 6 Nov 2001 13:12:38 -0800
Mea culpa, Julien, I misunderstood what you were asking here (there is
another bug outstanding which I was confusing with your case, and it
doesn't really apply).
After talking it over with another engineer here (thank you, Chris
Kane), it sounds like what you're asking for is the opposite of what
most apps want in a setuid situation.
Your workaround is correct - there is a release note regarding this for
Foundation:
/Developer/Documentation/ReleaseNotes/Foundation.html
Accessing User Preferences in setuid Processes
Setuid Cocoa apps that want to access the real user's defaults should
call the public method +[NSUserDefaults resetStandardUserDefaults] then
call seteuid() to change to the user's uid. +resetStandardUserDefaults
will flush out any changes made to the user defaults to that point, and
clear all the cached state. Any previously fetched standardUserDefaults
instance is then invalid at that point and must be refetched with
+[NSUserDefaults standardUserDefaults] (ie, be careful about storing
that value in a local variable if you're switching euids in a function).
Similarly, before reverting to run as root, +[NSUserDefaults
resetStandardUserDefaults] should again be called to push out any
changes and reset all state. Essentially, this is something that should
be done prior to calling seteuid(). (Even if the app isn't using
defaults, since AppKit does and other frameworks might.)
So you're pretty much doing the right thing.
For your side question:
/Library/Preferences is the "any user" location for preferences -
NSUserDefaults does not at present have coverage for this, but
CFPreferences does. Adding your key using CFPreferences should expose
it to NSUD, however.
.chris
On Monday, November 5, 2001, at 04:30 PM, Julien Jalon wrote:
I was trying something with my application (DNSUpdate) and found a
problem with the user identification by the FoundationKit while playing
with User defaults... I think the problem is also the cause of some
other problems I have.
Let me explain:
DNSUpdate launch a daemon as root (using the SecurityFramework).
the daemon register and use some defaults but... the defaults plist
file is stored in the user preferences folder (the one who launched
DNSUpdate).
Since the daemon is launched as root, the plist file normally has to be
stored in the root preferences folder. The daemon acts as if it was
launched by the user (Except it has root priviledges...).
My question: how to be sure the daemon acts as if it was launched at
boot time and so acts as a program launched by root? (e.g.
[NSUserDefaults standardUserDefaults] points to the defaults file in
the root preferences folder!)
(I know that I can use the -initWithUser: method of NSUserDefaults as a
workaround but I don't want that... I want my tool to behave as
expected).
--Julien Jalon
PS: As a side question, how to make [NSUserDefaults
standardUserDefaults] point to /Library/Preferences instead of
~root/Library/Preferences?
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev