From: wolfgang Date: Thu, 10 May 2007 21:19:05 +0000 (+0000) Subject: git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1062 d1b88da0-ebda-0310... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa84f1942aa28c46eb90b8e82f575b434ed31ea6;p=scalable-opengroupware.org git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1062 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/ChangeLog b/ChangeLog index 59e3d314..4f005d52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2007-05-10 Wolfgang Sourdeau + * SoObjects/SOGo/LDAPSource.m ([LDAPSource + -checkLogin:loginToCheckandPassword:passwordToCheck]): if a + "bindFields" value is present in the user defaults, use the + specified fields to find the dn of the user to bind. + ([LDAPSource -allEntryIDs]) + ([LDAPSource -fetchContactsMatching:match]) + ([LDAPSource -lookupContactEntry:entryID]) + ([LDAPSource -lookupContactEntryWithUIDorEmail:uid]): + bind and unbind the connection on each request. + * UI/MailerUI/UIxMailAddressbook.m: removed obsolete module. * UI/Contacts/UIxContactFoldersView.m ([UIxContactFoldersView diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index 2af01024..3e8a3c7b 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -40,6 +40,7 @@ NSString *IDField; /* the first part of a user DN */ NSString *CNField; NSString *UIDField; + NSString *bindFields; NGLdapConnection *ldapConnection; NSMutableArray *searchAttributes; @@ -56,7 +57,8 @@ - (void) setBaseDN: (NSString *) newBaseDN IDField: (NSString *) newIDField CNField: (NSString *) newCNField - andUIDField: (NSString *) newUIDField; + UIDField: (NSString *) newUIDField + andBindFields: (NSString *) newBindFields; - (BOOL) checkLogin: (NSString *) login andPassword: (NSString *) password; diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index 51fdadaf..75fe64d4 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -135,6 +135,7 @@ static NSArray *commonSearchFields; IDField = @"cn"; /* the first part of a user DN */ CNField = @"cn"; UIDField = @"uid"; + bindFields = nil; ldapConnection = nil; searchAttributes = nil; @@ -152,6 +153,7 @@ static NSArray *commonSearchFields; [IDField release]; [CNField release]; [UIDField release]; + [bindFields release]; [ldapConnection release]; [super dealloc]; } @@ -167,7 +169,8 @@ static NSArray *commonSearchFields; [self setBaseDN: [udSource objectForKey: @"baseDN"] IDField: [udSource objectForKey: @"IDFieldName"] CNField: [udSource objectForKey: @"CNFieldName"] - andUIDField: [udSource objectForKey: @"UIDFieldName"]]; + UIDField: [udSource objectForKey: @"UIDFieldName"] + andBindFields: [udSource objectForKey: @"bindFields"]]; return self; } @@ -187,7 +190,8 @@ static NSArray *commonSearchFields; - (void) setBaseDN: (NSString *) newBaseDN IDField: (NSString *) newIDField CNField: (NSString *) newCNField - andUIDField: (NSString *) newUIDField + UIDField: (NSString *) newUIDField + andBindFields: (NSString *) newBindFields { ASSIGN (baseDN, newBaseDN); if (newIDField) @@ -196,6 +200,8 @@ static NSArray *commonSearchFields; ASSIGN (CNField, newCNField); if (UIDField) ASSIGN (UIDField, newUIDField); + if (newBindFields) + ASSIGN (bindFields, newBindFields); } - (void) _initLDAPConnection @@ -208,6 +214,45 @@ static NSArray *commonSearchFields; } /* user management */ +- (EOQualifier *) _qualifierForBindFilter: (NSString *) uid +{ + NSMutableString *qs; + NSEnumerator *fields; + NSString *currentField; + + qs = [NSMutableString string]; + fields = [[bindFields componentsSeparatedByString: @","] objectEnumerator]; + currentField = [fields nextObject]; + while (currentField) + { + [qs appendFormat: @"OR (%@='%@')", currentField, uid]; + currentField = [fields nextObject]; + } + [qs deleteCharactersInRange: NSMakeRange (0, 3)]; + + return [EOQualifier qualifierWithQualifierFormat: qs]; +} + +- (NSString *) _fetchUserDNForLogin: (NSString *) loginToCheck +{ + NSString *userDN; + NSEnumerator *entries; + NGLdapEntry *userEntry; + + [self _initLDAPConnection]; + entries = [ldapConnection deepSearchAtBaseDN: baseDN + qualifier: [self _qualifierForBindFilter: loginToCheck] + attributes: [NSArray arrayWithObject: @"dn"]]; + userEntry = [entries nextObject]; + if (userEntry) + userDN = [userEntry dn]; + else + userDN = nil; + [ldapConnection release]; + + return userDN; +} + - (BOOL) checkLogin: (NSString *) loginToCheck andPassword: (NSString *) passwordToCheck { @@ -219,15 +264,21 @@ static NSArray *commonSearchFields; { bindConnection = [[NGLdapConnection alloc] initWithHostName: hostname port: port]; - userDN = [NSString stringWithFormat: @"%@=%@,%@", - IDField, loginToCheck, baseDN]; - NS_DURING - didBind = [bindConnection bindWithMethod: @"simple" binddn: userDN - credentials: passwordToCheck]; - NS_HANDLER - didBind = NO; - NS_ENDHANDLER - + if (bindFields) + userDN = [self _fetchUserDNForLogin: loginToCheck]; + else + userDN = [NSString stringWithFormat: @"%@=%@,%@", + IDField, loginToCheck, baseDN]; + if (userDN) + { + NS_DURING + didBind = [bindConnection bindWithMethod: @"simple" + binddn: userDN + credentials: passwordToCheck]; + NS_HANDLER + didBind = NO; + NS_ENDHANDLER + } [bindConnection release]; } else @@ -298,8 +349,7 @@ static NSArray *commonSearchFields; ids = [NSMutableArray array]; - if (!ldapConnection) - [self _initLDAPConnection]; + [self _initLDAPConnection]; entries = [ldapConnection deepSearchAtBaseDN: baseDN qualifier: nil attributes: [NSArray arrayWithObject: IDField]]; @@ -315,6 +365,7 @@ static NSArray *commonSearchFields; currentEntry = [entries nextObject]; } } + [ldapConnection release]; return ids; } @@ -362,8 +413,7 @@ static NSArray *commonSearchFields; if ([match length] > 0) { - if (!ldapConnection) - [self _initLDAPConnection]; + [self _initLDAPConnection]; entries = [ldapConnection deepSearchAtBaseDN: baseDN qualifier: [self _qualifierForFilter: match] attributes: [self _searchAttributes]]; @@ -377,6 +427,7 @@ static NSArray *commonSearchFields; currentEntry = [entries nextObject]; } } + [ldapConnection release]; } return contacts; @@ -391,14 +442,14 @@ static NSArray *commonSearchFields; if ([entryID length] > 0) { - if (!ldapConnection) - [self _initLDAPConnection]; + [self _initLDAPConnection]; ldapEntry = [ldapConnection entryAtDN: [NSString stringWithFormat: @"%@=%@,%@", IDField, entryID, baseDN] attributes: [self _searchAttributes]]; if (ldapEntry) contactEntry = [self _convertLDAPEntryToContact: ldapEntry]; + [ldapConnection release]; } return contactEntry; @@ -415,8 +466,7 @@ static NSArray *commonSearchFields; if ([uid length] > 0) { - if (!ldapConnection) - [self _initLDAPConnection]; + [self _initLDAPConnection]; qualifier = [self _qualifierForUIDFilter: uid]; entries = [ldapConnection deepSearchAtBaseDN: baseDN qualifier: qualifier @@ -424,6 +474,7 @@ static NSArray *commonSearchFields; ldapEntry = [entries nextObject]; if (ldapEntry) contactEntry = [self _convertLDAPEntryToContact: ldapEntry]; + [ldapConnection release]; } return contactEntry;