From 05ed28bbcbe9abe242c19fc7088cfd383db52588 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 18 Sep 2015 16:59:23 +0200 Subject: [ldap/ad] Figure out proper spelling of search base --- inc/util.inc.php | 4 ++++ modules/sysconfig/addmodule_adauth.inc.php | 12 ++++++++++-- modules/sysconfig/addmodule_ldapauth.inc.php | 11 +++++++++-- templates/sysconfig/ad-checkconnection.html | 1 + templates/sysconfig/ad-checkcredentials.html | 5 +++++ templates/sysconfig/ldap-checkconnection.html | 1 + templates/sysconfig/ldap-checkcredentials.html | 16 +++++----------- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/inc/util.inc.php b/inc/util.inc.php index 4378a084..06eebfa4 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -285,5 +285,9 @@ SADFACE; @unlink($file); exit(0); } + + public static function normalizeDn($dn) { + return preg_replace('/[,;]\s*/', ',', $dn); + } } diff --git a/modules/sysconfig/addmodule_adauth.inc.php b/modules/sysconfig/addmodule_adauth.inc.php index 1b04eab0..251ee5d6 100644 --- a/modules/sysconfig/addmodule_adauth.inc.php +++ b/modules/sysconfig/addmodule_adauth.inc.php @@ -80,8 +80,8 @@ class AdAuth_CheckConnection extends AddModule_Base 'edit' => Request::post('edit'), 'title' => Request::post('title'), 'server' => $this->server, - 'searchbase' => Request::post('searchbase'), - 'binddn' => Request::post('binddn'), + 'searchbase' => Util::normalizeDn(Request::post('searchbase')), + 'binddn' => Util::normalizeDn(Request::post('binddn')), 'bindpw' => Request::post('bindpw'), 'home' => Request::post('home'), 'ssl' => Request::post('ssl'), @@ -206,6 +206,14 @@ class AdAuth_Finish extends AddModule_Base if ($i === false) $i = -1; $searchbase = mb_substr($binddn, $i + 1); + } else { + $somedn = Request::post('somedn', false); + if (!empty($somedn)) { + $i = stripos($somedn, $searchbase); + if ($i !== false) { + $searchbase = substr($somedn, $i, strlen($searchbase)); + } + } } $title = Request::post('title'); if (empty($title)) diff --git a/modules/sysconfig/addmodule_ldapauth.inc.php b/modules/sysconfig/addmodule_ldapauth.inc.php index d00ff41c..44dbcca1 100644 --- a/modules/sysconfig/addmodule_ldapauth.inc.php +++ b/modules/sysconfig/addmodule_ldapauth.inc.php @@ -80,8 +80,8 @@ class LdapAuth_CheckConnection extends AddModule_Base 'edit' => Request::post('edit'), 'title' => Request::post('title'), 'server' => $this->server, - 'searchbase' => Request::post('searchbase'), - 'binddn' => Request::post('binddn'), + 'searchbase' => Util::normalizeDn(Request::post('searchbase')), + 'binddn' => Util::normalizeDn(Request::post('binddn')), 'bindpw' => Request::post('bindpw'), 'home' => Request::post('home'), 'ssl' => Request::post('ssl'), @@ -177,6 +177,13 @@ class LdapAuth_Finish extends AddModule_Base $module = ConfigModule::getInstance('LdapAuth'); else $module = $this->edit; + $somedn = Request::post('somedn', false); + if (!empty($somedn)) { + $i = stripos($somedn, $searchbase); + if ($i !== false) { + $searchbase = substr($somedn, $i, strlen($searchbase)); + } + } $ssl = Request::post('ssl', 'off') === 'on'; $module->setData('server', Request::post('server')); $module->setData('searchbase', $searchbase); diff --git a/templates/sysconfig/ad-checkconnection.html b/templates/sysconfig/ad-checkconnection.html index f5fcb2a8..0c7cd77f 100644 --- a/templates/sysconfig/ad-checkconnection.html +++ b/templates/sysconfig/ad-checkconnection.html @@ -9,6 +9,7 @@