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

Commit

Permalink
Merge branch 'upstream/master' into module-class-map-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 33 deletions.
63 changes: 49 additions & 14 deletions src/Collection/DefaultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Zend\Ldap;
use Zend\Ldap\Exception;
use Zend\Stdlib\ErrorHandler;

/**
* Zend\Ldap\Collection\DefaultIterator is the default collection iterator implementation
Expand Down Expand Up @@ -57,7 +58,7 @@ class DefaultIterator implements \Iterator, \Countable
/**
* The method that will be applied to the attribute's names.
*
* @var integer|callback
* @var integer|callable
*/
protected $attributeNameTreatment = self::ATTRIBUTE_TO_LOWER;

Expand All @@ -73,7 +74,11 @@ public function __construct(Ldap\Ldap $ldap, $resultId)
{
$this->ldap = $ldap;
$this->resultId = $resultId;
$this->itemCount = @ldap_count_entries($ldap->getResource(), $resultId);

$resource = $ldap->getResource();
ErrorHandler::start();
$this->itemCount = ldap_count_entries($resource, $resultId);
ErrorHandler::stop();
if ($this->itemCount === false) {
throw new Exception\LdapException($this->ldap, 'counting entries');
}
Expand All @@ -93,7 +98,10 @@ public function close()
{
$isClosed = false;
if (is_resource($this->resultId)) {
$isClosed = @ldap_free_result($this->resultId);
ErrorHandler::start();
$isClosed = ldap_free_result($this->resultId);
ErrorHandler::stop();

$this->resultId = null;
$this->current = null;
}
Expand All @@ -120,7 +128,7 @@ public function getLDAP()
* or a valid callback accepting the attribute's name as it's only
* argument and returning the new attribute's name.
*
* @param integer|callback $attributeNameTreatment
* @param integer|callable $attributeNameTreatment
* @return DefaultIterator Provides a fluent interface
*/
public function setAttributeNameTreatment($attributeNameTreatment)
Expand Down Expand Up @@ -155,7 +163,7 @@ public function setAttributeNameTreatment($attributeNameTreatment)
/**
* Returns the currently set attribute name treatment
*
* @return integer|callback
* @return integer|callable
*/
public function getAttributeNameTreatment()
{
Expand Down Expand Up @@ -191,13 +199,27 @@ public function current()

$entry = array('dn' => $this->key());
$ber_identifier = null;
$name = @ldap_first_attribute(
$this->ldap->getResource(), $this->current,

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

while ($name) {
$data = @ldap_get_values_len($this->ldap->getResource(), $this->current, $name);
unset($data['count']);
ErrorHandler::start();
$data = ldap_get_values_len($resource, $this->current, $name);
ErrorHandler::stop();

if (!$data) {
$data = array();
}

if (isset($data['count'])) {
unset($data['count']);
}

switch ($this->attributeNameTreatment) {
case self::ATTRIBUTE_TO_LOWER:
Expand All @@ -214,10 +236,13 @@ public function current()
break;
}
$entry[$attrName] = $data;
$name = @ldap_next_attribute(
$this->ldap->getResource(), $this->current,

ErrorHandler::start();
$name = ldap_next_attribute(
$resource, $this->current,
$ber_identifier
);
ErrorHandler::stop();
}
ksort($entry, SORT_LOCALE_STRING);
return $entry;
Expand All @@ -236,7 +261,11 @@ public function key()
$this->rewind();
}
if (is_resource($this->current)) {
$currentDn = @ldap_get_dn($this->ldap->getResource(), $this->current);
$resource = $this->ldap->getResource();
ErrorHandler::start();
$currentDn = ldap_get_dn($resource, $this->current);
ErrorHandler::stop();

if ($currentDn === false) {
throw new Exception\LdapException($this->ldap, 'getting dn');
}
Expand All @@ -259,7 +288,10 @@ public function next()
$code = 0;

if (is_resource($this->current) && $this->itemCount > 0) {
$this->current = @ldap_next_entry($this->ldap->getResource(), $this->current);
$resource = $this->ldap->getResource();
ErrorHandler::start();
$this->current = ldap_next_entry($resource, $this->current);
ErrorHandler::stop();
if ($this->current === false) {
$msg = $this->ldap->getLastError($code);
if ($code === Exception\LdapException::LDAP_SIZELIMIT_EXCEEDED) {
Expand All @@ -284,7 +316,10 @@ public function next()
public function rewind()
{
if (is_resource($this->resultId)) {
$this->current = @ldap_first_entry($this->ldap->getResource(), $this->resultId);
$resource = $this->ldap->getResource();
ErrorHandler::start();
$this->current = ldap_first_entry($resource, $this->resultId);
ErrorHandler::stop();
if ($this->current === false
&& $this->ldap->getLastErrorCode() > Exception\LdapException::LDAP_SUCCESS
) {
Expand Down
6 changes: 5 additions & 1 deletion src/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use DateTime;
use DateTimeZone;
use Zend\Stdlib\ErrorHandler;

/**
* Zend\Ldap\Converter is a collection of useful LDAP related conversion functions.
Expand Down Expand Up @@ -382,7 +383,10 @@ public static function fromLdapBoolean($value)
*/
public static function fromLdapUnserialize($value)
{
$v = @unserialize($value);
ErrorHandler::start(E_NOTICE);
$v = unserialize($value);
ErrorHandler::stop();

if (false === $v && $value != 'b:0;') {
throw new Exception\UnexpectedValueException('The given value could not be unserialized');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dn.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ public static function checkDn(
* Returns a DN part in the form $attribute = $value
*
* This method supports the creation of multi-valued RDNs
* $part must contain an even number of elemets.
* $part must contain an even number of elements.
*
* @param array $part
* @param string $caseFold
Expand Down
37 changes: 23 additions & 14 deletions src/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
/* Only OpenLDAP 2.2 + supports URLs so if SSL is not requested, just
* use the old form.
*/
$resource = ($useUri) ? @ldap_connect($this->connectString) : @ldap_connect($host, $port);
ErrorHandler::start();
$resource = ($useUri) ? ldap_connect($this->connectString) : ldap_connect($host, $port);
ErrorHandler::stop();

if (is_resource($resource) === true) {
$this->resource = $resource;
Expand All @@ -736,7 +738,7 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls
if ($networkTimeout) {
ldap_set_option($resource, LDAP_OPT_NETWORK_TIMEOUT, $networkTimeout);
}
if ($useSsl || !$useStartTls || @ldap_start_tls($resource)) {
if ($useSsl || !$useStartTls || ldap_start_tls($resource)) {
ErrorHandler::stop();
return $this;
}
Expand Down Expand Up @@ -904,17 +906,18 @@ public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
$filter = $filter->toString();
}

$resource = $this->getResource();
ErrorHandler::start(E_WARNING);
switch ($scope) {
case self::SEARCH_SCOPE_ONE:
$search = ldap_list($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
$search = ldap_list($resource, $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
break;
case self::SEARCH_SCOPE_BASE:
$search = ldap_read($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
$search = ldap_read($resource, $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
break;
case self::SEARCH_SCOPE_SUB:
default:
$search = ldap_search($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
$search = ldap_search($resource, $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
break;
}
ErrorHandler::stop();
Expand All @@ -924,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 @@ -1170,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 @@ -1211,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 @@ -1268,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 @@ -1295,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 @@ -1397,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
2 changes: 1 addition & 1 deletion src/Node/Schema/ObjectClass/OpenLdap.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getParentClasses()
}

/**
* Returns the parent object classes in the inhertitance tree if one exists
* Returns the parent object classes in the inheritance tree if one exists
*
* @return array of OpenLdap
*/
Expand Down
2 changes: 1 addition & 1 deletion test/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function assertLocalDateTimeString($timestamp, $value)
{
$tsValue = date('YmdHisO', $timestamp);

if(date('O', strtotime('20120101'))) {
if (date('O', strtotime('20120101'))) {
// Local timezone is +0000 when DST is off. Zend_Ldap converts
// +0000 to "Z" (see Zend\Ldap\Converter\Converter:toLdapDateTime()), so
// take account of that here
Expand Down
2 changes: 1 addition & 1 deletion test/Node/OfflineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function assertLocalDateTimeString($timestamp, $value)
{
$tsValue = date('YmdHisO', $timestamp);

if(date('O', strtotime('20120101'))) {
if (date('O', strtotime('20120101'))) {
// Local timezone is +0000 when DST is off. Zend_Ldap converts
// +0000 to "Z" (see Zend\Ldap\Converter\Converter:toLdapDateTime()), so
// take account of that here
Expand Down

0 comments on commit 1a68958

Please sign in to comment.