You are here

function ldapauth_extract_puid in LDAP integration 6

Extracts the puid value from an ldap search result with binary handling

Parameters

Mixed $server The server object or sid:

The drupal user name:

Array $ldap_entry LDAP search or retrieveAttributes result.:

3 calls to ldapauth_extract_puid()
ldapauth_drupal_user_create in includes/ldap.core.inc
Create a new Drupal user from an LDAP user entry with checks to ensure that:
ldapauth_drupal_user_lookup in includes/ldap.core.inc
Map an LDAP user to a Drupal user account if one exists.
_ldapsync_process_entry in ./ldapsync.module
Take an ldap object entry and determine if there is an existing account or a new account needs to be created.

File

includes/ldap.core.inc, line 260
The core functions that ldapauth supplies for submodules. Will be included by default by ldapauth.

Code

function ldapauth_extract_puid($server, $name, $ldap_entry) {
  if (is_numeric($server)) {
    $server = ldapauth_server_load($server);
  }

  // DO NOT CONVERT TO Drupal STRING FUNCTIONS AS CODER SUGGESTS...
  // These are byte operations.
  $puid = $ldap_entry[strtolower($server->puid_attr)][0];
  if ($puid && $server->binary_puid) {
    if (strlen($puid) == 16) {

      // Assume a binary GUID ala MS
      $hex_string = bin2hex($puid);

      // (MS?) GUID are displayed with first three GUID parts as "big endian"
      // Doing this so String value matches what other LDAP tool displays for AD.
      $puid = strtoupper(substr($hex_string, 6, 2) . substr($hex_string, 4, 2) . substr($hex_string, 2, 2) . substr($hex_string, 0, 2) . '-' . substr($hex_string, 10, 2) . substr($hex_string, 8, 2) . '-' . substr($hex_string, 14, 2) . substr($hex_string, 12, 2) . '-' . substr($hex_string, 16, 4) . '-' . substr($hex_string, 20, 12));
    }
    else {
      $puid = bin2hex($puid);
    }
  }
  if (empty($puid)) {

    // Give other modules a chance to create a puid if needed.
    drupal_alter('ldap_user_puid', $puid, $name, $ldap_entry['dn'], $server->sid);
  }
  return $puid;
}