Skip to content

Commit 5656185

Browse files
authored
Merge pull request #26797 from nextcloud/backport/26785/stable21
[stable21] LDAP: do not bother to search after the last page
2 parents 7358312 + 4dc4b76 commit 5656185

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

apps/user_ldap/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
'OCA\\User_LDAP\\Events\\UserBackendRegistered' => $baseDir . '/../lib/Events/UserBackendRegistered.php',
3030
'OCA\\User_LDAP\\Exceptions\\AttributeNotSet' => $baseDir . '/../lib/Exceptions/AttributeNotSet.php',
3131
'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => $baseDir . '/../lib/Exceptions/ConstraintViolationException.php',
32+
'OCA\\User_LDAP\\Exceptions\\NoMoreResults' => $baseDir . '/../lib/Exceptions/NoMoreResults.php',
3233
'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => $baseDir . '/../lib/Exceptions/NotOnLDAP.php',
3334
'OCA\\User_LDAP\\FilesystemHelper' => $baseDir . '/../lib/FilesystemHelper.php',
3435
'OCA\\User_LDAP\\GroupPluginManager' => $baseDir . '/../lib/GroupPluginManager.php',

apps/user_ldap/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ComposerStaticInitUser_LDAP
4444
'OCA\\User_LDAP\\Events\\UserBackendRegistered' => __DIR__ . '/..' . '/../lib/Events/UserBackendRegistered.php',
4545
'OCA\\User_LDAP\\Exceptions\\AttributeNotSet' => __DIR__ . '/..' . '/../lib/Exceptions/AttributeNotSet.php',
4646
'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => __DIR__ . '/..' . '/../lib/Exceptions/ConstraintViolationException.php',
47+
'OCA\\User_LDAP\\Exceptions\\NoMoreResults' => __DIR__ . '/..' . '/../lib/Exceptions/NoMoreResults.php',
4748
'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => __DIR__ . '/..' . '/../lib/Exceptions/NotOnLDAP.php',
4849
'OCA\\User_LDAP\\FilesystemHelper' => __DIR__ . '/..' . '/../lib/FilesystemHelper.php',
4950
'OCA\\User_LDAP\\GroupPluginManager' => __DIR__ . '/..' . '/../lib/GroupPluginManager.php',

apps/user_ldap/lib/Access.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OC\Hooks\PublicEmitter;
5353
use OC\ServerNotAvailableException;
5454
use OCA\User_LDAP\Exceptions\ConstraintViolationException;
55+
use OCA\User_LDAP\Exceptions\NoMoreResults;
5556
use OCA\User_LDAP\Mapping\AbstractMapping;
5657
use OCA\User_LDAP\Mapping\UserMapping;
5758
use OCA\User_LDAP\User\Manager;
@@ -264,7 +265,14 @@ public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
264265
* @throws ServerNotAvailableException
265266
*/
266267
public function executeRead($cr, $dn, $attribute, $filter, $maxResults) {
267-
$this->initPagedSearch($filter, $dn, [$attribute], $maxResults, 0);
268+
try {
269+
$this->initPagedSearch($filter, $dn, [$attribute], $maxResults, 0);
270+
} catch (NoMoreResults $e) {
271+
// does not happen, no pagination here since offset is 0, but the
272+
// previous call is needed for a potential reset of the state.
273+
// Tools would still point out a possible NoMoreResults exception.
274+
return false;
275+
}
268276
$dn = $this->helper->DNasBaseParameter($dn);
269277
$rr = @$this->invokeLDAPMethod('read', $cr, $dn, $filter, [$attribute]);
270278
if (!$this->ldap->isResource($rr)) {
@@ -1143,7 +1151,12 @@ private function executeSearch(
11431151
}
11441152

11451153
//check whether paged search should be attempted
1146-
$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, (int)$offset);
1154+
try {
1155+
$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, (int)$offset);
1156+
} catch (NoMoreResults $e) {
1157+
// beyond last results page
1158+
return false;
1159+
}
11471160

11481161
$sr = $this->invokeLDAPMethod('search', $cr, $base, $filter, $attr);
11491162
// cannot use $cr anymore, might have changed in the previous call!
@@ -1996,6 +2009,7 @@ public function getPagedSearchResultState() {
19962009
* @param int $offset
19972010
* @return bool|true
19982011
* @throws ServerNotAvailableException
2012+
* @throws NoMoreResults
19992013
*/
20002014
private function initPagedSearch(
20012015
string $filter,
@@ -2027,7 +2041,7 @@ private function initPagedSearch(
20272041
if (!$this->hasMoreResults()) {
20282042
// when the cookie is reset with != 0 offset, there are no further
20292043
// results, so stop.
2030-
return false;
2044+
throw new NoMoreResults();
20312045
}
20322046
}
20332047
if ($this->lastCookie !== '' && $offset === 0) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2021 Arthur Schiwon <[email protected]>
7+
*
8+
* @author Arthur Schiwon <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\User_LDAP\Exceptions;
28+
29+
class NoMoreResults extends \Exception {
30+
}

0 commit comments

Comments
 (0)