Re: -[NSUserDefaults initWithUser:] broken?
Re: -[NSUserDefaults initWithUser:] broken?
- Subject: Re: -[NSUserDefaults initWithUser:] broken?
- From: Andreas Monitzer <email@hidden>
- Date: Thu, 6 Sep 2001 01:45:35 +0200
On Thursday, September 6, 2001, at 01:26 , Chris Kane wrote:
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.
My app will only run on that hypothetical system, so this isn't an issue
for me.
It works now, thanks! I've written the following workaround:
NSDictionary *userDefaultsForUser(int uid, NSString *domain) {
NSDictionary *result;
[NSUserDefaults resetStandardUserDefaults];
seteuid(uid);
result=[[NSUserDefaults standardUserDefaults] persistentDomainForName:
domain];
[NSUserDefaults resetStandardUserDefaults];
seteuid(0);
return result;
}
Maybe you should add a note in the docs like "NOTE: This method doesn't
work at all." or just remove it.
andy
--
Description forthcoming.