Skip to content

Commit 2411b62

Browse files
committed
ensure that only valid group members are returned
Signed-off-by: Arthur Schiwon <[email protected]>
1 parent f657ded commit 2411b62

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

apps/user_ldap/lib/Group_LDAP.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ private function getGroupsByMember($dn, &$seen = null) {
812812
* @param int $limit
813813
* @param int $offset
814814
* @return array with user ids
815+
* @throws \Exception
815816
*/
816817
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
817818
if(!$this->enabled) {
@@ -872,17 +873,32 @@ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
872873
$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
873874
} else {
874875
//we got DNs, check if we need to filter by search or we can give back all of them
875-
if ($search !== '') {
876-
if(!$this->access->readAttribute($member,
876+
$uid = $this->access->dn2username($member);
877+
if(!$uid) {
878+
continue;
879+
}
880+
881+
$cacheKey = 'userExistsOnLDAP' . $uid;
882+
$userExists = $this->access->connection->getFromCache($cacheKey);
883+
if($userExists === false) {
884+
continue;
885+
}
886+
if($userExists === null || $search !== '') {
887+
if (!$this->access->readAttribute($member,
877888
$this->access->connection->ldapUserDisplayName,
878-
$this->access->getFilterPartForUserSearch($search))) {
889+
$this->access->combineFilterWithAnd([
890+
$this->access->getFilterPartForUserSearch($search),
891+
$this->access->connection->ldapUserFilter
892+
])))
893+
{
894+
if($search === '') {
895+
$this->access->connection->writeToCache($cacheKey, false);
896+
}
879897
continue;
880898
}
899+
$this->access->connection->writeToCache($cacheKey, true);
881900
}
882-
// dn2username will also check if the users belong to the allowed base
883-
if($ocname = $this->access->dn2username($member)) {
884-
$groupUsers[] = $ocname;
885-
}
901+
$groupUsers[] = $uid;
886902
}
887903
}
888904

0 commit comments

Comments
 (0)