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 @@
+ diff --git a/templates/sysconfig/ad-checkcredentials.html b/templates/sysconfig/ad-checkcredentials.html index 9378adad..dbd09d58 100644 --- a/templates/sysconfig/ad-checkcredentials.html +++ b/templates/sysconfig/ad-checkcredentials.html @@ -11,6 +11,7 @@
+ @@ -30,6 +31,7 @@ + @@ -47,6 +49,9 @@ if (!task || !task.statusCode) return; if (task.statusCode === 'TASK_FINISHED') { + if (task.data && task.data.dn) { + $('#setbase').val(task.data.dn); + } $('#nextbutton').html('Weiter »').show(); } if (task.statusCode === 'TASK_ERROR' || task.statusCode === 'PARENT_FAILED') { diff --git a/templates/sysconfig/ldap-checkconnection.html b/templates/sysconfig/ldap-checkconnection.html index 39408526..b661a263 100644 --- a/templates/sysconfig/ldap-checkconnection.html +++ b/templates/sysconfig/ldap-checkconnection.html @@ -9,6 +9,7 @@
+ diff --git a/templates/sysconfig/ldap-checkcredentials.html b/templates/sysconfig/ldap-checkcredentials.html index f089c4ab..77736c9c 100644 --- a/templates/sysconfig/ldap-checkcredentials.html +++ b/templates/sysconfig/ldap-checkcredentials.html @@ -3,7 +3,6 @@

-
LDAP Self-Query
LDAP Test-Query
{{lang_onProblemSearchBase}} @@ -11,6 +10,7 @@
+ @@ -30,6 +30,7 @@ + @@ -47,6 +48,9 @@ if (!task || !task.statusCode) return; if (task.statusCode === 'TASK_FINISHED') { + if (task.data && task.data.dn) { + $('#setbase').val(task.data.dn); + } $('#nextbutton').html('Weiter »').show(); } if (task.statusCode === 'TASK_ERROR' || task.statusCode === 'PARENT_FAILED') { @@ -56,14 +60,4 @@ $('#nextbutton').show(); } } - function selfCb(task) - { - if (!task || !task.statusCode) - return; - if (task.statusCode === 'TASK_FINISHED' && task.data && task.data.dn) { - $('#setdn').val(task.data.dn); - } else { - $('#nextbutton').html('Trotzdem weiter »'); - } - } -- cgit v1.2.3-55-g7522