You are here

public static function LdapServer::removeUnchangedAttributes in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/LdapServer.class.php \LdapServer::removeUnchangedAttributes()

given 2 ldap entries, old and new, removed unchanged values to avoid security errors and incorrect date modifieds

Parameters

ldap entry array $new_entry in form <attribute> => <value>:

ldap entry array $old_entry in form <attribute> => array('count' => N, array(<value>,...<value>:

Return value

ldap array with no values that have NOT changed

1 call to LdapServer::removeUnchangedAttributes()
LdapServer::modifyLdapEntry in ldap_servers/LdapServer.class.php
modify attributes of ldap entry

File

ldap_servers/LdapServer.class.php, line 454
Defines server classes and related functions.

Class

LdapServer
LDAP Server Class

Code

public static function removeUnchangedAttributes($new_entry, $old_entry) {
  foreach ($new_entry as $key => $new_val) {
    $old_value = FALSE;
    $key_lcase = drupal_strtolower($key);
    if (isset($old_entry[$key_lcase])) {
      if ($old_entry[$key_lcase]['count'] == 1) {
        $old_value = $old_entry[$key_lcase][0];
        $old_value_is_scalar = TRUE;
      }
      else {
        unset($old_entry[$key_lcase]['count']);
        $old_value = $old_entry[$key_lcase];
        $old_value_is_scalar = FALSE;
      }
    }

    // identical multivalued attributes
    if (is_array($new_val) && is_array($old_value) && count(array_diff($new_val, $old_value)) == 0) {
      unset($new_entry[$key]);
    }
    elseif ($old_value_is_scalar && !is_array($new_val) && drupal_strtolower($old_value) == drupal_strtolower($new_val)) {
      unset($new_entry[$key]);

      // don't change values that aren't changing to avoid false permission constraints
    }
  }
  return $new_entry;
}