Skip to content

Commit bb262f5

Browse files
authored
Merge pull request #13923 from nextcloud/backport/13865/stable14
[stable14] fix paged search with multiple bases (LDAP)
2 parents 257f9c4 + d77220b commit bb262f5

4 files changed

Lines changed: 52 additions & 7 deletions

File tree

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ services:
11351135
matrix:
11361136
TESTS: acceptance
11371137
openldap:
1138-
image: nextcloudci/openldap:openldap-4
1138+
image: nextcloudci/openldap:openldap-6
11391139
environment:
11401140
- SLAPD_DOMAIN=nextcloud.ci
11411141
- SLAPD_ORGANIZATION=Nextcloud

apps/user_ldap/lib/Access.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,11 @@ private function fetchList($list, $manyAttributes) {
976976
* Executes an LDAP search
977977
*/
978978
public function searchUsers($filter, $attr = null, $limit = null, $offset = null) {
979-
return $this->search($filter, $this->connection->ldapBaseUsers, $attr, $limit, $offset);
979+
$result = [];
980+
foreach($this->connection->ldapBaseUsers as $base) {
981+
$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
982+
}
983+
return $result;
980984
}
981985

982986
/**
@@ -987,7 +991,12 @@ public function searchUsers($filter, $attr = null, $limit = null, $offset = null
987991
* @return false|int
988992
*/
989993
public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) {
990-
return $this->count($filter, $this->connection->ldapBaseUsers, $attr, $limit, $offset);
994+
$result = false;
995+
foreach($this->connection->ldapBaseUsers as $base) {
996+
$count = $this->count($filter, [$base], $attr, $limit, $offset);
997+
$result = is_int($count) ? (int)$result + $count : $result;
998+
}
999+
return $result;
9911000
}
9921001

9931002
/**
@@ -1001,7 +1010,11 @@ public function countUsers($filter, $attr = array('dn'), $limit = null, $offset
10011010
* Executes an LDAP search
10021011
*/
10031012
public function searchGroups($filter, $attr = null, $limit = null, $offset = null) {
1004-
return $this->search($filter, $this->connection->ldapBaseGroups, $attr, $limit, $offset);
1013+
$result = [];
1014+
foreach($this->connection->ldapBaseGroups as $base) {
1015+
$result = array_merge($result, $this->search($filter, [$base], $attr, $limit, $offset));
1016+
}
1017+
return $result;
10051018
}
10061019

10071020
/**
@@ -1013,7 +1026,12 @@ public function searchGroups($filter, $attr = null, $limit = null, $offset = nul
10131026
* @return int|bool
10141027
*/
10151028
public function countGroups($filter, $attr = array('dn'), $limit = null, $offset = null) {
1016-
return $this->count($filter, $this->connection->ldapBaseGroups, $attr, $limit, $offset);
1029+
$result = false;
1030+
foreach($this->connection->ldapBaseGroups as $base) {
1031+
$count = $this->count($filter, [$base], $attr, $limit, $offset);
1032+
$result = is_int($count) ? (int)$result + $count : $result;
1033+
}
1034+
return $result;
10171035
}
10181036

10191037
/**
@@ -1024,7 +1042,12 @@ public function countGroups($filter, $attr = array('dn'), $limit = null, $offset
10241042
* @return int|bool
10251043
*/
10261044
public function countObjects($limit = null, $offset = null) {
1027-
return $this->count('objectclass=*', $this->connection->ldapBase, array('dn'), $limit, $offset);
1045+
$result = false;
1046+
foreach($this->connection->ldapBase as $base) {
1047+
$count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
1048+
$result = is_int($count) ? (int)$result + $count : $result;
1049+
}
1050+
return $result;
10281051
}
10291052

10301053
/**

build/integration/ldap_features/ldap-openldap.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Feature: LDAP
2424
And Sending a "GET" to "/remote.php/webdav/welcome.txt" with requesttoken
2525
Then the HTTP status code should be "200"
2626

27-
Scenario: Test valid configuration with LDAP protoccol and port by logging in
27+
Scenario: Test valid configuration with LDAP protocol and port by logging in
2828
Given modify LDAP configuration
2929
| ldapHost | ldap://openldap:389 |
3030
And cookies are reset

build/integration/ldap_features/openldap-uid-username.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,25 @@ Feature: LDAP
8686
| juliana |
8787
| leo |
8888
| stigur |
89+
90+
Scenario: Fetch from second batch of all users, invoking pagination with two bases
91+
Given modify LDAP configuration
92+
| ldapBaseUsers | ou=PagingTest,dc=nextcloud,dc=ci;ou=PagingTestSecondBase,dc=nextcloud,dc=ci |
93+
| ldapPagingSize | 2 |
94+
And As an "admin"
95+
And sending "GET" to "/cloud/users?limit=10&offset=2"
96+
Then the OCS status code should be "200"
97+
And the "users" result should contain "5" of
98+
| ebba |
99+
| eindis |
100+
| fjolnir |
101+
| gunna |
102+
| juliana |
103+
| leo |
104+
| stigur |
105+
And the "users" result should contain "3" of
106+
| allisha |
107+
| dogukan |
108+
| lloyd |
109+
| priscilla |
110+
| shannah |

0 commit comments

Comments
 (0)