You are here

function LdapServerTest::bind in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_test/LdapServerTest.class.php \LdapServerTest::bind()
  2. 7.2 ldap_test/LdapServerTest.class.php \LdapServerTest::bind()

* Bind (authenticate) against an active LDAP database. * *

Parameters

$userdn: * The DN to bind against. If NULL, we use $this->binddn * @param $pass * The password search base. If NULL, we use $this->bindpw

Return value

Result of bind; TRUE if successful, FALSE otherwise.

Overrides LdapServer::bind

File

ldap_servers/tests/LdapServerTest.class.php, line 77
Simpletest ldapServer class for testing without an actual ldap server

Class

LdapServerTest

Code

function bind($userdn = NULL, $pass = NULL, $anon_bind = FALSE) {
  $userdn = $userdn != NULL ? $userdn : $this->binddn;
  $pass = $pass != NULL ? $pass : $this->bindpw;
  if (!isset($this->testUsers[$userdn])) {
    $ldap_errno = LDAP_NO_SUCH_OBJECT;
    if (function_exists('ldap_err2str')) {
      $ldap_error = ldap_err2str($ldap_errno);
    }
    else {
      $ldap_error = "Failed to find {$userdn} in LdapServerTest.class.php";
    }
  }
  elseif (isset($this->testUsers[$userdn]['attr']['password'][0]) && $this->testUsers[$userdn]['attr']['password'][0] != $pass) {
    $ldap_errno = LDAP_INVALID_CREDENTIALS;
    if (function_exists('ldap_err2str')) {
      $ldap_error = ldap_err2str($ldap_errno);
    }
    else {
      $ldap_error = "Credentials for {$userdn} failed in LdapServerTest.class.php";
    }
  }
  else {
    return LDAP_SUCCESS;
  }
  debug(t("LDAP bind failure for user %user. Error %errno: %error", array(
    '%user' => $userdn,
    '%errno' => $ldap_errno,
    '%error' => $ldap_error,
  )));
  return $ldap_errno;
}