mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-24 22:22:21 +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
|
@ -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…
Add table
Add a link
Reference in a new issue