summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-12-04 11:17:41 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-12-04 11:20:01 (GMT)
commitf4f6374404541248172bc16603d9bdb087366bf1 (patch)
tree2e4e659f7285f57e859f465077ee9a2a315e2b73
parent3336c74b7b699729563f43cd72e233fa2df8a24b (diff)
downloadkolab-wap-f4f6374404541248172bc16603d9bdb087366bf1.tar.gz
Store domain_root_dn() result in memory to skip redundant searches (if memcache cache is disabled)
-rw-r--r--lib/Auth/LDAP.php55
1 files changed, 29 insertions, 26 deletions
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;
}