From 2dedb7d3090b5c6a06548b22475cb44b76f9875d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 3 May 2007 18:46:45 +0000 Subject: [PATCH] Monotone-Parent: 1aa812c42c241f2c5d21c2beac51ba74f407f6bb Monotone-Revision: 825591a847de774d1464963d3c32fe5a6bd19140 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-05-03T18:46:45 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 4 + SoObjects/SOGo/AgenorUserManager.h | 35 +- SoObjects/SOGo/AgenorUserManager.m | 1242 ++++++++++++++-------------- 3 files changed, 661 insertions(+), 620 deletions(-) diff --git a/ChangeLog b/ChangeLog index 522476ad3..7bb0af74d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2007-05-03 Wolfgang Sourdeau + * SoObjects/SOGo/AgenorUserManager.m ([AgenorUserManager + -getSystemEMailForUID:uid]): new method that returns the email + formed with the user's uid and the default mail domain. + * SoObjects/Appointments/SOGoCalendarComponent.m ([SOGoCalendarComponent -rolesOfUser:login]): removed method that was previously commented out. diff --git a/SoObjects/SOGo/AgenorUserManager.h b/SoObjects/SOGo/AgenorUserManager.h index 2ad609093..12c4fd276 100644 --- a/SoObjects/SOGo/AgenorUserManager.h +++ b/SoObjects/SOGo/AgenorUserManager.h @@ -48,40 +48,41 @@ NSTimer *gcTimer; } -+ (id)sharedUserManager; ++ (id) sharedUserManager; -- (NSString *)getUIDForEmail:(NSString *)_email; -- (NSString *)getEmailForUID:(NSString *)_uid; +- (NSString *) getUIDForEmail: (NSString *) email; +- (NSString *) getEmailForUID: (NSString *) uid; +- (NSString *) getSystemEMailForUID: (NSString *) uid; - (iCalPerson *) iCalPersonWithUid: (NSString *) uid; -- (NSString *) getUIDForICalPerson: (iCalPerson *) _person; -/* may insert NSNulls into returned array if _mapStrictly -> YES */ -- (NSArray *)getUIDsForICalPersons:(NSArray *)_persons - applyStrictMapping:(BOOL)_mapStrictly; +- (NSString *) getUIDForICalPerson: (iCalPerson *) person; +/* may insert NSNulls into returned array if mapStrictly -> YES */ +- (NSArray *) getUIDsForICalPersons: (NSArray *) persons + applyStrictMapping: (BOOL) mapStrictly; /* i.e. BUTTO Hercule, CETE Lyon/DI/ET/TEST */ -- (NSString *)getCNForUID:(NSString *)_uid; +- (NSString *) getCNForUID: (NSString *) uid; /* i.e. hercule.butto@amelie-ida01.melanie2.i2 */ -- (NSString *)getIMAPAccountStringForUID:(NSString *)_uid; +- (NSString *) getIMAPAccountStringForUID: (NSString *) uid; /* i.e. amelie-ida01.melanie2.i2 */ -- (NSString *)getServerForUID:(NSString *)_uid; +- (NSString *) getServerForUID: (NSString *) uid; -- (NSArray *)getSharedMailboxAccountStringsForUID:(NSString *)_uid; -- (NSArray *)getSharedMailboxEMailsForUID:(NSString *)_uid; -- (NSDictionary *)getSharedMailboxesAndEMailsForUID:(NSString *)_uid; +- (NSArray *) getSharedMailboxAccountStringsForUID: (NSString *) uid; +- (NSArray *) getSharedMailboxEMailsForUID: (NSString *) uid; +- (NSDictionary *) getSharedMailboxesAndEMailsForUID: (NSString *) uid; -- (NSURL *)getFreeBusyURLForUID:(NSString *)_uid; +- (NSURL *) getFreeBusyURLForUID: (NSString *) uid; - (NSUserDefaults *) getUserDefaultsForUID: (NSString *) uid; - (NSUserDefaults *) getUserSettingsForUID: (NSString *) uid; -- (BOOL)isUserAllowedToChangeSOGoInternetAccess:(NSString *)_uid; +- (BOOL) isUserAllowedToChangeSOGoInternetAccess: (NSString *) uid; -- (BOOL)isInternetAutoresponderEnabledForUser:(NSString *)_uid; -- (BOOL)isIntranetAutoresponderEnabledForUser:(NSString *)_uid; +- (BOOL) isInternetAutoresponderEnabledForUser: (NSString *) uid; +- (BOOL) isIntranetAutoresponderEnabledForUser: (NSString *) uid; @end diff --git a/SoObjects/SOGo/AgenorUserManager.m b/SoObjects/SOGo/AgenorUserManager.m index 6b10fa3f9..dc2df4920 100644 --- a/SoObjects/SOGo/AgenorUserManager.m +++ b/SoObjects/SOGo/AgenorUserManager.m @@ -10,11 +10,11 @@ OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with OGo; see the file COPYING. If not, write to the + License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -30,35 +30,35 @@ #define qualifierFormat @"uid = %@" @interface AgenorUserManager (PrivateAPI) -- (NGLdapConnection *)ldapConnection; +- (NGLdapConnection *) ldapConnection; -- (void)_cacheCN:(NSString *)_cn forUID:(NSString *)_uid; -- (NSString *)_cachedCNForUID:(NSString *)_uid; -- (void)_cacheServer:(NSString *)_server forUID:(NSString *)_uid; -- (NSString *)_cachedServerForUID:(NSString *)_uid; -- (void)_cacheEmail:(NSString *)_email forUID:(NSString *)_uid; -- (NSString *)_cachedEmailForUID:(NSString *)_uid; -- (void)_cacheUID:(NSString *)_uid forEmail:(NSString *)_email; -- (NSString *)_cachedUIDForEmail:(NSString *)_email; +- (void) _cacheCN: (NSString *) cn forUID: (NSString *) uid; +- (NSString *) _cachedCNForUID: (NSString *) uid; +- (void) _cacheServer: (NSString *) server forUID: (NSString *) uid; +- (NSString *) _cachedServerForUID: (NSString *) uid; +- (void) _cacheEmail: (NSString *) email forUID: (NSString *) uid; +- (NSString *) _cachedEmailForUID: (NSString *) uid; +- (void) _cacheUID: (NSString *) uid forEmail: (NSString *) email; +- (NSString *) _cachedUIDForEmail: (NSString *) email; -- (BOOL)primaryIsUserAllowedToChangeSOGoInternetAccess:(NSString *)_uid; +- (BOOL) primaryIsUserAllowedToChangeSOGoInternetAccess: (NSString *) uid; -- (BOOL)primaryIsInternetAutoresponderEnabledForUser:(NSString *)_uid; -- (BOOL)primaryIsIntranetAutoresponderEnabledForUser:(NSString *)_uid; -- (NGLdapAttribute *)primaryGetMailAutoresponderAttribute:(NSString *)_uid; -- (BOOL)isAutoresponderEnabledForAttribute:(NGLdapAttribute *)_attr - matchingPrefix:(NSString *)_prefix; +- (BOOL) primaryIsInternetAutoresponderEnabledForUser: (NSString *) uid; +- (BOOL) primaryIsIntranetAutoresponderEnabledForUser: (NSString *) uid; +- (NGLdapAttribute *) primaryGetMailAutoresponderAttribute: (NSString *) uid; +- (BOOL) isAutoresponderEnabledForAttribute: (NGLdapAttribute *) attr + matchingPrefix: (NSString *) prefix; @end // TODO: add a timer to flush LRU caches every some hours @implementation AgenorUserManager -static BOOL debugOn = NO; -static BOOL useLDAP = NO; +static BOOL debugOn = NO; +static BOOL useLDAP = NO; static NSString *ldapHost = nil; static NSString *ldapBaseDN = nil; -static NSNull *sharedNull = nil; +static NSNull *sharedNull = nil; static NSString *fallbackIMAP4Server = nil; static NSString *defaultMailDomain = nil; static NSString *shareLDAPClass = @"mineqMelBoite"; @@ -66,7 +66,7 @@ static NSString *shareLoginSeparator = @".-."; static NSString *mailEmissionAttrName = @"mineqMelmailEmission"; static NSString *changeInternetAccessAttrName = @"mineqOgoAccesInternet"; static NSString *mailAutoresponderAttrName = @"mineqMelReponse"; /* sic! */ -static NSURL *AgenorProfileURL = nil; +static NSURL *AgenorProfileURL = nil; static NSArray *fromEMailAttrs = nil; @@ -80,112 +80,114 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; if (didInit) return; didInit = YES; - + ud = [NSUserDefaults standardUserDefaults]; - debugOn = [ud boolForKey:@"SOGoUserManagerDebugEnabled"]; - - useLDAP = [ud boolForKey:@"SOGoUserManagerUsesLDAP"]; + debugOn = [ud boolForKey: @"SOGoUserManagerDebugEnabled"]; + + useLDAP = [ud boolForKey: @"SOGoUserManagerUsesLDAP"]; if (useLDAP) { - ldapHost = [[ud stringForKey:@"LDAPHost"] copy]; - ldapBaseDN = [[ud stringForKey:@"LDAPRootDN"] copy]; - NSLog(@"Note: using LDAP host to manage accounts: %@", ldapHost); + ldapHost = [[ud stringForKey: @"LDAPHost"] copy]; + ldapBaseDN = [[ud stringForKey: @"LDAPRootDN"] copy]; + NSLog(@"Note: using LDAP host to manage accounts: %@", ldapHost) ; } else - NSLog(@"Note: LDAP access is disabled."); - - fallbackIMAP4Server = [[ud stringForKey:@"SOGoFallbackIMAP4Server"] copy]; - if ([fallbackIMAP4Server length] > 0) - NSLog(@"Note: using fallback IMAP4 server: '%@'", fallbackIMAP4Server); + NSLog(@"Note: LDAP access is disabled.") ; + + fallbackIMAP4Server = [[ud stringForKey: @"SOGoFallbackIMAP4Server"] copy]; + if ([fallbackIMAP4Server length] > 0) + NSLog(@"Note: using fallback IMAP4 server: '%@'", fallbackIMAP4Server) ; else { - if (fallbackIMAP4Server) - [fallbackIMAP4Server release]; + if (fallbackIMAP4Server) + [fallbackIMAP4Server release]; fallbackIMAP4Server = nil; } - defaultMailDomain = [[ud stringForKey:@"SOGoDefaultMailDomain"] copy]; - if ([defaultMailDomain length] == 0) + defaultMailDomain = [[ud stringForKey: @"SOGoDefaultMailDomain"] copy]; + if ([defaultMailDomain length] == 0) { - if (defaultMailDomain) - [defaultMailDomain release]; + if (defaultMailDomain) + [defaultMailDomain release]; defaultMailDomain = nil; NSLog(@"WARNING: no default mail domain (please specify" - " 'SOGoDefaultMailDomain' in the user default db)"); + " 'SOGoDefaultMailDomain' in the user default db)"); } fromEMailAttrs = - [[NSArray alloc] initWithObjects:mailEmissionAttrName, nil]; + [[NSArray alloc] initWithObjects: mailEmissionAttrName, nil]; sharedNull = [[NSNull null] retain]; /* profile database URL */ - - if ((tmp = [ud stringForKey:@"AgenorProfileURL"]) == nil) - NSLog(@"ERROR: no 'AgenorProfileURL' database URL configured!"); - else if ((AgenorProfileURL = [[NSURL alloc] initWithString:tmp]) == nil) - NSLog(@"ERROR: could not parse AgenorProfileURL: '%@'", tmp); + + if ((tmp = [ud stringForKey: @"AgenorProfileURL"]) == nil) + NSLog(@"ERROR: no 'AgenorProfileURL' database URL configured!") ; + else if ((AgenorProfileURL = [[NSURL alloc] initWithString: tmp]) == nil) + NSLog(@"ERROR: could not parse AgenorProfileURL: '%@'", tmp) ; else - NSLog(@"Note: using profile at: %@", [AgenorProfileURL absoluteString]); + NSLog(@"Note: using profile at: %@", [AgenorProfileURL absoluteString]) ; - if ((tmp = [ud stringForKey: @"SOGoDefaultMailDomain"])) + if ((tmp = [ud stringForKey: @"SOGoDefaultMailDomain"])) { defaultMailDomain = [tmp copy]; } - - PoolScanInterval = [[ud objectForKey:@"AgenorCacheCheckInterval"] intValue]; + + PoolScanInterval = [[ud objectForKey: @"AgenorCacheCheckInterval"] intValue]; if (PoolScanInterval == 0) PoolScanInterval = 60 * 60 /* every hour */; NSLog(@"AgenorUserManager: flushing caches every %d minutes " - @"(AgenorCacheCheckInterval)", + @"(AgenorCacheCheckInterval) ", PoolScanInterval / 60); } -+ (id)sharedUserManager { ++ (id) sharedUserManager { static AgenorUserManager *mgr = nil; - if (mgr == nil) + if (mgr == nil) mgr = [[self alloc] init]; return mgr; } -- (id)init { +- (id) init +{ self = [super init]; if(self) { serverCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; cnCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; uidCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; emailCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; shareStoreCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; shareEMailCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; changeInternetAccessCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; internetAutoresponderFlagCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; intranetAutoresponderFlagCache = - [[NSMutableDictionary alloc] initWithCapacity:10000]; - - gcTimer = [[NSTimer scheduledTimerWithTimeInterval: - PoolScanInterval - target:self selector:@selector(_garbageCollect:) - userInfo:nil repeats:YES] retain]; + [[NSMutableDictionary alloc] initWithCapacity: 10000]; + + gcTimer = [[NSTimer scheduledTimerWithTimeInterval: + PoolScanInterval + target: self selector: @selector(_garbageCollect: ) + userInfo: nil repeats: YES] retain]; } return self; } -- (void)dealloc { +- (void) dealloc +{ if (gcTimer) [gcTimer invalidate]; - [serverCache release]; - [cnCache release]; - [uidCache release]; - [emailCache release]; + [serverCache release]; + [cnCache release]; + [uidCache release]; + [emailCache release]; [shareStoreCache release]; [shareEMailCache release]; - [changeInternetAccessCache release]; + [changeInternetAccessCache release]; [internetAutoresponderFlagCache release]; [intranetAutoresponderFlagCache release]; [gcTimer release]; @@ -194,32 +196,35 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; /* cache */ -- (void)flush { - [cnCache removeAllObjects]; - [serverCache removeAllObjects]; - [uidCache removeAllObjects]; - [emailCache removeAllObjects]; +- (void) flush +{ + [cnCache removeAllObjects]; + [serverCache removeAllObjects]; + [uidCache removeAllObjects]; + [emailCache removeAllObjects]; [shareStoreCache removeAllObjects]; [shareEMailCache removeAllObjects]; - - [changeInternetAccessCache removeAllObjects]; + + [changeInternetAccessCache removeAllObjects]; [internetAutoresponderFlagCache removeAllObjects]; [intranetAutoresponderFlagCache removeAllObjects]; } -- (void)_garbageCollect:(NSTimer *)_timer { - [self debugWithFormat:@"flushing caches."]; +- (void) _garbageCollect: (NSTimer *) timer +{ + [self debugWithFormat: @"flushing caches."]; [self flush]; } /* LDAP */ -- (NGLdapConnection *)ldapConnection { +- (NGLdapConnection *) ldapConnection +{ static NGLdapConnection *ldapConnection = nil; if(!ldapConnection) { ldapConnection = [[NGLdapConnection alloc] initWithHostName: ldapHost]; #if 0 - [ldapConnection setUseCache:YES]; + [ldapConnection setUseCache: YES]; #endif } return ldapConnection; @@ -229,784 +234,812 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; /* private cache helpers */ // TODO: this is really unnecessary, no? -- (void)_cacheCN:(NSString *)_cn forUID:(NSString *)_uid { - if (_cn == nil) return; - [cnCache setObject:_cn forKey:_uid]; -} -- (NSString *)_cachedCNForUID:(NSString *)_uid { - return [cnCache objectForKey:_uid]; +- (void) _cacheCN: (NSString *) cn forUID: (NSString *) uid +{ + if (cn == nil) return; + [cnCache setObject: cn forKey: uid]; } -- (void)_cacheServer:(NSString *)_server forUID:(NSString *)_uid { - if (_server == nil) return; - [serverCache setObject:_server forKey:_uid]; -} -- (NSString *)_cachedServerForUID:(NSString *)_uid { - return [serverCache objectForKey:_uid]; +- (NSString *) _cachedCNForUID: (NSString *) uid +{ + return [cnCache objectForKey: uid]; } -- (void)_cacheEmail:(NSString *)_email forUID:(NSString *)_uid { - if (_email == nil) return; - [emailCache setObject:_email forKey:_uid]; +- (void) _cacheServer: (NSString *) server forUID: (NSString *) uid +{ + if (server == nil) return; + [serverCache setObject: server forKey: uid]; } -- (NSString *)_cachedEmailForUID:(NSString *)_uid { - return [emailCache objectForKey:_uid]; +- (NSString *) _cachedServerForUID: (NSString *) uid +{ + return [serverCache objectForKey: uid]; } -- (void)_cacheUID:(NSString *)_uid forEmail:(NSString *)_email { - if (_uid == nil) return; - [uidCache setObject:_uid forKey:_email]; +- (void) _cacheEmail: (NSString *) email forUID: (NSString *) uid +{ + if (email == nil) return; + [emailCache setObject: email forKey: uid]; } -- (NSString *)_cachedUIDForEmail:(NSString *)_email { - return [uidCache objectForKey:_email]; +- (NSString *) _cachedEmailForUID: (NSString *) uid +{ + return [emailCache objectForKey: uid]; +} + +- (void) _cacheUID: (NSString *) uid forEmail: (NSString *) email +{ + if (uid == nil) return; + [uidCache setObject: uid forKey: email]; +} +- (NSString *) _cachedUIDForEmail: (NSString *) email +{ + return [uidCache objectForKey: email]; } /* uid <-> email mapping */ /* - UPDATE: the email excerpt below has been marked by Maxime as being - wrong. This algorithm can not be expected to work, thus - the mapping has been replaced with an LDAP query. + UPDATE: the email excerpt below has been marked by Maxime as being + wrong. This algorithm can not be expected to work, thus + the mapping has been replaced with an LDAP query. - --- snip --- - The uid field is in bijection this the email adress : - this field can be construct from the email. Email are uniques. + --- snip --- + The uid field is in bijection this the email adress : + this field can be construct from the email. Email are uniques. - So, we can use email adresse from identifier. - The field is made like this : - _ if the email is equipement.gouv.fr then the login - is the part before the @ - for example : fisrtName.lastName - _ if the email is not equipement.gouv.fr then the login - is the full email adress where @ is change to . (dot) - for example : fisrtName.lastName.subDomain.domain.tld - --- snap --- + So, we can use email adresse from identifier. + The field is made like this : + _ if the email is equipement.gouv.fr then the login + is the part before the @ + for example : fisrtName.lastName + _ if the email is not equipement.gouv.fr then the login + is the full email adress where @ is change to . (dot) + for example : fisrtName.lastName.subDomain.domain.tld + --- snap --- - NOTE: mapping email -> uid is easy, but can also generate uid's not known - to the system (i.e. for private addressbook entries, obvious). - The reverse mapping can work _only_ if "firstName.lastname." is - guaranteed, because the second dot would be mapped to '@'. This - is probably error prone. - Only LDAP fetches would guarantee correctness in both cases. + NOTE: mapping email -> uid is easy, but can also generate uid's not known + to the system (i.e. for private addressbook entries, obvious) . + The reverse mapping can work _only_ if "firstName.lastname." is + guaranteed, because the second dot would be mapped to '@'. This + is probably error prone. + Only LDAP fetches would guarantee correctness in both cases. */ -- (NSString *)primaryGetAgenorUIDForEmail:(NSString *)_email { - static NSArray *uidAttrs = nil; +- (NSString *) primaryGetAgenorUIDForEmail: (NSString *) email +{ + static NSArray *uidAttrs = nil; NGLdapConnection *conn; - EOQualifier *q; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - NGLdapAttribute *uidAttr; - NSString *uid; + EOQualifier *q; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + NGLdapAttribute *uidAttr; + NSString *uid; - if (uidAttrs == nil) - uidAttrs = [[NSArray alloc] initWithObjects:@"uid", nil]; - - q = [EOQualifier qualifierWithQualifierFormat:@"mail = %@", _email]; - + if (uidAttrs == nil) + uidAttrs = [[NSArray alloc] initWithObjects: @"uid", nil]; + + q = [EOQualifier qualifierWithQualifierFormat: @"mail = %@", email]; + conn = [self ldapConnection]; - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:uidAttrs]; + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: uidAttrs]; entry = [resultEnum nextObject]; if (entry == nil) { if(debugOn) { - [self logWithFormat:@"%s Didn't find LDAP entry for email '%@'!", + [self logWithFormat: @"%s Didn't find LDAP entry for email '%@'!", __PRETTY_FUNCTION__, - _email]; + email]; } return nil; } - uidAttr = [entry attributeWithName:@"uid"]; - if (!uidAttr) + uidAttr = [entry attributeWithName: @"uid"]; + if (!uidAttr) return nil; /* can happen, not unlikely */ - uid = [uidAttr stringValueAtIndex:0]; + uid = [uidAttr stringValueAtIndex: 0]; return uid; } -- (NSString *) getUIDForEmail: (NSString *)_email +- (NSString *) getUIDForEmail: (NSString *) email { NSString *uid; NSRange r; NSString *domain; uid = nil; - if ([_email length] > 0) + if ([email length] > 0) { - uid = [self _cachedUIDForEmail:_email]; - if (!uid) + uid = [self _cachedUIDForEmail: email]; + if (!uid) { - if (useLDAP) - uid = [self primaryGetAgenorUIDForEmail:_email]; + if (useLDAP) + uid = [self primaryGetAgenorUIDForEmail: email]; - if (!uid) - { - r = [_email rangeOfString:@"@"]; - if (r.length == 0) + if (!uid) + { + r = [email rangeOfString: @"@"]; + if (r.length == 0) return nil; - - domain = [_email substringFromIndex:NSMaxRange(r)]; - if (![domain isEqualToString:defaultMailDomain]) - uid = _email; + + domain = [email substringFromIndex: NSMaxRange(r) ]; + if (![domain isEqualToString: defaultMailDomain]) + uid = email; else - uid = [_email substringToIndex:r.location]; + uid = [email substringToIndex: r.location]; } - if (uid) - [self _cacheUID:uid forEmail:_email]; + if (uid) + [self _cacheUID: uid forEmail: email]; } } - + return uid; } #warning big ugly hack. LDAP lookup should be fixed -- (NSString *) getUIDForICalPerson: (iCalPerson *) _person +- (NSString *) getUIDForICalPerson: (iCalPerson *) person { NSString *domainString, *email, *uid; domainString = [NSString stringWithFormat: @"@%@", defaultMailDomain]; - email = [_person rfc822Email]; - if ([email hasSuffix: domainString]) - uid = [_person cn]; + email = [person rfc822Email]; + if ([email hasSuffix: domainString]) + uid = [person cn]; else uid = [self getUIDForEmail: email]; return uid; } - /* may insert NSNulls into returned array */ -- (NSArray *)getUIDsForICalPersons:(NSArray *)_persons - applyStrictMapping:(BOOL)_mapStrictly +/* may insert NSNulls into returned array */ +- (NSArray *) getUIDsForICalPersons: (NSArray *) persons + applyStrictMapping: (BOOL) mapStrictly { NSMutableArray *ma; - unsigned i, count; + unsigned i, count; - count = [_persons count]; - ma = [[[NSMutableArray alloc] initWithCapacity:count] autorelease]; + count = [persons count]; + ma = [[[NSMutableArray alloc] initWithCapacity: count] autorelease]; for (i = 0; i < count; i++) { iCalPerson *p; - id uid; - - p = [_persons objectAtIndex:i]; - uid = [self getUIDForICalPerson:p]; - if (uid != nil) - [ma addObject:uid]; - else if (uid == nil && _mapStrictly) - [ma addObject:sharedNull]; + id uid; + + p = [persons objectAtIndex: i]; + uid = [self getUIDForICalPerson: p]; + if (uid != nil) + [ma addObject: uid]; + else if (uid == nil && mapStrictly) + [ma addObject: sharedNull]; } return ma; } -- (NSString *)primaryGetEmailForAgenorUID:(NSString *)_uid { +- (NSString *) primaryGetEmailForAgenorUID: (NSString *) uid +{ NGLdapConnection *conn; - EOQualifier *q; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - NGLdapAttribute *emailAttr; - NSString *email; - unsigned count; - - q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, _uid]; - + EOQualifier *q; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + NGLdapAttribute *emailAttr; + NSString *email; + unsigned count; + + q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, uid]; + conn = [self ldapConnection]; - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:fromEMailAttrs]; + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: fromEMailAttrs]; entry = [resultEnum nextObject]; if (entry == nil) { - if(debugOn) { - [self logWithFormat:@"%s Didn't find LDAP entry for uid '%@'!", - __PRETTY_FUNCTION__, - _uid]; - } - return nil; + if(debugOn) { + [self logWithFormat: @"%s Didn't find LDAP entry for uid '%@'!", + __PRETTY_FUNCTION__, + uid]; + } + return nil; } - emailAttr = [entry attributeWithName:mailEmissionAttrName]; - if (emailAttr == nil) + emailAttr = [entry attributeWithName: mailEmissionAttrName]; + if (emailAttr == nil) return nil; /* shit happens */ - + email = nil; count = [emailAttr count]; #if 0 // TODO: explain why this is commented out! if (count > 1) { - unsigned i; + unsigned i; - /* in case there are multiple email addresses, select the first - which doesn't have '@equipement.gouv.fr' in it */ - for (i = 0; i < count; i++) { - NSString *candidate; - - candidate = [emailAttr stringValueAtIndex:i]; - if (![candidate hasSuffix:defaultMailDomain]) { - // TODO: also check for '@' - email = candidate; - break; - } - } + /* in case there are multiple email addresses, select the first + which doesn't have '@equipement.gouv.fr' in it */ + for (i = 0; i < count; i++) { + NSString *candidate; + + candidate = [emailAttr stringValueAtIndex: i]; + if (![candidate hasSuffix: defaultMailDomain]) { + // TODO: also check for '@' + email = candidate; + break; + } + } } #endif - if (email == nil && count > 0) - email = [emailAttr stringValueAtIndex:0]; - + if (email == nil && count > 0) + email = [emailAttr stringValueAtIndex: 0]; + return email; } -- (NSString *)getEmailForUID:(NSString *)_uid +- (NSString *) getEmailForUID: (NSString *) uid { NSString *email; NSRange r; - + email = nil; - if ([_uid length] > 0) + if ([uid length] > 0) { - email = [self _cachedEmailForUID: _uid]; - if (!email) + email = [self _cachedEmailForUID: uid]; + if (!email) { - if (useLDAP) - email = [self primaryGetEmailForAgenorUID:_uid]; + if (useLDAP) + email = [self primaryGetEmailForAgenorUID: uid]; - if (!email) + if (!email) { - r = [_uid rangeOfString:@"@"]; - email = ((r.length > 0) - ? _uid - : [[_uid stringByAppendingString:@"@"] - stringByAppendingString: defaultMailDomain]); + r = [uid rangeOfString: @"@"]; + email = ((r.length > 0) + ? uid + : [self getSystemEMailForUID: uid]); } - if (email) - [self _cacheEmail: email forUID: _uid]; + if (email) + [self _cacheEmail: email forUID: uid]; } } return email; } +- (NSString *) getSystemEMailForUID: (NSString *) uid +{ + return [NSString stringWithFormat: @"%@@%@", uid, defaultMailDomain]; +} /* CN */ -- (NSString *)primaryGetCNForAgenorUID:(NSString *)_uid { - static NSArray *cnAttrs = nil; +- (NSString *) primaryGetCNForAgenorUID: (NSString *) uid +{ + static NSArray *cnAttrs = nil; NGLdapConnection *conn; - EOQualifier *q; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - NGLdapAttribute *cnAttr; - NSString *cn; + EOQualifier *q; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + NGLdapAttribute *cnAttr; + NSString *cn; - if (cnAttrs == nil) - cnAttrs = [[NSArray alloc] initWithObjects:@"cn", nil]; - - q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, _uid]; - + if (cnAttrs == nil) + cnAttrs = [[NSArray alloc] initWithObjects: @"cn", nil]; + + q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, uid]; + conn = [self ldapConnection]; - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:cnAttrs]; + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: cnAttrs]; entry = [resultEnum nextObject]; if (entry == nil) { - if(debugOn) { - [self logWithFormat:@"%s Didn't find LDAP entry for uid '%@'!", - __PRETTY_FUNCTION__, - _uid]; - } - return nil; + if(debugOn) { + [self logWithFormat: @"%s Didn't find LDAP entry for uid '%@'!", + __PRETTY_FUNCTION__, + uid]; + } + return nil; } - cnAttr = [entry attributeWithName:@"cn"]; + cnAttr = [entry attributeWithName: @"cn"]; if(cnAttr == nil && debugOn) { - [self logWithFormat:@"%s LDAP entry for uid '%@' has no common name?", - __PRETTY_FUNCTION__, - _uid]; - return nil; /* nothing we can do about it */ + [self logWithFormat: @"%s LDAP entry for uid '%@' has no common name?", + __PRETTY_FUNCTION__, + uid]; + return nil; /* nothing we can do about it */ } - cn = [cnAttr stringValueAtIndex:0]; + cn = [cnAttr stringValueAtIndex: 0]; return cn; } -- (NSString *)getCNForUID:(NSString *)_uid { +- (NSString *) getCNForUID: (NSString *) uid +{ NSString *cn; - if ((cn = [self _cachedCNForUID:_uid]) != nil) + if ((cn = [self _cachedCNForUID: uid]) != nil) return cn; - + if (useLDAP) { - cn = [self primaryGetCNForAgenorUID:_uid]; + cn = [self primaryGetCNForAgenorUID: uid]; } else { NSString *s; - NSRange r; - - s = _uid; - if ([s length] < 10) + NSRange r; + + s = uid; + if ([s length] < 10) return s; - + // TODO: algorithm might be inappropriate, depends on the actual UID - r = [s rangeOfString:@"."]; - if (r.length == 0) + r = [s rangeOfString: @"."]; + if (r.length == 0) cn = s; else - cn = [s substringToIndex:r.location]; + cn = [s substringToIndex: r.location]; } - - [self _cacheCN:cn forUID:_uid]; + + [self _cacheCN: cn forUID: uid]; return cn; } /* Servers, IMAP */ -- (NSString *)getIMAPAccountStringForUID:(NSString *)_uid { +- (NSString *) getIMAPAccountStringForUID: (NSString *) uid +{ NSString *server; - - server = [self getServerForUID:_uid]; - if (server == nil) + + server = [self getServerForUID: uid]; + if (server == nil) return nil; - return [NSString stringWithFormat:@"%@@%@", _uid, server]; + return [NSString stringWithFormat: @"%@@%@", uid, server]; } -- (NSArray *)mailServerDiscoveryAttributes { +- (NSArray *) mailServerDiscoveryAttributes +{ static NSArray *attrs = nil; if (attrs == nil) { - attrs = [[NSArray alloc] initWithObjects: + attrs = [[NSArray alloc] initWithObjects: @"uid", /* required for shares */ - @"mineqMelRoutage", - @"mineqMelServeurPrincipal", - @"mineqMelPartages", - mailEmissionAttrName, + @"mineqMelRoutage", + @"mineqMelServeurPrincipal", + @"mineqMelPartages", + mailEmissionAttrName, nil]; } return attrs; } -- (NGLdapEntry *)_fetchEntryForAgenorUID:(NSString *)_uid { +- (NGLdapEntry *) _fetchEntryForAgenorUID: (NSString *) uid +{ // TODO: badly named, this fetches the mail server discovery attributes /* called by -primaryGetServerForAgenorUID: */ NGLdapConnection *conn; - EOQualifier *q; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - - q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, _uid]; - + EOQualifier *q; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + + q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, uid]; + conn = [self ldapConnection]; - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:[self mailServerDiscoveryAttributes]]; + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: [self mailServerDiscoveryAttributes]]; /* we just expect one entry, thus drop the rest */ entry = [resultEnum nextObject]; if (entry == nil) { - if(debugOn) { - NSLog(@"%s Didn't find LDAP entry for uid '%@'!", - __PRETTY_FUNCTION__, - _uid); - } - return nil; + if(debugOn) { + NSLog(@"%s Didn't find LDAP entry for uid '%@'!", + __PRETTY_FUNCTION__, + uid); + } + return nil; } return entry; } -- (NSArray *)_serverCandidatesForMineqMelRoutage:(NGLdapAttribute *)attr { +- (NSArray *) serverCandidatesForMineqMelRoutage: (NGLdapAttribute *) attr +{ /* - eg: - "Baluh.Hommes.Tests-Montee-En-Charge-Ogo%equipement.gouv.fr@\ - amelie-01.ac.melanie2.i2" + eg: + "Baluh.Hommes.Tests-Montee-En-Charge-Ogo%equipement.gouv.fr@\ + amelie-01.ac.melanie2.i2" */ NSMutableArray *serverCandidates; unsigned i, count; count = [attr count]; - serverCandidates = [NSMutableArray arrayWithCapacity:count]; + serverCandidates = [NSMutableArray arrayWithCapacity: count]; for (i = 0; i < count; i++) { - NSRange r; + NSRange r; NSString *route; unsigned length; unsigned start; - NSRange serverNameRange; + NSRange serverNameRange; NSString *serverName; - - route = [attr stringValueAtIndex:i]; + + route = [attr stringValueAtIndex: i]; /* check for melanie suffix and ignore other entries */ - - r = [route rangeOfString:@".melanie2.i2" options:NSBackwardsSearch]; + + r = [route rangeOfString: @".melanie2.i2" options: NSBackwardsSearch]; if (r.length == 0) { #if 0 - [self logWithFormat:@"found no melanie in route: '%@'", route]; + [self logWithFormat: @"found no melanie in route: '%@'", route]; #endif continue; } /* check for @ inside the string, searching backwards (ignoring suffix) */ - + // be clever: TODO: in what way is this clever? length = [route length]; - r = NSMakeRange(0, length - r.length); /* cut of suffix (.melanie2.i2) */ - r = [route rangeOfString:@"@" options:NSBackwardsSearch range:r]; + r = NSMakeRange(0, length - r.length) ; /* cut of suffix (.melanie2.i2) */ + r = [route rangeOfString: @"@" options: NSBackwardsSearch range: r]; if (r.length == 0) { #if 0 - [self logWithFormat:@"found no @ in route: '%@'", route]; + [self logWithFormat: @"found no @ in route: '%@'", route]; #endif continue; } - + /* check for percent sign */ - - start = NSMaxRange(r); /* start behind the @ */ - + + start = NSMaxRange(r) ; /* start behind the @ */ + /* this range covers everything after @: 'amelie-01.ac.melanie2.i2' */ - serverNameRange = NSMakeRange(start, length - start); - + serverNameRange = NSMakeRange(start, length - start) ; + /* and this range covers everything to the @ */ - r = NSMakeRange(0, start - 1); - r = [route rangeOfString:@"%" options:NSBackwardsSearch range:r]; + r = NSMakeRange(0, start - 1) ; + r = [route rangeOfString: @"%" options: NSBackwardsSearch range: r]; if (r.length == 0) { #if 0 - [self logWithFormat:@"found no %% in route: '%@' / '%@'", - route, [route substringWithRange:NSMakeRange(0, length - start)]]; + [self logWithFormat: @"found no %% in route: '%@' / '%@'", + route, [route substringWithRange: NSMakeRange(0, length - start) ]]; #endif continue; } - - serverName = [route substringWithRange:serverNameRange]; - [serverCandidates addObject:serverName]; + + serverName = [route substringWithRange: serverNameRange]; + [serverCandidates addObject: serverName]; } return serverCandidates; } -- (NSString *)serverFromEntry:(NGLdapEntry *)_entry { - NSString *server; +- (NSString *) serverFromEntry: (NGLdapEntry *) entry +{ + NSString *server; NGLdapAttribute *attr; server = nil; - - attr = [_entry attributeWithName:@"mineqMelRoutage"]; + + attr = [entry attributeWithName: @"mineqMelRoutage"]; if (attr != nil) { NSArray *serverCandidates; - - serverCandidates = [self _serverCandidatesForMineqMelRoutage:attr]; - if ([serverCandidates count] > 0) - server = [serverCandidates objectAtIndex:0]; - + + serverCandidates = [self serverCandidatesForMineqMelRoutage: attr]; + if ([serverCandidates count] > 0) + server = [serverCandidates objectAtIndex: 0]; + if ([serverCandidates count] > 1) { - [self logWithFormat: + [self logWithFormat: @"WARNING: more than one value for 'mineqMelRoutage': %@", - serverCandidates]; + serverCandidates]; } } else { - [self debugWithFormat: + [self debugWithFormat: @"%s LDAP entry '%@' has no mineqMelRoutage entry?", - __PRETTY_FUNCTION__, [_entry dn]]; + __PRETTY_FUNCTION__, [entry dn]]; } - + /* last resort */ if (server == nil) { - attr = [_entry attributeWithName:@"mineqMelServeurPrincipal"]; - if ([attr count] > 0) - server = [attr stringValueAtIndex:0]; + attr = [entry attributeWithName: @"mineqMelServeurPrincipal"]; + if ([attr count] > 0) + server = [attr stringValueAtIndex: 0]; } - + return server; } -- (NSString *)primaryGetServerForAgenorUID:(NSString *)_uid { +- (NSString *) primaryGetServerForAgenorUID: (NSString *) uid +{ /* - First of all : for a particular user IMAP and SMTP are served on the same - host. - - The name of the machine is determined by applying a regex on every values of - the mineqMelRoutage LDAP attribute. - The regex is : .*%.*@(.*\.melanie2\.i2$) - It extracts the substring that follows '@', ends with 'melanie2', on - adresses which have a '%' before the '@' - - Example: helge.hesse%opengroupware.org@servername1.melanie2.i2 - -> servername1.melanie2.i2 - - If only one server name is found by applying the regex on every value of the - attribute, then this name is the IMAP/SMTP server for that user. - Note that this is the case when we got a unique (well formed) value for the - attribute. - If the regex finds more than one servername when applied to the differents - values, then the IMAP/SMTP server name is to be found in the - mineqMelServeurPrincipal attribute of the user. + First of all : for a particular user IMAP and SMTP are served on the same + host. + + The name of the machine is determined by applying a regex on every values of + the mineqMelRoutage LDAP attribute. + The regex is : .*%.*@(.*\.melanie2\.i2$) + It extracts the substring that follows '@', ends with 'melanie2', on + adresses which have a '%' before the '@' + + Example: helge.hesse%opengroupware.org@servername1.melanie2.i2 + -> servername1.melanie2.i2 + + If only one server name is found by applying the regex on every value of the + attribute, then this name is the IMAP/SMTP server for that user. + Note that this is the case when we got a unique (well formed) value for the + attribute. + If the regex finds more than one servername when applied to the differents + values, then the IMAP/SMTP server name is to be found in the + mineqMelServeurPrincipal attribute of the user. */ - NSString *server; + NSString *server; NGLdapEntry *entry; - - if ((entry = [self _fetchEntryForAgenorUID:_uid]) == nil) + + if ((entry = [self _fetchEntryForAgenorUID: uid]) == nil) return nil; - - if ((server = [self serverFromEntry:entry]) != nil) + + if ((server = [self serverFromEntry: entry]) != nil) return server; - - [self debugWithFormat: + + [self debugWithFormat: @"%s no chance of getting at server info for user '%@', " - @"tried everything. Sorry.", - __PRETTY_FUNCTION__, _uid]; + @"tried everything. Sorry.", + __PRETTY_FUNCTION__, uid]; return nil; } -- (NSString *)getServerForUID:(NSString *)_uid { +- (NSString *) getServerForUID: (NSString *) uid +{ NSString *server; - if (_uid == nil || [_uid length] == 0) + if (uid == nil || [uid length] == 0) return nil; - - if ((server = [self _cachedServerForUID:_uid]) != nil) + + if ((server = [self _cachedServerForUID: uid]) != nil) return server; - - if (useLDAP) - server = [self primaryGetServerForAgenorUID:_uid]; - else if (fallbackIMAP4Server != nil) + + if (useLDAP) + server = [self primaryGetServerForAgenorUID: uid]; + else if (fallbackIMAP4Server != nil) server = fallbackIMAP4Server; else { - [self logWithFormat:@"ERROR: could not get server for uid '%@', " + [self logWithFormat: @"ERROR: could not get server for uid '%@', " @"neither LDAP (SOGoUserManagerUsesLDAP) nor " @"a fallback (SOGoFallbackIMAP4Server) is configured.", - _uid]; + uid]; server = nil; } - - [self _cacheServer:server forUID:_uid]; + + [self _cacheServer: server forUID: uid]; return server; } /* shared mailboxes */ -- (NSArray *)getSharedMailboxAccountStringsForUID:(NSString *)_uid { +- (NSArray *) getSharedMailboxAccountStringsForUID: (NSString *) uid +{ NSArray *k; - - k = [[self getSharedMailboxesAndEMailsForUID:_uid] allKeys]; - + + k = [[self getSharedMailboxesAndEMailsForUID: uid] allKeys]; + /* ensure that ordering is always the same */ - return [k sortedArrayUsingSelector:@selector(compare:)]; + return [k sortedArrayUsingSelector: @selector(compare: ) ]; } -- (NSString *)emissionEMailFromEntry:(NGLdapEntry *)_entry { +- (NSString *) emissionEMailFromEntry: (NGLdapEntry *) entry +{ id emissionAttr; - - emissionAttr = [_entry attributeWithName:mailEmissionAttrName]; + + emissionAttr = [entry attributeWithName: mailEmissionAttrName]; if ([emissionAttr count] == 0) { - [self logWithFormat:@"WARNING: share has no %@ attr: %@", - mailEmissionAttrName, [_entry dn]]; + [self logWithFormat: @"WARNING: share has no %@ attr: %@", + mailEmissionAttrName, [entry dn]]; return nil; } - + if ([emissionAttr count] > 1) { - [self logWithFormat: + [self logWithFormat: @"WARNING: share has more than one value in %@ attr: %@", - mailEmissionAttrName, [_entry dn]]; + mailEmissionAttrName, [entry dn]]; return nil; } - - return [emissionAttr stringValueAtIndex:0]; + + return [emissionAttr stringValueAtIndex: 0]; } -- (NSArray *)getSharedMailboxEMailsForUID:(NSString *)_uid { - NSMutableArray *shares = nil; +- (NSArray *) getSharedMailboxEMailsForUID: (NSString *) uid +{ + NSMutableArray *shares = nil; NGLdapConnection *conn; - EOQualifier *q; - NSString *gPattern, *cPattern; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - - if ([_uid length] == 0) + EOQualifier *q; + NSString *gPattern, *cPattern; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + + if ([uid length] == 0) return nil; - + if (!useLDAP) { - [self logWithFormat: + [self logWithFormat: @"Note: LDAP access is disabled, returning no shared froms."]; return nil; } - + /* check cache */ - if ((shares = [shareEMailCache objectForKey:_uid]) != nil) + if ((shares = [shareEMailCache objectForKey: uid]) != nil) return shares; - + /* G and C mean "emission access" */ - gPattern = [_uid stringByAppendingString:@":G"]; - cPattern = [_uid stringByAppendingString:@":C"]; - - q = [EOQualifier qualifierWithQualifierFormat: - @"((mineqMelPartages = %@) OR (mineqMelPartages = %@)) " - @"AND (objectclass = %@)", + gPattern = [uid stringByAppendingString: @": G"]; + cPattern = [uid stringByAppendingString: @": C"]; + + q = [EOQualifier qualifierWithQualifierFormat: + @"((mineqMelPartages = %@) OR (mineqMelPartages = %@) ) " + @"AND (objectclass = %@) ", gPattern, cPattern, shareLDAPClass]; - + conn = [self ldapConnection]; - - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:fromEMailAttrs]; - + + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: fromEMailAttrs]; + while ((entry = [resultEnum nextObject]) != nil) { NSString *emissionAttr; - if ((emissionAttr = [self emissionEMailFromEntry:entry]) == nil) + if ((emissionAttr = [self emissionEMailFromEntry: entry]) == nil) continue; - - if (shares == nil) shares = [NSMutableArray arrayWithCapacity:4]; - [shares addObject:emissionAttr]; + + if (shares == nil) shares = [NSMutableArray arrayWithCapacity: 4]; + [shares addObject: emissionAttr]; } - + /* ensure that ordering is always the same */ - [shares sortUsingSelector:@selector(compare:)]; - + [shares sortUsingSelector: @selector(compare: ) ]; + /* cache */ shares = (shares == nil) ? [NSArray array] : [[shares copy] autorelease]; - [shareEMailCache setObject:shares forKey:_uid]; + [shareEMailCache setObject: shares forKey: uid]; return shares; } /* identities */ -- (BOOL)hasUser:(NSString *)_uid partageAccess:(char *)_rightset - inEntry:(NGLdapEntry *)_entry +- (BOOL) hasUser: (NSString *) uid partageAccess: (char *) rightset + inEntry: (NGLdapEntry *) entry { NGLdapAttribute *attr; unsigned i, count; - - attr = [_entry attributeWithName:@"mineqMelPartages"]; + + attr = [entry attributeWithName: @"mineqMelPartages"]; if ((count = [attr count]) == 0) { - [self logWithFormat:@"WARNING: share has no 'mineqMelPartages' attr: %@", - [_entry dn]]; + [self logWithFormat: @"WARNING: share has no 'mineqMelPartages' attr: %@", + [entry dn]]; return NO; } - + for (i = 0; i < count; i++) { NSString *p; - NSRange r; - unichar c; + NSRange r; + unichar c; register unsigned j; - - p = [attr stringValueAtIndex:i]; - r = [p rangeOfString:@":"]; + + p = [attr stringValueAtIndex: i]; + r = [p rangeOfString: @": "]; if (r.length == 0) { - [self errorWithFormat:@"Invalid mineqMelPartages value: '%@'", p]; + [self errorWithFormat: @"Invalid mineqMelPartages value: '%@'", p]; continue; } - - /* check whether prefix matches, eg: "helian.h:G" */ - if (r.location != [_uid length]) /* check length */ + + /* check whether prefix matches, eg: "helian.h: G" */ + if (r.location != [uid length]) /* check length */ continue; - if (![p hasPrefix:_uid]) + if (![p hasPrefix: uid]) continue; - - c = [p characterAtIndex:(r.location + r.length)]; - + + c = [p characterAtIndex: (r.location + r.length) ]; + /* check whether permissions match */ - for (j = 0; _rightset[j] != '\0'; j++) { - if (c == _rightset[j]) + for (j = 0; rightset[j] != '\0'; j++) { + if (c == rightset[j]) return YES; } } return NO; } -- (NSDictionary *)getSharedMailboxesAndEMailsForUID:(NSString *)_uid { +- (NSDictionary *) getSharedMailboxesAndEMailsForUID: (NSString *) uid +{ /* - Sample: - "(&(mineqMelPartages=guizmo.g:*)(objectclass=mineqMelBoite))" - "guizmo.g" is the uid of the user - - Login: - guizmo.g.-.baluh.hommes.tests-montee-en-charge-ogo - (uid + ".-." + share-uid) - + Sample: + "(&(mineqMelPartages=guizmo.g: *)(objectclass=mineqMelBoite)) " + "guizmo.g" is the uid of the user + + Login: + guizmo.g.-.baluh.hommes.tests-montee-en-charge-ogo + (uid + ".-." + share-uid) + Note: shared mailboxes can be on different hosts! - + This returns a dictionary where the keys are the IMAP4 connect strings while the values are the emitter addresses for the box or NSNull if the uid is not allowed to emit for this box. */ NSMutableDictionary *shares = nil; NGLdapConnection *conn; - EOQualifier *q; - NSString *sharePattern; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - - if ([_uid length] == 0) + EOQualifier *q; + NSString *sharePattern; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + + if ([uid length] == 0) return nil; - + if (!useLDAP) { - [self logWithFormat: + [self logWithFormat: @"Note: LDAP access is disabled, returning no shared accounts."]; return nil; } /* check cache */ - if ((shares = [shareStoreCache objectForKey:_uid]) != nil) + if ((shares = [shareStoreCache objectForKey: uid]) != nil) return shares; - - sharePattern = [_uid stringByAppendingString:@":*"]; - - q = [EOQualifier qualifierWithQualifierFormat: - @"(mineqMelPartages = %@) AND (objectclass = %@)", - sharePattern, shareLDAPClass]; - + + sharePattern = [uid stringByAppendingString: @": *"]; + + q = [EOQualifier qualifierWithQualifierFormat: + @"(mineqMelPartages = %@) AND (objectclass = %@) ", + sharePattern, shareLDAPClass]; + conn = [self ldapConnection]; - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:[self mailServerDiscoveryAttributes]]; - + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: [self mailServerDiscoveryAttributes]]; + while ((entry = [resultEnum nextObject]) != nil) { NSString *server, *shareLogin; id shareUid, emitterAddress; /* calculate server connect string */ - - if ([(server = [self serverFromEntry:entry]) length] == 0) { - [self errorWithFormat:@"found no mail server host for share: %@", - [entry dn]]; + + if ([(server = [self serverFromEntry: entry]) length] == 0) { + [self errorWithFormat: @"found no mail server host for share: %@", + [entry dn]]; continue; } - - shareUid = [entry attributeWithName:@"uid"]; + + shareUid = [entry attributeWithName: @"uid"]; if ([shareUid count] < 1) { - [self errorWithFormat:@"found no 'uid' for share: %@", [entry dn]]; + [self errorWithFormat: @"found no 'uid' for share: %@", [entry dn]]; continue; } - shareUid = [shareUid stringValueAtIndex:0]; - - shareLogin = [_uid stringByAppendingString:shareLoginSeparator]; - shareLogin = [shareLogin stringByAppendingString:shareUid]; - - if (shares == nil) - shares = [NSMutableDictionary dictionaryWithCapacity:4]; - - shareLogin = [shareLogin stringByAppendingString:@"@"]; - shareLogin = [shareLogin stringByAppendingString:server]; - + shareUid = [shareUid stringValueAtIndex: 0]; + + shareLogin = [uid stringByAppendingString: shareLoginSeparator]; + shareLogin = [shareLogin stringByAppendingString: shareUid]; + + if (shares == nil) + shares = [NSMutableDictionary dictionaryWithCapacity: 4]; + + shareLogin = [shareLogin stringByAppendingString: @"@"]; + shareLogin = [shareLogin stringByAppendingString: server]; + /* calculate emitter address (check for proper access right) */ - - if ([self hasUser:_uid partageAccess:"GC" inEntry:entry]) - emitterAddress = [self emissionEMailFromEntry:entry]; + + if ([self hasUser: uid partageAccess: "GC" inEntry: entry]) + emitterAddress = [self emissionEMailFromEntry: entry]; else emitterAddress = [NSNull null]; - + /* set value */ - + [shares setObject: emitterAddress forKey: shareLogin]; } - + /* cache */ shares = (shares == nil) ? [NSDictionary dictionary] : [[shares copy] autorelease]; - [shareStoreCache setObject:shares forKey:_uid]; + [shareStoreCache setObject: shares forKey: uid]; return shares; } /* free busy */ -- (NSURL *)getFreeBusyURLForUID:(NSString *)_uid { - [self logWithFormat:@"TODO(%s): implement", __PRETTY_FUNCTION__]; +- (NSURL *) getFreeBusyURLForUID: (NSString *) uid +{ + [self logWithFormat: @"TODO(%s): implement", __PRETTY_FUNCTION__]; return nil; } @@ -1016,8 +1049,8 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; fieldName: (NSString *) fieldName { id defaults; - - if (AgenorProfileURL) + + if (AgenorProfileURL) { /* Note: do not cache, otherwise updates can be quite tricky */ defaults = [[AgenorUserDefaults alloc] initWithTableURL: AgenorProfileURL @@ -1026,7 +1059,7 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; } else { - [self warnWithFormat: + [self warnWithFormat: @"no profile configured, cannot retrieve defaults for user: '%@'", uid]; return defaults = nil; @@ -1047,122 +1080,124 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; /* internet access lock */ -- (BOOL)isUserAllowedToChangeSOGoInternetAccess:(NSString *)_uid { +- (BOOL) isUserAllowedToChangeSOGoInternetAccess: (NSString *) uid +{ NSNumber *bv; - - bv = [changeInternetAccessCache objectForKey:_uid]; + + bv = [changeInternetAccessCache objectForKey: uid]; if (!bv) { BOOL value; - - value = [self primaryIsUserAllowedToChangeSOGoInternetAccess:_uid]; - bv = [NSNumber numberWithBool:value]; - [changeInternetAccessCache setObject:bv forKey:_uid]; + + value = [self primaryIsUserAllowedToChangeSOGoInternetAccess: uid]; + bv = [NSNumber numberWithBool: value]; + [changeInternetAccessCache setObject: bv forKey: uid]; } return [bv boolValue]; } -- (BOOL)primaryIsUserAllowedToChangeSOGoInternetAccess:(NSString *)_uid { - static NSArray *attrs = nil; +- (BOOL) primaryIsUserAllowedToChangeSOGoInternetAccess: (NSString *) uid +{ + static NSArray *attrs = nil; NGLdapConnection *conn; - EOQualifier *q; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - NGLdapAttribute *attr; - NSString *value; - - if (attrs == nil) - attrs = [[NSArray alloc] initWithObjects:changeInternetAccessAttrName, nil]; - - q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, _uid]; - + EOQualifier *q; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + NGLdapAttribute *attr; + NSString *value; + + if (attrs == nil) + attrs = [[NSArray alloc] initWithObjects: changeInternetAccessAttrName, nil]; + + q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, uid]; + conn = [self ldapConnection]; - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:attrs]; + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: attrs]; entry = [resultEnum nextObject]; if (entry == nil) { if(debugOn) { - [self logWithFormat:@"%s Didn't find LDAP entry for uid '%@'!", - __PRETTY_FUNCTION__, - _uid]; + [self logWithFormat: @"%s Didn't find LDAP entry for uid '%@'!", + __PRETTY_FUNCTION__, + uid]; } return NO; } - attr = [entry attributeWithName:changeInternetAccessAttrName]; + attr = [entry attributeWithName: changeInternetAccessAttrName]; if(attr == nil && debugOn) { - [self logWithFormat:@"%s LDAP entry for uid '%@' " - @"has no mineqOgoAccesInternet attribute?", - __PRETTY_FUNCTION__, - _uid]; + [self logWithFormat: @"%s LDAP entry for uid '%@' " + @"has no mineqOgoAccesInternet attribute?", + __PRETTY_FUNCTION__, + uid]; return NO; /* nothing we can do about it */ } - value = [attr stringValueAtIndex:0]; + value = [attr stringValueAtIndex: 0]; return [value boolValue]; } -- (BOOL) isInternetAutoresponderEnabledForUser: (NSString *) _uid +- (BOOL) isInternetAutoresponderEnabledForUser: (NSString *) uid { NSNumber *bv; BOOL value; - bv = [internetAutoresponderFlagCache objectForKey:_uid]; + bv = [internetAutoresponderFlagCache objectForKey: uid]; if (!bv) { - value = [self primaryIsInternetAutoresponderEnabledForUser:_uid]; - bv = [NSNumber numberWithBool:value]; - [internetAutoresponderFlagCache setObject:bv forKey:_uid]; + value = [self primaryIsInternetAutoresponderEnabledForUser: uid]; + bv = [NSNumber numberWithBool: value]; + [internetAutoresponderFlagCache setObject: bv forKey: uid]; } return [bv boolValue]; } -- (BOOL) primaryIsInternetAutoresponderEnabledForUser: (NSString *) _uid +- (BOOL) primaryIsInternetAutoresponderEnabledForUser: (NSString *) uid { NGLdapAttribute *attr; - - attr = [self primaryGetMailAutoresponderAttribute:_uid]; + + attr = [self primaryGetMailAutoresponderAttribute: uid]; if (!attr) return NO; return [self isAutoresponderEnabledForAttribute: attr - matchingPrefix: @"60~"]; + matchingPrefix: @"60~"]; } -- (BOOL) isIntranetAutoresponderEnabledForUser: (NSString *) _uid +- (BOOL) isIntranetAutoresponderEnabledForUser: (NSString *) uid { NSNumber *bv; BOOL value; - - bv = [intranetAutoresponderFlagCache objectForKey:_uid]; - if (!bv) + + bv = [intranetAutoresponderFlagCache objectForKey: uid]; + if (!bv) { - value = [self primaryIsIntranetAutoresponderEnabledForUser:_uid]; - bv = [NSNumber numberWithBool:value]; - [intranetAutoresponderFlagCache setObject:bv forKey:_uid]; + value = [self primaryIsIntranetAutoresponderEnabledForUser: uid]; + bv = [NSNumber numberWithBool: value]; + [intranetAutoresponderFlagCache setObject: bv forKey: uid]; } return [bv boolValue]; } -- (BOOL) primaryIsIntranetAutoresponderEnabledForUser: (NSString *) _uid +- (BOOL) primaryIsIntranetAutoresponderEnabledForUser: (NSString *) uid { NGLdapAttribute *attr; - - attr = [self primaryGetMailAutoresponderAttribute:_uid]; + + attr = [self primaryGetMailAutoresponderAttribute: uid]; if (!attr) return NO; - return [self isAutoresponderEnabledForAttribute:attr matchingPrefix:@"50~"]; + return [self isAutoresponderEnabledForAttribute: attr matchingPrefix: @"50~"]; } -- (BOOL) isAutoresponderEnabledForAttribute: (NGLdapAttribute *)_attr - matchingPrefix: (NSString *)_prefix +- (BOOL) isAutoresponderEnabledForAttribute: (NGLdapAttribute *) attr + matchingPrefix: (NSString *) prefix { unsigned i, count; - - count = [_attr count]; + + count = [attr count]; for (i = 0; i < count; i++) { NSString *value; - - value = [_attr stringValueAtIndex:i]; - if ([value hasPrefix:_prefix]) { - if ([value rangeOfString:@"DFIN:0"].length > 0) - return NO; + + value = [attr stringValueAtIndex: i]; + if ([value hasPrefix: prefix]) { + if ([value rangeOfString: @"DFIN: 0"].length > 0) + return NO; return YES; } } @@ -1170,34 +1205,34 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; return NO; } -- (NGLdapAttribute *) primaryGetMailAutoresponderAttribute: (NSString *) _uid +- (NGLdapAttribute *) primaryGetMailAutoresponderAttribute: (NSString *) uid { - static NSArray *attrs = nil; + static NSArray *attrs = nil; NGLdapConnection *conn; - EOQualifier *q; - NSEnumerator *resultEnum; - NGLdapEntry *entry; - NGLdapAttribute *attr; - - if (attrs == nil) - attrs = [[NSArray alloc] initWithObjects:mailAutoresponderAttrName, nil]; + EOQualifier *q; + NSEnumerator *resultEnum; + NGLdapEntry *entry; + NGLdapAttribute *attr; + + if (attrs == nil) + attrs = [[NSArray alloc] initWithObjects: mailAutoresponderAttrName, nil]; - q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, _uid]; - + q = [EOQualifier qualifierWithQualifierFormat: qualifierFormat, uid]; + conn = [self ldapConnection]; - resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN - qualifier:q - attributes:attrs]; + resultEnum = [conn deepSearchAtBaseDN: ldapBaseDN + qualifier: q + attributes: attrs]; entry = [resultEnum nextObject]; if (entry == nil) { if(debugOn) { - [self logWithFormat:@"%s Didn't find LDAP entry for uid '%@'!", - __PRETTY_FUNCTION__, - _uid]; + [self logWithFormat: @"%s Didn't find LDAP entry for uid '%@'!", + __PRETTY_FUNCTION__, + uid]; } return nil; } - attr = [entry attributeWithName:mailAutoresponderAttrName]; + attr = [entry attributeWithName: mailAutoresponderAttrName]; return attr; } @@ -1215,7 +1250,8 @@ static unsigned PoolScanInterval = 5 * 60 /* every five minutes */; /* debugging */ -- (BOOL)isDebuggingEnabled { +- (BOOL) isDebuggingEnabled +{ return debugOn; }