From 3dbfe18afbf834a6b8e5d9b2d3b766b0c8bf1c0b Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 6 Aug 2020 16:43:35 +0200 Subject: [PATCH] LSsession: add setSubDn() method --- src/includes/class/class.LSsession.php | 43 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/includes/class/class.LSsession.php b/src/includes/class/class.LSsession.php index 9eb879fe..f6475c3f 100644 --- a/src/includes/class/class.LSsession.php +++ b/src/includes/class/class.LSsession.php @@ -684,12 +684,8 @@ class LSsession { LStemplate :: assign('LSsession_username',self :: getLSuserObject() -> getDisplayName()); - if (isset ($_POST['LSsession_topDn']) && $_POST['LSsession_topDn']) { - if (self :: validSubDnLdapServer($_POST['LSsession_topDn'])) { - self :: $topDn = $_POST['LSsession_topDn']; - $_SESSION['LSsession']['topDn'] = $_POST['LSsession_topDn']; - } // end if - } // end if + if (isset($_POST['LSsession_topDn']) && $_POST['LSsession_topDn']) + self :: setSubDn($_POST['LSsession_topDn']); return true; @@ -1130,27 +1126,46 @@ class LSsession { } /** - * Définition du serveur Ldap de la session + * Set the LDAP server of the session * - * Définition du serveur Ldap de la session à partir de son ID dans - * le tableau LSconfig :: get('ldap_servers'). + * Set the LDAP server of the session from its ID in configuration array + * LSconfig :: get('ldap_servers'). * - * @param[in] integer Index du serveur Ldap + * @param[in] $id integer Index of LDAP server + * @param[in] $subDn integer SubDN of LDAP server (optional) * - * @retval boolean True sinon false. + * @retval boolean True if set, false otherwise */ - public static function setLdapServer($id) { + public static function setLdapServer($id, $subDn=null) { $conf = LSconfig :: get("ldap_servers.$id"); if ( is_array($conf) ) { self :: $ldapServerId = $id; self :: $ldapServer = $conf; LSlang :: setLocale(); self :: setGlobals(); + + if ($subDn) + return self :: setSubDn($subDn); + return true; } - else { - return; + return false; + } + + /** + * Set the subDn of the session + * + * @param[in] $subDn string SubDN of LDAP server + * + * @retval boolean True if set, false otherwise + */ + public static function setSubDn($subDn) { + if (self :: validSubDnLdapServer($subDn)) { + self :: $topDn = $subDn; + $_SESSION['LSsession']['topDn'] = $subDn; + return true; } + return; } /**