fix limit-flaw in search on paged results

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2017-09-11 12:10:32 +02:00 committed by Morris Jobke
parent 7698781a1e
commit 89f4e16cdb
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
2 changed files with 17 additions and 12 deletions

View File

@ -1149,9 +1149,9 @@ class Access extends LDAPUtility implements IUserTools {
* @return array with the search result * @return array with the search result
*/ */
public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { public function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
if($limit <= 0) { $limitPerPage = intval($this->connection->ldapPagingSize);
//otherwise search will fail if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
$limit = null; $limitPerPage = $limit;
} }
/* ++ Fixing RHDS searches with pages with zero results ++ /* ++ Fixing RHDS searches with pages with zero results ++
@ -1163,7 +1163,7 @@ class Access extends LDAPUtility implements IUserTools {
$findings = array(); $findings = array();
$savedoffset = $offset; $savedoffset = $offset;
do { do {
$search = $this->executeSearch($filter, $base, $attr, $limit, $offset); $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
if($search === false) { if($search === false) {
return array(); return array();
} }
@ -1174,7 +1174,7 @@ class Access extends LDAPUtility implements IUserTools {
//i.e. result do not need to be fetched, we just need the cookie //i.e. result do not need to be fetched, we just need the cookie
//thus pass 1 or any other value as $iFoundItems because it is not //thus pass 1 or any other value as $iFoundItems because it is not
//used //used
$this->processPagedSearchStatus($sr, $filter, $base, 1, $limit, $this->processPagedSearchStatus($sr, $filter, $base, 1, $limitPerPage,
$offset, $pagedSearchOK, $offset, $pagedSearchOK,
$skipHandling); $skipHandling);
return array(); return array();
@ -1185,10 +1185,10 @@ class Access extends LDAPUtility implements IUserTools {
} }
$continue = $this->processPagedSearchStatus($sr, $filter, $base, $findings['count'], $continue = $this->processPagedSearchStatus($sr, $filter, $base, $findings['count'],
$limit, $offset, $pagedSearchOK, $limitPerPage, $offset, $pagedSearchOK,
$skipHandling); $skipHandling);
$offset += $limit; $offset += $limitPerPage;
} while ($continue && $pagedSearchOK && $findings['count'] < $limit); } while ($continue && $pagedSearchOK && ($limit === null || $findings['count'] < $limit));
// reseting offset // reseting offset
$offset = $savedoffset; $offset = $savedoffset;

View File

@ -47,6 +47,13 @@ class IntegrationTestPaging extends AbstractIntegrationTest {
$this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager()); $this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager());
} }
public function initConnection() {
parent::initConnection();
$this->connection->setConfiguration([
'ldapPagingSize' => 1
]);
}
/** /**
* tests that paging works properly against a simple example (reading all * tests that paging works properly against a simple example (reading all
* of few users in smallest steps) * of few users in smallest steps)
@ -54,20 +61,18 @@ class IntegrationTestPaging extends AbstractIntegrationTest {
* @return bool * @return bool
*/ */
protected function case1() { protected function case1() {
$limit = 1;
$offset = 0; $offset = 0;
$filter = 'objectclass=inetorgperson'; $filter = 'objectclass=inetorgperson';
$attributes = ['cn', 'dn']; $attributes = ['cn', 'dn'];
$users = []; $users = [];
do { do {
$result = $this->access->searchUsers($filter, $attributes, $limit, $offset); $result = $this->access->searchUsers($filter, $attributes, null, $offset);
foreach($result as $user) { foreach($result as $user) {
$users[] = $user['cn']; $users[] = $user['cn'];
} }
$offset += $limit; $offset += count($users);
} while ($this->access->hasMoreResults()); } while ($this->access->hasMoreResults());
if(count($users) === 2) { if(count($users) === 2) {
return true; return true;
} }