diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-03-20 00:21:51 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-04-09 11:31:56 +0200 |
commit | 40f9875f11e1bd35dd96ebd8fc8cf718be49689c (patch) | |
tree | 6872bbb53790faf76447fbe2b6115e089e871d38 /apps/user_ldap | |
parent | 8bb27551bde2d5aa516f4df2918ca3ed0ccd18b0 (diff) | |
download | nextcloud-server-40f9875f11e1bd35dd96ebd8fc8cf718be49689c.tar.gz nextcloud-server-40f9875f11e1bd35dd96ebd8fc8cf718be49689c.zip |
LDAP: fix user report i.e. count for LDAP servers with really many users
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/access.php | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index b8e7e9bb670..7640a5b1bc0 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -659,7 +659,7 @@ class Access extends LDAPUtility { * @param string $filter */ public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) { - return $this->count($filter, $this->connection->ldapBaseGroups, $attr, $limit, $offset); + return $this->count($filter, $this->connection->ldapBaseUsers, $attr, $limit, $offset); } /** @@ -775,22 +775,34 @@ class Access extends LDAPUtility { */ private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); - $search = $this->executeSearch($filter, $base, $attr, $limit, $offset); - if($search === false) { - return false; + + if(is_null($limit)) { + //TODO replace 400 with $this->connection->ldapPagingSize; once PR 6221 is merged and move it to callee countUsers() + $limit = 400; } - list($sr, $pagedSearchOK) = $search; - $cr = $this->connection->getConnectionResource(); + $counter = 0; - foreach($sr as $key => $res) { - $count = $this->ldap->countEntries($cr, $res); - if($count !== false) { - $counter += $count; + $cr = $this->connection->getConnectionResource(); + + do { + $search = $this->executeSearch($filter, $base, $attr, + $limit, $offset); + if($search === false) { + return $counter > 0 ? $counter : false; + } + list($sr, $pagedSearchOK) = $search; + + foreach($sr as $key => $res) { + $count = $this->ldap->countEntries($cr, $res); + if($count !== false) { + $counter += $count; + } } - } - $this->processPagedSearchStatus($sr, $filter, $base, $counter, $limit, + $this->processPagedSearchStatus($sr, $filter, $base, $count, $limit, $offset, $pagedSearchOK, $skipHandling); + $offset += $limit; + } while($count === $limit); return $counter; } @@ -891,7 +903,7 @@ class Access extends LDAPUtility { //we slice the findings, when //a) paged search insuccessful, though attempted //b) no paged search, but limit set - if((!$this->pagedSearchedSuccessful + if((!$this->getPagedSearchResultState() && $pagedSearchOK) || ( !$pagedSearchOK |