public static function LdapServer::removeUnchangedAttributes in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.2 ldap_servers/LdapServer.class.php \LdapServer::removeUnchangedAttributes()
Compares 2 LDAP entries and returns the difference.
Given 2 ldap entries, old and new, removes unchanged values to avoid security errors and incorrect date modified.
Parameters
array $new_entry: LDAP entry array in form <attribute> => <value>, or <attribute> => array(<value1>, <value2>, ...).
array $old_entry: LDAP entry in form <attribute> => array('count' => N, <value1>, <value2>, ...).
Return value
array The $new_entry with unchanged attributes removed.
See also
\LdapServer::modifyLdapEntry()
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 584 - 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;
$old_value_is_scalar = 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)) {
// don't change values that aren't changing to avoid false permission constraints.
unset($new_entry[$key]);
}
}
return $new_entry;
}