Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(ldap): allow nested groups filter in ldap configuration (#6128)
Browse files Browse the repository at this point in the history
Refs: #6127
  • Loading branch information
kduret authored and Ridene committed Mar 20, 2018
1 parent 636ffd1 commit e03db3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 17 additions & 8 deletions www/class/centreonLDAP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,27 @@ public function listGroupsForUser($userdn)
*/
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;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion www/include/configuration/configObject/contact/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,10 @@ function insertLdapContactInDB($tmpContacts = array())
}
$pearDB->query(sprintf($sqlUpdate, $tmplSql));
}
$listGroup = $ldap->listGroupsForUser($tmpContacts["dn"][$select_key]);
$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);
Expand Down

0 comments on commit e03db3c

Please sign in to comment.