diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-06-06 09:45:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-06 09:45:58 +0200 |
commit | 789adb9fa9cf9be3d1ec21758ff6b1f7a57d10b8 (patch) | |
tree | 2446fc20cc9c14c6a03da198d0304b6fc077e800 | |
parent | 3d1273d2f288902b56c5377c11290626f4b88d9e (diff) | |
parent | 5f1cfbc4acbfc2fef12ab894d67fcb5892520b3f (diff) | |
download | nextcloud-server-789adb9fa9cf9be3d1ec21758ff6b1f7a57d10b8.tar.gz nextcloud-server-789adb9fa9cf9be3d1ec21758ff6b1f7a57d10b8.zip |
Merge pull request #21129 from nextcloud/backport/21123/stable18
[stable18] simplify getGroups, fixing wrong chunking logic
-rw-r--r-- | apps/user_ldap/lib/Group_LDAP.php | 57 |
1 files changed, 7 insertions, 50 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index bdcf9be8d3d..b369842d847 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -1002,16 +1002,19 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD } /** - * get a list of all groups + * get a list of all groups using a paged search * * @param string $search - * @param $limit + * @param int $limit * @param int $offset * @return array with group names * - * Returns a list with all groups (used by getGroups) + * Returns a list with all groups + * Uses a paged search if available to override a + * server side search limit. + * (active directory has a limit of 1000 by default) */ - protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) { + public function getGroups($search = '', $limit = -1, $offset = 0) { if(!$this->enabled) { return array(); } @@ -1045,52 +1048,6 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD } /** - * get a list of all groups using a paged search - * - * @param string $search - * @param int $limit - * @param int $offset - * @return array with group names - * - * Returns a list with all groups - * Uses a paged search if available to override a - * server side search limit. - * (active directory has a limit of 1000 by default) - */ - public function getGroups($search = '', $limit = -1, $offset = 0) { - if(!$this->enabled) { - return array(); - } - $search = $this->access->escapeFilterPart($search, true); - $pagingSize = (int)$this->access->connection->ldapPagingSize; - if ($pagingSize <= 0) { - return $this->getGroupsChunk($search, $limit, $offset); - } - $maxGroups = 100000; // limit max results (just for safety reasons) - if ($limit > -1) { - $overallLimit = min($limit + $offset, $maxGroups); - } else { - $overallLimit = $maxGroups; - } - $chunkOffset = $offset; - $allGroups = array(); - while ($chunkOffset < $overallLimit) { - $chunkLimit = min($pagingSize, $overallLimit - $chunkOffset); - $ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset); - $nread = count($ldapGroups); - \OCP\Util::writeLog('user_ldap', 'getGroups('.$search.'): read '.$nread.' at offset '.$chunkOffset.' (limit: '.$chunkLimit.')', ILogger::DEBUG); - if ($nread) { - $allGroups = array_merge($allGroups, $ldapGroups); - $chunkOffset += $nread; - } - if ($nread < $chunkLimit) { - break; - } - } - return $allGroups; - } - - /** * @param string $group * @return bool */ |