You are here

public function LdapServer::ldapQuery in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/LdapServer.class.php \LdapServer::ldapQuery()
  2. 7 ldap_servers/LdapServer.class.php \LdapServer::ldapQuery()

Execute ldap query and return ldap records.

@params see pagedLdapQuery $params

Parameters

scope:

Return value

array of ldap entries

3 calls to LdapServer::ldapQuery()
LdapServer::dnExists in ldap_servers/LdapServer.class.php
Does dn exist for this server?
LdapServer::pagedLdapQuery in ldap_servers/LdapServer.class.php
Execute a paged ldap query and return entries as one aggregated array.
LdapServer::search in ldap_servers/LdapServer.class.php
Perform an LDAP search.

File

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

Class

LdapServer
LDAP Server Class.

Code

public function ldapQuery($scope, $params) {
  $this
    ->connectAndBindIfNotAlready();
  switch ($scope) {
    case LDAP_SCOPE_SUBTREE:
      $result = @ldap_search($this->connection, $params['base_dn'], $params['filter'], $params['attributes'], $params['attrsonly'], $params['sizelimit'], $params['timelimit'], $params['deref']);
      if ($params['sizelimit'] && $this
        ->ldapErrorNumber() == LDAP_SIZELIMIT_EXCEEDED) {

        // False positive error thrown.  do not return result limit error when $sizelimit specified.
      }
      elseif ($this
        ->hasError()) {
        watchdog('ldap_servers', 'ldap_search() function error. LDAP Error: %message, ldap_search() parameters: %query', [
          '%message' => $this
            ->errorMsg('ldap'),
          '%query' => $params['query_display'],
        ], WATCHDOG_ERROR);
      }
      break;
    case LDAP_SCOPE_BASE:
      $result = @ldap_read($this->connection, $params['base_dn'], $params['filter'], $params['attributes'], $params['attrsonly'], $params['sizelimit'], $params['timelimit'], $params['deref']);
      if ($params['sizelimit'] && $this
        ->ldapErrorNumber() == LDAP_SIZELIMIT_EXCEEDED) {

        // False positive error thrown.  do not result limit error when $sizelimit specified.
      }
      elseif ($this
        ->hasError()) {
        watchdog('ldap_servers', 'ldap_read() function error.  LDAP Error: %message, ldap_read() parameters: %query', [
          '%message' => $this
            ->errorMsg('ldap'),
          '%query' => @$params['query_display'],
        ], WATCHDOG_ERROR);
      }
      break;
    case LDAP_SCOPE_ONELEVEL:
      $result = @ldap_list($this->connection, $params['base_dn'], $params['filter'], $params['attributes'], $params['attrsonly'], $params['sizelimit'], $params['timelimit'], $params['deref']);
      if ($params['sizelimit'] && $this
        ->ldapErrorNumber() == LDAP_SIZELIMIT_EXCEEDED) {

        // False positive error thrown.  do not result limit error when $sizelimit specified.
      }
      elseif ($this
        ->hasError()) {
        watchdog('ldap_servers', 'ldap_list() function error. LDAP Error: %message, ldap_list() parameters: %query', [
          '%message' => $this
            ->errorMsg('ldap'),
          '%query' => $params['query_display'],
        ], WATCHDOG_ERROR);
      }
      break;
  }
  return $result;
}