You are here

public function LdapServer::searchAllBaseDns in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/LdapServer.class.php \LdapServer::searchAllBaseDns()

Perform an LDAP search on all base dns and aggregate into one result

@remaining params mimick ldap_search() function params

Parameters

string $filter: The search filter. such as sAMAccountName=jbarclay. attribute values (e.g. jbarclay) should be esacaped before calling

array $attributes: List of desired attributes. If omitted, we only return "dn".

Return value

An array of matching entries->attributes (will have 0 elements if search returns no results), or FALSE on error on any of the basedn queries

File

ldap_servers/LdapServer.class.php, line 607
Defines server classes and related functions.

Class

LdapServer
LDAP Server Class

Code

public function searchAllBaseDns($filter, $attributes = array(), $attrsonly = 0, $sizelimit = 0, $timelimit = 0, $deref = NULL, $scope = LDAP_SCOPE_SUBTREE) {
  $all_entries = array();
  foreach ($this->basedn as $base_dn) {

    // need to search on all basedns one at a time
    $entries = $this
      ->search($base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref, $scope);

    // no attributes, just dns needed
    if ($entries === FALSE) {

      // if error in any search, return false
      return FALSE;
    }
    if (count($all_entries) == 0) {
      $all_entries = $entries;
    }
    else {
      $existing_count = $all_entries['count'];
      unset($entries['count']);
      foreach ($entries as $i => $entry) {
        $all_entries[$existing_count + $i] = $entry;
      }
      $all_entries['count'] = count($all_entries);
    }
  }
  return $all_entries;
}