Fix: Gros bug dans les fonctions LDAP qui ne gérait pas bien la majuscule, minuscule.
This commit is contained in:
parent
54a71b8d93
commit
bfd1c18f36
@ -735,69 +735,89 @@ class Ldap
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 2.5 User methods ----------------------------------------------------------
|
|
||||||
/**
|
/**
|
||||||
* 2.5.1 : Returns an array containing a details of users, sorted by
|
* \brief Returns an array containing a details of elements
|
||||||
* username. The search criteria is a standard LDAP query - * returns all
|
* \param $search
|
||||||
* users. The $attributeArray variable contains the required user detail field names
|
* \param $userDn
|
||||||
|
* \param $useridentifier
|
||||||
|
* \param $attributeArray Variables required
|
||||||
|
* \param $activefilter 1=utilise le champ this->filter comme filtre
|
||||||
|
*
|
||||||
|
* \remarks ldapsearch -LLLx -hlocalhost -Dcn=admin,dc=parinux,dc=org -w password -b "ou=adherents,ou=people,dc=parinux,dc=org" userPassword
|
||||||
*/
|
*/
|
||||||
function getUsers($search, $userDn, $useridentifier, $attributeArray, $activefilter=0)
|
function getUsers($search, $userDn, $useridentifier, $attributeArray, $activefilter=0)
|
||||||
{
|
{
|
||||||
$userslist=array();
|
$userslist=array();
|
||||||
|
|
||||||
dolibarr_syslog("Ldap.class::getUsers search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=".$attributeArray);
|
dolibarr_syslog("Ldap::getUsers search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=array(".join(',',$attributeArray).")");
|
||||||
|
|
||||||
// if the directory is AD, then bind first with the search user first
|
// if the directory is AD, then bind first with the search user first
|
||||||
if ($this->serverType == "activedirectory") {
|
if ($this->serverType == "activedirectory") {
|
||||||
$this->bindauth($this->searchUser, $this->searchPassword);
|
$this->bindauth($this->searchUser, $this->searchPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
//permet de choisir le filtre adequat
|
// Define filter
|
||||||
if ($activefilter == 1)
|
if ($activefilter == 1)
|
||||||
{
|
{
|
||||||
$filter = '('.$this->filter.')';
|
if ($this->filter) $filter = '('.$this->filter.')';
|
||||||
|
else $filter='('.$useridentifier.'=*)';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$filter = '('.$useridentifier.'='.$search.')';
|
$filter = '('.$useridentifier.'='.$search.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->result = @ldap_search($this->connection, $userDn, $filter);
|
if (is_array($attributeArray))
|
||||||
|
{
|
||||||
|
// Return list with required fields
|
||||||
|
dolibarr_syslog("Ldap::getUsers connection=".$this->connection." userDn=".$userDn." filter=".$filter. " attributeArray=(".join(',',$attributeArray).")");
|
||||||
|
$this->result = @ldap_search($this->connection, $userDn, $filter, $attributeArray);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Return list with fields selected by default
|
||||||
|
dolibarr_syslog("Ldap::getUsers connection=".$this->connection." userDn=".$userDn." filter=".$filter);
|
||||||
|
$this->result = @ldap_search($this->connection, $userDn, $filter);
|
||||||
|
}
|
||||||
if (!$this->result)
|
if (!$this->result)
|
||||||
{
|
{
|
||||||
$this->error = ldap_errno($this->connection)." ".ldap_error($this->connection);
|
$this->error = 'LDAP search failed: '.ldap_errno($this->connection)." ".ldap_error($this->connection);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$info = @ldap_get_entries($this->connection, $this->result);
|
$info = @ldap_get_entries($this->connection, $this->result);
|
||||||
|
|
||||||
|
// Warning: Dans info, les noms d'attributs sont en minuscule meme si passé
|
||||||
|
// a ldap_search en majuscule !!!
|
||||||
//print_r($info);
|
//print_r($info);
|
||||||
for ($i = 0; $i < $info["count"]; $i++)
|
|
||||||
{
|
for ($i = 0; $i < $info["count"]; $i++)
|
||||||
$recordid=$this->ldap_utf8_decode($info[$i][$useridentifier][0]);
|
{
|
||||||
if ($recordid)
|
$recordid=$this->ldap_utf8_decode($info[$i][$useridentifier][0]);
|
||||||
{
|
if ($recordid)
|
||||||
//print "Found record with key $useridentifier=".$recordid."<br>\n";
|
{
|
||||||
$userslist[$recordid][$useridentifier]=$recordid;
|
//print "Found record with key $useridentifier=".$recordid."<br>\n";
|
||||||
|
$userslist[$recordid][$useridentifier]=$recordid;
|
||||||
// Add to the array for each attribute in my list
|
|
||||||
for ($j = 0; $j < count($attributeArray); $j++)
|
// Add to the array for each attribute in my list
|
||||||
{
|
for ($j = 0; $j < count($attributeArray); $j++)
|
||||||
//print " Param ".$attributeArray[$j]."=".$info[$i][$attributeArray[$j]][0]."<br>\n";
|
{
|
||||||
|
$keyattributelower=strtolower($attributeArray[$j]);
|
||||||
//permet de récupérer le SID avec Active Directory
|
//print " Param ".$attributeArray[$j]."=".$info[$i][$keyattributelower][0]."<br>\n";
|
||||||
if ($this->serverType == "activedirectory" && strtolower($attributeArray[$j]) == "objectsid")
|
|
||||||
{
|
//permet de récupérer le SID avec Active Directory
|
||||||
$objectsid = $this->getObjectSid($recordid);
|
if ($this->serverType == "activedirectory" && $keyattributelower == "objectsid")
|
||||||
$userslist[$recordid][$attributeArray[$j]] = $objectsid;
|
{
|
||||||
}
|
$objectsid = $this->getObjectSid($recordid);
|
||||||
else
|
$userslist[$recordid][$attributeArray[$j]] = $objectsid;
|
||||||
{
|
}
|
||||||
$userslist[$recordid][$attributeArray[$j]] = $this->ldap_utf8_decode($info[$i][$attributeArray[$j]][0]);
|
else
|
||||||
}
|
{
|
||||||
}
|
$userslist[$recordid][$attributeArray[$j]] = $this->ldap_utf8_decode($info[$i][$keyattributelower][0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
asort($userslist);
|
asort($userslist);
|
||||||
return $userslist;
|
return $userslist;
|
||||||
|
|||||||
@ -345,7 +345,7 @@ if ($_POST["action"] == 'adduserldap')
|
|||||||
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
||||||
$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
||||||
|
|
||||||
$ldapusers = $ldap->getUsers($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields);
|
$ldapusers = $ldap->getRecords($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields);
|
||||||
//print_r($ldapusers);
|
//print_r($ldapusers);
|
||||||
|
|
||||||
if (is_array($ldapusers))
|
if (is_array($ldapusers))
|
||||||
@ -419,7 +419,7 @@ if (($action == 'create') || ($action == 'adduserldap'))
|
|||||||
$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
|
||||||
|
|
||||||
// Get from LDAP database an array of results
|
// Get from LDAP database an array of results
|
||||||
$ldapusers = $ldap->getUsers('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
|
$ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
|
||||||
if (is_array($ldapusers))
|
if (is_array($ldapusers))
|
||||||
{
|
{
|
||||||
$liste=array();
|
$liste=array();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user