function ldapauth_auth in LDAP integration 5
Same name and namespace in other branches
- 5.2 ldapauth.module \ldapauth_auth()
1 call to ldapauth_auth()
File
- ./
ldapauth.module, line 609
Code
function ldapauth_auth($name, $pass, $server) {
global $ldapauth_ldap;
// Don't allow empty passwords because they cause problems on some setups
// http://drupal.org/node/87831
if (empty($pass)) {
return false;
}
$login_name = $server ? $name . '@' . $server : $name;
if (function_exists('ldapauth_transform_login_name')) {
$login_name = call_user_func('ldapauth_transform_login_name', $login_name);
}
// Cycle through LDAP configurations. First one to succeed wins.
$result = db_query("SELECT name FROM {ldapauth} WHERE status = '%d' ORDER BY sid", 1);
while ($row = db_fetch_object($result)) {
// Initialize LDAP
_ldapauth_init($row->name);
// Get distinguished name
$dn = _ldapauth_login2dn($login_name);
if (empty($dn)) {
continue;
}
// Try to authenticate
if (!$ldapauth_ldap
->connect($dn, $pass)) {
continue;
}
if (function_exists('ldapauth_user_filter') && !call_user_func('ldapauth_user_filter', $ldapauth_ldap
->retrieveAttributes($dn))) {
continue;
}
return true;
}
return false;
}