Re: -[NSUserDefaults initWithUser:] broken?
Re: -[NSUserDefaults initWithUser:] broken?
- Subject: Re: -[NSUserDefaults initWithUser:] broken?
- From: Chris Kane <email@hidden>
- Date: Wed, 5 Sep 2001 16:26:56 -0700
This has always been this way. The initWithUser: method was a mistake 7
years ago, and still doesn't work as you'd expect, and never will. In
general, it is not possible to do this in all situations. [If anyone
thinks otherwise, then they're not very experienced with UNIX systems
and certain filesystems.]
You need to seteuid() to the user whose defaults you want to access, do
the access, then go back to being root if needed. There is a note about
this in the Foundation release notes in 10.1. I'll paste it in here,
but it's a little premature: in 10.0, +resetStandardUserDefaults doesn't
reset all the state necessary, and so won't have the needed effect. In
10.0, there's no way to do all the necessary flushing/clearing, as far
as I know.
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.)
Chris Kane
Cocoa Frameworks, Apple
On Wednesday, September 5, 2001, at 03:42 PM, Andreas Monitzer wrote:
I've got a Foundation tool that is run as root and has to access
regular users' defaults.
[[NSUserDefaults alloc] initWithUser:@"otheruser"] (which should be
correct according to the docs) always returns the defaults of the
current user! Looks like a critical bug (for my app), should I report
it?
Any idea for a workaround other than accessing
~user/Library/Preferences/domain.plist (which could break someday)?
(this was tested on a hypothetical system)
andy
--
Description forthcoming.
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev