Skip to content

Commit 7b72d0b

Browse files
authored
Merge pull request #21130 from nextcloud/backport/21123/stable17
[stable17] simplify getGroups, fixing wrong chunking logic
2 parents e8ffefd + f1cf05a commit 7b72d0b

File tree

1 file changed

+7
-50
lines changed

1 file changed

+7
-50
lines changed

apps/user_ldap/lib/Group_LDAP.php

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,16 +1001,19 @@ public function countUsersInGroup($gid, $search = '') {
10011001
}
10021002

10031003
/**
1004-
* get a list of all groups
1004+
* get a list of all groups using a paged search
10051005
*
10061006
* @param string $search
1007-
* @param $limit
1007+
* @param int $limit
10081008
* @param int $offset
10091009
* @return array with group names
10101010
*
1011-
* Returns a list with all groups (used by getGroups)
1011+
* Returns a list with all groups
1012+
* Uses a paged search if available to override a
1013+
* server side search limit.
1014+
* (active directory has a limit of 1000 by default)
10121015
*/
1013-
protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
1016+
public function getGroups($search = '', $limit = -1, $offset = 0) {
10141017
if(!$this->enabled) {
10151018
return array();
10161019
}
@@ -1043,52 +1046,6 @@ protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
10431046
return $ldap_groups;
10441047
}
10451048

1046-
/**
1047-
* get a list of all groups using a paged search
1048-
*
1049-
* @param string $search
1050-
* @param int $limit
1051-
* @param int $offset
1052-
* @return array with group names
1053-
*
1054-
* Returns a list with all groups
1055-
* Uses a paged search if available to override a
1056-
* server side search limit.
1057-
* (active directory has a limit of 1000 by default)
1058-
*/
1059-
public function getGroups($search = '', $limit = -1, $offset = 0) {
1060-
if(!$this->enabled) {
1061-
return array();
1062-
}
1063-
$search = $this->access->escapeFilterPart($search, true);
1064-
$pagingSize = (int)$this->access->connection->ldapPagingSize;
1065-
if ($pagingSize <= 0) {
1066-
return $this->getGroupsChunk($search, $limit, $offset);
1067-
}
1068-
$maxGroups = 100000; // limit max results (just for safety reasons)
1069-
if ($limit > -1) {
1070-
$overallLimit = min($limit + $offset, $maxGroups);
1071-
} else {
1072-
$overallLimit = $maxGroups;
1073-
}
1074-
$chunkOffset = $offset;
1075-
$allGroups = array();
1076-
while ($chunkOffset < $overallLimit) {
1077-
$chunkLimit = min($pagingSize, $overallLimit - $chunkOffset);
1078-
$ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset);
1079-
$nread = count($ldapGroups);
1080-
\OCP\Util::writeLog('user_ldap', 'getGroups('.$search.'): read '.$nread.' at offset '.$chunkOffset.' (limit: '.$chunkLimit.')', ILogger::DEBUG);
1081-
if ($nread) {
1082-
$allGroups = array_merge($allGroups, $ldapGroups);
1083-
$chunkOffset += $nread;
1084-
}
1085-
if ($nread < $chunkLimit) {
1086-
break;
1087-
}
1088-
}
1089-
return $allGroups;
1090-
}
1091-
10921049
/**
10931050
* @param string $group
10941051
* @return bool

0 commit comments

Comments
 (0)