You are here

function ldapauth_auth in LDAP integration 5

Same name and namespace in other branches
  1. 5.2 ldapauth.module \ldapauth_auth()
1 call to ldapauth_auth()
_ldapauth_user_authenticate in ./ldapauth.module

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;
}