From 536fafe5726347806ba2a44d31b33b68abfb58b4 Mon Sep 17 00:00:00 2001
From: =?iso-8859-1?q?I=F1aki=20Arenaza?= <iarenuno@eteo.mondragon.edu>
Date: Sat, 17 Nov 2007 14:06:01 +0100
Subject: [PATCH] user_login() was not converted to using get_cache_flags().

It was still using the 'old' get_config() interface, so the 'cookie'
set by ntlmsso_finish() wasn't retrieved at all, and the automatic
login always failed.

Signed-off-by: Iņaki Arenaza <iarenuno@eteo.mondragon.edu>
---
 auth/ldap/auth.php |   51 +++++++++++++++++++++++----------------------------
 1 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php
index 6b473ba..d626e78 100644
--- a/auth/ldap/auth.php
+++ b/auth/ldap/auth.php
@@ -95,42 +95,37 @@ class auth_plugin_ldap extends auth_plugin_base {
         //
         $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)) {
-                    // $matches[0] is the whole matched string...
-                    $time         = $matches[1];
-                    $sessusername = $matches[2];
-                    if (((time() - ((int)$time)) < AUTH_NTLMTIMEOUT)
-                        && $sessusername === $username) {
-
-                        unset($cookie);
-                        unset($time);
-                        unset($sessusername);
-
-                        // Check that the user is inside one of the configured LDAP contexts
-                        $validuser = false;
-                        $ldapconnection = $this->ldap_connect();
-                        if ($ldapconnection) {
-                            // if the user is not inside the configured contexts,
-                            // ldap_find_userdn returns false.
-                            if ($this->ldap_find_userdn($ldapconnection, $extusername)) {
-                                $validuser = true;
-                            }
-                            ldap_close($ldapconnection);
-                        }
+            $cf = get_cache_flags('auth/ldap/ntlmsess');
+            // We only get the cache flag if we retrieve it before
+            // it expires (AUTH_NTLMTIMEOUT seconds).
+            if (!isset($cf[$key]) || $cf[$key] === '') {
+                return false;
+            }
 
-                        // Shortcut here - SSO confirmed
-                        return $validuser;
+            $sessusername = $cf[$key];
+            if ($username === $sessusername) {
+                unset($sessusername);
+                unset($cf);
+
+                // Check that the user is inside one of the configured LDAP contexts
+                $validuser = false;
+                $ldapconnection = $this->ldap_connect();
+                if ($ldapconnection) {
+                    // if the user is not inside the configured contexts,
+                    // ldap_find_userdn returns false.
+                    if ($this->ldap_find_userdn($ldapconnection, $extusername)) {
+                        $validuser = true;
                     }
+                    ldap_close($ldapconnection);
                 }
+
+                // Shortcut here - SSO confirmed
+                return $validuser;
             }
         } // End SSO processing
         unset($key);
 
-
         $ldapconnection = $this->ldap_connect();
-
         if ($ldapconnection) {
             $ldap_user_dn = $this->ldap_find_userdn($ldapconnection, $extusername);
 
-- 
1.5.3.1


