diff --git a/lib/LDAP.php b/lib/LDAP.php index 711281de..eeb678d1 100644 --- a/lib/LDAP.php +++ b/lib/LDAP.php @@ -33,7 +33,6 @@ class LDAP implements ILDAPWrapper { protected $curFunc = ''; protected $curArgs = []; private array $pagedSearchControl; - private array $pagedSearchControlResult; /** * @param resource $link @@ -71,8 +70,12 @@ public function connect($host, $port) { * @return bool|LDAP */ public function controlPagedResultResponse($link, $result, &$cookie = null, &$estimated = null) { - $cookie = $this->pagedSearchControlResult['cookie']; - $estimated = $this->pagedSearchControlResult['size']; + $ret = ldap_parse_result($link, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls); + if (!$ret) { + throw new \Exception('ldap_parse_result failed'); + } + $cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? ''; + $estimated = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['size'] ?? ''; return true; } @@ -204,16 +207,13 @@ public function read($link, $baseDN, $filter, $attr) { * @return mixed */ public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0) { - $control = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => $this->pagedSearchControl['pageSize'], 'cookie' => $this->pagedSearchControl['cookie']]]]; - - $result = ldap_search($link, $baseDN, $filter, $attr, $attrsOnly, $limit, -1, 0, $control); - - ldap_parse_result($link, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls); - $cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? ''; - $size = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['size'] ?? ''; - $this->pagedSearchControlResult = compact('cookie', 'size'); + if ($this->pagedSearchControl['pageSize'] > 0) { + $control = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => [ + 'size' => $this->pagedSearchControl['pageSize'], + 'cookie' => $this->pagedSearchControl['cookie']]]]; + } - return $result; + return ldap_search($link, $baseDN, $filter, $attr, $attrsOnly, $limit, -1, 0, $control ?? []); } /** @@ -263,6 +263,9 @@ public function hasPagedResultSupport(): bool { * @return bool true if it is a resource, false otherwise */ public function isResource($resource) { + if ($resource instanceof \LDAP\Connection) { + return true; + } return \is_resource($resource); } diff --git a/tests/integration/AbstractIntegrationTest.php b/tests/integration/AbstractIntegrationTest.php index 181737ed..b77b3855 100644 --- a/tests/integration/AbstractIntegrationTest.php +++ b/tests/integration/AbstractIntegrationTest.php @@ -22,13 +22,13 @@ namespace OCA\User_LDAP\Tests\Integration; -use Exception; use OC; use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; use OCA\User_LDAP\Configuration; use OCA\User_LDAP\LDAP; use OCA\User_LDAP\User\Manager; +use Throwable; use function get_class_methods; use function strpos; @@ -164,7 +164,7 @@ private function runTest(string $method): void { print(PHP_EOL . '>>> !!! Test ' . $method . ' FAILED !!! <<<' . PHP_EOL . PHP_EOL); exit(1); } - } catch (Exception $ex) { + } catch (Throwable $ex) { print(PHP_EOL . '>>> !!! Test ' . $method . ' FAILED !!! <<<' . PHP_EOL . PHP_EOL); print((string)$ex); exit(1);