diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-12-04 09:17:59 (GMT) |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-12-04 11:19:46 (GMT) |
commit | 185d3fec9829aa1aa5f61255d1e0e288293ee8d4 (patch) | |
tree | b03ad2bbbc5eb5196738d31182486e38c96791e2 | |
parent | 19627e08d6a5bee73e19ad40d16402cb927e8208 (diff) | |
download | kolab-wap-185d3fec9829aa1aa5f61255d1e0e288293ee8d4.tar.gz |
Code for finding a domain by name moved to _find_domain() method
-rw-r--r-- | lib/Auth/LDAP.php | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php index 25cb754..54b8943 100644 --- a/lib/Auth/LDAP.php +++ b/lib/Auth/LDAP.php @@ -309,16 +309,14 @@ class LDAP extends Net_LDAP3 { } // Query the ACI for the primary domain - $domain_filter = $this->conf->get('ldap', 'domain_filter'); - $domain_filter = '(&(' . $domain_name_attribute . '=' . $primary_domain . ')' . $domain_filter . ')'; - $results = $this->_search($domain_base_dn, $domain_filter); - $entries = $results->entries(true); - $domain_entry = array_shift($entries); - - if (in_array('inetdomainbasedn', $domain_entry)) { - $_base_dn = $domain_entry['inetdomainbasedn']; + if ($domain_entry = $this->_find_domain($primary_domain)) { + $domain_entry = array_shift($domain_entry); + if (in_array('inetdomainbasedn', $domain_entry)) { + $_base_dn = $domain_entry['inetdomainbasedn']; + } } - else { + + if (empty($_base_dn)) { $_base_dn = $this->_standard_root_dn($primary_domain); } @@ -511,27 +509,15 @@ class LDAP extends Net_LDAP3 { $domain_dn = $this->entry_dn($domain, array(), $domain_base_dn); if (!$domain_dn) { - $domain_filter = $this->conf->get('ldap', 'domain_filter'); - $domain_name_attribute = $this->conf->get('ldap', 'domain_name_attribute'); - $domain_filter = "(&" . $domain_filter . "(" . $domain_name_attribute . "=" . $domain . "))"; - - $this->_log(LOG_DEBUG, "Auth::LDAP::domain_info() uses _search()"); - if ($result = $this->_search($domain_base_dn, $domain_filter, $attributes)) { - $result = $result->entries(true); - } + $result = $this->_find_domain($domain, $attributes); } else { - $this->_log(LOG_DEBUG, "Auth::LDAP::domain_info() uses _read()"); $result = $this->_read($domain_dn, $attributes); } - if (!$result) { - return false; - } - $this->_log(LOG_DEBUG, "Auth::LDAP::domain_info() result: " . var_export($result, true)); - return $result; + return $result ? $result : false; } /** @@ -1424,25 +1410,19 @@ class LDAP extends Net_LDAP3 { return false; } - $domain_base_dn = $this->conf->get('ldap', 'domain_base_dn'); - $domain_filter = $this->conf->get('ldap', 'domain_filter'); $domain_name_attribute = $this->conf->get('ldap', 'domain_name_attribute'); if (empty($domain_name_attribute)) { $domain_name_attribute = 'associateddomain'; } - $domain_filter = "(&" . $domain_filter . "(" . $domain_name_attribute . "=" . $domain . "))"; - - $result = $this->_search($domain_base_dn, $domain_filter); + $entry_attrs = $this->_find_domain($domain); - if (!$result) { + if (!$entry_attrs) { return $this->_standard_root_dn($domain); } - $entries = $result->entries(true); - $entry_dn = key($entries); - $entry_attrs = $entries[$entry_dn]; + $entry_attrs = array_shift($entry_attrs); if (is_array($entry_attrs)) { if (array_key_exists('inetdomainbasedn', $entry_attrs) && !empty($entry_attrs['inetdomainbasedn'])) { @@ -1462,7 +1442,6 @@ class LDAP extends Net_LDAP3 { } return $domain_root_dn; - } /** @@ -1520,6 +1499,33 @@ class LDAP extends Net_LDAP3 { } /** + * Find domain by name + * + * @param string $domain Domain name + * @param array $attributes Result attributes + * + * @return array Domain records indexed by base DN + */ + private function _find_domain($domain, $attributes = array('*')) + { + $this->_log(LOG_DEBUG, "Auth::LDAP::_find_domain($domain)"); + + $domain_base_dn = $this->conf->get('ldap', 'domain_base_dn'); + $domain_filter = $this->conf->get('ldap', 'domain_filter'); + $domain_name_attribute = $this->conf->get('ldap', 'domain_name_attribute'); + + if (empty($domain_name_attribute)) { + $domain_name_attribute = 'associateddomain'; + } + + $domain_filter = "(&" . $domain_filter . "(" . $domain_name_attribute . "=" . $domain . "))"; + + if ($result = $this->_search($domain_base_dn, $domain_filter, $attributes)) { + return $result->entries(true); + } + } + + /** * From a domain name, such as 'kanarip.com', create a standard root * dn, such as 'dc=kanarip,dc=com'. * |