Writing 0, NULL or empty value into a LDAP will delete the attribute and doesn't check if the delete was done.

Based on this issue http://us2.php.net/manual/fr/function.ldap-mod-del.php#9706 , the fields without EQUALITY definition cannot be changed

The LDAP error: "Inappropriate Matching".

For fixing I changed the method writeAttributes from LDAPInterface class:

function writeAttributes($dn, $attributes) {
  foreach ($attributes as $key => $cur_val) {
    if ($cur_val === '') {
      $old_value = $this->retrieveAttribute($dn, $key);
      if (isset($old_value)) {
        $success = @ldap_mod_del($this->connection, $dn, array($key => $old_value));
      }
      //http://www.php.net/manual/en/function.ldap-mod-del.php#9706
      if($success){
        unset($attributes[$key]);
      }
    }
    //Encodes password for use in Active Directory // http://drupal.org/node/339821
    if ($key == "unicodePwd") {
      $cur_val = "\"" . $cur_val . "\"";
      $attributes[$key] = mb_convert_encoding($cur_val, "UTF-16LE");
    }
    if (is_array ($cur_val)) {
      foreach ($cur_val as $mv_key => $mv_cur_val) {
        if ($mv_cur_val == '') {
          unset($attributes[$key][$mv_key]);
        }
        else {
          $attributes[$key][$mv_key] = $mv_cur_val;
        }
      }
    }
  }
  if($attributes){
    return ldap_modify($this->connection, $dn, $attributes);
  }
  return TRUE;
}

Comments

john franklin’s picture

Status: Active » Fixed

Writing zero (0) works. I don't know when the fix was applied, but I can confirm writing zeros to attributes on my sites.

There is no way to write NULL or an empty string to LDAP. LDAP treats no value as no value and removes the attribute.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.