Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSUserDefaults initWithUser:] broken?



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.


References: 
 >Re: -[NSUserDefaults initWithUser:] broken? (From: Chris Kane <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.