Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/ldap-errors' into releases/2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 30, 2012
2 parents 1432712 + abff541 commit 4ce1f7e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -17,6 +17,8 @@ XX August 2012
- Zend\Di
- Fixes ArrayDefinition and ClassDefinition hasMethods() methods to return
boolean values.
- Zend\Ldap
- Fixes an error nesting condition
- Zend\Log
- Fixes an issue with Zend\Log\Formatter\Simple whereby it was using a legacy
key ("info") instead of the key standardized upon in ZF2 ("extra").
Expand Down
19 changes: 12 additions & 7 deletions library/Zend/Ldap/Collection/DefaultIterator.php
Expand Up @@ -75,8 +75,9 @@ public function __construct(Ldap\Ldap $ldap, $resultId)
$this->ldap = $ldap;
$this->resultId = $resultId;

$resource = $ldap->getResource();
ErrorHandler::start();
$this->itemCount = ldap_count_entries($ldap->getResource(), $resultId);
$this->itemCount = ldap_count_entries($resource, $resultId);
ErrorHandler::stop();
if ($this->itemCount === false) {
throw new Exception\LdapException($this->ldap, 'counting entries');
Expand Down Expand Up @@ -199,16 +200,17 @@ public function current()
$entry = array('dn' => $this->key());
$ber_identifier = null;

$resource = $this->ldap->getResource();
ErrorHandler::start();
$name = ldap_first_attribute(
$this->ldap->getResource(), $this->current,
$resource, $this->current,
$ber_identifier
);
ErrorHandler::stop();

while ($name) {
ErrorHandler::start();
$data = ldap_get_values_len($this->ldap->getResource(), $this->current, $name);
$data = ldap_get_values_len($resource, $this->current, $name);
ErrorHandler::stop();

if (!$data) {
Expand Down Expand Up @@ -237,7 +239,7 @@ public function current()

ErrorHandler::start();
$name = ldap_next_attribute(
$this->ldap->getResource(), $this->current,
$resource, $this->current,
$ber_identifier
);
ErrorHandler::stop();
Expand All @@ -259,8 +261,9 @@ public function key()
$this->rewind();
}
if (is_resource($this->current)) {
$resource = $this->ldap->getResource();
ErrorHandler::start();
$currentDn = ldap_get_dn($this->ldap->getResource(), $this->current);
$currentDn = ldap_get_dn($resource, $this->current);
ErrorHandler::stop();

if ($currentDn === false) {
Expand All @@ -285,8 +288,9 @@ public function next()
$code = 0;

if (is_resource($this->current) && $this->itemCount > 0) {
$resource = $this->ldap->getResource();
ErrorHandler::start();
$this->current = ldap_next_entry($this->ldap->getResource(), $this->current);
$this->current = ldap_next_entry($resource, $this->current);
ErrorHandler::stop();
if ($this->current === false) {
$msg = $this->ldap->getLastError($code);
Expand All @@ -312,8 +316,9 @@ public function next()
public function rewind()
{
if (is_resource($this->resultId)) {
$resource = $this->ldap->getResource();
ErrorHandler::start();
$this->current = ldap_first_entry($this->ldap->getResource(), $this->resultId);
$this->current = ldap_first_entry($resource, $this->resultId);
ErrorHandler::stop();
if ($this->current === false
&& $this->ldap->getLastErrorCode() > Exception\LdapException::LDAP_SUCCESS
Expand Down
24 changes: 15 additions & 9 deletions library/Zend/Ldap/Ldap.php
Expand Up @@ -927,7 +927,7 @@ public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
}
if ($sort !== null && is_string($sort)) {
ErrorHandler::start(E_WARNING);
$isSorted = ldap_sort($this->getResource(), $search, $sort);
$isSorted = ldap_sort($resource, $search, $sort);
ErrorHandler::stop();
if ($isSorted === false) {
throw new Exception\LdapException($this, 'sorting: ' . $sort);
Expand Down Expand Up @@ -1173,8 +1173,9 @@ public function add($dn, array $entry)
}
}

$resource = $this->getResource();
ErrorHandler::start(E_WARNING);
$isAdded = ldap_add($this->getResource(), $dn->toString(), $entry);
$isAdded = ldap_add($resource, $dn->toString(), $entry);
ErrorHandler::stop();
if ($isAdded === false) {
throw new Exception\LdapException($this, 'adding: ' . $dn->toString());
Expand Down Expand Up @@ -1214,8 +1215,9 @@ public function update($dn, array $entry)
}

if (count($entry) > 0) {
$resource = $this->getResource();
ErrorHandler::start(E_WARNING);
$isModified = ldap_modify($this->getResource(), $dn->toString(), $entry);
$isModified = ldap_modify($resource, $dn->toString(), $entry);
ErrorHandler::stop();
if ($isModified === false) {
throw new Exception\LdapException($this, 'updating: ' . $dn->toString());
Expand Down Expand Up @@ -1271,8 +1273,10 @@ public function delete($dn, $recursively = false)
}
}
}

$resource = $this->getResource();
ErrorHandler::start(E_WARNING);
$isDeleted = ldap_delete($this->getResource(), $dn);
$isDeleted = ldap_delete($resource, $dn);
ErrorHandler::stop();
if ($isDeleted === false) {
throw new Exception\LdapException($this, 'deleting: ' . $dn);
Expand All @@ -1298,14 +1302,15 @@ protected function getChildrenDns($parentDn)
}
$children = array();

$resource = $this->getResource();
ErrorHandler::start(E_WARNING);
$search = ldap_list($this->getResource(), $parentDn, '(objectClass=*)', array('dn'));
$search = ldap_list($resource, $parentDn, '(objectClass=*)', array('dn'));
for (
$entry = ldap_first_entry($this->getResource(), $search);
$entry = ldap_first_entry($resource, $search);
$entry !== false;
$entry = ldap_next_entry($this->getResource(), $entry)
$entry = ldap_next_entry($resource, $entry)
) {
$childDn = ldap_get_dn($this->getResource(), $entry);
$childDn = ldap_get_dn($resource, $entry);
if ($childDn === false) {
ErrorHandler::stop();
throw new Exception\LdapException($this, 'getting dn');
Expand Down Expand Up @@ -1400,8 +1405,9 @@ public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
$newRdn = Dn::implodeRdn(array_shift($newDnParts));
$newParent = Dn::implodeDn($newDnParts);

$resource = $this->getResource();
ErrorHandler::start(E_WARNING);
$isOK = ldap_rename($this->getResource(), $from, $newRdn, $newParent, true);
$isOK = ldap_rename($resource, $from, $newRdn, $newParent, true);
ErrorHandler::stop();
if ($isOK === false) {
throw new Exception\LdapException($this, 'renaming ' . $from . ' to ' . $to);
Expand Down

0 comments on commit 4ce1f7e

Please sign in to comment.