diff --git a/htdocs/adherents/ldap.php b/htdocs/adherents/ldap.php index 983e6d9aada..4b64290f107 100644 --- a/htdocs/adherents/ldap.php +++ b/htdocs/adherents/ldap.php @@ -209,7 +209,6 @@ if ($result > 0) { } $ldap->unbind(); - $ldap->close(); } else { setEventMessages($ldap->error, $ldap->errors, 'errors'); } diff --git a/htdocs/adherents/type_ldap.php b/htdocs/adherents/type_ldap.php index f932b65e98c..43902a5e1bf 100644 --- a/htdocs/adherents/type_ldap.php +++ b/htdocs/adherents/type_ldap.php @@ -170,7 +170,6 @@ if ($result > 0) { } $ldap->unbind(); - $ldap->close(); } else { setEventMessages($ldap->error, $ldap->errors, 'errors'); } diff --git a/htdocs/admin/ldap.php b/htdocs/admin/ldap.php index 4010d724c1a..abdf6b75073 100644 --- a/htdocs/admin/ldap.php +++ b/htdocs/admin/ldap.php @@ -290,24 +290,24 @@ if (function_exists("ldap_connect")) { print ''.$langs->trans("LDAPTestConnect").'

'; } - if ($_GET["action"] == 'test') { + if ($action == 'test') { $ldap = new Ldap(); // Les parametres sont passes et recuperes via $conf $result = $ldap->connect_bind(); if ($result > 0) { // Test ldap connect and bind print img_picto('', 'info').' '; - print ''.$langs->trans("LDAPTCPConnectOK", $conf->global->LDAP_SERVER_HOST, $conf->global->LDAP_SERVER_PORT).''; + print ''.$langs->trans("LDAPTCPConnectOK", $ldap->connectedServer, $conf->global->LDAP_SERVER_PORT).''; print '
'; - if ($conf->global->LDAP_ADMIN_DN && !empty($conf->global->LDAP_ADMIN_PASS)) { + if (!empty($conf->global->LDAP_ADMIN_DN) && !empty($conf->global->LDAP_ADMIN_PASS)) { if ($result == 2) { print img_picto('', 'info').' '; - print ''.$langs->trans("LDAPBindOK", $conf->global->LDAP_SERVER_HOST, $conf->global->LDAP_SERVER_PORT, $conf->global->LDAP_ADMIN_DN, preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)).''; + print ''.$langs->trans("LDAPBindOK", $ldap->connectedServer, $conf->global->LDAP_SERVER_PORT, $conf->global->LDAP_ADMIN_DN, preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)).''; print '
'; } else { print img_picto('', 'error').' '; - print ''.$langs->trans("LDAPBindKO", $conf->global->LDAP_SERVER_HOST, $conf->global->LDAP_SERVER_PORT, $conf->global->LDAP_ADMIN_DN, preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)).''; + print ''.$langs->trans("LDAPBindKO", $ldap->connectedServer, $conf->global->LDAP_SERVER_PORT, $conf->global->LDAP_ADMIN_DN, preg_replace('/./i', '*', $conf->global->LDAP_ADMIN_PASS)).''; print '
'; print $langs->trans("Error").' '.$ldap->error; print '
'; @@ -330,10 +330,10 @@ if (function_exists("ldap_connect")) { print '
'; } - $unbind = $ldap->unbind(); + $ldap->unbind(); } else { print img_picto('', 'error').' '; - print ''.$langs->trans("LDAPTCPConnectKO", $conf->global->LDAP_SERVER_HOST, $conf->global->LDAP_SERVER_PORT).''; + print ''.$langs->trans("LDAPTCPConnectKO", $ldap->connectedServer, $conf->global->LDAP_SERVER_PORT).''; print '
'; print $langs->trans("Error").' '.$ldap->error; print '
'; diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php index e6041650d63..33bec1cb2e8 100644 --- a/htdocs/admin/ldap_users.php +++ b/htdocs/admin/ldap_users.php @@ -192,7 +192,7 @@ print "\n"; // DN Pour les utilisateurs print ''; print ''.$langs->trans("LDAPUserDn").''; -print ''; +print ''; print ''.$langs->trans("LDAPUserDnExample").''; print ' '; print ''; @@ -200,7 +200,7 @@ print ''; // List of object class used to define attributes in structure print ''; print ''.$langs->trans("LDAPUserObjectClassList").''; -print ''; +print ''; print ''.$langs->trans("LDAPUserObjectClassListExample").''; print ' '; print ''; @@ -208,7 +208,7 @@ print ''; // Filter, used to filter search print ''; print ''.$langs->trans("LDAPFilterConnection").''; -print ''; +print ''; print ''.$langs->trans("LDAPFilterConnectionExample").''; print ''; print ''; @@ -225,168 +225,168 @@ print "\n"; // Common name print ''.$langs->trans("LDAPFieldFullname").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldFullnameExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_FULLNAME) ? ' checked' : '').">"; +print '"; print ''; // Name print ''.$langs->trans("LDAPFieldName").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldNameExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_NAME) ? ' checked' : '').">"; +print '"; print ''; // Firstname print ''.$langs->trans("LDAPFieldFirstName").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldFirstNameExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_FIRSTNAME) ? ' checked' : '').">"; +print '"; print ''; // Login unix print ''.$langs->trans("LDAPFieldLoginUnix").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldLoginExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) ? ' checked' : '').">"; +print '"; print ''; // Login samba print ''.$langs->trans("LDAPFieldLoginSamba").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldLoginSambaExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN_SAMBA) ? ' checked' : '').">"; +print '"; print ''; // Password not crypted print ''.$langs->trans("LDAPFieldPasswordNotCrypted").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldPasswordExample").''; print ' '; print ''; // Password crypted print ''.$langs->trans("LDAPFieldPasswordCrypted").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldPasswordExample").''; print ' '; print ''; // Mail print ''.$langs->trans("LDAPFieldMail").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldMailExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_MAIL) ? ' checked' : '').">"; +print '"; print ''; // Phone print ''.$langs->trans("LDAPFieldPhone").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldPhoneExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_PHONE) ? ' checked' : '').">"; +print '"; print ''; // Mobile print ''.$langs->trans("LDAPFieldMobile").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldMobileExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_MOBILE) ? ' checked' : '').">"; +print '"; print ''; // Skype print ''.$langs->trans("LDAPFieldSkype").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldSkypeExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SKYPE) ? ' checked' : '').">"; +print '"; print ''; // Fax print ''.$langs->trans("LDAPFieldFax").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldFaxExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_FAX) ? ' checked' : '').">"; +print '"; print ''; // Company print ''.$langs->trans("LDAPFieldCompany").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldCompanyExample").''; print ' '; print ''; // Address print ''.$langs->trans("LDAPFieldAddress").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldAddressExample").''; print ' '; print ''; // ZIP print ''.$langs->trans("LDAPFieldZip").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldZipExample").''; print ' '; print ''; // TOWN print ''.$langs->trans("LDAPFieldTown").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldTownExample").''; print ' '; print ''; // COUNTRY print ''.$langs->trans("LDAPFieldCountry").''; -print ''; +print ''; print ' '; print ' '; print ''; // Title print ''.$langs->trans("LDAPFieldTitle").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldTitleExample").''; print ' '; print ''; // Note print ''.$langs->trans("Note").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldDescriptionExample").''; print ' '; print ''; // Sid print ''.$langs->trans("LDAPFieldSid").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldSidExample").''; -print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) ? ' checked' : '').">"; +print '"; print ''; // Group id print ''.$langs->trans("LDAPFieldGroupid").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldGroupidExample").''; print ' '; print ''; // Userid print ''.$langs->trans("LDAPFieldUserid").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldUseridExample").''; print ' '; print ''; // Home Directory print ''.$langs->trans("LDAPFieldHomedirectory").''; -print ''; +print ''; print ''.$langs->trans("LDAPFieldHomedirectoryExample").''; print ' '; print ''; // Home Directory Prefix print ''.$langs->trans("LDAPFieldHomedirectoryprefix").''; -print ''; +print ''; print ''; print ' '; print ''; @@ -405,20 +405,20 @@ print ''; /* * Test de la connexion */ -if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') { +if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') == 'dolibarr2ldap') { $butlabel = $langs->trans("LDAPTestSynchroUser"); $testlabel = 'testuser'; - $key = $conf->global->LDAP_KEY_USERS; - $dn = $conf->global->LDAP_USER_DN; - $objectclass = $conf->global->LDAP_USER_OBJECT_CLASS; + $key = getDolGlobalString('LDAP_KEY_USERS'); + $dn = getDolGlobalString('LDAP_USER_DN'); + $objectclass = getDolGlobalString('LDAP_USER_OBJECT_CLASS'); show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass); -} elseif ($conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') { +} elseif (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') == 'ldap2dolibarr') { $butlabel = $langs->trans("LDAPTestSearch"); $testlabel = 'testsearchuser'; - $key = $conf->global->LDAP_KEY_USERS; - $dn = $conf->global->LDAP_USER_DN; - $objectclass = $conf->global->LDAP_USER_OBJECT_CLASS; + $key = getDolGlobalString('LDAP_KEY_USERS'); + $dn = getDolGlobalString('LDAP_USER_DN'); + $objectclass = getDolGlobalString('LDAP_USER_OBJECT_CLASS'); show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass); } @@ -479,29 +479,29 @@ if (function_exists("ldap_connect")) { if ($result > 0) { $required_fields = array( - $conf->global->LDAP_KEY_USERS, - $conf->global->LDAP_FIELD_FULLNAME, - $conf->global->LDAP_FIELD_NAME, - $conf->global->LDAP_FIELD_FIRSTNAME, - $conf->global->LDAP_FIELD_LOGIN, - $conf->global->LDAP_FIELD_LOGIN_SAMBA, - $conf->global->LDAP_FIELD_PASSWORD, - $conf->global->LDAP_FIELD_PASSWORD_CRYPTED, - $conf->global->LDAP_FIELD_PHONE, - $conf->global->LDAP_FIELD_FAX, - $conf->global->LDAP_FIELD_SKYPE, - $conf->global->LDAP_FIELD_MOBILE, - $conf->global->LDAP_FIELD_MAIL, - $conf->global->LDAP_FIELD_TITLE, - $conf->global->LDAP_FIELD_DESCRIPTION, - $conf->global->LDAP_FIELD_SID + getDolGlobalString('LDAP_KEY_USERS'), + getDolGlobalString('LDAP_FIELD_FULLNAME'), + getDolGlobalString('LDAP_FIELD_NAME'), + getDolGlobalString('LDAP_FIELD_FIRSTNAME'), + getDolGlobalString('LDAP_FIELD_LOGIN'), + getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA'), + getDolGlobalString('LDAP_FIELD_PASSWORD'), + getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED'), + getDolGlobalString('LDAP_FIELD_PHONE'), + getDolGlobalString('LDAP_FIELD_FAX'), + getDolGlobalString('LDAP_FIELD_SKYPE'), + getDolGlobalString('LDAP_FIELD_MOBILE'), + getDolGlobalString('LDAP_FIELD_MAIL'), + getDolGlobalString('LDAP_FIELD_TITLE'), + getDolGlobalString('LDAP_FIELD_DESCRIPTION'), + getDolGlobalString('LDAP_FIELD_SID') ); // Remove from required_fields all entries not configured in LDAP (empty) and duplicated $required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement"))); // Get from LDAP database an array of results - $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1); + $ldapusers = $ldap->getRecords('*', getDolGlobalString('LDAP_USER_DN'), getDolGlobalString('LDAP_KEY_USERS'), $required_fields, 1); //$ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, '', 1); if (is_array($ldapusers)) { @@ -523,8 +523,8 @@ if (function_exists("ldap_connect")) { print "
\n"; print "LDAP search for user:
\n"; print "search: *
\n"; - print "userDN: ".$conf->global->LDAP_USER_DN."
\n"; - print "useridentifier: ".$conf->global->LDAP_KEY_USERS."
\n"; + print "userDN: ".getDolGlobalString('LDAP_USER_DN')."
\n"; + print "useridentifier: ".getDolGlobalString('LDAP_KEY_USERS')."
\n"; print "required_fields: ".implode(',', $required_fields)."
\n"; print "=> ".count($liste)." records
\n"; print "\n
"; diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php index 8babb849e7e..d29aab0386b 100644 --- a/htdocs/contact/ldap.php +++ b/htdocs/contact/ldap.php @@ -182,7 +182,6 @@ if ($result > 0) { } $ldap->unbind(); - $ldap->close(); } else { setEventMessages($ldap->error, $ldap->errors, 'errors'); } diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index e2ce33cc45f..6f42ffb5fac 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -1,8 +1,8 @@ * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005-2017 Regis Houssin - * Copyright (C) 2006-2015 Laurent Destailleur + * Copyright (C) 2005-2021 Regis Houssin + * Copyright (C) 2006-2021 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,6 +48,11 @@ class Ldap */ public $server = array(); + /** + * Current connected server + */ + public $connectedServer; + /** * Base DN (e.g. "dc=foo,dc=com") */ @@ -132,35 +137,33 @@ class Ldap if (!empty($conf->global->LDAP_SERVER_HOST_SLAVE)) { $this->server[] = $conf->global->LDAP_SERVER_HOST_SLAVE; } - $this->serverPort = $conf->global->LDAP_SERVER_PORT; - $this->ldapProtocolVersion = $conf->global->LDAP_SERVER_PROTOCOLVERSION; - $this->dn = $conf->global->LDAP_SERVER_DN; - $this->serverType = $conf->global->LDAP_SERVER_TYPE; + $this->serverPort = getDolGlobalInt('LDAP_SERVER_PORT', 389); + $this->ldapProtocolVersion = getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION'); + $this->dn = getDolGlobalString('LDAP_SERVER_DN'); + $this->serverType = getDolGlobalString('LDAP_SERVER_TYPE'); - $this->domain = $conf->global->LDAP_SERVER_DN; - $this->searchUser = $conf->global->LDAP_ADMIN_DN; - $this->searchPassword = $conf->global->LDAP_ADMIN_PASS; - $this->people = $conf->global->LDAP_USER_DN; - $this->groups = $conf->global->LDAP_GROUP_DN; + $this->domain = getDolGlobalString('LDAP_SERVER_DN'); + $this->searchUser = getDolGlobalString('LDAP_ADMIN_DN'); + $this->searchPassword = getDolGlobalString('LDAP_ADMIN_PASS'); + $this->people = getDolGlobalString('LDAP_USER_DN'); + $this->groups = getDolGlobalString('LDAP_GROUP_DN'); - $this->filter = $conf->global->LDAP_FILTER_CONNECTION; // Filter on user - $this->filtergroup = $conf->global->LDAP_GROUP_FILTER; // Filter on groups - $this->filtermember = $conf->global->LDAP_MEMBER_FILTER; // Filter on member + $this->filter = getDolGlobalString('LDAP_FILTER_CONNECTION'); // Filter on user + $this->filtergroup = getDolGlobalString('LDAP_GROUP_FILTER'); // Filter on groups + $this->filtermember = getDolGlobalString('LDAP_MEMBER_FILTER'); // Filter on member // Users - $this->attr_login = $conf->global->LDAP_FIELD_LOGIN; //unix - $this->attr_sambalogin = $conf->global->LDAP_FIELD_LOGIN_SAMBA; //samba, activedirectory - $this->attr_name = $conf->global->LDAP_FIELD_NAME; - $this->attr_firstname = $conf->global->LDAP_FIELD_FIRSTNAME; - $this->attr_mail = $conf->global->LDAP_FIELD_MAIL; - $this->attr_phone = $conf->global->LDAP_FIELD_PHONE; - $this->attr_skype = $conf->global->LDAP_FIELD_SKYPE; - $this->attr_fax = $conf->global->LDAP_FIELD_FAX; - $this->attr_mobile = $conf->global->LDAP_FIELD_MOBILE; + $this->attr_login = getDolGlobalString('LDAP_FIELD_LOGIN'); //unix + $this->attr_sambalogin = getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA'); //samba, activedirectory + $this->attr_name = getDolGlobalString('LDAP_FIELD_NAME'); + $this->attr_firstname = getDolGlobalString('LDAP_FIELD_FIRSTNAME'); + $this->attr_mail = getDolGlobalString('LDAP_FIELD_MAIL'); + $this->attr_phone = getDolGlobalString('LDAP_FIELD_PHONE'); + $this->attr_skype = getDolGlobalString('LDAP_FIELD_SKYPE'); + $this->attr_fax = getDolGlobalString('LDAP_FIELD_FAX'); + $this->attr_mobile = getDolGlobalString('LDAP_FIELD_MOBILE'); } - - // Connection handling methods ------------------------------------------- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -288,6 +291,7 @@ class Ldap $return = -1; dol_syslog(get_class($this)."::connect_bind return=".$return.' - '.$this->error, LOG_WARNING); } + $this->connectedServer = $host; return $return; } @@ -298,6 +302,8 @@ class Ldap * Returns true if OK, false if there was an error. * * @return boolean true or false + * @deprecated ldap_close is an alias of ldap_unbind + * @see unbind() */ public function close() { @@ -351,7 +357,7 @@ class Ldap /** * Unbind du serveur ldap. * - * @return boolean true or false + * @return boolean true or false */ public function unbind() { @@ -411,7 +417,7 @@ class Ldap */ public function add($dn, $info, $user) { - dol_syslog(get_class($this)."::add dn=".$dn." info=".join(',', $info)); + dol_syslog(get_class($this)."::add dn=".$dn." info=".json_encode($info)); // Check parameters if (!$this->connection) { diff --git a/htdocs/core/lib/ldap.lib.php b/htdocs/core/lib/ldap.lib.php index 9d6e0193108..56a8bcc4285 100644 --- a/htdocs/core/lib/ldap.lib.php +++ b/htdocs/core/lib/ldap.lib.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006-2017 Regis Houssin + * Copyright (C) 2006-2021 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -89,7 +89,6 @@ function ldap_prepare_head() return $head; } - /** * Show button test LDAP synchro * @@ -119,7 +118,6 @@ function show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass) print '

'; } - /** * Show a LDAP array into an HTML output array. * @@ -153,7 +151,7 @@ function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount = if ("$key" == "dn") { continue; } - if ("$val" == "objectclass") { + if (!is_array($val) && "$val" == "objectclass") { continue; } @@ -181,7 +179,7 @@ function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount = } print '
'; } - if ("$val" != $lastkey[$level] && !$subcount) { + if (!is_array($val) && "$val" != $lastkey[$level] && !$subcount) { print ''; } } diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index b4aae4e5679..ede899d7761 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -1,6 +1,6 @@ - * Copyright (C) 2008-2017 Regis Houssin +/* Copyright (C) 2008-2021 Laurent Destailleur + * Copyright (C) 2008-2021 Regis Houssin * Copyright (C) 2020 Ferran Marcet * * This program is free software; you can redistribute it and/or modify @@ -91,7 +91,6 @@ function dol_decode($chain, $key = '1') return $chain; } - /** * Returns a hash of a string. * If constant MAIN_SECURITY_HASH_ALGO is defined, we use this function as hashing function (recommanded value is 'password_hash') @@ -123,7 +122,7 @@ function dol_hash($chain, $type = '0') } elseif ($type == '3' || $type == 'md5') { return md5($chain); } elseif ($type == '4' || $type == 'md5openldap') { - return '{md5}'.base64_encode(mhash(MHASH_MD5, $chain)); // For OpenLdap with md5 (based on an unencrypted password in base) + return '{md5}'.base64_encode(pack("H*", md5($chain))); // For OpenLdap with md5 (based on an unencrypted password in base) } elseif ($type == '5' || $type == 'sha256') { return hash('sha256', $chain); } elseif ($type == '6' || $type == 'password_hash') { @@ -168,7 +167,6 @@ function dol_verifyHash($chain, $hash, $type = '0') return dol_hash($chain, $type) == $hash; } - /** * Check permissions of a user to show a page and an object. Check read permission. * If GETPOST('action','aZ09') defined, we also check write and delete permission. diff --git a/htdocs/core/login/functions_ldap.php b/htdocs/core/login/functions_ldap.php index 6b11474995b..2d55ca2815b 100644 --- a/htdocs/core/login/functions_ldap.php +++ b/htdocs/core/login/functions_ldap.php @@ -120,7 +120,7 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest) if ($ldapdebug) { print "DEBUG: User ".$usertotest." must change password
\n"; } - $ldap->close(); + $ldap->unbind(); sleep(1); $langs->load('ldap'); $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("YouMustChangePassNextLogon", $usertotest, $ldap->domainFQDN); @@ -131,7 +131,7 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest) print "DEBUG: ".$ldap->error."
\n"; } } - $ldap->close(); + $ldap->unbind(); } // Forge LDAP user and password to test with them @@ -166,14 +166,14 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest) $now = dol_now(); if ($tmpuser->datestartvalidity && $db->jdate($tmpuser->datestartvalidity) >= $now) { - $ldap->close(); + $ldap->unbind(); // Load translation files required by the page $langs->loadLangs(array('main', 'errors')); $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorLoginDateValidity"); return '--bad-login-validity--'; } if ($tmpuser->dateendvalidity && $db->jdate($tmpuser->dateendvalidity) <= dol_get_first_hour($now)) { - $ldap->close(); + $ldap->unbind(); // Load translation files required by the page $langs->loadLangs(array('main', 'errors')); $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorLoginDateValidity"); @@ -271,7 +271,7 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest) $_SESSION["dol_loginmesg"] = ($ldap->error ? $ldap->error : $langs->transnoentitiesnoconv("ErrorBadLoginPassword")); } - $ldap->close(); + $ldap->unbind(); } return $login; diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 79ae03cbe4f..e3a72384050 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -2774,7 +2774,7 @@ if ($action == 'create' || $action == 'adduserldap') { } if (!empty($conf->ldap->enabled) && !empty($object->ldap_sid)) { - $ldap->close(); + $ldap->unbind(); } } } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 1114aa826d5..d1aa62b25ee 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2901,7 +2901,7 @@ class User extends CommonObject } } foreach ($socialnetworks as $key => $value) { - if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])})) { + if (!empty($this->socialnetworks[$value['label']]) && !empty($conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])})) { $info[$conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']]; } } diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php index 710dab1ee22..d8d1995a847 100644 --- a/htdocs/user/group/ldap.php +++ b/htdocs/user/group/ldap.php @@ -192,7 +192,6 @@ if ($result > 0) { print ''.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')'; } $ldap->unbind(); - $ldap->close(); } else { setEventMessages($ldap->error, $ldap->errors, 'errors'); } diff --git a/htdocs/user/ldap.php b/htdocs/user/ldap.php index b7ea48f7734..8e12bf1b461 100644 --- a/htdocs/user/ldap.php +++ b/htdocs/user/ldap.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php'; $langs->loadLangs(array('users', 'admin', 'companies', 'ldap')); $id = GETPOST('id', 'int'); +$action = GETPOST('action', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userldap'; // To manage different context of search // Security check @@ -62,7 +63,7 @@ if ($reshook < 0) { } if (empty($reshook)) { - if ($_GET["action"] == 'dolibarr2ldap') { + if ($action == 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); @@ -97,7 +98,7 @@ print dol_get_fiche_head($head, 'ldap', $title, 0, 'user'); $linkback = ''; -if ($user->rights->user->user->lire || $user->admin) { +if (!empty($user->rights->user->user->lire) || !empty($user->admin)) { $linkback = ''.$langs->trans("BackToList").''; } @@ -198,7 +199,6 @@ if ($result > 0) { } $ldap->unbind(); - $ldap->close(); } else { setEventMessages($ldap->error, $ldap->errors, 'errors'); }