]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1062 d1b88da0-ebda-0310...
authorwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Thu, 10 May 2007 21:19:05 +0000 (21:19 +0000)
committerwolfgang <wolfgang@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Thu, 10 May 2007 21:19:05 +0000 (21:19 +0000)
ChangeLog
SoObjects/SOGo/LDAPSource.h
SoObjects/SOGo/LDAPSource.m

index 59e3d31416919b91d306b252411d0f25ee2e7128..4f005d52262ab02501f0476f8167deba3e17d79a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2007-05-10  Wolfgang Sourdeau  <wsourdeau@inverse.ca>
 
+       * 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
index 2af01024133ab512132e867ea3d311e73c8e4af8..3e8a3c7b4906ab8edbfc0ba588c38e570649104f 100644 (file)
@@ -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;
index 51fdadaf740fd43b3b900094400cd8c66dadbc2c..75fe64d40586ed942c6bfa670e429b819f3ed1d7 100644 (file)
@@ -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;