From d61908d33bc8a05721b6872746831784e1e4572b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 1 Feb 2018 11:13:08 +0100
Subject: [PATCH] :ambulance: fix(simpleplugin) Fix object renaming when
 mainAttr is SINGLE-VALUE

Fixes object renaming in case the main attribute is single valued, as is
 the case for SUPANN.
Also cancels the save when the rename fails, and show the error
 correctly.

issue #5758
---
 include/class_ldap.inc                      | 3 ++-
 include/simpleplugin/class_simplePlugin.inc | 4 +++-
 include/simpleplugin/class_simpleTabs.inc   | 5 +++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index 200d76289..234fc2ded 100644
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
@@ -588,7 +588,8 @@ class LDAP
       if ($this->reconnect) {
         $this->connect();
       }
-      $r = ldap_rename($this->cid, $source, $dest_rdn, $parent, FALSE);
+      /* We have to pass TRUE as deleteoldrdn in case the attribute is single-valued */
+      $r = ldap_rename($this->cid, $source, $dest_rdn, $parent, TRUE);
       $this->error = ldap_error($this->cid);
 
       /* Check if destination dn exists, if not the
diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc
index 471662414..2fc769a08 100644
--- a/include/simpleplugin/class_simplePlugin.inc
+++ b/include/simpleplugin/class_simplePlugin.inc
@@ -576,6 +576,8 @@ class simplePlugin
     * \param  string  $src_dn the source DN.
     *
     * \param  string  $dst_dn the destination DN.
+    *
+    * \return TRUE on success, error string on failure
     */
   function move($src_dn, $dst_dn)
   {
@@ -595,7 +597,7 @@ class simplePlugin
         "FROM: $src_dn  -- TO: $dst_dn", array(), $ldap->get_error());
       @DEBUG(DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__, "Rename failed FROM: $src_dn  -- TO:  $dst_dn",
         'Ldap Protocol v3 implementation error. Error:'.$ldap->get_error());
-      return FALSE;
+      return $ldap->get_error();
     }
 
     /* Update userinfo if necessary */
diff --git a/include/simpleplugin/class_simpleTabs.inc b/include/simpleplugin/class_simpleTabs.inc
index 54f624603..bfe432fd5 100644
--- a/include/simpleplugin/class_simpleTabs.inc
+++ b/include/simpleplugin/class_simpleTabs.inc
@@ -394,10 +394,11 @@ class simpleTabs
         /* use the new one */
         $this->dn = $new_dn;
       } else {
-        if ($baseobject->move($this->dn, $new_dn)) {
+        if (($error = $baseobject->move($this->dn, $new_dn)) === TRUE) {
           $this->dn = $new_dn;
         } else {
-          $errors[] = sprintf(_('Move from "%s" to "%s" failed'), $this->dn, $new_dn);
+          $errors[] = sprintf(_('Move from "%s" to "%s" failed: %s'), $this->dn, $new_dn, $error);
+          return $errors;
         }
       }
     }
-- 
GitLab