From e6acc84d685860d9e2345af3a07cda2074d92fe8 Mon Sep 17 00:00:00 2001 From: alec Date: Sat, 29 Aug 2009 18:41:17 +0000 Subject: - Fix LDAP contact update when RDN field is changed (#1485788) git-svn-id: https://svn.roundcube.net/trunk@2889 208e9e7b-5314-0410-a742-e7e81cd9613c --- roundcubemail/program/include/rcube_ldap.php | 31 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'roundcubemail/program/include') diff --git a/roundcubemail/program/include/rcube_ldap.php b/roundcubemail/program/include/rcube_ldap.php index 37edca7aa..b13e88395 100644 --- a/roundcubemail/program/include/rcube_ldap.php +++ b/roundcubemail/program/include/rcube_ldap.php @@ -480,32 +480,43 @@ class rcube_ldap extends rcube_addressbook } // end if } // end foreach - // Update the entry as required. $dn = base64_decode($id); + + // Update the entry as required. if (!empty($deletedata)) { // Delete the fields. - $res = ldap_mod_del($this->conn, $dn, $deletedata); - if ($res === FALSE) { + if (!ldap_mod_del($this->conn, $dn, $deletedata)) return false; - } // end if } // end if if (!empty($replacedata)) { + // Handle RDN change + if ($replacedata[$this->prop['LDAP_rdn']]) { + $newdn = $this->prop['LDAP_rdn'].'='.$replacedata[$this->prop['LDAP_rdn']].','.$this->prop['base_dn']; + if ($dn != $newdn) { + $newrdn = $this->prop['LDAP_rdn'].'='.$replacedata[$this->prop['LDAP_rdn']]; + unset($replacedata[$this->prop['LDAP_rdn']]); + } + } // Replace the fields. - $res = ldap_mod_replace($this->conn, $dn, $replacedata); - if ($res === FALSE) { - return false; + if (!empty($replacedata)) { + if (!ldap_mod_replace($this->conn, $dn, $replacedata)) + return false; } // end if } // end if if (!empty($newdata)) { // Add the fields. - $res = ldap_mod_add($this->conn, $dn, $newdata); - if ($res === FALSE) { + if (!ldap_mod_add($this->conn, $dn, $newdata)) return false; - } // end if } // end if + // Handle RDN change + if (!empty($newrdn)) { + if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE)) + return base64_encode($newdn); + } + return true; } -- cgit v1.2.3