Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 7 additions & 50 deletions apps/user_ldap/lib/Group_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,16 +1015,19 @@ public function countUsersInGroup($gid, $search = '') {
}

/**
* 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 [];
}
Expand Down Expand Up @@ -1057,52 +1060,6 @@ protected function getGroupsChunk($search = '', $limit = -1, $offset = 0) {
return $ldap_groups;
}

/**
* 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 [];
}
$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 = [];
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
Expand Down