diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.m b/SoObjects/Contacts/SOGoContactSourceFolder.m index b92b953a1..457edf8c5 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.m +++ b/SoObjects/Contacts/SOGoContactSourceFolder.m @@ -166,9 +166,10 @@ ldifEntry = [childRecords objectForKey: objectName]; if (!ldifEntry) { - ldifEntry = [source lookupContactEntry: objectName]; - if (ldifEntry) - [childRecords setObject: ldifEntry forKey: objectName]; + ldifEntry = [source lookupContactEntry: objectName + inDomain: [[context activeUser] domain]]; + if (ldifEntry) + [childRecords setObject: ldifEntry forKey: objectName]; else if ([self isValidContentName: objectName]) { url = [[[lookupContext request] uri] urlWithoutParameters]; @@ -341,10 +342,14 @@ NSDictionary *record; if (aName && [aName length] > 0) - record = [self _flattenedRecord: [source lookupContactEntry: aName]]; + { + record = [source lookupContactEntry: aName + inDomain: [[context activeUser] domain]]; + record = [self _flattenedRecord: record]; + } else record = nil; - + return record; } @@ -579,7 +584,7 @@ toResponse: (WOResponse *) response { NSObject *element; - NSString *url, *baseURL, *cname; + NSString *url, *baseURL, *cname, *domain; NSString **propertiesArray; NSMutableString *buffer; NSDictionary *object; @@ -596,13 +601,13 @@ max = [refs length]; buffer = [NSMutableString stringWithCapacity: max*512]; - + domain = [[context activeUser] domain]; for (count = 0; count < max; count++) { element = [refs objectAtIndex: count]; url = [[[element firstChild] nodeValue] stringByUnescapingURL]; cname = [self _deduceObjectNameFromURL: url fromBaseURL: baseURL]; - object = [source lookupContactEntry: cname]; + object = [source lookupContactEntry: cname inDomain: domain]; if (object) [self appendObject: object properties: propertiesArray diff --git a/SoObjects/SOGo/GNUmakefile b/SoObjects/SOGo/GNUmakefile index 40e19725b..65713871a 100644 --- a/SoObjects/SOGo/GNUmakefile +++ b/SoObjects/SOGo/GNUmakefile @@ -32,6 +32,12 @@ SOGo_HEADER_FILES = \ SOGoGCSFolder.h \ SOGoParentFolder.h \ SOGoUserFolder.h \ + SOGoSource.h \ + SOGoSystemDefaults.h \ + SOGoDomainDefaults.h \ + SOGoLDAPDefaults.h \ + SOGoDefaultsSource.h \ + SOGoUserDefaults.h \ \ SOGoSieveManager.h \ \ diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index 3877ec4ee..9081196be 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -120,8 +120,10 @@ andMultipleBookingsField: (NSString *) newMultipleBookingsField; - (void) setContactMapping: (NSDictionary *) newMapping andObjectClasses: (NSArray *) newObjectClasses; -- (NGLdapEntry *) lookupGroupEntryByUID: (NSString *) theUID; -- (NGLdapEntry *) lookupGroupEntryByEmail: (NSString *) theEmail; +- (NGLdapEntry *) lookupGroupEntryByUID: (NSString *) theUID + inDomain: (NSString *) domain; +- (NGLdapEntry *) lookupGroupEntryByEmail: (NSString *) theEmail + inDomain: (NSString *) domain; @end diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index 55115efdd..2fa8f3773 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -162,6 +162,7 @@ static Class NSStringK; [multipleBookingsField release]; [MSExchangeHostname release]; [modifiers release]; + [displayName release]; [super dealloc]; } @@ -1242,6 +1243,7 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses } - (NSDictionary *) lookupContactEntry: (NSString *) theID + inDomain: (NSString *) domain { NGLdapEntry *ldapEntry; EOQualifier *qualifier; @@ -1339,12 +1341,14 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses } - (NGLdapEntry *) lookupGroupEntryByUID: (NSString *) theUID + inDomain: (NSString *) domain { return [self _lookupGroupEntryByAttributes: [NSArray arrayWithObject: UIDField] andValue: theUID]; } - (NGLdapEntry *) lookupGroupEntryByEmail: (NSString *) theEmail + inDomain: (NSString *) domain { return [self _lookupGroupEntryByAttributes: mailFields andValue: theEmail]; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.m b/SoObjects/SOGo/SOGoDomainDefaults.m index b55cc0851..4c7541b19 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.m +++ b/SoObjects/SOGo/SOGoDomainDefaults.m @@ -50,6 +50,9 @@ andParentSource: systemDefaults]; } + if (!domainDefaults) + domainDefaults = [SOGoSystemDefaults sharedSystemDefaults]; + return domainDefaults; } diff --git a/SoObjects/SOGo/SOGoGroup.m b/SoObjects/SOGo/SOGoGroup.m index c72095fb6..431b39028 100644 --- a/SoObjects/SOGo/SOGoGroup.m +++ b/SoObjects/SOGo/SOGoGroup.m @@ -113,7 +113,7 @@ uid = [theID hasPrefix: @"@"] ? [theID substringFromIndex: 1] : theID; return [SOGoGroup groupWithValue: uid - andSourceSelector: @selector (lookupGroupEntryByUID:) + andSourceSelector: @selector (lookupGroupEntryByUID:inDomain:) inDomain: domain]; } @@ -121,7 +121,7 @@ inDomain: (NSString *) domain { return [SOGoGroup groupWithValue: theEmail - andSourceSelector: @selector (lookupGroupEntryByEmail:) + andSourceSelector: @selector (lookupGroupEntryByEmail:inDomain:) inDomain: domain]; } @@ -158,9 +158,9 @@ // Our different sources might not all implements groups support if ([source respondsToSelector: theSelector]) - entry = [source performSelector: theSelector - withObject: theValue]; - + entry = [source performSelector: theSelector + withObject: theValue + withObject: domain]; if (entry) break; diff --git a/SoObjects/SOGo/SOGoSession.m b/SoObjects/SOGo/SOGoSession.m index 9af654b90..73bbbfa5d 100644 --- a/SoObjects/SOGo/SOGoSession.m +++ b/SoObjects/SOGo/SOGoSession.m @@ -41,6 +41,7 @@ #include #import "SOGoSystemDefaults.h" +#import "SOGoUserManager.h" @implementation SOGoSession @@ -262,7 +263,7 @@ // The domain is probably appended to the username; // make sure it is defined as a domain in the configuration. *theDomain = [*theLogin substringFromIndex: (r.location + r.length)]; - if (![[sd domainIds] containsObject: *theDomain]) + if (![[SOGoUserManager sharedUserManager] isDomainDefined: *theDomain]) *theDomain = nil; } } diff --git a/SoObjects/SOGo/SOGoSource.h b/SoObjects/SOGo/SOGoSource.h index b55a5a14a..d59a81086 100644 --- a/SoObjects/SOGo/SOGoSource.h +++ b/SoObjects/SOGo/SOGoSource.h @@ -56,7 +56,8 @@ newPassword: (NSString *) newPassword perr: (SOGoPasswordPolicyError *) perr; -- (NSDictionary *) lookupContactEntry: (NSString *) theID; +- (NSDictionary *) lookupContactEntry: (NSString *) theID + inDomain: (NSString *) domain; - (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID inDomain: (NSString *) domain; diff --git a/SoObjects/SOGo/SOGoSystemDefaults.m b/SoObjects/SOGo/SOGoSystemDefaults.m index 8c9181665..9447b1da3 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.m +++ b/SoObjects/SOGo/SOGoSystemDefaults.m @@ -261,7 +261,7 @@ _injectConfigurationFromFile (NSMutableDictionary *defaultsDict, - (BOOL) enableDomainBasedUID { - return ([[self domainIds] count] > 0 && [self boolForKey: @"SOGoEnableDomainBasedUID"]); + return [self boolForKey: @"SOGoEnableDomainBasedUID"]; } - (NSArray *) loginDomains diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index d81dcf52c..d84eb6188 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -165,7 +165,7 @@ // The domain is probably appended to the username; // make sure it is defined as a domain in the configuration. domain = [newLogin substringFromIndex: (r.location + r.length)]; - if ([[sd domainIds] containsObject: domain] && + if ([[SOGoUserManager sharedUserManager] isDomainDefined: domain] && ![sd enableDomainBasedUID]) newLogin = [newLogin substringToIndex: r.location]; diff --git a/SoObjects/SOGo/SOGoUserManager.h b/SoObjects/SOGo/SOGoUserManager.h index d30821108..5cf246d3a 100644 --- a/SoObjects/SOGo/SOGoUserManager.h +++ b/SoObjects/SOGo/SOGoUserManager.h @@ -58,6 +58,7 @@ - (NSArray *) sourceIDsInDomain: (NSString *) domain; - (NSArray *) authenticationSourceIDsInDomain: (NSString *) domain; - (NSArray *) addressBookSourceIDsInDomain: (NSString *) domain; +- (BOOL) isDomainDefined: (NSString *) domain; - (NSObject *) sourceWithID: (NSString *) sourceID; - (NSDictionary *) metadataForSourceID: (NSString *) sourceID; diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 598a44614..3a1b542da 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -67,10 +67,12 @@ static Class NSNullK; if (type) { - if ([type isEqualToString: @"ldap"]) + if ([type caseInsensitiveCompare: @"ldap"] == NSOrderedSame) sourceClass = @"LDAPSource"; - else if ([type isEqualToString: @"sql"]) + else if ([type caseInsensitiveCompare: @"sql"] == NSOrderedSame) sourceClass = @"SQLSource"; + else if (NSClassFromString(type)) + sourceClass = type; else { [NSException raise: @"SOGoUserManagerRegistryException" @@ -104,65 +106,58 @@ static Class NSNullK; NSString *sourceID, *value, *type; NSMutableDictionary *metadata; NSObject *sogoSource; - BOOL isAddressBook, result; + BOOL isAddressBook; Class c; - result = NO; sourceID = [udSource objectForKey: @"id"]; - if ([sourceID length] > 0) + if (!sourceID || [sourceID length] == 0) { - if ([_sourcesMetadata objectForKey: sourceID]) - [self errorWithFormat: @"attempted to register a contact/user source" - @" with duplicated id (%@)", sourceID]; - else - { - type = [[udSource objectForKey: @"type"] lowercaseString]; - c = NSClassFromString([_registry sourceClassForType: type]); - sogoSource = [c sourceFromUDSource: udSource inDomain: domain]; - if (sourceID) - [_sources setObject: sogoSource forKey: sourceID]; - else - [self errorWithFormat: @"id field missing in an user source," - @" check the SOGoUserSources defaults"]; - metadata = [NSMutableDictionary dictionary]; - if (domain) - [metadata setObject: domain forKey: @"domain"]; - value = [udSource objectForKey: @"canAuthenticate"]; - if (value) - [metadata setObject: value forKey: @"canAuthenticate"]; - value = [udSource objectForKey: @"isAddressBook"]; - if (value) - { - [metadata setObject: value forKey: @"isAddressBook"]; - isAddressBook = [value boolValue]; - } - else - isAddressBook = NO; - value = [udSource objectForKey: @"displayName"]; - if (value) - [metadata setObject: value forKey: @"displayName"]; - else - { - if (isAddressBook) - [self errorWithFormat: @"addressbook source '%@' has" - @" no displayname", sourceID]; - } - value = [udSource objectForKey: @"MailFieldNames"]; - if (value) - [metadata setObject: value forKey: @"MailFieldNames"]; - value = [udSource objectForKey: @"SearchFieldNames"]; - if (value) - [metadata setObject: value forKey: @"SearchFieldNames"]; - - [_sourcesMetadata setObject: metadata forKey: sourceID]; - result = YES; - } + [self errorWithFormat: @"attempted to register a contact/user source " + @"without id (skipped)"]; + return NO; + } + if ([_sourcesMetadata objectForKey: sourceID]) + { + [self errorWithFormat: @"attempted to register a contact/user source " + @"with duplicated id (%@)", sourceID]; + return NO; + } + + type = [udSource objectForKey: @"type"]; + c = NSClassFromString([_registry sourceClassForType: type]); + sogoSource = [c sourceFromUDSource: udSource inDomain: domain]; + [_sources setObject: sogoSource forKey: sourceID]; + + metadata = [NSMutableDictionary dictionary]; + if (domain) + [metadata setObject: domain forKey: @"domain"]; + value = [udSource objectForKey: @"canAuthenticate"]; + if (value) + [metadata setObject: value forKey: @"canAuthenticate"]; + value = [udSource objectForKey: @"isAddressBook"]; + if (value) + { + [metadata setObject: value forKey: @"isAddressBook"]; + isAddressBook = [value boolValue]; } else - [self errorWithFormat: @"attempted to register a contact/user source" - @" without id (skipped)"]; + isAddressBook = NO; + value = [udSource objectForKey: @"displayName"]; + if (value) + [metadata setObject: value forKey: @"displayName"]; + else if (isAddressBook) + [self errorWithFormat: @"addressbook source '%@' has no displayname", sourceID]; - return result; + value = [udSource objectForKey: @"MailFieldNames"]; + if (value) + [metadata setObject: value forKey: @"MailFieldNames"]; + value = [udSource objectForKey: @"SearchFieldNames"]; + if (value) + [metadata setObject: value forKey: @"SearchFieldNames"]; + + [_sourcesMetadata setObject: metadata forKey: sourceID]; + + return YES; } - (int) _registerSourcesInDomain: (NSString *) domain @@ -171,11 +166,7 @@ static Class NSNullK; unsigned int count, max, total; SOGoDomainDefaults *dd; - if (domain) - dd = [SOGoDomainDefaults defaultsForDomain: domain]; - else - dd = [SOGoSystemDefaults sharedSystemDefaults]; - + dd = [SOGoDomainDefaults defaultsForDomain: domain]; userSources = [dd userSources]; max = [userSources count]; total = 0; @@ -305,6 +296,35 @@ static Class NSNullK; return sourceIDs; } +- (BOOL) isDomainDefined: (NSString *) domain +{ + NSEnumerator *allIDs; + NSArray *ids; + NSString *currentID, *sourceDomain; + SOGoSystemDefaults *sd; + + if (!domain) return NO; + + ids = [_sources allKeys]; + if ([ids containsObject: domain]) + // FIXME check SOGoMailDomain? + // Now source id is being considered as the domain + return YES; + + sd = [SOGoSystemDefaults sharedSystemDefaults]; + if ([sd enableDomainBasedUID]) + { + allIDs = [ids objectEnumerator]; + while ((currentID = [allIDs nextObject])) + { + sourceDomain = [[_sources objectForKey: currentID] domain]; + if (!sourceDomain) // source that can identify any domain + return YES; + } + } + + return NO; +} - (NSString *) displayNameForSourceWithID: (NSString *) sourceID { NSDictionary *metadata; @@ -328,7 +348,6 @@ static Class NSNullK; { NSDictionary *contactInfos; -// NSLog (@"getEmailForUID: %@", uid); contactInfos = [self contactInfosForUserWithUIDorEmail: uid]; return [contactInfos objectForKey: @"c_email"]; @@ -345,8 +364,7 @@ static Class NSNullK; if ([cn length] > 0) { if ([email length] > 0) - fullEmail = [NSString stringWithFormat: @"%@ <%@>", - cn, email]; + fullEmail = [NSString stringWithFormat: @"%@ <%@>", cn, email]; else fullEmail = cn; } @@ -369,11 +387,7 @@ static Class NSNullK; login = [contactInfos objectForKey: @"c_imaplogin"]; if (login == nil) { - if ([domain length]) - dd = [SOGoDomainDefaults defaultsForDomain: domain]; - else - dd = [SOGoSystemDefaults sharedSystemDefaults]; - + dd = [SOGoDomainDefaults defaultsForDomain: domain]; if ([dd forceExternalLoginWithEmail]) { sd = [SOGoSystemDefaults sharedSystemDefaults]; @@ -415,16 +429,16 @@ static Class NSNullK; - (BOOL) _sourceChangePasswordForLogin: (NSString *) login inDomain: (NSString *) domain oldPassword: (NSString *) oldPassword - newPassword: (NSString *) newPassword - perr: (SOGoPasswordPolicyError *) perr + newPassword: (NSString *) newPassword + perr: (SOGoPasswordPolicyError *) perr { NSObject *sogoSource; NSEnumerator *authIDs; NSString *currentID; BOOL didChange; - + didChange = NO; - + authIDs = [[self authenticationSourceIDsInDomain: domain] objectEnumerator]; while (!didChange && (currentID = [authIDs nextObject])) { @@ -449,8 +463,6 @@ static Class NSNullK; NSEnumerator *authIDs; NSString *currentID; BOOL checkOK; - SOGoSystemDefaults *sd; - NSRange r; checkOK = NO; @@ -467,7 +479,24 @@ static Class NSNullK; } if (checkOK && *domain == nil) - *domain = [sogoSource domain]; + { + SOGoSystemDefaults *sd = [SOGoSystemDefaults sharedSystemDefaults]; + BOOL multidomainSource = [sd enableDomainBasedUID] && + [sogoSource domain] == nil; + if (multidomainSource) + { + NSArray *parts = [login componentsSeparatedByString: @"@"]; + if ([parts count] != 2) + { + [self errorWithFormat: @"Authenticated with multidomain source " + @"but login is not an email (%@).", login]; + return NO; + } + *domain = [parts objectAtIndex: 1]; + } + else + *domain = [sogoSource domain]; + } return checkOK; } @@ -548,7 +577,7 @@ static Class NSNullK; delta = current_time - start_time; block_time = [sd failedLoginBlockInterval]; - + if ([[failedCount objectForKey: @"FailedCount"] intValue] >= [sd maximumFailedLoginCount] && delta >= [sd maximumFailedLoginInterval] && delta <= block_time ) @@ -556,7 +585,7 @@ static Class NSNullK; *_perr = PolicyAccountLocked; return NO; } - + if (delta > block_time) { [[SOGoCache sharedCache] setFailedCount: 0 @@ -640,7 +669,7 @@ static Class NSNullK; [[SOGoCache sharedCache] setFailedCount: ([[failedCount objectForKey: @"FailedCount"] intValue] + 1) forLogin: username]; } - + checkOK = NO; } @@ -651,7 +680,7 @@ static Class NSNullK; { NSObject *currentSource; NSEnumerator *sources; - + sources = [[_sources allValues] objectEnumerator]; while ((currentSource = [sources nextObject])) if ([currentSource conformsToProtocol: @protocol(SOGoDNSource)] && @@ -671,9 +700,9 @@ static Class NSNullK; // - (BOOL) changePasswordForLogin: (NSString *) login inDomain: (NSString *) domain - oldPassword: (NSString *) oldPassword - newPassword: (NSString *) newPassword - perr: (SOGoPasswordPolicyError *) perr + oldPassword: (NSString *) oldPassword + newPassword: (NSString *) newPassword + perr: (SOGoPasswordPolicyError *) perr { NSString *jsonUser, *userLogin; NSMutableDictionary *currentUser; @@ -722,21 +751,19 @@ static Class NSNullK; SOGoDomainDefaults *dd; domain = [contact objectForKey: @"c_domain"]; - if ([domain length]) - dd = [SOGoDomainDefaults defaultsForDomain: domain]; - else - dd = [SOGoSystemDefaults sharedSystemDefaults]; + dd = [SOGoDomainDefaults defaultsForDomain: domain]; emails = [contact objectForKey: @"emails"]; - uid = [contact objectForKey: @"c_uid"]; - if ([uid rangeOfString: @"@"].location == NSNotFound) - systemEmail - = [NSString stringWithFormat: @"%@@%@", uid, [dd mailDomain]]; - else - systemEmail = uid; - - // We always add the system email, which will always be returned - // by SOGoUser -systemEmail. - [emails addObject: systemEmail]; + if ([emails count] == 0) + { + uid = [contact objectForKey: @"c_uid"]; + if ([uid rangeOfString: @"@"].location == NSNotFound) + systemEmail = [NSString stringWithFormat: @"%@@%@", uid, [dd mailDomain]]; + else + systemEmail = uid; + // We always add the system email, which will always be returned + // by SOGoUser -systemEmail. + [emails addObject: systemEmail]; + } [contact setObject: [emails objectAtIndex: 0] forKey: @"c_email"]; } @@ -791,7 +818,7 @@ static Class NSNullK; while (!userEntry && (sourceID = [sogoSources nextObject])) { currentSource = [_sources objectForKey: sourceID]; - + userEntry = [currentSource lookupContactEntryWithUIDorEmail: theUID inDomain: theDomain]; if (userEntry) @@ -906,7 +933,7 @@ static Class NSNullK; [user setObject: [NSNumber numberWithBool: YES] forKey: @"CalendarAccess"]; [user setObject: [NSNumber numberWithBool: NO] - forKey: @"MailAccess"]; + forKey: @"MailAccess"]; } return user; @@ -935,7 +962,7 @@ static Class NSNullK; // The domain is probably appended to the username; // make sure it is a defined domain in the configuration. domain = [uid substringFromIndex: (r.location + r.length)]; - if ([[sd domainIds] containsObject: domain]) + if ([self isDomainDefined: domain]) username = [uid substringToIndex: r.location]; else domain = nil; @@ -950,7 +977,7 @@ static Class NSNullK; // search using the original uid. infos = [self contactInfosForUserWithUIDorEmail: uid inDomain: nil]; - + return infos; } @@ -979,29 +1006,29 @@ static Class NSNullK; if ([currentUser isKindOfClass: NSNullK]) currentUser = nil; else if (!([currentUser objectForKey: @"emails"] - && [currentUser objectForKey: @"cn"])) - { - // We make sure that we either have no occurence of a cache entry or - // that we have an occurence with only a cached password. In the - // latter case, we update the entry with the remaining information - // and recache the value. - if (!currentUser || + && [currentUser objectForKey: @"cn"])) + { + // We make sure that we either have no occurence of a cache entry or + // that we have an occurence with only a cached password. In the + // latter case, we update the entry with the remaining information + // and recache the value. + if (!currentUser || ([currentUser count] == 1 && [currentUser objectForKey: @"password"]) || ([currentUser count] == 2 && [currentUser objectForKey: @"password"] && [currentUser objectForKey: @"DomainLessLogin"])) { - newUser = YES; + newUser = YES; - if (!currentUser) - currentUser = [NSMutableDictionary dictionary]; - } - else - newUser = NO; - [self _fillContactInfosForUser: currentUser + if (!currentUser) + currentUser = [NSMutableDictionary dictionary]; + } + else + newUser = NO; + [self _fillContactInfosForUser: currentUser withUIDorEmail: aUID inDomain: domain]; - if (newUser) - { - if ([[currentUser objectForKey: @"c_uid"] length] == 0) + if (newUser) + { + if ([[currentUser objectForKey: @"c_uid"] length] == 0) { [self _retainUser: (NSDictionary *) [NSNull null] withLogin: cacheUid]; @@ -1024,7 +1051,7 @@ static Class NSNullK; [self _retainUser: currentUser withLogin: cacheUid]; } } - } + } } else currentUser = nil; @@ -1050,7 +1077,7 @@ static Class NSNullK; while ((sourceID = [sources nextObject])) { currentSource = [_sources objectForKey: sourceID]; - contact = [currentSource lookupContactEntry: uid]; + contact = [currentSource lookupContactEntry: uid inDomain: domain]; if (contact) [contacts addObject: contact]; } @@ -1079,30 +1106,30 @@ static Class NSNullK; { uid = [userEntry objectForKey: @"c_uid"]; if ([uid length]) - { - returnContact = [compactContacts objectForKey: uid]; - if (!returnContact) - { - returnContact = [NSMutableDictionary dictionary]; - [returnContact setObject: uid forKey: @"c_uid"]; + { + returnContact = [compactContacts objectForKey: uid]; + if (!returnContact) + { + returnContact = [NSMutableDictionary dictionary]; + [returnContact setObject: uid forKey: @"c_uid"]; source = [userEntry objectForKey: @"source"]; if (source) [returnContact setObject: source forKey: @"source"]; [compactContacts setObject: returnContact forKey: uid]; } - if (![[returnContact objectForKey: @"c_name"] length]) - [returnContact setObject: [userEntry objectForKey: @"c_name"] - forKey: @"c_name"]; - if (![[returnContact objectForKey: @"cn"] length]) - [returnContact setObject: [userEntry objectForKey: @"c_cn"] - forKey: @"cn"]; - emails = [returnContact objectForKey: @"emails"]; - if (!emails) - { - emails = [NSMutableArray array]; - [returnContact setObject: emails forKey: @"emails"]; - } - email = [userEntry objectForKey: @"mail"]; + if (![[returnContact objectForKey: @"c_name"] length]) + [returnContact setObject: [userEntry objectForKey: @"c_name"] + forKey: @"c_name"]; + if (![[returnContact objectForKey: @"cn"] length]) + [returnContact setObject: [userEntry objectForKey: @"c_cn"] + forKey: @"cn"]; + emails = [returnContact objectForKey: @"emails"]; + if (!emails) + { + emails = [NSMutableArray array]; + [returnContact setObject: emails forKey: @"emails"]; + } + email = [userEntry objectForKey: @"mail"]; if ([email isKindOfClass: [NSArray class]]) { allEmails = (NSArray *) email; @@ -1114,22 +1141,22 @@ static Class NSNullK; } } else if (email && ![emails containsObject: email]) - [emails addObject: email]; - email = [userEntry objectForKey: @"mozillasecondemail"]; - if (email && ![emails containsObject: email]) - [emails addObject: email]; - email = [userEntry objectForKey: @"xmozillasecondemail"]; - if (email && ![emails containsObject: email]) - [emails addObject: email]; + [emails addObject: email]; + email = [userEntry objectForKey: @"mozillasecondemail"]; + if (email && ![emails containsObject: email]) + [emails addObject: email]; + email = [userEntry objectForKey: @"xmozillasecondemail"]; + if (email && ![emails containsObject: email]) + [emails addObject: email]; info = [userEntry objectForKey: @"c_info"]; if ([info length] > 0 && ![[returnContact objectForKey: @"c_info"] length]) [returnContact setObject: info forKey: @"c_info"]; - [self _fillContactMailRecords: returnContact]; + [self _fillContactMailRecords: returnContact]; isGroup = [userEntry objectForKey: @"isGroup"]; if (isGroup) [returnContact setObject: isGroup forKey: @"isGroup"]; - } + } } newContacts = [compactContacts allValues]; @@ -1138,7 +1165,7 @@ static Class NSNullK; } - (NSArray *) _fetchEntriesInSources: (NSArray *) sourcesList - matching: (NSString *) filter + matching: (NSString *) filter inDomain: (NSString *) domain { NSMutableArray *contacts; @@ -1152,7 +1179,7 @@ static Class NSNullK; { currentSource = [_sources objectForKey: sourceID]; [contacts addObjectsFromArray: - [currentSource fetchContactsMatching: filter + [currentSource fetchContactsMatching: filter inDomain: domain]]; } diff --git a/SoObjects/SOGo/SQLSource.m b/SoObjects/SOGo/SQLSource.m index 2e117f54d..307348f80 100644 --- a/SoObjects/SOGo/SQLSource.m +++ b/SoObjects/SOGo/SQLSource.m @@ -620,8 +620,9 @@ - (NSDictionary *) lookupContactEntry: (NSString *) theID + inDomain: (NSString *) domain { - return [self _lookupContactEntry: theID considerEmail: NO inDomain: nil]; + return [self _lookupContactEntry: theID considerEmail: NO inDomain: domain]; } - (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) entryID diff --git a/Tools/SOGoToolBackup.m b/Tools/SOGoToolBackup.m index fb2b4d016..3f2cb27bc 100644 --- a/Tools/SOGoToolBackup.m +++ b/Tools/SOGoToolBackup.m @@ -363,6 +363,7 @@ } - (BOOL) extractUserLDIFRecord: (NSString *) uid + inDomain: (NSString *) domain intoRecord: (NSMutableDictionary *) userRecord { NSEnumerator *ldapSources; @@ -375,11 +376,11 @@ lm = [SOGoUserManager sharedUserManager]; done = NO; - ldapSources = [[lm authenticationSourceIDsInDomain: nil] objectEnumerator]; + ldapSources = [[lm authenticationSourceIDsInDomain: domain] objectEnumerator]; while (!done && (sourceID = [ldapSources nextObject])) { currentSource = [lm sourceWithID: sourceID]; - userEntry = [currentSource lookupContactEntry: uid]; + userEntry = [currentSource lookupContactEntry: uid inDomain: domain]; if (userEntry) { [userRecord setObject: [userEntry ldifRecordAsString] @@ -411,25 +412,26 @@ - (BOOL) exportUser: (NSDictionary *) theUser { - NSString *exportPath, *gcsUID, *ldapUID; + NSString *exportPath, *gcsUID, *ldapUID, *domain; NSMutableDictionary *userRecord; SOGoSystemDefaults *sd; - + sd = [SOGoSystemDefaults sharedSystemDefaults]; userRecord = [NSMutableDictionary dictionary]; ldapUID = [theUser objectForKey: @"c_uid"]; exportPath = [directory stringByAppendingPathComponent: ldapUID]; - + domain = [theUser objectForKey: @"c_domain"]; 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: ldapUID + inDomain: domain intoRecord: userRecord] && [self extractUserPreferences: gcsUID intoRecord: userRecord]