(fix) fixed multi-domain support for sogo-tool backup/restore (#2600)

pull/89/head
Ludovic Marcotte 2015-06-11 13:32:57 -04:00
parent 667e38ff0c
commit 5ad3662640
5 changed files with 62 additions and 28 deletions

1
NEWS
View File

@ -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)
-------------------

View File

@ -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])
{

View File

@ -1,9 +1,6 @@
/* SOGoToolBackup.m - this file is part of SOGo
*
* Copyright (C) 2009-2011 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Francis Lachapelle <flachapelle@inverse.ca>
* 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 <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserProfile.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <Contacts/NSDictionary+LDIF.h>
#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];
}

View File

@ -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 <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoUserProfile.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <NGCards/iCalCalendar.h>
#import <NGCards/NGVCard.h>
@ -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;

View File

@ -1,8 +1,6 @@
/* sogo-tool.m - this file is part of SOGo
*
* Copyright (C) 2009 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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