lib/Auth
Aleksander Machniak
machniak at kolabsys.com
Wed Dec 4 12:18:53 CET 2013
lib/Auth/LDAP.php | 55 ++++++++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 26 deletions(-)
New commits:
commit 41c44365cc3839b9b967ad0e72666f8bc4a41436
Author: Aleksander Machniak <alec at alec.pl>
Date: Wed Dec 4 12:17:41 2013 +0100
Store domain_root_dn() result in memory to skip redundant searches (if memcache cache is disabled)
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index d6e9119..ac07d6f 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -1386,6 +1386,15 @@ class LDAP extends Net_LDAP3 {
*/
private function domain_root_dn($domain)
{
+ if (empty($domain)) {
+ return false;
+ }
+
+ $ckey = 'domain.root::' . $domain;
+ if ($result = $this->icache[$ckey]) {
+ return $result;
+ }
+
if (!$this->connect()) {
$this->_log(LOG_DEBUG, "Could not connect");
return false;
@@ -1395,46 +1404,40 @@ class LDAP extends Net_LDAP3 {
$bind_pw = $this->config_get("service_bind_pw", $this->conf->get("service_bind_pw"));
if (!$this->bind($bind_dn, $bind_pw)) {
- $this->_log(LOG_DEBUG, "Could not connect");
return false;
}
- $this->_log(LOG_DEBUG, "Auth::LDAP::domain_root_dn(\$domain = $domain) called");
- if (empty($domain)) {
- return false;
- }
-
- $domain_name_attribute = $this->conf->get('ldap', 'domain_name_attribute');
-
- if (empty($domain_name_attribute)) {
- $domain_name_attribute = 'associateddomain';
- }
-
- $entry_attrs = $this->_find_domain($domain);
+ $this->_log(LOG_DEBUG, "Auth::LDAP::domain_root_dn(\$domain = $domain)");
- if (!$entry_attrs) {
- return $this->_standard_root_dn($domain);
- }
-
- $entry_attrs = array_shift($entry_attrs);
+ if ($entry_attrs = $this->_find_domain($domain)) {
+ $entry_attrs = array_shift($entry_attrs);
- if (is_array($entry_attrs)) {
- if (array_key_exists('inetdomainbasedn', $entry_attrs) && !empty($entry_attrs['inetdomainbasedn'])) {
- $domain_root_dn = $entry_attrs['inetdomainbasedn'];
+ $domain_name_attribute = $this->conf->get('ldap', 'domain_name_attribute');
+ if (empty($domain_name_attribute)) {
+ $domain_name_attribute = 'associateddomain';
}
- else {
- if (is_array($entry_attrs[$domain_name_attribute])) {
- $domain_root_dn = $this->_standard_root_dn($entry_attrs[$domain_name_attribute][0]);
+
+ if (is_array($entry_attrs)) {
+ if (array_key_exists('inetdomainbasedn', $entry_attrs) && !empty($entry_attrs['inetdomainbasedn'])) {
+ $domain_root_dn = $entry_attrs['inetdomainbasedn'];
}
else {
- $domain_root_dn = $this->_standard_root_dn($entry_attrs[$domain_name_attribute]);
+ if (is_array($entry_attrs[$domain_name_attribute])) {
+ $domain_root_dn = $this->_standard_root_dn($entry_attrs[$domain_name_attribute][0]);
+ }
+ else {
+ $domain_root_dn = $this->_standard_root_dn($entry_attrs[$domain_name_attribute]);
+ }
}
}
}
- else {
+
+ if (empty($domain_root_dn)) {
$domain_root_dn = $this->_standard_root_dn($domain);
}
+ $this->icache[$ckey] = $domain_root_dn;
+
return $domain_root_dn;
}
More information about the commits
mailing list