From 3b2174eeec1843eeb011129134cecf5b6bfd2246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20S=C3=A1ez?= Date: Mon, 17 Mar 2014 21:08:12 +0100 Subject: [PATCH] if there is no password file for specific user, try to read global password file This way we can have a master password for imap access --- OpenChange/MAPIStoreUserContext.m | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/OpenChange/MAPIStoreUserContext.m b/OpenChange/MAPIStoreUserContext.m index e034ce3bc..04300fd35 100644 --- a/OpenChange/MAPIStoreUserContext.m +++ b/OpenChange/MAPIStoreUserContext.m @@ -100,16 +100,12 @@ static NSMapTable *contextsTable = nil; return self; } -- (NSString *) _readUserPassword: (NSString *) newUsername +- (NSString *) _readPasswordFile: (NSString *) path { - NSString *password, *path; + NSString *password; NSData *content; - - password = nil; - - path = [NSString stringWithFormat: SAMBA_PRIVATE_DIR - @"/mapistore/%@/password", newUsername]; + password = nil; content = [NSData dataWithContentsOfFile: path]; if (content) @@ -124,6 +120,24 @@ static NSMapTable *contextsTable = nil; return password; } +- (NSString *) _readUserPassword: (NSString *) newUsername +{ + NSString *password, *path; + + path = [NSString stringWithFormat: SAMBA_PRIVATE_DIR + @"/mapistore/%@/password", newUsername]; + + password = [self _readPasswordFile: path]; + if (password == nil) + { + // Try to get master password + path = [NSString stringWithFormat: SAMBA_PRIVATE_DIR @"/mapistore/master.password"]; + password = [self _readPasswordFile: path]; + } + + return password; +} + - (id) initWithUsername: (NSString *) newUsername andTDBIndexing: (struct indexing_context *) indexing {