2 commits - lib/Auth lib/Conf.php lib/kolab_recipient_policy.php

Aleksander Machniak machniak at kolabsys.com
Tue Sep 10 12:53:39 CEST 2013


 lib/Auth/LDAP.php              |    4 ++--
 lib/Conf.php                   |   37 +++++++++++++++++++++++++------------
 lib/kolab_recipient_policy.php |   35 ++++++++++++++++-------------------
 3 files changed, 43 insertions(+), 33 deletions(-)

New commits:
commit 0c3eaa895c8f387389fba28e1470c162d651ab67
Author: Aleksander Machniak <alec at alec.pl>
Date:   Tue Sep 10 12:51:25 2013 +0200

    Refactored config getter so when section is specified, but requested
    setting doesn't exist there, we'll fall back to (global) 'kolab' and
    primary domain section (in this order).
    This fixes empty primary_mail/secondary_mail for newly created domains,
    where we do not have [$domain] section in kolab.conf (Bug #1925).

diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index cdda6b6..afe68e5 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -73,7 +73,7 @@ class LDAP extends Net_LDAP3 {
         }
 
         // Continue and default to the primary domain.
-        $this->domain       = $domain ? $domain : $this->conf->get('primary_domain');
+        $this->domain = $domain ? $domain : $this->conf->get('primary_domain');
 
         $unique_attr = $this->conf->get($domain, 'unique_attribute');
 
diff --git a/lib/Conf.php b/lib/Conf.php
index f95df5f..01ea946 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -81,8 +81,7 @@ class Conf {
 
     public function get_list($key1, $key2 = NULL)
     {
-        $list = array();
-
+        $list  = array();
         $value = $this->get($key1, $key2);
         $value_components = explode(',', $value);
 
@@ -112,26 +111,40 @@ class Conf {
             }
         }
 
+        // If section is specified, but requested setting doesn't exist there
+        // we'll fall back to (global) 'kolab' and primary domain section (in this order).
+        if ($key2) {
+            if (isset($this->_conf['kolab'][$key2])) {
+                return $this->_conf['kolab'][$key2];
+            }
+
+            $primary_domain = $this->_conf['kolab']['primary_domain'];
+            if ($primary_domain && isset($this->_conf[$primary_domain])) {
+                if (isset($this->_conf[$primary_domain][$key2])) {
+                    return $this->_conf[$primary_domain][$key2];
+                }
+            }
+
+            return null;
+        }
+
         // 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.
+        // First, try user domain.
         if (isset($_SESSION['user']) && method_exists($_SESSION['user'], 'get_domain')) {
             try {
-                $domain_section_name = $_SESSION['user']->get_domain();
-                if (isset($this->_conf[$domain_section_name]) && isset($this->_conf[$domain_section_name][$key1])) {
-                    return $this->_conf[$domain_section_name][$key1];
-                }
-            } catch (Exception $e) {
-                if ($domain_section_name = $this->_conf['kolab']['primary_domain']) {
-                    if (isset($this->_conf[$domain_section_name]) && isset($this->_conf[$domain_section_name][$key1])) {
-                        return $this->_conf[$domain_section_name][$key1];
+                $domain = $_SESSION['user']->get_domain();
+
+                if ($domain && isset($this->_conf[$domain])) {
+                    if (isset($this->_conf[$domain][$key1])) {
+                        return $this->_conf[$domain][$key1];
                     }
                 }
-            }
+            } catch (Exception $e) { }
         }
 
         // Fall back to whatever is the equivalent of auth_mechanism as the
diff --git a/lib/kolab_recipient_policy.php b/lib/kolab_recipient_policy.php
index c9e892d..e8923ec 100644
--- a/lib/kolab_recipient_policy.php
+++ b/lib/kolab_recipient_policy.php
@@ -132,17 +132,14 @@ class kolab_recipient_policy {
     static function primary_mail($userdata)
     {
         $userdata = self::normalize_userdata($userdata);
+        $conf     = Conf::get_instance();
 
-        $conf = Conf::get_instance();
-
-        if (isset($userdata['domain'])) {
-            $primary_mail = $conf->get_raw($userdata['domain'], 'primary_mail');
-        } else {
-            $primary_mail = $conf->get_raw($_SESSION['user']->get_domain(), 'primary_mail');
-            // Also append the domain to the userdata
+        if (empty($userdata['domain'])) {
             $userdata['domain'] = $_SESSION['user']->get_domain();
         }
 
+        $primary_mail = $conf->get_raw($userdata['domain'], 'primary_mail');
+
         preg_match_all('/%\((\w+)\)s/', $primary_mail, $substrings);
 
         // Update userdata array
@@ -206,19 +203,18 @@ class kolab_recipient_policy {
             );
 
         $userdata = self::normalize_userdata($userdata);
+        $conf     = Conf::get_instance();
+
         if (!array_key_exists('mail', $userdata)) {
             $userdata['mail'] = self::primary_mail($userdata);
         }
 
-        $conf = Conf::get_instance();
-
-        if (isset($userdata['domain'])) {
-            $secondary_mail = $conf->get_raw($userdata['domain'], 'secondary_mail');
-        } else {
-            $secondary_mail = $conf->get_raw($_SESSION['user']->get_domain(), 'secondary_mail');
+        if (empty($userdata['domain'])) {
             $userdata['domain'] = $_SESSION['user']->get_domain();
         }
 
+        $secondary_mail = $conf->get_raw($userdata['domain'], 'secondary_mail');
+
         $secondary_mail = preg_replace('/^{\d:\s*/','',$secondary_mail);
         $secondary_mail = preg_replace('/\s*}$/','',$secondary_mail);
         $secondary_mail = preg_replace('/,\d+:\s*/',',',$secondary_mail);
@@ -284,7 +280,8 @@ class kolab_recipient_policy {
         return $secondary_mail_addresses;
     }
 
-    static public function transliterate($mystring, $locale) {
+    static public function transliterate($mystring, $locale)
+    {
         $locale_translit_map = Array(
                 'ru_RU' => 'cyrillic'
             );
@@ -367,16 +364,16 @@ class kolab_recipient_policy {
         return $mystring;
     }
 
-    static public function uid($userdata) {
+    static public function uid($userdata)
+    {
         $conf = Conf::get_instance();
 
-        if (isset($userdata['domain'])) {
-            $policy_uid = $conf->get_raw($userdata['domain'], 'policy_uid');
-        } else {
-            $policy_uid = $conf->get_raw($_SESSION['user']->get_domain(), 'policy_uid');
+        if (empty($userdata['domain'])) {
             $userdata['domain'] = $_SESSION['user']->get_domain();
         }
 
+        $policy_uid = $conf->get_raw($userdata['domain'], 'policy_uid');
+
         if (empty($policy_uid)) {
             $policy_uid = "%(surname)s.lower()";
         }


commit 364e45dfeff6f51dbe3df4b0715bdce0bb82c1cc
Author: Aleksander Machniak <alec at alec.pl>
Date:   Tue Sep 10 12:07:21 2013 +0200

    Fix invalid Conf::get_list() usage

diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 0434b45..cdda6b6 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -583,7 +583,7 @@ class LDAP extends Net_LDAP3 {
     {
         $this->bind($_SESSION['user']->user_bind_dn, $_SESSION['user']->user_bind_pw);
 
-        $mail_attrs = $this->conf->get_list('mail_attributes', array('mail', 'alias'));
+        $mail_attrs = $this->conf->get_list('mail_attributes') ?: array('mail', 'alias');
         $search     = array('operator' => 'OR');
 
         foreach ($mail_attrs as $num => $attr) {




More information about the commits mailing list