From 83cd2dce5a44f9f6b80fea54a16ee49faea6f840 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 14 Nov 2007 22:11:48 +0000 Subject: [PATCH] MDL-9399 auth/ldap: NTLM SSO - cleanup of sesskey handling Fix a bug in ntlmsso_finish(), and tighten up user_login() to avoid a pointless DB lookup if the password doesn't match the sesskey. Hopefully this makes things work again... (thanks I~naki for the testing!) --- auth/ldap/auth.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index f761d28a18..8461b3531c 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -89,8 +89,8 @@ class auth_plugin_ldap extends auth_plugin_base { // Before we connect to LDAP, check if this is an AD SSO login // if we succeed in this block, we'll return success early. // - if (!empty($this->config->ntlmsso_enabled)) { - $key = sesskey(); + $key = sesskey(); + if (!empty($this->config->ntlmsso_enabled) && $key === $password) { if ($cookie = get_config('auth/ldap/ntlmsess', $key)) { // These checks match the work done if (preg_match('/^(\d+):(.+)$/',$cookie,$matches)) { @@ -98,11 +98,9 @@ class auth_plugin_ldap extends auth_plugin_base { $time = $matches[1]; $sessusername = $matches[2]; if (((time() - ((int)$time)) < AUTH_NTLMTIMEOUT) - && $key === $password && $sessusername === $username) { unset($cookie); - unset($key); unset($time); unset($sessusername); @@ -124,6 +122,7 @@ class auth_plugin_ldap extends auth_plugin_base { } } } // End SSO processing + unset($key); $textlib = textlib_get_instance(); @@ -1821,11 +1820,10 @@ class auth_plugin_ldap extends auth_plugin_base { // $matches[0] is the whole matched string... $time = $matches[1]; $username = $matches[2]; - if (((time() - ((int)$time)) < AUTH_NTLMTIMEOUT) // timewindow for the process, in secs... - && $sesskey === sesskey()) { + if (((time() - ((int)$time)) < AUTH_NTLMTIMEOUT)) { // Here we want to trigger the whole authentication machinery // to make sure no step is bypassed... - $user = authenticate_user_login($username, $sesskey); + $user = authenticate_user_login($username, $key); if ($user) { add_to_log(SITEID, 'user', 'login', "view.php?id=$USER->id&course=".SITEID, $user->id, 0, $user->id); -- 2.39.5