You are here

function ldaphelp_ldap_user_verify in LDAP integration 6

Verify that a user can be found from the Drupal account information.

Parameters

int $sid The server id to look on:

string $dn The user's dn from the account data.:

string $puid The user's PUID or NULL if not using PUIDs.:

1 call to ldaphelp_ldap_user_verify()
ldaphelp_users_list in ldaphelp/ldaphelp.module
Generate a list of all Drupal users marked as ldap_authentified.

File

ldaphelp/ldaphelp.module, line 485
The ldaphelp module is a module to help admins debug ldap_integration modules.

Code

function ldaphelp_ldap_user_verify($sid, $dn, $puid) {
  global $_ldapauth_ldap;
  static $ldap_sid;

  // Only re init/bind if new server.
  if ($ldap_sid != $sid) {
    $ldap = _ldapauth_init($sid);
    if (!$ldap) {
      return t("LDAP server init failed!");
    }

    // If there is no bindn and bindpw - the connect will be an anonymous connect.
    $success = $ldap
      ->connect($ldap
      ->getOption('binddn'), $ldap
      ->getOption('bindpw'));
    if (!$success) {
      return t("LDAP bind failed!");
    }
    $ldap_sid = $sid;
  }
  else {
    $ldap = $_ldapauth_ldap;
  }
  if ($puid) {
    $puid_dn = ldaphelp_ldap_user_find_by_puid($ldap, $puid);
    if ($puid_dn === FALSE) {
      return t('PUID not unique!');
    }
    elseif ($puid_dn === NULL) {

      //return t('PUID not found');
    }
    elseif (strtolower($puid_dn) != strtolower($dn)) {
      return t('PUID dn does not match - will be corrected next time the user logs in or is synced.');
    }
    else {
      return t('User found by PUID');
    }
  }
  $entry = ldapauth_user_lookup_by_dn($ldap, $dn, LDAPAUTH_SYNC_CONTEXT_AUTHENTICATE_DRUPAL_USER, TRUE);
  if (isset($entry['dn'])) {
    if ($puid) {

      // PUID not found but DN valid
      return t("User found / No PUID set, but will be be set next time this user login in or is synced.");
    }
    return t("User found");
  }
  if ($puid) {

    // PUID not found and DN invalid
    return t("User not found / PUID can not be set for this user!");
  }
  return t("User not found");
}