[turba] problem w/ turba/lib/Driver/ldap.php read() function
Gary Windham
windhamg at email.arizona.edu
Fri Dec 5 09:50:01 PST 2003
It appears that the read() method in the Turba LDAP driver doesn't work
properly when passed an array of DNs. I stumbled across this while
trying to add a client link to a Nag task from an LDAP address book
source. If the $dn argument is an array, the read() method attempts to
construct a search filter comprised of the array values, logically ORed.
The 'dn' attribute, at least in the various LDAP servers I've dealt
with, is not a real, "searchable" attribute--to retrieve a single DN
entry, one needs to set the search base to the desired entry's DN.
I've attached a patch for turba/lib/Driver/ldap.php that seems to
resolve this issue.
Thanks,
--
Gary Windham
Systems Programmer, Principal
The University of Arizona, CCIT
-------------- next part --------------
--- ldap.php.orig Fri Dec 5 10:36:22 2003
+++ ldap.php.new Fri Dec 5 10:37:11 2003
@@ -179,15 +179,6 @@
return array();
}
- // Handle a request for multiple records.
- if (is_array($dn)) {
- $criteria = array();
- foreach ($dn as $d) {
- $criteria[] = array('field' => 'dn', 'op' => '=', 'test' => $d);
- }
- return $this->search(array('OR' => $criteria), $fields);
- }
-
$filter = $this->_buildObjectclassFilter();
/* Four11 (at least) doesn't seem to return 'cn' if you don't
@@ -197,6 +188,25 @@
$attr[] = 'sn';
}
+ // Handle a request for multiple records.
+ if (is_array($dn)) {
+ $results = array();
+ foreach ($dn as $d) {
+ $res = @ldap_read($this->_ds, $d, $filter, $attr);
+ if ($res) {
+ if (!is_a($result = $this->getResults($fields, $res), 'PEAR_Error')) {
+ $results = array_merge($results, $result);
+ }
+ else {
+ return $result;
+ }
+ } else {
+ return PEAR::raiseError(sprintf(_("Read failed: (%s) %s"), ldap_errno($this->_ds), ldap_error($this->_ds)));
+ }
+ }
+ return $results;
+ }
+
$res = @ldap_read($this->_ds, $dn, $filter, $attr);
if (!$res) {
return PEAR::raiseError(sprintf(_("Read failed: (%s) %s"), ldap_errno($this->_ds), ldap_error($this->_ds)));
More information about the turba
mailing list