4 commits - lib/api lib/Auth lib/Conf.php lib/kolab_recipient_policy.php
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Fri Apr 20 12:21:20 CEST 2012
lib/Auth/LDAP.php | 59 +++++++++++++++++------------
lib/Conf.php | 62 +++++++++++++++++--------------
lib/api/kolab_api_service_form_value.php | 15 ++++++-
lib/kolab_recipient_policy.php | 10 +++++
4 files changed, 92 insertions(+), 54 deletions(-)
New commits:
commit 8eb7357b248952f16c50da9a2483e56d9f449c89
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Fri Apr 20 11:04:55 2012 +0200
Bug #704: Cannot override auto_form_field values
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index bcd3491..52ea985 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -568,7 +568,7 @@ class LDAP
$_user_dn = key($_user);
$_user = $this->user_info($_user_dn, array_keys($attributes));
- //console("user_edit \$_user", $_user);
+ //console("Auth::LDAP::user_edit() existing \$_user info", $_user);
// We should start throwing stuff over the fence here.
return $this->modify_entry($_user_dn, $_user[$_user_dn], $attributes);
@@ -999,7 +999,7 @@ class LDAP
$rdn_attr = $rdn_components[0];
- //console($rdn_attr);
+ //console("Auth::LDAP::modify_entry() using rdn attribute: " . $rdn_attr);
$mod_array = Array(
"add" => Array(), // For use with ldap_mod_add()
@@ -1019,15 +1019,14 @@ class LDAP
foreach ($old_attrs as $attr => $old_attr_value) {
if (array_key_exists($attr, $new_attrs)) {
- $_sort1 = false;
- $_sort2 = false;
- if (is_array($new_attrs[$attr])) {
+ if (is_array($old_attrs[$attr]) && is_array($new_attrs[$attr])) {
$_sort1 = $new_attrs[$attr];
sort($_sort1);
- }
- if (is_array($old_attr_value)) {
$_sort2 = $old_attr_value;
sort($_sort2);
+ } else {
+ $_sort1 = true;
+ $_sort2 = false;
}
if (!($new_attrs[$attr] === $old_attr_value) && !($_sort1 === $_sort2)) {
@@ -1120,12 +1119,38 @@ class LDAP
// Opportunities to set false include failed ldap commands.
$result = true;
+ if (is_array($attributes['rename']) && !empty($attributes['rename'])) {
+ $olddn = $attributes['rename']['dn'];
+ $newrdn = $attributes['rename']['new_rdn'];
+ if (!empty($attributes['rename']['new_parent'])) {
+ $new_parent = $attributes['rename']['new_parent'];
+ } else {
+ $new_parent = null;
+ }
+
+ //console("Attempt to rename $olddn to $newrdn,$new_parent");
+
+ $result = ldap_rename($this->conn, $olddn, $newrdn, $new_parent, true);
+ if ($result) {
+ if ($new_parent) {
+ $subject_dn = $newrdn . ',' . $new_parent;
+ } else {
+ $old_parent_dn_components = ldap_explode_dn($olddn, 0);
+ unset($old_parent_dn_components["count"]);
+ $old_rdn = array_shift($old_parent_dn_components);
+ $old_parent_dn = implode(",", $old_parent_dn_components);
+ $subject_dn = $newrdn . ',' . $old_parent_dn;
+ }
+ }
+
+ }
+
if (is_array($attributes['replace']) && !empty($attributes['replace'])) {
$result = ldap_mod_replace($this->conn, $subject_dn, $attributes['replace']);
}
if (!$result) {
- //console("Failed to replace the following attributes", $attributes['replace']);
+ console("Failed to replace the following attributes on subject " . $subject_dn, $attributes['replace']);
return false;
}
@@ -1134,7 +1159,7 @@ class LDAP
}
if (!$result) {
- //console("Failed to delete the following attributes", $attributes['del']);
+ console("Failed to delete the following attributes", $attributes['del']);
return false;
}
@@ -1144,24 +1169,10 @@ class LDAP
}
if (!$result) {
- //console("Failed to add the following attributes", $attributes['add']);
+ console("Failed to add the following attributes", $attributes['add']);
return false;
}
- if (is_array($attributes['rename']) && !empty($attributes['rename'])) {
- $olddn = $attributes['rename']['dn'];
- $newrdn = $attributes['rename']['new_rdn'];
- if (!empty($attributes['rename']['new_parent'])) {
- $new_parent = $attributes['rename']['new_parent'];
- } else {
- $new_parent = null;
- }
-
- //console("Attempt to rename $olddn to $newrdn,$new_parent");
-
- $result = ldap_rename($this->conn, $olddn, $newrdn, $new_parent, true);
- }
-
if (!$result) {
error_log("LDAP Error: " . $this->_errstr());
return false;
commit 9c9a7b3e782386e50933006221a26de54748c170
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Fri Apr 20 11:03:35 2012 +0200
Ensure any primary email addresses are not included in the result for secondary email addresses
diff --git a/lib/kolab_recipient_policy.php b/lib/kolab_recipient_policy.php
index 492df0b..6667631 100644
--- a/lib/kolab_recipient_policy.php
+++ b/lib/kolab_recipient_policy.php
@@ -175,6 +175,9 @@ class kolab_recipient_policy {
);
$userdata = self::normalize_userdata($userdata);
+ if (!array_key_exists('mail', $userdata)) {
+ $userdata['mail'] = self::primary_mail($userdata);
+ }
$conf = Conf::get_instance();
@@ -234,6 +237,13 @@ class kolab_recipient_policy {
eval("\$result = sprintf('" . $format . "', '" . implode("', '", array_values($result)) . "');");
if ($result = self::parse_email($result)) {
+ // See if the equivalent is already in the 'mail' attribute value(s)
+ if (!empty($userdata['mail'])) {
+ if (strtolower($userdata['mail']) == strtolower($result)) {
+ continue;
+ }
+ }
+
$secondary_mail_addresses[] = $result;
}
}
commit 2cf72fefc2d987f4b97b376cdc13d96998e730db
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Fri Apr 20 11:01:56 2012 +0200
Extract reading configuration file to a different function, make sure configuration is read in time
diff --git a/lib/Conf.php b/lib/Conf.php
index 4f1f883..e8a9a02 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -26,6 +26,8 @@
class Conf {
static private $instance;
+ private $_conf = array();
+
const CONFIG_FILE = '/etc/kolab/kolab.conf';
/**
@@ -49,33 +51,8 @@ class Conf {
return;
}
- $_ini_raw = file(self::CONFIG_FILE);
-
- $this->_conf = array();
+ $this->read_config();
- foreach ($_ini_raw as $_line) {
- if (preg_match('/^\[([a-z0-9-_\.]+)\]/', $_line, $matches)) {
- $_cur_section = $matches[1];
- $this->_conf[$_cur_section] = array();
- unset($_cur_key);
- }
-
- if (preg_match('/^;/', $_line, $matches)) {
- }
-
- if (preg_match('/^([a-z0-9\.-_]+)\s*=\s*(.*)/', $_line, $matches)) {
- if (isset($_cur_section) && !empty($_cur_section)) {
- $_cur_key = $matches[1];
- $this->_conf[$_cur_section][$matches[1]] = isset($matches[2]) ? $matches[2] : '';
- }
- }
-
- if (preg_match('/^\s+(.*)$/', $_line, $matches)) {
- if (isset($_cur_key) && !empty($_cur_key)) {
- $this->_conf[$_cur_section][$_cur_key] .= $matches[1];
- }
- }
- }
}
public function get($key1, $key2 = NULL)
@@ -130,7 +107,7 @@ class Conf {
return $this->_conf[$domain_section_name][$key1];
}
} catch (Exception $e) {
- $domain_section_name = $this->get('kolab', 'primary_domain');
+ $domain_section_name = $this->get_raw('kolab', 'primary_domain');
if (isset($this->_conf[$domain_section_name][$key1])) {
return $this->_conf[$domain_section_name][$key1];
}
@@ -183,4 +160,35 @@ class Conf {
return $str;
}
}
+
+ private function read_config()
+ {
+ $_ini_raw = file(self::CONFIG_FILE);
+
+ $this->_conf = array();
+
+ foreach ($_ini_raw as $_line) {
+ if (preg_match('/^\[([a-z0-9-_\.]+)\]/', $_line, $matches)) {
+ $_cur_section = $matches[1];
+ $this->_conf[$_cur_section] = array();
+ unset($_cur_key);
+ }
+
+ if (preg_match('/^;/', $_line, $matches)) {
+ }
+
+ if (preg_match('/^([a-z0-9\.-_]+)\s*=\s*(.*)/', $_line, $matches)) {
+ if (isset($_cur_section) && !empty($_cur_section)) {
+ $_cur_key = $matches[1];
+ $this->_conf[$_cur_section][$matches[1]] = isset($matches[2]) ? $matches[2] : '';
+ }
+ }
+
+ if (preg_match('/^\s+(.*)$/', $_line, $matches)) {
+ if (isset($_cur_key) && !empty($_cur_key)) {
+ $this->_conf[$_cur_section][$_cur_key] .= $matches[1];
+ }
+ }
+ }
+ }
}
commit f9da7438d93d12de64cfd08e02d4c8d2949ffdaa
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Fri Apr 20 11:00:30 2012 +0200
Make sure the secondary mail addresses are unique, too
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 614bd18..8af2f8f 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -389,7 +389,7 @@ class kolab_api_service_form_value extends kolab_api_service
private function generate_secondary_mail($postdata, $attribs = array())
{
- $secondary_mail_address = Array();
+ $secondary_mail_addresses = Array();
if (isset($attribs['auto_form_fields'])) {
if (isset($attribs['auto_form_fields']['alias'])) {
@@ -412,9 +412,17 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- $secondary_mail = kolab_recipient_policy::secondary_mail($postdata);
+ if (array_key_exists('mail', $attribs['auto_form_fields'])) {
+ if (!array_key_exists('mail', $postdata)) {
+ $postdata['mail'] = $this->generate_primary_mail($postdata, $attribs);
+ }
+ }
+
+ $secondary_mail_addresses = kolab_recipient_policy::secondary_mail($postdata);
+
+ // TODO: Check for uniqueness. Not sure what to do if not unique.
- return $secondary_mail;
+ return $secondary_mail_addresses;
}
}
@@ -459,6 +467,7 @@ class kolab_api_service_form_value extends kolab_api_service
$user_found_unique_attr = $auth->get_attribute($user_found_dn, $unique_attr);
//console("user with uid $uid found", $user_found_unique_attr);
if ($user_found_unique_attr == $postdata['id']) {
+ //console("that's us.");
break;
}
}
More information about the commits
mailing list