Re: SquirrelMail LDAP address book feature needs implementing/tweaking

David Härdeman <[email protected]>
Newsgroups gmane.mail.squirrelmail.devel
Message-ID <[email protected]>
On Wed, Jun 18, 2008 at 06:16:19PM -0700, Paul Lesniewski wrote:
>Hi David,
>
>I saw that your code was adopted for the SquirrelMail development
>branch for LDAP address book lookups, adds, deletes, etc.  If you are
>interested, the other address book backends now have the ability to
>look up address book entries by fields other than the nickname/alias.
>The LDAP backend needs to have this implemented.  See:
>
>http://squirrelmail.svn.sourceforge.net/squirrelmail/?rev=13186&view=rev

The attached patch should hopefully do the right thing. I can 
unfortunately not test it right now since I don't have access to an LDAP 
enabled SQ installation at the moment.

-- 
David Härdeman

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

-----
squirrelmail-devel mailing list
Posting guidelines: http://squirrelmail.org/postingguidelines
List address: [email protected]
List archives: http://news.gmane.org/gmane.mail.squirrelmail.devel
List info (subscribe/unsubscribe/change options): https://lists.sourceforge.net/lists/listinfo/squirrelmail-devel
ldap-fields.patch (text/x-diff, 2.1 KB)
Index: functions/abook_ldap_server.php
===================================================================
--- functions/abook_ldap_server.php	(revision 13202)
+++ functions/abook_ldap_server.php	(working copy)
@@ -12,7 +12,7 @@
  * StartTLS code by John Lane
  *   <starfry at users.sourceforge.net> (#1197703)
  * Code for remove, add, modify, lookup by David Härdeman
- *   <david at 2gen.com> (#1495763)
+ *   <david at hardeman.nu> (#1495763)
  *
  * This backend uses LDAP person (RFC2256), organizationalPerson (RFC2256)
  * and inetOrgPerson (RFC2798) objects and dn, description, sn, givenname,
@@ -424,7 +424,7 @@
             return false;
         }
 
-        $attributes = array('dn', 'description', 'sn', 'givenname', 'cn', 'mail');
+        $attributes = array('dn', 'description', 'sn', 'givenName', 'cn', 'mail');
 
         if ($singleentry) {
             // ldap_read - search for one single entry
@@ -742,21 +742,25 @@
      *
      */
     function lookup($value, $field=SM_ABOOK_FIELD_NICKNAME) {
+		/* Pick the LDAP attribute to base the search on */
+		switch ($field) {
+			case SM_ABOOK_FIELD_NICKNAME:
+				$attr = 'cn';
+			case SM_ABOOK_FIELD_FIRSTNAME:
+				$attr = 'givenName';
+			case SM_ABOOK_FIELD_LASTNAME:
+				$attr = 'sn';
+			case SM_ABOOK_FIELD_EMAIL:
+				$attr = 'mail';
+			case SM_ABOOK_FIELD_LABEL:
+				$attr = 'description';
+			default:
+				return $this->set_error('Invalid LDAP lookup field');
+		}
 
-//FIXME: implement lookup by other fields
-        if ($field != SM_ABOOK_FIELD_NICKNAME)
-            return $this->set_error('LDAP lookup of fields other than nickname/alias not yet implemented');
-
-        /* Generate the dn and try to retrieve that single entry */
-        $cn = $this->quotevalue($value);
-        $dn = 'cn=' . $cn . ',' . $this->basedn;
-
-        /* Do the search */
-        $result = $this->ldap_search($dn, true);
-        if (!is_array($result) || count($result) < 1)
-            return array();
-
-        return $result[0];
+        /* Generate the dn and retrieve all matching entries */
+        $dn = $attr . '=' . $this->quotevalue($value);
+        return $this->ldap_search($dn, false);
     }
 
     /**
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.