diff --git a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2.php b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2.php index 14966ef..aaa7f49 100644 --- a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2.php +++ b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2.php @@ -824,7 +824,7 @@ public function delete($dn, $recursive = false) if ((Net_LDAP2::errorMessage($error_code) === 'LDAP_OPERATIONS_ERROR') && ($this->_config['auto_reconnect'])) { // The server has become disconnected before trying the - // operation. We should try again, possibly with a + // operation. We should try again, possibly with a // different server. $this->_link = false; $this->performReconnect(); @@ -1319,10 +1319,11 @@ public function getEntry($dn, $attr = array()) * @param string|Net_LDAP2_Entry $entry Entry DN or Entry object * @param string $newdn New location * @param Net_LDAP2 $target_ldap (optional) Target directory for cross server move; should be passed via reference + * @param boolean $deleteoldrdn (optional) if false the old RDN value(s) is retained as non-distinguishided values of the entry. * * @return Net_LDAP2_Error|true */ - public function move($entry, $newdn, $target_ldap = null) + public function move($entry, $newdn, $target_ldap = null, $deleteoldrdn = true) { if (is_string($entry)) { $entry_o = $this->getEntry($entry); @@ -1363,7 +1364,7 @@ public function move($entry, $newdn, $target_ldap = null) // local move $entry_o->dn($newdn); $entry_o->setLDAP($this); - return $entry_o->update(); + return $entry_o->update($deleteoldrdn); } } @@ -1744,7 +1745,7 @@ protected function utf8($attributes, $function) * auto_reconnect has been turned on (see the _config array documentation). * * @access public - * @return resource LDAP link + * @return resource|\LDAP\Connection LDAP link (resource on PHP < 8.1) */ public function getLink() { diff --git a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Entry.php b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Entry.php index bd6544a..0008eaa 100644 --- a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Entry.php +++ b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Entry.php @@ -151,7 +151,7 @@ public function __construct($ldap, $entry = null) parent::__construct('Net_LDAP2_Error'); // set up entry resource or DN - if ($entry !== false) { + if (is_resource($entry) || $entry instanceof \LDAP\ResultEntry) { $this->_entry = $entry; } else { $this->_dn = $entry; @@ -161,7 +161,7 @@ public function __construct($ldap, $entry = null) if ($ldap instanceof Net_LDAP2) { $this->_ldap = $ldap; $this->_link = $ldap->getLink(); - } elseif ($ldap !== false) { + } elseif (is_resource($ldap) || $ldap instanceof \LDAP\Connection) { $this->_link = $ldap; } elseif (is_array($ldap)) { // Special case: here $ldap is an array of attributes, @@ -173,7 +173,9 @@ public function __construct($ldap, $entry = null) // if this is an entry existing in the directory, // then set up as old and fetch attrs - if (($this->_entry !== false) && ($this->_link !== false)) { + if ((is_resource($this->_entry) || $this->_entry instanceof \LDAP\ResultEntry) + && (is_resource($this->_link) || $this->_link instanceof \LDAP\Connection) + ) { $this->_new = false; $this->_dn = @ldap_get_dn($this->_link, $this->_entry); $this->setAttributes(); // fetch attributes from server @@ -235,7 +237,7 @@ public static function createConnected($ldap, $entry) if (!$ldap instanceof Net_LDAP2) { return PEAR::raiseError("Unable to create connected entry: Parameter \$ldap needs to be a Net_LDAP2 object!"); } - if ($entry == false) { + if (!is_resource($entry) && !$entry instanceof \LDAP\ResultEntry) { return PEAR::raiseError("Unable to create connected entry: Parameter \$entry needs to be a ldap entry resource!"); } @@ -354,7 +356,10 @@ protected function setAttributes($attributes = null) /* * fetch attributes from the server */ - if (is_null($attributes) && ($this->_entry !== false) && ($this->_link !== false)) { + if (is_null($attributes) + && (is_resource($this->_entry) || $this->_entry instanceof \LDAP\ResultEntry) + && (is_resource($this->_link) || $this->_link instanceof \LDAP\Connection) + ) { // fetch schema if ($this->_ldap instanceof Net_LDAP2) { $schema = $this->_ldap->schema(); @@ -489,7 +494,7 @@ public function getValue($attr, $option = null) $value = array_shift($value); } } - + } return $value; @@ -744,13 +749,14 @@ public function replace($attr = array(), $force = false) * Remove the entry from the server and readd it as new in such cases. * This also will deal with problems with setting structural object classes. * - * @param Net_LDAP2 $ldap If passed, a call to setLDAP() is issued prior update, thus switching the LDAP-server. This is for perl-ldap interface compliance + * @param Net_LDAP2 $ldap If passed, a call to setLDAP() is issued prior update, thus switching the LDAP-server. This is for perl-ldap interface compliance + * @param boolean $deleteoldrdn (optional) if false the old RDN value(s) is retained as non-distinguishided values of the entry. * * @access public * @return true|Net_LDAP2_Error * @todo Entry rename with a DN containing special characters needs testing! */ - public function update($ldap = null) + public function update($deleteoldrdn = true, $ldap = null) { if ($ldap) { $msg = $this->setLDAP($ldap); @@ -767,7 +773,7 @@ public function update($ldap = null) // Get and check link $link = $ldap->getLink(); - if ($link == false) { + if (!is_resource($link) && !$link instanceof \LDAP\Connection) { return PEAR::raiseError("Could not update entry: internal LDAP link is invalid"); } @@ -825,7 +831,7 @@ public function update($ldap = null) $parent = Net_LDAP2_Util::canonical_dn($parent); // rename/move - if (false == @ldap_rename($link, $this->_dn, $child, $parent, false)) { + if (false == @ldap_rename($link, $this->_dn, $child, $parent, $deleteoldrdn)) { return PEAR::raiseError("Entry not renamed: " . @ldap_error($link), @ldap_errno($link)); @@ -850,8 +856,8 @@ public function update($ldap = null) if ($fullEntry->exists($attr)) { $currentValue = $fullEntry->getValue($attr, "all"); $value = array_merge( $currentValue, $value ); - } - + } + $modifications[$attr] = $value; } @@ -864,7 +870,7 @@ public function update($ldap = null) if (!is_array($value)) { $value = array($value); } - + // Find out what is missing from $value and exclude it $currentValue = isset($modifications[$attr]) ? $modifications[$attr] : $fullEntry->getValue($attr, "all"); $modifications[$attr] = array_values( array_diff( $currentValue, $value ) ); diff --git a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Search.php b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Search.php index f91681b..794307c 100644 --- a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Search.php +++ b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Search.php @@ -189,6 +189,11 @@ public function shiftEntry() } $entry = Net_LDAP2_Entry::createConnected($this->_ldap, $this->_entry); if ($entry instanceof PEAR_Error) $entry = false; + + } else if ($this->_entry === false) { + //no more results + return false; + } else { if (!$this->_entry = @ldap_next_entry($this->_link, $this->_entry)) { $false = false; @@ -498,7 +503,9 @@ public function getErrorCode() */ public function _Net_LDAP2_Search() { - @ldap_free_result($this->_search); + if ($this->_search !== false) { + @ldap_free_result($this->_search); + } } /** diff --git a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Util.php b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Util.php index 87525e6..bb8ec84 100644 --- a/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Util.php +++ b/lib/pear-pear.php.net/net_ldap2/Net/LDAP2/Util.php @@ -409,7 +409,7 @@ public static function canonical_dn($dn, $options = array('casefold' => 'upper', // escaping of dn-value $val = self::escape_dn_value(array($val)); - $val = str_replace('/', '\/', $val[0]); + $val = str_replace('/', '\\2f', $val[0]); $dn[$pos] = $ocl.'='.$val; }