From 5ad36626406e55e82867351c9775a357748e2b28 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 11 Jun 2015 13:32:57 -0400 Subject: [PATCH] (fix) fixed multi-domain support for sogo-tool backup/restore (#2600) --- NEWS | 1 + SoObjects/SOGo/SOGoUserManager.m | 2 +- Tools/SOGoToolBackup.m | 47 +++++++++++++++++++------------- Tools/SOGoToolRestore.m | 36 ++++++++++++++++++++---- Tools/sogo-tool.m | 4 +-- 5 files changed, 62 insertions(+), 28 deletions(-) diff --git a/NEWS b/NEWS index 48db9ee3d..cb6c05995 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ Bug fixes - fixed potential organizer highjacking when using EAS (#3131) - properly support big characters in EAS and fix encoding QP EAS error for Outlook (#3082) - properly encode id of DOM elements in Address Book module (#3239, #3245) + - fixed multi-domain support for sogo-tool backup/restore (#2600) 2.3.0 (2015-06-01) ------------------- diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index a29ebb356..5dcd007df 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -568,7 +568,7 @@ static Class NSNullK; // mail: broccoli@example.com // // and authenticates with "foo", using bindFields = (uid, mail) and SOGoEnableDomainBasedUID = YES; - // Otherwise, -_sourceCheckLogin:... would have failed because SOGo would to bind using: foo@example.com + // Otherwise, -_sourceCheckLogin:... would have failed because SOGo would try to bind using: foo@example.com // if ([[currentUser objectForKey: @"DomainLessLogin"] boolValue]) { diff --git a/Tools/SOGoToolBackup.m b/Tools/SOGoToolBackup.m index 8dd7ea04a..fb2b4d016 100644 --- a/Tools/SOGoToolBackup.m +++ b/Tools/SOGoToolBackup.m @@ -1,9 +1,6 @@ /* SOGoToolBackup.m - this file is part of SOGo * - * Copyright (C) 2009-2011 Inverse inc. - * - * Author: Wolfgang Sourdeau - * Francis Lachapelle + * Copyright (C) 2009-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +39,7 @@ #import #import #import +#import #import #import "SOGoTool.h" @@ -55,7 +53,7 @@ @interface SOGoToolBackup : SOGoTool { NSString *directory; - NSArray *userIDs; + NSArray *usersToBackup; } @end @@ -83,7 +81,7 @@ if ((self = [super init])) { directory = nil; - userIDs = nil; + usersToBackup = nil; } return self; @@ -92,7 +90,7 @@ - (void) dealloc { [directory release]; - [userIDs release]; + [usersToBackup release]; [super dealloc]; } @@ -143,6 +141,7 @@ lm = [SOGoUserManager sharedUserManager]; pool = [[NSAutoreleasePool alloc] init]; + max = [users count]; user = [users objectAtIndex: 0]; @@ -198,11 +197,11 @@ NSLog (@"user '%@' unknown", user); } [allUsers autorelease]; - - ASSIGN (userIDs, [allUsers objectsForKey: @"c_uid" notFoundMarker: nil]); + + ASSIGN (usersToBackup, allUsers); DESTROY(pool); - return ([userIDs count] > 0); + return ([usersToBackup count] > 0); } - (BOOL) parseArguments @@ -410,19 +409,29 @@ return YES; } -- (BOOL) exportUser: (NSString *) uid +- (BOOL) exportUser: (NSDictionary *) theUser { + NSString *exportPath, *gcsUID, *ldapUID; NSMutableDictionary *userRecord; - NSString *exportPath; - + SOGoSystemDefaults *sd; + + sd = [SOGoSystemDefaults sharedSystemDefaults]; userRecord = [NSMutableDictionary dictionary]; - exportPath = [directory stringByAppendingPathComponent: uid]; - return ([self extractUserFolders: uid + ldapUID = [theUser objectForKey: @"c_uid"]; + exportPath = [directory stringByAppendingPathComponent: ldapUID]; + + gcsUID = [theUser objectForKey: @"c_uid"]; + + if ([sd enableDomainBasedUID] && [gcsUID rangeOfString: @"@"].location == NSNotFound) + gcsUID = [NSString stringWithFormat: @"%@@%@", gcsUID, [theUser objectForKey: @"c_domain"]]; + + + return ([self extractUserFolders: gcsUID intoRecord: userRecord] - && [self extractUserLDIFRecord: uid + && [self extractUserLDIFRecord: ldapUID intoRecord: userRecord] - && [self extractUserPreferences: uid + && [self extractUserPreferences: gcsUID intoRecord: userRecord] && [userRecord writeToFile: exportPath atomically: NO]); @@ -438,10 +447,10 @@ pool = [NSAutoreleasePool new]; - max = [userIDs count]; + max = [usersToBackup count]; for (count = 0; rc && count < max; count++) { - rc = [self exportUser: [userIDs objectAtIndex: count]]; + rc = [self exportUser: [usersToBackup objectAtIndex: count]]; if ((count % 10) == 0) [pool emptyPool]; } diff --git a/Tools/SOGoToolRestore.m b/Tools/SOGoToolRestore.m index d3fb601f9..5e43b769e 100644 --- a/Tools/SOGoToolRestore.m +++ b/Tools/SOGoToolRestore.m @@ -1,6 +1,6 @@ /* SOGoToolRestore.m - this file is part of SOGo * - * Copyright (C) 2009-2014 Inverse inc. + * Copyright (C) 2009-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,6 +40,7 @@ #import #import #import +#import #import #import @@ -65,6 +66,7 @@ typedef enum SOGoToolRestoreMode { { NSString *directory; NSString *userID; + NSString *filename; NSString *restoreFolder; BOOL destructive; /* destructive mode not handled */ SOGoToolRestoreMode restoreMode; @@ -90,6 +92,7 @@ typedef enum SOGoToolRestoreMode { { directory = nil; userID = nil; + filename = nil; restoreFolder = nil; destructive = NO; } @@ -101,6 +104,7 @@ typedef enum SOGoToolRestoreMode { { [directory release]; [userID release]; + [filename release]; [restoreFolder release]; [super dealloc]; } @@ -169,13 +173,35 @@ typedef enum SOGoToolRestoreMode { - (BOOL) fetchUserID: (NSString *) identifier { - BOOL rc; + SOGoSystemDefaults *sd; SOGoUserManager *lm; NSDictionary *infos; + NSString *uid; + + BOOL rc; lm = [SOGoUserManager sharedUserManager]; infos = [lm contactInfosForUserWithUIDorEmail: identifier]; - ASSIGN (userID, [infos objectForKey: @"c_uid"]); + uid = nil; + + if (infos) + { + sd = [SOGoSystemDefaults sharedSystemDefaults]; + uid = [infos objectForKey: @"c_uid"]; + + if ([sd enableDomainBasedUID] && [uid rangeOfString: @"@"].location == NSNotFound) + uid = [NSString stringWithFormat: @"%@@%@", + [infos objectForKey: @"c_uid"], + [infos objectForKey: @"c_domain"]]; + + if ([[infos objectForKey: @"DomainLessLogin"] boolValue]) + ASSIGN(filename, [infos objectForKey: @"c_uid"]); + else + ASSIGN(filename, uid); + } + + ASSIGN (userID, uid); + if (userID) rc = YES; else @@ -613,7 +639,7 @@ typedef enum SOGoToolRestoreMode { NSString *importPath; BOOL rc; - importPath = [directory stringByAppendingPathComponent: userID]; + importPath = [directory stringByAppendingPathComponent: filename]; userRecord = [NSDictionary dictionaryWithContentsOfFile: importPath]; if (userRecord) { @@ -631,7 +657,7 @@ typedef enum SOGoToolRestoreMode { else { rc = NO; - NSLog (@"user backup file could not be loaded"); + NSLog(@"user backup (%@) file could not be loaded", importPath); } return rc; diff --git a/Tools/sogo-tool.m b/Tools/sogo-tool.m index d2d8b5c87..bc4755416 100644 --- a/Tools/sogo-tool.m +++ b/Tools/sogo-tool.m @@ -1,8 +1,6 @@ /* sogo-tool.m - this file is part of SOGo * - * Copyright (C) 2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2009-2015 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by