You are here

function ldap_servers_get_first_rdn_value_from_dn in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/ldap_servers.module \ldap_servers_get_first_rdn_value_from_dn()

Given a dn (such as cn=jdoe,ou=people) and an rdn (such as cn) determine that rdn value (such as jdoe)

Parameters

string $dn:

string $rdn:

Return value

string value of rdn

2 calls to ldap_servers_get_first_rdn_value_from_dn()
LdapServer::groupMembershipsFromEntryRecursive in ldap_servers/LdapServer.class.php
Recurse through all groups, adding parent groups to $all_group_dns array.
LdapServer::groupUserMembershipsFromUserAttr in ldap_servers/LdapServer.class.php
Get list of all groups that a user is a member of by using memberOf attribute first, then if nesting is true, using group entries to find parent groups.

File

ldap_servers/ldap_servers.module, line 1022

Code

function ldap_servers_get_first_rdn_value_from_dn($dn, $rdn) {

  // Escapes attribute values, need to be unescaped later.
  $pairs = ldap_explode_dn($dn, 0);
  $count = array_shift($pairs);
  $rdn = drupal_strtolower($rdn);
  $rdn_value = FALSE;
  foreach ($pairs as $p) {
    $pair = explode('=', $p);
    if (drupal_strtolower(trim($pair[0])) == $rdn) {
      $rdn_value = ldap_pear_unescape_dn_value(trim($pair[1]));
      break;
    }
  }
  return $rdn_value;
}