Skip to content

Commit d67ef95

Browse files
committed
ensure that only valid group members are returned
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent f657ded commit d67ef95

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

apps/user_ldap/lib/Group_LDAP.php

Lines changed: 20 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,29 @@ 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->getFilterPartForUserSearch($search)))
890+
{
891+
if($search === '') {
892+
$this->access->connection->writeToCache($cacheKey, false);
893+
}
879894
continue;
880895
}
896+
$this->access->connection->writeToCache($cacheKey, true);
881897
}
882-
// dn2username will also check if the users belong to the allowed base
883-
if($ocname = $this->access->dn2username($member)) {
884-
$groupUsers[] = $ocname;
885-
}
898+
$groupUsers[] = $uid;
886899
}
887900
}
888901

0 commit comments

Comments
 (0)