[bugs] [Bug 1286] Changed - renaming an entry when using openLDAP 2.1.x fails to succeed.

bugs at bugs.horde.org bugs at bugs.horde.org
Tue Jun 17 13:30:01 PDT 2003


http://bugs.horde.org/show_bug.cgi?id=1286

*** shadow/1286	Tue Jun 17 16:55:28 2003
--- shadow/1286.tmp.21362	Tue Jun 17 17:30:01 2003
***************
*** 151,153 ****
--- 151,249 ----
  There is no way to notify the Application that the driver has renamed the KEY
  (for the LDAP backend driver this is the DN of the entry)
  
+ 
+ ------- Additional Comments From urkle at drip.ws  06/17/03 17:30 -------
+ Patch #2 for CVS that fixes the key changing issue.
+ Index: lib/AbstractObject.php
+ ===================================================================
+ RCS file: /repository/turba/lib/AbstractObject.php,v
+ retrieving revision 1.20
+ diff -u -3 -p -r1.20 AbstractObject.php
+ --- lib/AbstractObject.php	18 Feb 2003 05:08:48 -0000	1.20
+ +++ lib/AbstractObject.php	17 Jun 2003 20:27:17 -0000
+ @@ -132,7 +132,7 @@ class Turba_AbstractObject {
+       */
+      function store()
+      {
+ -        return $this->source->setObject($this);
+ +        return $this->source->setObject(&$this);
+      }
+  
+  }
+ Index: lib/Source.php
+ ===================================================================
+ RCS file: /repository/turba/lib/Source.php,v
+ retrieving revision 1.59
+ diff -u -3 -p -r1.59 Source.php
+ --- lib/Source.php	18 Feb 2003 05:47:20 -0000	1.59
+ +++ lib/Source.php	17 Jun 2003 20:27:17 -0000
+ @@ -323,7 +323,13 @@ class Turba_Source {
+          $attributes = $this->toDriverKeys($object->getAttributes());
+          list($object_key, $object_id) = each($this->toDriverKeys(array('__key'
+ => $object->getValue('__key'))));
+  
+ -        return $this->driver->setObject($object_key, $object_id, $attributes);
+ +	$retval = $this->driver->setObject($object_key, $object_id, $attributes);
+ +	if (is_string($retval)) { //Key has changed assign the new one in $object
+ +	    $object->setValue('__key',$retval);
+ +	    return true;
+ +	} else {
+ +            return $retval;
+ +	}
+      }
+  
+      /**
+ Index: lib/Driver/ldap.php
+ ===================================================================
+ RCS file: /repository/turba/lib/Driver/ldap.php,v
+ retrieving revision 1.33
+ diff -u -3 -p -r1.33 ldap.php
+ --- lib/Driver/ldap.php	13 Jun 2003 15:21:15 -0000	1.33
+ +++ lib/Driver/ldap.php	17 Jun 2003 20:27:19 -0000
+ @@ -372,8 +372,23 @@ class Turba_Driver_ldap extends Turba_Dr
+                  }
+                  unset($attributes[$lowerkey]);
+              }
+ +	    if (isset($attributes[$lowerkey]) &&
+ + 		($var[0] != $attributes[$lowerkey]) &&
+ + 		$lowerkey == 'cn') {
+ + 		// OK we need to change the CN of the entry
+ + 		// so lets save the old and new name and rename it later
+ + 		$modrdn["olddn"] = $object_id;
+ + 		$modrdn["newdn"] = $attributes["cn"];
+ + 	    }
+          }
+  
+ +	//we can't change the CN (well not supposed to)
+ +	//older LDAP servers allow the CN attribute to be different than
+ +	//the entry in the DN. the LDAPv3 spec specifies that they have to
+ +	// be the same.. note there can be multiple cn entries. but one of 
+ +	// them HAS to be the entry in the DN.
+ +	unset($attributes["cn"]);
+ +
+          // Encode entries.
+          foreach ($attributes as $key => $val) {
+              if (!is_array($val)) {
+ @@ -389,6 +404,19 @@ class Turba_Driver_ldap extends Turba_Dr
+              $this->errstr = ldap_error($this->ds);
+              return false;
+          } else {
+ +	    // ok the modify passed now lets rename the DN if we need to
+ +	    if (isset($modrdn)) {
+ +		$modrdn['newroot'] = substr($modrdn['olddn'],strpos($modrdn['olddn'],",")+1);
+ +		$modrdn['newdn'] = "cn=".$modrdn['newdn'];
+ +		if
+ (@ldap_rename($this->ds,$modrdn['olddn'],$modrdn['newdn'],$modrdn['newroot'],true))
+ {
+ +		    // return new Key
+ +		    return $modrdn['newdn'].",".$modrdn['newroot'];
+ +		} else {
+ +		    $this->errno = ldap_errno($this->ds);
+ +		    $this->errstr = ldap_error($this->ds);
+ +		    return false;
+ +		}
+ +	    }
+              return true;
+          }
+      }
+ 


More information about the bugs mailing list