From 1ce631e4099f087ba84942e94dc31c90b5496f5b Mon Sep 17 00:00:00 2001
From: =?utf-8?q?I=C3=B1aki=20Arenaza?= <iarenaza@mondragon.edu>
Date: Sun, 31 Jul 2011 17:27:57 +0200
Subject: [PATCH] MDL-28402 LDAP configuration values being stored in lower case, causing misconfiguration
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

It looks like array_change_key_case() does not work recursively, so we
were not actually lowercasing the expiration attribute key. As the
configuration setting is always lowercase they didn't match.

Signed-off-by: Iñaki Arenaza <iarenaza@mondragon.edu>
---
 auth/ldap/auth.php |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php
index d6cc893..c56ee54 100644
--- a/auth/ldap/auth.php
+++ b/auth/ldap/auth.php
@@ -579,16 +579,18 @@ class auth_plugin_ldap extends auth_plugin_base {
         $sr = ldap_read($ldapconnection, $user_dn, '(objectClass=*)', $search_attribs);
         if ($sr)  {
             $info = ldap_get_entries_moodle($ldapconnection, $sr);
-            $info = array_change_key_case($info, CASE_LOWER);
-            if (!empty ($info) and !empty($info[0][$this->config->expireattr][0])) {
-                $expiretime = $this->ldap_expirationtime2unix($info[0][$this->config->expireattr][0], $ldapconnection, $user_dn);
-                if ($expiretime != 0) {
-                    $now = time();
-                    if ($expiretime > $now) {
-                        $result = ceil(($expiretime - $now) / DAYSECS);
-                    }
-                    else {
-                        $result = floor(($expiretime - $now) / DAYSECS);
+            if (!empty ($info)) {
+                $info = array_change_key_case($info[0], CASE_LOWER);
+                if (!empty($info[$this->config->expireattr][0])) {
+                    $expiretime = $this->ldap_expirationtime2unix($info[$this->config->expireattr][0], $ldapconnection, $user_dn);
+                    if ($expiretime != 0) {
+                        $now = time();
+                        if ($expiretime > $now) {
+                            $result = ceil(($expiretime - $now) / DAYSECS);
+                        }
+                        else {
+                            $result = floor(($expiretime - $now) / DAYSECS);
+                        }
                     }
                 }
             }
-- 
1.7.2.5

