summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-31 23:52:46 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-31 23:52:46 +0200
commit9abe372a0aa14187f1a3e098d2f2b7c99f746c09 (patch)
tree0c0a030724acbfee32ae45c57129c377592a945a
parent4b7bcf0bcd74ccfe367fdd12c2f7dbccfc1408c1 (diff)
downloadwebadmin-9abe372a0aa14187f1a3e098d2f2b7c99f746c09.tar.gz
Only replace attributes that are not empty.
Delete attributes that are empty.
-rw-r--r--lib/Auth/LDAP.php38
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 2a26c0a..506e3e5 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -401,8 +401,13 @@ class LDAP
if ($attr === $rdn_attr) {
$mod_array['rename'][$subject_dn] = $rdn_attr . '=' . $new_attrs[$attr];
} else {
- console("Adding to replace: $attr");
- $mod_array['replace'][$attr] = (array)($new_attrs[$attr]);
+ if (empty($new_attrs[$attr])) {
+ console("Adding to del: $attr");
+ $mod_array['del'][$attr] = (array)($old_attr_value);
+ } else {
+ console("Adding to replace: $attr");
+ $mod_array['replace'][$attr] = (array)($new_attrs[$attr]);
+ }
}
} else {
console("Attribute $attr unchanged");
@@ -416,14 +421,23 @@ class LDAP
foreach ($new_attrs as $attr => $value) {
if (array_key_exists($attr, $old_attrs)) {
- if (!($old_attrs[$attr] === $value) && !($attr === $rdn_attr)) {
- if (!array_key_exists($attr, $mod_array['replace'])) {
- console("Adding to replace(2): $attr");
- $mod_array['replace'][$attr] = $value;
+ if (empty($value)) {
+ if (!array_key_exists($attr, $mod_array['del'])) {
+ console("Adding to del(2): $attr");
+ $mod_array['del'][$attr] = (array)($old_attrs[$attr]);
+ }
+ } else {
+ if (!($old_attrs[$attr] === $value) && !($attr === $rdn_attr)) {
+ if (!array_key_exists($attr, $mod_array['replace'])) {
+ console("Adding to replace(2): $attr");
+ $mod_array['replace'][$attr] = $value;
+ }
}
}
} else {
- $mod_array['add'][$attr] = $value;
+ if (!empty($value)) {
+ $mod_array['add'][$attr] = $value;
+ }
}
}
@@ -453,6 +467,16 @@ class LDAP
return false;
}
+ if (is_array($attributes['del']) && !empty($attributes['del'])) {
+ $result = ldap_mod_del($this->conn, $subject_dn, $attributes['del']);
+ }
+
+ if (!$result) {
+ console("Failed to delete the following attributes", $attributes['del']);
+ return false;
+ }
+
+
if (is_array($attributes['add']) && !empty($attributes['add'])) {
$result = ldap_mod_add($this->conn, $subject_dn, $attributes['add']);
}