Skip to content

Commit

Permalink
fix: paged search
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Feb 29, 2024
1 parent aab847c commit 1bbd274
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions lib/LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class LDAP implements ILDAPWrapper {
protected $curFunc = '';
protected $curArgs = [];
private array $pagedSearchControl;
private array $pagedSearchControlResult;

/**
* @param resource $link
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 ?? []);
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/AbstractIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1bbd274

Please sign in to comment.