lib/Auth lib/Auth.php
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Fri Mar 30 18:36:20 CEST 2012
lib/Auth.php | 5 +++++
lib/Auth/LDAP.php | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
New commits:
commit afa582a38e00123e9d57e91421f80d3254f8fafe
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Fri Mar 30 18:35:49 2012 +0200
Make adding groups work
Strip empty attribute values from the ldap_add() function call, as it seems to not be able to digest those
diff --git a/lib/Auth.php b/lib/Auth.php
index 7b7b379..dfafc06 100644
--- a/lib/Auth.php
+++ b/lib/Auth.php
@@ -171,6 +171,11 @@ class Auth {
return $this->_auth[$_SESSION['user']->get_domain()]->find_user_groups($member_dn);
}
+ public function group_add($attributes, $type=NULL)
+ {
+ return $this->_auth[$_SESSION['user']->get_domain()]->group_add($attributes, $type);
+ }
+
public function group_info($groupdata)
{
return $this->_auth[$_SESSION['user']->get_domain()]->group_info($groupdata);
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 5aff9f6..73701b7 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -460,6 +460,36 @@ class LDAP
return $groups;
}
+ public function group_add($attrs, $type = null)
+ {
+ if ($type == null) {
+ $type_str = 'group';
+ }
+ else {
+ $db = SQL::get_instance();
+ $_key = $db->fetch_assoc($db->query("SELECT `key` FROM group_types WHERE id = ?", $type));
+ $type_str = $_key['key'];
+ }
+
+ // Check if the user_type has a specific base DN specified.
+ $base_dn = $this->conf->get($this->domain, $type_str . "_group_base_dn");
+ // If not, take the regular user_base_dn
+ if (!$base_dn)
+ $base_dn = $this->conf->get($this->domain, "group_base_dn");
+
+ // If no user_base_dn either, take the user type specific from the parent
+ // configuration
+ if (!$base_dn)
+ $base_dn = $this->conf->get('ldap', $type_str . "_group_base_dn");
+
+ // TODO: The rdn is configurable as well.
+ // Use [$type_str . "_"]user_rdn_attr
+ $dn = "cn=" . $attrs['cn'] . "," . $base_dn;
+
+ return $this->_add($dn, $attrs);
+ }
+
+
public function group_info($group)
{
$is_dn = ldap_explode_dn($group, 1);
@@ -795,6 +825,15 @@ class LDAP
// Always bind with the session credentials
$this->_bind($_SESSION['user']->user_bind_dn, $_SESSION['user']->user_bind_pw);
+// console("Entry DN", $entry_dn);
+// console("Attributes", $attributes);
+
+ foreach ($attributes as $attr_name => $attr_value) {
+ if (empty($attr_value)) {
+ unset($attributes[$attr_name]);
+ }
+ }
+
if (($add_result = ldap_add($this->conn, $entry_dn, $attributes)) == false) {
// Issue warning
return false;
More information about the commits
mailing list