mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Force defaults file to be accessible only to the user
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11330 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
19e8aa1957
commit
b9d21eebc8
2 changed files with 33 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
2001-11-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSUserDefaults.m: force defaults data to be read/write
|
||||
only to the user. Supplied by Ludovic Marcotte
|
||||
|
||||
Wed Nov 7 09:04:51 2001 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
After this change you need the latest gnustep-make to compile.
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include <Foundation/NSDistributedLock.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <base/GSLocale.h>
|
||||
|
||||
/* Wait for access */
|
||||
|
@ -904,6 +905,9 @@ static NSString *pathForUser(NSString *user)
|
|||
// Read the persistent data from the stored database
|
||||
if ([mgr fileExistsAtPath: _defaultsDatabase])
|
||||
{
|
||||
unsigned long desired;
|
||||
unsigned long attributes;
|
||||
|
||||
newDict = [[NSMutableDictionaryClass allocWithZone: [self zone]]
|
||||
initWithContentsOfFile: _defaultsDatabase];
|
||||
if (newDict == nil)
|
||||
|
@ -912,6 +916,30 @@ static NSString *pathForUser(NSString *user)
|
|||
NSLog(@"Unable to load defaults from '%@'", _defaultsDatabase);
|
||||
return NO;
|
||||
}
|
||||
|
||||
attributes = [[mgr fileAttributesAtPath: _defaultsDatabase
|
||||
traverseLink: YES] filePosixPermissions];
|
||||
// We enforce the permission mode 0600 on the defaults database
|
||||
#if !(defined(S_IRUSR) && defined(S_IWUSR))
|
||||
desired = 0600;
|
||||
#else
|
||||
desired = (S_IRUSR|S_IWUSR);
|
||||
#endif
|
||||
if (attributes != desired)
|
||||
{
|
||||
NSMutableDictionary *enforced_attributes;
|
||||
NSNumber *permissions;
|
||||
|
||||
enforced_attributes = [NSMutableDictionary dictionaryWithDictionary:
|
||||
[mgr fileAttributesAtPath: _defaultsDatabase traverseLink: YES]];
|
||||
|
||||
permissions = [NSNumber numberWithUnsignedLong: desired];
|
||||
[enforced_attributes setObject: permissions
|
||||
forKey: NSFilePosixPermissions];
|
||||
|
||||
[mgr changeFileAttributes: enforced_attributes
|
||||
atPath: _defaultsDatabase];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue