From c4200203ca28e01811052f514e697081895483a2 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Wed, 13 Feb 2008 10:35:16 +1300 Subject: [PATCH] Allow specifying the search scope to use. --- config/example-config.php | 2 ++ inc/drivers_ldap.php | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config/example-config.php b/config/example-config.php index 37099f79..d69537e8 100644 --- a/config/example-config.php +++ b/config/example-config.php @@ -200,6 +200,8 @@ $c->admin_email ='calendar-admin@example.com'; // certificate. Try adding "TLS_REQCERT never" to the // ldap configuration file that php uses (e.g. /etc/ldap.conf // or /etc/ldap/ldap.conf). Of course, this lessens security! +// 'scope' => 'subtree', // Search scope to use, defaults to subtree. +// // Allowed values: base, onelevel, subtree. // // ); // diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index d1b2a127..3dd79a7d 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -80,6 +80,22 @@ class ldapDrivers } } + //Set the search scope to be used + switch (strtolower($config['scope'])) { + case "base": + $this->ldap_query_one = ldap_read; + $this->ldap_query_all = ldap_read; + break; + case "onelevel": + $this->ldap_query_one = ldap_list; + $this->ldap_query_all = ldap_list; + break; + default: + $this->ldap_query_one = ldap_search; + $this->ldap_query_all = ldap_list; + break; + } + //connect as root if (!ldap_bind($this->connect,$config['bindDN'],$config['passDN'])){ $bindDN = isset($config['bindDN']) ? $config['bindDN'] : 'anonymous'; @@ -102,7 +118,7 @@ class ldapDrivers */ function getAllUsers($attributes){ global $c; - $entry = ldap_list($this->connect,$this->baseDNUsers,$this->filterUsers,$attributes); + $entry = $this->ldap_query_all($this->connect,$this->baseDNUsers,$this->filterUsers,$attributes); if (!ldap_first_entry($this->connect,$entry)) $c->messages[] = sprintf(i18n("Error NoUserFound with filter >%s<, attributes >%s< , dn >%s<"),$this->filterUsers,join(', ',$attributes), $this->baseDNUsers); for($i=ldap_first_entry($this->connect,$entry); @@ -130,7 +146,7 @@ class ldapDrivers $entry=NULL; // We get the DN of the USER - $entry = ldap_search($this->connect, $this->baseDNUsers, $filter,$attributes); + $entry = this->ldap_query($this->connect, $this->baseDNUsers, $filter,$attributes); if ( !ldap_first_entry($this->connect, $entry) ){ dbg_error_log( "ERROR", "drivers_ldap : Unable to find the user with filter %s",$filter ); return false;