You are here

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

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

Bind (authenticate) against an active LDAP database.

Parameters

$userdn: The DN to bind against. If NULL, we use $this->binddn

$pass: The password search base. If NULL, we use $this->bindpw

Return value

Result of bind; TRUE if successful, FALSE otherwise.

5 calls to LdapServer::bind()
LdapServer::connectAndBindIfNotAlready in ldap_servers/LdapServer.class.php
LdapServer::createLdapEntry in ldap_servers/LdapServer.class.php
Create ldap entry.
LdapServer::delete in ldap_servers/LdapServer.class.php
Perform an LDAP delete.
LdapServer::search in ldap_servers/LdapServer.class.php
Perform an LDAP search.
LdapServer::__invoke in ldap_servers/LdapServer.class.php
Invoke Method.
1 method overrides LdapServer::bind()
LdapServerTest::bind in ldap_test/LdapServerTest.class.php
Bind (authenticate) against an active LDAP database.

File

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

Class

LdapServer
LDAP Server Class.

Code

public function bind($userdn = NULL, $pass = NULL, $anon_bind = FALSE) {

  // Ensure that we have an active server connection.
  if (!$this->connection) {
    watchdog('ldap_servers', "LDAP bind failure for user %user. Not connected to LDAP server.", [
      '%user' => $userdn,
    ]);
    return LDAP_CONNECT_ERROR;
  }
  if ($anon_bind === FALSE && $userdn === NULL && $pass === NULL && $this->bind_method == LDAP_SERVERS_BIND_METHOD_ANON) {
    $anon_bind = TRUE;
  }
  if ($anon_bind === TRUE) {
    if (@(!ldap_bind($this->connection))) {
      if ($this->detailedWatchdogLog) {
        watchdog('ldap_servers', "LDAP anonymous bind error. Error %errno: %error", [
          '%errno' => ldap_errno($this->connection),
          '%error' => ldap_error($this->connection),
        ]);
      }
      return ldap_errno($this->connection);
    }
  }
  else {
    $userdn = $userdn != NULL ? $userdn : $this->binddn;
    $pass = $pass != NULL ? $pass : $this->bindpw;
    if ($this->followrefs) {
      $rebHandler = new LdapServersRebindHandler($userdn, $pass);
      ldap_set_rebind_proc($this->connection, [
        $rebHandler,
        'rebind_callback',
      ]);
    }
    if (drupal_strlen($pass) == 0 || drupal_strlen($userdn) == 0) {
      watchdog('ldap_servers', "LDAP bind failure for user userdn=%userdn, pass=%pass.", [
        '%userdn' => $userdn,
        '%pass' => $pass,
      ]);
      return LDAP_LOCAL_ERROR;
    }
    if (@(!ldap_bind($this->connection, $userdn, $pass))) {
      if ($this->detailedWatchdogLog) {
        watchdog('ldap_servers', "LDAP bind failure for user %user. Error %errno: %error", [
          '%user' => $userdn,
          '%errno' => ldap_errno($this->connection),
          '%error' => ldap_error($this->connection),
        ]);
      }
      return ldap_errno($this->connection);
    }
  }
  return LDAP_SUCCESS;
}