From 904377f5a44da9b49a2411f801d39361cc885438 Mon Sep 17 00:00:00 2001
From: Nathan Neulinger <nneul@umr.edu>
Date: Tue, 31 Jan 2006 23:20:58 +0100
Subject: [PATCH] some fix for getUserData in the LDAP auth backend

darcs-hash:20060131222058-effc9-0d09141c02e3698329d038af90588b553fd6a44b.gz
---
 inc/auth/ldap.class.php | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/inc/auth/ldap.class.php b/inc/auth/ldap.class.php
index ac067c888..f59800476 100644
--- a/inc/auth/ldap.class.php
+++ b/inc/auth/ldap.class.php
@@ -11,6 +11,7 @@
 class auth_ldap extends auth_basic {
     var $cnf = null;
     var $con = null;
+    var $bound = false;
 
     /**
      * Constructor
@@ -78,6 +79,7 @@ class auth_ldap extends auth_basic {
                 }
                 return false;
             }
+            $this->bound = true;
             return true;
         }else{
             // See if we can find the user
@@ -96,6 +98,7 @@ class auth_ldap extends auth_basic {
                 }
                 return false;
             }
+            $this->bound = true;
             return true;
         }
 
@@ -128,6 +131,18 @@ class auth_ldap extends auth_basic {
         global $conf;
         if(!$this->_openLDAP()) return false;
 
+        if(!$this->bound){
+            if($this->cnf['binddn'] && $this->cnf['bindpw']){
+                // use superuser credentials
+                if(!@ldap_bind($this->con,$this->cnf['binddn'],$this->cnf['bindpw'])){
+                    if($this->cnf['debug'])
+                        msg('LDAP bind as superuser: '.htmlspecialchars(ldap_error($this->con)),0);
+                    return false;
+                }
+            }
+            $this->bound = true;
+        }
+
         $info['user']   = $user;
         $info['server'] = $this->cnf['server'];
 
-- 
GitLab