diff options
-rw-r--r-- | lib/Auth/LDAP.php | 15 | ||||
-rw-r--r-- | lib/Conf.php | 38 |
2 files changed, 42 insertions, 11 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php index 3c2e96e..7c5b658 100644 --- a/lib/Auth/LDAP.php +++ b/lib/Auth/LDAP.php @@ -64,8 +64,19 @@ class LDAP { $this->conf = Conf::get_instance(); + // See if we are to connect to any domain explicitly defined. + if (!isset($domain) || empty($domain)) { + // If not, attempt to get the domain from the session. + if (isset($_SESSION['user'])) { + $domain = $_SESSION['user']->get_domain(); + } + } + + // Continue and default to the primary domain. $this->domain = $domain ? $domain : $this->conf->get('primary_domain'); - $this->_ldap_uri = $this->conf->get('uri'); + + $this->_ldap_uri = $this->conf->get('ldap_uri'); + $this->_ldap_server = parse_url($this->_ldap_uri, PHP_URL_HOST); $this->_ldap_port = parse_url($this->_ldap_uri, PHP_URL_PORT); $this->_ldap_scheme = parse_url($this->_ldap_uri, PHP_URL_SCHEME); @@ -955,7 +966,7 @@ class LDAP if (empty($search) || !is_array($search) || empty($search['params'])) { return null; } - + $filter = ''; foreach ((array) $search['params'] as $field => $param) { $value = self::_quote_string($param['value']); diff --git a/lib/Conf.php b/lib/Conf.php index 704c3c4..d843cdd 100644 --- a/lib/Conf.php +++ b/lib/Conf.php @@ -99,19 +99,39 @@ class Conf { } } - // Simple (global) settings may be obtained by calling the key and omitting - // the section. This goes for sections 'kolab', and whatever is the equivalent - // of 'kolab', 'auth_mechanism'. -// echo "<pre>"; -// print_r($this->_conf); -// echo "</pre>"; + // Simple (global) settings may be obtained by calling the key and + // omitting the section. This goes for sections 'kolab', and whatever + // is the equivalent of 'kolab', 'auth_mechanism', such as getting + // 'ldap_uri', which is in the [$domain] section, or in section 'ldap', + // and we can try and iterate over it. + + // First, try the most exotic. + if (isset($_SESSION['user'])) { + $domain_section_name = $_SESSION['user']->get_domain(); + if (isset($this->_conf[$domain_section_name][$key1])) { + return $this->_conf[$domain_section_name][$key1]; + } + } + + // Fall back to whatever is the equivalent of auth_mechanism as the + // section (i.e. 'ldap', or 'sql') + $auth_mech = $this->_conf['kolab']['auth_mechanism']; + if (isset($this->_conf[$auth_mech])) { + if (isset($this->_conf[$auth_mech][$key1])) { + return $this->_conf[$auth_mech][$key1]; + } + } + // Fall back to global settings in the 'kolab' section. if (isset($this->_conf['kolab'][$key1])) { return $this->_conf['kolab'][$key1]; } - else if (isset($this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1])) { - return $this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1]; - } + + error_log("Could not find setting for \$key1: " . $key1 . + " with \$key2: " . $key2 + ); + + return null; } public function expand($str, $custom = FALSE) |