function LdapServerTest::bind in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 7.2 ldap_test/LdapServerTest.class.php \LdapServerTest::bind()
- 7 ldap_servers/tests/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_test/
LdapServerTest.class.php, line 81 - Simpletest ldapServer class for testing without an actual ldap server
Class
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->entries[$userdn])) {
$ldap_errno = LDAP_NO_SUCH_OBJECT;
// 0x20 or 32
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->entries[$userdn]['password'][0]) && $this->entries[$userdn]['password'][0] == $pass && $pass) {
return LDAP_SUCCESS;
}
else {
if (!$pass) {
debug("Simpletest failure for {$userdn}. No password submitted");
}
if (!isset($this->entries[$userdn]['password'][0])) {
debug("Simpletest failure for {$userdn}. No password in entry to test for bind");
debug($this->entries[$userdn]);
}
$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";
}
}
$watchdog_tokens = array(
'%user' => $userdn,
'%errno' => $ldap_errno,
'%error' => $ldap_error,
);
watchdog('ldap', "LDAP bind failure for user %user. Error %errno: %error", $watchdog_tokens);
return $ldap_errno;
}