From: znek Date: Wed, 20 Oct 2004 17:02:36 +0000 (+0000) Subject: complete LDAP support X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9a9aa61d80a0c13682588cacceb8807ef8a417f;p=scalable-opengroupware.org complete LDAP support git-svn-id: http://svn.opengroupware.org/SOGo/trunk@416 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SOGo.xcode/project.pbxproj b/SOGo/SOGo.xcode/project.pbxproj index a5a783e8..d7333037 100644 --- a/SOGo/SOGo.xcode/project.pbxproj +++ b/SOGo/SOGo.xcode/project.pbxproj @@ -570,7 +570,6 @@ AD071D1206CD2BCB00A9EEF4, AD071D1306CD2BCB00A9EEF4, ADA6333607140E0D0058C21C, - ADA6333707140E0D0058C21C, ); isa = PBXGroup; name = Classes; @@ -1448,15 +1447,6 @@ refType = 4; sourceTree = ""; }; - ADA6333707140E0D0058C21C = { - fileEncoding = 5; - indentWidth = 2; - isa = PBXFileReference; - lastKnownFileType = sourcecode.c.objc; - path = "NSString+iCal.m"; - refType = 4; - sourceTree = ""; - }; ADBE3C490726AF4C000FEA6A = { fileEncoding = 5; indentWidth = 2; diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index e9d301e3..954effab 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,8 @@ +2004-10-20 Marcus Mueller + + * SOGoMailAccounts.m: changed methods according to new API of + AgenorUserManager (v0.9.35) + 2004-10-19 Marcus Mueller * SOGoMailAccounts.m: values for toManyRelationshipKeys are constructed diff --git a/SOGo/SoObjects/Mailer/SOGoMailAccounts.m b/SOGo/SoObjects/Mailer/SOGoMailAccounts.m index 078269c1..27e9355d 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailAccounts.m +++ b/SOGo/SoObjects/Mailer/SOGoMailAccounts.m @@ -31,17 +31,14 @@ - (NSArray *)toManyRelationshipKeys { static AgenorUserManager *um = nil; - NSString *uid, *server, *account; + NSString *uid, *account; if(!um) um = [AgenorUserManager sharedUserManager]; uid = [[self container] davDisplayName]; - server = [um getIMAPServerForUID:uid]; - if(!server) + account = [um getIMAPAccountStringForUID:uid]; + if(!account) return nil; - account = [NSString stringWithFormat:@"%@@%@", - uid, - server]; return [NSArray arrayWithObject:account]; } diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 8d1e9bd6..79d695bd 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,3 +1,6 @@ # $Id$ -SUBMINOR_VERSION:=34 +SUBMINOR_VERSION:=35 + +# v0.9.35 requires SOGoLogic v0.9.24 +# v0.9.34 requires SOGoLogic v0.9.22 diff --git a/SOGoLogic/AgenorUserManager.h b/SOGoLogic/AgenorUserManager.h index 910ded38..3ca73558 100644 --- a/SOGoLogic/AgenorUserManager.h +++ b/SOGoLogic/AgenorUserManager.h @@ -30,7 +30,6 @@ @interface AgenorUserManager : NSObject { - } + (id)sharedUserManager; @@ -38,9 +37,12 @@ - (NSString *)getUIDForEmail:(NSString *)_email; - (NSString *)getEmailForUID:(NSString *)_uid; +/* i.e. BUTTO Hercule, CETE Lyon/DI/ET/TEST */ - (NSString *)getCNForUID:(NSString *)_uid; - -- (NSString *)getIMAPServerForUID:(NSString *)_uid; +/* i.e. hercule.butto@amelie-ida01.melanie2.i2 */ +- (NSString *)getIMAPAccountStringForUID:(NSString *)_uid; +/* i.e. amelie-ida01.melanie2.i2 */ +- (NSString *)getServerForUID:(NSString *)_uid; @end diff --git a/SOGoLogic/AgenorUserManager.m b/SOGoLogic/AgenorUserManager.m index 062aa262..15880827 100644 --- a/SOGoLogic/AgenorUserManager.m +++ b/SOGoLogic/AgenorUserManager.m @@ -27,6 +27,12 @@ @interface AgenorUserManager (PrivateAPI) - (NGLdapConnection *)ldapConnection; + +- (void)_cacheCN:(NSString *)_cn forUID:(NSString *)_uid; +- (NSString *)_cachedCNForUID:(NSString *)_uid; +- (void)_cacheServer:(NSString *)_server forUID:(NSString *)_uid; +- (NSString *)_cachedServerForUID:(NSString *)_uid; + @end @@ -83,6 +89,21 @@ static NSString *ldapBaseDN = nil; return ldapConnection; } +- (void)_cacheCN:(NSString *)_cn forUID:(NSString *)_uid { +} + +- (NSString *)_cachedCNForUID:(NSString *)_uid { + return nil; +} + +- (void)_cacheServer:(NSString *)_server forUID:(NSString *)_uid { +} + +- (NSString *)_cachedServerForUID:(NSString *)_uid { + return nil; +} + + - (NSString *)getUIDForEmail:(NSString *)_email { NSRange r; NSString *domain; @@ -91,7 +112,9 @@ static NSString *ldapBaseDN = nil; return nil; r = [_email rangeOfString:@"@"]; - domain = [_email substringFromIndex:r.location + 1]; + if(r.length == 0) + return nil; + domain = [_email substringFromIndex:NSMaxRange(r)]; if(![domain isEqualToString:@"equipement.gouv.fr"]) return _email; return [_email substringToIndex:r.location]; @@ -116,10 +139,15 @@ static NSString *ldapBaseDN = nil; NSEnumerator *resultEnum; NGLdapEntry *entry; NGLdapAttribute *cnAttr; + NSString *cn; if(!cnAttrs) { cnAttrs = [[NSArray alloc] initWithObjects:@"cn", nil]; } + + if((cn = [self _cachedCNForUID:_uid])) + return cn; + q = [EOQualifier qualifierWithQualifierFormat:@"uid = %@", _uid]; conn = [self ldapConnection]; @@ -129,15 +157,21 @@ static NSString *ldapBaseDN = nil; entry = [resultEnum nextObject]; if(!entry) { if(debugOn) { - NSLog(@"Didn't find LDAP entry for uid '%@'!", _uid); + NSLog(@"%s Didn't find LDAP entry for uid '%@'!", + __PRETTY_FUNCTION__, + _uid); } return nil; } cnAttr = [entry attributeWithName:@"cn"]; if(!cnAttr && debugOn) { - NSLog(@"LDAP entry for uid '%@' has no common name?", _uid); + NSLog(@"%s LDAP entry for uid '%@' has no common name?", + __PRETTY_FUNCTION__, + _uid); } - return [cnAttr stringValueAtIndex:0]; + cn = [cnAttr stringValueAtIndex:0]; + [self _cacheCN:cn forUID:_uid]; + return cn; } else { NSString *s; @@ -156,7 +190,16 @@ static NSString *ldapBaseDN = nil; } } -- (NSString *)getIMAPServerForUID:(NSString *)_uid { +- (NSString *)getIMAPAccountStringForUID:(NSString *)_uid { + NSString *server; + + server = [self getServerForUID:_uid]; + if(!server) + return nil; + return [NSString stringWithFormat:@"%@@%@", _uid, server]; +} + +- (NSString *)getServerForUID:(NSString *)_uid { /* First of all : for a particular user IMAP and SMTP are served on the same host. @@ -178,7 +221,113 @@ static NSString *ldapBaseDN = nil; values, then the IMAP/SMTP server name is to be found in the mineqMelServeurPrincipal attribute of the user. */ - return @"mail.opengroupware.org"; + if(useLDAP) { + static NSArray *attrs = nil; + NGLdapConnection *conn; + EOQualifier *q; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + NGLdapAttribute *attr; + NSMutableArray *serverCandidates; + NSString *server; + + if(!attrs) { + attrs = [[NSArray alloc] initWithObjects:@"mineqMelRoutage", + @"mineqMelServeurPrincipal", + nil]; + } + + if((server = [self _cachedServerForUID:_uid])) + return server; + + q = [EOQualifier qualifierWithQualifierFormat:@"uid = %@", _uid]; + + conn = [self ldapConnection]; + resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN + qualifier:q + attributes:attrs]; + /* we just expect one entry, thus drop the rest */ + entry = [resultEnum nextObject]; + if(!entry) { + if(debugOn) { + NSLog(@"%s Didn't find LDAP entry for uid '%@'!", + __PRETTY_FUNCTION__, + _uid); + } + return nil; + } + attr = [entry attributeWithName:@"mineqMelRoutage"]; + if(attr) { + unsigned i, count; + + count = [attr count]; + serverCandidates = [NSMutableArray arrayWithCapacity:count]; + for(i = 0; i < count; i++) { + NSRange r; + NSString *route; + + route = [attr stringValueAtIndex:i]; + r = [route rangeOfString:@".melanie2.i2" options:NSBackwardsSearch]; + if(r.length > 0) { + unsigned length; + + /* be clever */ + length = [route length]; + r = NSMakeRange(0, length - r.length); + r = [route rangeOfString:@"@" options:NSBackwardsSearch range:r]; + if(r.length > 0) { + unsigned start; + NSRange serverNameRange; + + start = NSMaxRange(r); + serverNameRange = NSMakeRange(start, length - start); + r = NSMakeRange(0, length - start); + r = [route rangeOfString:@"%" options:NSBackwardsSearch range:r]; + if(r.length > 0) { + NSString *serverName; + + serverName = [route substringWithRange:serverNameRange]; + [serverCandidates addObject:serverName]; + } + } + } + } + } + else { + if(debugOn) { + NSLog(@"%s LDAP entry for uid '%@' has no mineqMelRoutage entry?", + __PRETTY_FUNCTION__, + _uid); + } + serverCandidates = nil; + } + if([serverCandidates count] == 1) { + server = [serverCandidates objectAtIndex:0]; + } + + /* last resort */ + if(!server) { + attr = [entry attributeWithName:@"mineqMelServeurPrincipal"]; + if([attr count] > 0) + server = [attr stringValueAtIndex:0]; + } + + if(!server) { + if(debugOn) { + NSLog(@"%s no chance of getting at server info for user '%@', " + @"tried everything. Sorry.", + __PRETTY_FUNCTION__, + _uid); + } + return nil; + } + + [self _cacheServer:server forUID:_uid]; + return server; + } + else { + return @"mail.opengroupware.org"; + } } @end diff --git a/SOGoLogic/ChangeLog b/SOGoLogic/ChangeLog index b34384bd..78bb6dd8 100644 --- a/SOGoLogic/ChangeLog +++ b/SOGoLogic/ChangeLog @@ -1,3 +1,9 @@ +2004-10-20 Marcus Mueller + + * AgenorUserManager.[hm]: slightly changed the interface for retrieving + the IMAP server, implemented all necessary LDAP functionality + (v0.9.24) + 2004-10-20 Helge Hess * moved NSString+iCal methods to NGiCal (v0.9.23) diff --git a/SOGoLogic/Version b/SOGoLogic/Version index b2808140..bd948570 100644 --- a/SOGoLogic/Version +++ b/SOGoLogic/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=23 +SUBMINOR_VERSION:=24 # v0.9.23 requires NGiCal v4.3.32 # v0.9.18 requires NGExtensions v4.3.123