Skip to content

Commit

Permalink
Add searchUsers method to LDAP storage class
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgelzpz committed Mar 11, 2013
1 parent 83d8e9f commit 6957671
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/Storage/LdapMod.php
Expand Up @@ -379,6 +379,40 @@ public function getUsers($attrlist, $search='*', $multivalued=false) {
}
return $entries;
}

public function searchUsers($attr, $pattern='*') {
$entries = array();
$this->adminBindLdap();
$filter = '('.$this->attributes[$attr].'='.$pattern.')';
$res = @ldap_search($this->ldap, $this->searchBase, $filter, array_values($this->attributes));

if ($res === false) {
// Bad filter
return array();
}

$info = ldap_get_entries($this->ldap, $res);

if($info !== FALSE) {
if($info['count']>0) {
unset($info['count']);
foreach($info as $entry) {
// Take care of case sensitive
$entry = array_change_key_case($entry, CASE_LOWER);
foreach ($this->attributes as $finalattr => $ldapattr) {
$ldapattr_lc = strtolower($ldapattr);
if (isset($entry[$ldapattr_lc]) &&
$entry[$ldapattr_lc]['count'] > 0) {
unset ($entry[$ldapattr_lc]['count']);
$retattr[$finalattr] = $entry[$ldapattr_lc][0];
}
}
$entries[] = $retattr;
}
}
}
return $entries;
}
}

?>

0 comments on commit 6957671

Please sign in to comment.