Private GIT

Skip to content
Snippets Groups Projects
Unverified Commit c54e4861 authored by Kevin Duret's avatar Kevin Duret Committed by GitHub
Browse files

fix(ldap): allow nested groups filter in ldap configuration (#6128)

Refs: #6127
parent 224d1e3d
No related branches found
No related tags found
No related merge requests found
......@@ -475,18 +475,27 @@ class CentreonLDAP
*/
public function listUserForGroup($groupdn)
{
if (trim($this->groupSearchInfo['member']) == '') {
$this->setErrorHandler();
if (trim($this->userSearchInfo['filter']) == '') {
restore_error_handler();
return array();
}
$groupdn = str_replace('\\', '\\\\', $groupdn);
$filter = '(&' . preg_replace('/%s/', '*', $this->userSearchInfo['filter']) .
'(' . $this->userSearchInfo['group'] . '=' . $this->replaceFilter($groupdn) . '))';
$result = @ldap_search($this->ds, $this->userSearchInfo['base_search'], $filter);
if (false === $result) {
restore_error_handler();
return array();
}
$group = $this->getEntry($groupdn, $this->groupSearchInfo['member']);
$entries = ldap_get_entries($this->ds, $result);
$nbEntries = $entries["count"];
$list = array();
if (!isset($group[$this->groupSearchInfo['member']])) {
return $list;
} elseif (is_array($group[$this->groupSearchInfo['member']])) {
return $group[$this->groupSearchInfo['member']];
} else {
return array($group[$this->groupSearchInfo['member']]);
for ($i = 0; $i < $nbEntries; $i++) {
$list[] = $entries[$i]['dn'];
}
restore_error_handler();
return $list;
}
/**
......
......@@ -919,7 +919,10 @@ function insertLdapContactInDB($tmpContacts = array())
}
$pearDB->query(sprintf($sqlUpdate, $tmplSql));
}
$listGroup = array();
if (false !== $ldap->connect()) {
$listGroup = $ldap->listGroupsForUser($tmpContacts["dn"][$select_key]);
}
if (count($listGroup) > 0) {
$query = "SELECT cg_id FROM contactgroup WHERE cg_name IN ('" . join("','", $listGroup) . "')";
$res = $pearDB->query($query);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment