diff --git a/www/class/centreonAuth.LDAP.class.php b/www/class/centreonAuth.LDAP.class.php index ab908310f0e..aced6bc9b82 100644 --- a/www/class/centreonAuth.LDAP.class.php +++ b/www/class/centreonAuth.LDAP.class.php @@ -202,7 +202,6 @@ public function updateUserDn() if ($this->ldap->rebind()) { $userDn = $this->ldap->findUserDn($contactAlias); - $userDn = $this->pearDB->escape($userDn); if (false === $userDn) { $this->CentreonLog->insertLog(3, "LDAP AUTH - Error : No DN for user " . $contactAlias); return false; diff --git a/www/install/php/Update-19.04.5.php b/www/install/php/Update-19.04.5.php index 9c6f16aed3a..691a26ec455 100644 --- a/www/install/php/Update-19.04.5.php +++ b/www/install/php/Update-19.04.5.php @@ -48,16 +48,34 @@ ); } -// remove ldap users missing contact name -// these users have been added using the auto-import ldap feature -// and will be re-imported at their next login. +// remove LDAP users missing contact name +// these users have been added using the auto-import LDAP feature and will be re-imported at their next login. try { - $pearDB->query( - "DELETE FROM contact WHERE contact_name is NULL" + $pearDB->query('DELETE FROM contact WHERE contact_name = ""'); +} catch (\PDOException $e) { + $centreonLog->insertLog( + 2, + "UPGRADE : 19.04.5 Unable to delete LDAP auto-imported users with empty contact_name" ); +} + +// correct the DN of manually imported users from an LDAP +try { + // finding the data of contacts linked to an LDAP + $stmt = $pearDB->query("SELECT contact_id, contact_name, contact_ldap_dn FROM contact WHERE ar_id is NOT NULL"); + $updateDB = $pearDB->prepare("UPDATE contact SET contact_ldap_dn = :newDn WHERE contact_id = :contactId"); + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + // removing the double slashes if needed and saving the corrected data + if (strpos($row['contact_ldap_dn'], "\\\\")) { + $newDn = str_replace("\\\\", "\\", $row['contact_ldap_dn']); + $updateDB->bindValue(':newDn', $newDn, \PDO::PARAM_STR); + $updateDB->bindValue(':contactId', $row['contact_id'], \PDO::PARAM_INT); + $updateDB->execute(); + } + } } catch (\PDOException $e) { $centreonLog->insertLog( 2, - "UPGRADE : 19.04.5 Unable to delete ldap auto-imported users with empty contact_name" + "UPGRADE : 19.04.5 Unable to correct the LDAP DN data" ); }