You are here

function ldaphelp_ldap_user_find_by_puid in LDAP integration 6

Lookup a user's ldap entry using the PUID attribute.

Parameters

LDAPInterface $ldap:

String $puid:

Return value

The user dn, NULL if not found, FALSE if not unique

1 call to ldaphelp_ldap_user_find_by_puid()
ldaphelp_ldap_user_verify in ldaphelp/ldaphelp.module
Verify that a user can be found from the Drupal account information.

File

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

Code

function ldaphelp_ldap_user_find_by_puid($ldap, $puid) {
  $sid = $ldap
    ->getOption('sid');
  $filter = ldapauth_puid_filter($sid, $puid);
  $attrs = array();
  foreach (explode("\r\n", $ldap
    ->getOption('basedn')) as $base_dn) {
    if (empty($base_dn)) {
      continue;
    }
    $result = $ldap
      ->search($base_dn, $filter, $attrs);
    if (!$result) {
      continue;
    }
    $num_matches = $result['count'];

    // Must find exactly one user for authentication to.
    if ($num_matches != 1) {
      return FALSE;
    }
    return $result[0]['dn'];
  }
  return NULL;
}