lib/Auth

Aleksander Machniak machniak at kolabsys.com
Fri Jan 2 10:37:53 CET 2015


 lib/Auth/LDAP.php |   51 ++++++++++++++++++++-------------------------------
 1 file changed, 20 insertions(+), 31 deletions(-)

New commits:
commit 17b5c924a7de8de86ce8755b9eb6d888b14fb888
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Fri Jan 2 04:32:34 2015 -0500

    Support OU attribute as a base for new sharedfolder and role object (#4043)

diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index b80a463..b0027be 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -552,13 +552,7 @@ class LDAP extends Net_LDAP3 {
 
     public function group_add($attrs, $typeid = null)
     {
-        if (!empty($attrs['ou'])) {
-            $base_dn = $attrs['ou'];
-            unset($attrs['ou']);
-        }
-        else {
-            $base_dn = $this->entry_base_dn('group', $typeid);
-        }
+        $base_dn = $this->entry_base_dn('group', $typeid, $attrs);
 
         // TODO: The rdn is configurable as well.
         // Use [$type_str . "_"]user_rdn_attr
@@ -724,13 +718,7 @@ class LDAP extends Net_LDAP3 {
 
     public function organizationalunit_add($attrs, $typeid = null)
     {
-        if (!empty($attrs['base_dn'])) {
-            $base_dn = $attrs['base_dn'];
-            unset($attrs['base_dn']);
-        }
-        else {
-            $base_dn = $this->entry_base_dn('ou', $typeid);
-        }
+        $base_dn = $this->entry_base_dn('ou', $typeid, $attrs);
 
         // TODO: The rdn is configurable as well.
         // Use [$type_str . "_"]ou_rdn_attr
@@ -782,13 +770,7 @@ class LDAP extends Net_LDAP3 {
 
     public function resource_add($attrs, $typeid = null)
     {
-        if (!empty($attrs['ou'])) {
-            $base_dn = $attrs['ou'];
-            unset($attrs['ou']);
-        }
-        else {
-            $base_dn = $this->entry_base_dn('resource', $typeid);
-        }
+        $base_dn = $this->entry_base_dn('resource', $typeid, $attrs);
 
         // TODO: The rdn is configurable as well.
         // Use [$type_str . "_"]resource_rdn_attr
@@ -839,7 +821,7 @@ class LDAP extends Net_LDAP3 {
 
     public function role_add($attrs, $typeid = null)
     {
-        $base_dn = $this->entry_base_dn('role', $typeid);
+        $base_dn = $this->entry_base_dn('role', $typeid, $attrs);
 
         // TODO: The rdn is configurable as well.
         // Use [$type_str . "_"]role_rdn_attr
@@ -891,7 +873,7 @@ class LDAP extends Net_LDAP3 {
 
     public function sharedfolder_add($attrs, $typeid = null)
     {
-        $base_dn = $this->entry_base_dn('sharedfolder', $typeid);
+        $base_dn = $this->entry_base_dn('sharedfolder', $typeid, $attrs);
 
         // TODO: The rdn is configurable as well.
         // Use [$type_str . "_"]user_rdn_attr
@@ -956,12 +938,7 @@ class LDAP extends Net_LDAP3 {
 
     public function user_add($attrs, $typeid = null)
     {
-        $base_dn = $this->entry_base_dn('user', $typeid);
-
-        if (!empty($attrs['ou'])) {
-            $base_dn = $attrs['ou'];
-            unset($attrs['ou']);
-        }
+        $base_dn = $this->entry_base_dn('user', $typeid, $attrs);
 
         // TODO: The rdn is configurable as well.
         // Use [$type_str . "_"]user_rdn_attr
@@ -1151,9 +1128,21 @@ class LDAP extends Net_LDAP3 {
     /**
      * Return base DN for specified object type
      */
-    protected function entry_base_dn($type, $typeid = null)
+    protected function entry_base_dn($type, $typeid = null, &$attrs = array())
     {
-        if ($typeid) {
+        // check if base_dn already exists in object attributes
+        if (!empty($attrs)) {
+            if (!empty($attrs['base_dn'])) {
+                $base_dn = $attrs['base_dn'];
+                unset($attrs['base_dn']);
+            }
+            else if ($type != 'ou' && !empty($attrs['ou'])) {
+                $base_dn = $attrs['ou'];
+                unset($attrs['ou']);
+            }
+        }
+
+        if (empty($base_dn) && $typeid) {
             $db    = SQL::get_instance();
             $query = $db->query("SELECT `key` FROM `{$type}_types` WHERE `id` = ?", array($typeid));
             $sql   = $db->fetch_assoc($query);




More information about the commits mailing list