10 commits - doc/sample-insert-role_types.php lib/api lib/Auth lib/Auth.php lib/client lib/kolab_api_controller.php lib/kolab_api_service.php lib/kolab_client_task.php public_html/js

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Thu Jun 21 13:48:13 CEST 2012


 doc/sample-insert-role_types.php         |   36 +++++
 lib/Auth.php                             |   10 +
 lib/Auth/LDAP.php                        |   26 +++
 lib/api/kolab_api_service_form_value.php |   17 +-
 lib/api/kolab_api_service_role.php       |  205 +++++++++++++++++++++++++++++++
 lib/api/kolab_api_service_role_types.php |   62 +++++++++
 lib/client/kolab_client_task_role.php    |   34 ++---
 lib/kolab_api_controller.php             |    4 
 lib/kolab_api_service.php                |   20 +--
 lib/kolab_client_task.php                |   12 +
 public_html/js/kolab_admin.js            |   76 +++++++++++
 11 files changed, 471 insertions(+), 31 deletions(-)

New commits:
commit 0c33b6d56cf3989083094fcf8b64508e80bd85e4
Merge: 1a9f063 16e7ac5
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:48:05 2012 +0200

    Merge branch 'master' of ssh://git.kolab.org/git/kolab-wap



commit 1a9f0637272ede89bbac9c0e9f43cf855a79d1c8
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:46:58 2012 +0200

    Here too, disable caching when in devel_mode

diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 9ed1845..e93aa40 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -577,8 +577,10 @@ class kolab_client_task
      */
     protected function user_name($dn)
     {
-        if (!empty($this->cache['user_names']) && isset($this->cache['user_names'][$dn])) {
-            return $this->cache['user_names'][$dn];
+        if (!$this->config_get('devel_mode', false)) {
+            if (!empty($this->cache['user_names']) && isset($this->cache['user_names'][$dn])) {
+                return $this->cache['user_names'][$dn];
+            }
         }
 
         $result   = $this->api->get('user.info', array('user' => $dn));
@@ -593,7 +595,11 @@ class kolab_client_task
             }
         }
 
-        return $this->cache['user_names'][$dn] = $username;
+        if (!$this->config_get('devel_mode', false)) {
+            return $this->cache['user_names'][$dn] = $username;
+        } else {
+            return $username;
+        }
     }
 
     /**


commit 3c6cc69a2c71005d6c6e08adffa0e44b9bf9320c
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:46:33 2012 +0200

    Enable 'role' in object_types() and disable caching in devel_mode

diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 7fca044..b984d54 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -165,17 +165,21 @@ abstract class kolab_api_service
      */
     protected function object_types($object_name)
     {
-        $supported = array('group', 'resource', 'user');
+        $supported = array('group', 'resource', 'role', 'user');
         if (!$object_name || !in_array($object_name, $supported)) {
             return array();
         }
 
+        $conf = Conf::get_instance();
+
+        $devel_mode = $conf->get('kolab_wap', 'devel_mode');
 
-        if (!empty($this->cache['object_types']) && !empty($this->cache['object_types'][$object_name])) {
-            return $this->cache['object_types'][$object_name];
+        if ($devel_mode == null) {
+            if (!empty($this->cache['object_types']) && !empty($this->cache['object_types'][$object_name])) {
+                return $this->cache['object_types'][$object_name];
+            }
         }
 
-        $conf = Conf::get_instance();
         $unique_attr = $conf->get('unique_attribute');
         if (!$unique_attr) {
             $unique_attr = 'nsuniqueid';
@@ -201,9 +205,11 @@ abstract class kolab_api_service
 
         //console("Object types for " . $object_name, $object_types);
 
-//         return $object_types;
-
-        return $this->cache['object_types'][$object_name] = $object_types;
+        if ($devel_mode == null) {
+            return $this->cache['object_types'][$object_name] = $object_types;
+        } else {
+            return $object_types;
+        }
 
     }
 


commit 491d874fb8f285c5f6f8c15926284f993b9a439a
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:46:00 2012 +0200

    Add a sample to insert role types into the database

diff --git a/doc/sample-insert-role_types.php b/doc/sample-insert-role_types.php
new file mode 100644
index 0000000..08f68a9
--- /dev/null
+++ b/doc/sample-insert-role_types.php
@@ -0,0 +1,36 @@
+#!/usr/bin/php
+<?php
+
+    if (isset($_SERVER["REQUEST_METHOD"]) && !empty($SERVER["REQUEST_METHOD"])) {
+        die("Not intended for execution through the webserver, sorry!");
+    }
+
+    require_once("lib/functions.php");
+
+    $db   = SQL::get_instance();
+
+    $result = $db->query("TRUNCATE `role_types`");
+
+    $attributes = Array(
+            "auto_form_fields" => Array(
+                ),
+            "fields" => Array(
+                    "objectclass" => Array(
+                            "top",
+                            "ldapsubentry",
+                            "nsroledefinition",
+                            "nssimpleroledefinition",
+                            "nsmanagedroledefinition"
+                        ),
+                ),
+            "form_fields" => Array(
+                    "cn" => Array(),
+                    "description" => Array(),
+                ),
+        );
+
+    $result = $db->query("INSERT INTO `role_types` (`key`, `name`, `description`, `attributes`) " .
+                "VALUES ('simple_managed','Standard Role', 'A standard role definition'," .
+                "'" . json_encode($attributes) . "')");
+
+?>


commit f818d9890952cf822228e3dcfbe723c383ee9fe0
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:45:41 2012 +0200

    Add role javascript functions

diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index b640679..3b7e97d 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1322,6 +1322,82 @@ function kolab_admin()
     this.command('resource.list', {page: this.env.list_page});
   };
 
+  this.role_info = function(id)
+  {
+    this.http_post('role.info', {id: id});
+  };
+
+  this.role_list = function(props)
+  {
+    if (!props)
+      props = {};
+
+    if (props.search === undefined && this.env.search_request)
+      props.search_request = this.env.search_request;
+
+    this.http_post('role.list', props);
+  };
+
+  this.role_delete = function(roleid)
+  {
+    this.set_busy(true, 'deleting');
+    this.api_post('role.delete', {role: roleid}, 'role_delete_response');
+  };
+
+  this.role_delete_response = function(response)
+  {
+    if (!this.api_response(response))
+      return;
+
+    var page = this.env.list_page;
+
+    // goto previous page if last user on the current page has been deleted
+    if (this.env.list_count)
+      page -= 1;
+
+    this.display_message('role.delete.success');
+    this.command('role.list', {page: page});
+  };
+
+  this.role_save = function(reload, section)
+  {
+    var data = this.serialize_form('#'+this.env.form_id),
+      action = data.id ? 'edit' : 'add';
+
+    if (reload) {
+      data.section = section;
+      this.http_post('role.' + action, {data: data});
+      return;
+    }
+
+    this.form_error_clear();
+
+    if (!this.check_required_fields(data)) {
+      this.display_message('form.required.empty', 'error');
+      return;
+    }
+
+    this.set_busy(true, 'saving');
+    this.api_post('role.' + action, data, 'role_' + action + '_response');
+  };
+
+  this.role_add_response = function(response)
+  {
+    if (!this.api_response(response))
+      return;
+
+    this.display_message('role.add.success');
+    this.command('role.list', {page: this.env.list_page});
+  };
+
+  this.role_edit_response = function(response)
+  {
+    if (!this.api_response(response))
+      return;
+
+    this.display_message('role.edit.success');
+    this.command('role.list', {page: this.env.list_page});
+  };
 
   this.generate_password = function(fieldname)
   {


commit 6f212bbc31886ce64a17b696a58c56c39a74a044
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:45:20 2012 +0200

    Add the new services to the controller

diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index e984c42..bdbc707 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -66,6 +66,8 @@ class kolab_api_controller
         $this->add_service('resource',          'kolab_api_service_resource');
         $this->add_service('resources',         'kolab_api_service_resources');
         $this->add_service('roles',             'kolab_api_service_roles');
+        $this->add_service('role',              'kolab_api_service_role');
+        $this->add_service('role_types',        'kolab_api_service_role_types');
         $this->add_service('user_types',        'kolab_api_service_user_types');
         $this->add_service('user',              'kolab_api_service_user');
         $this->add_service('users',             'kolab_api_service_users');
@@ -89,6 +91,8 @@ class kolab_api_controller
      */
     public function get_service($service)
     {
+        //console("Obtaining service $service");
+
         // we are the system!
         if ($service == 'system') {
             return $this;


commit eb12c40fda7cf6de4fddef4e92cc0e462ffb82d7
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:44:31 2012 +0200

    Add role and role_types services

diff --git a/lib/api/kolab_api_service_role.php b/lib/api/kolab_api_service_role.php
new file mode 100644
index 0000000..1e6ac3c
--- /dev/null
+++ b/lib/api/kolab_api_service_role.php
@@ -0,0 +1,205 @@
+<?php
+/*
+ +--------------------------------------------------------------------------+
+ | This file is part of the Kolab Web Admin Panel                           |
+ |                                                                          |
+ | Copyright (C) 2011-2012, Kolab Systems AG                                |
+ |                                                                          |
+ | This program is free software: you can redistribute it and/or modify     |
+ | it under the terms of the GNU Affero General Public License as published |
+ | by the Free Software Foundation, either version 3 of the License, or     |
+ | (at your option) any later version.                                      |
+ |                                                                          |
+ | This program is distributed in the hope that it will be useful,          |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             |
+ | GNU Affero General Public License for more details.                      |
+ |                                                                          |
+ | You should have received a copy of the GNU Affero General Public License |
+ | along with this program. If not, see <http://www.gnu.org/licenses/>      |
+ +--------------------------------------------------------------------------+
+ | Author: Aleksander Machniak <machniak at kolabsys.com>                      |
+ | Author: Jeroen van Meeuwen <vanmeeuwen at kolabsys.com>                     |
+ +--------------------------------------------------------------------------+
+*/
+
+/**
+ *
+ */
+class kolab_api_service_role extends kolab_api_service
+{
+    /**
+     * Returns service capabilities.
+     *
+     * @param string $domain Domain name
+     *
+     * @return array Capabilities list
+     */
+    public function capabilities($domain)
+    {
+        //console("kolab_api_service_role::capabilities");
+
+        $auth = Auth::get_instance();
+
+        $effective_rights = $auth->list_rights('role');
+
+        //console("effective_rights", $effective_rights);
+
+        $rights = array();
+
+        if (in_array('add', $effective_rights['entryLevelRights'])) {
+            $rights['add'] = "w";
+        }
+
+        if (in_array('delete', $effective_rights['entryLevelRights'])) {
+            $rights['delete'] = "w";
+        }
+
+        if (in_array('modrdn', $effective_rights['entryLevelRights'])) {
+            $rights['edit'] = "w";
+        }
+
+        if (in_array('read', $effective_rights['entryLevelRights'])) {
+            $rights['info'] = "r";
+            $rights['members_list'] = "r";
+        }
+
+        return $rights;
+    }
+
+    /**
+     * Group create.
+     *
+     * @param array $get   GET parameters
+     * @param array $post  POST parameters
+     *
+     * @return array|bool Group attributes or False on failure
+     */
+    public function role_add($getdata, $postdata)
+    {
+        $role_attributes = $this->parse_input_attributes('role', $postdata);
+
+        $auth   = Auth::get_instance();
+        $result = $auth->role_add($role_attributes, $postdata['type_id']);
+
+        if ($result) {
+            return $role_attributes;
+        }
+
+        return FALSE;
+    }
+
+    /**
+     * Group delete.
+     *
+     * @param array $get   GET parameters
+     * @param array $post  POST parameters
+     *
+     * @return bool True on success, False on failure
+     */
+    public function role_delete($getdata, $postdata)
+    {
+        if (empty($postdata['role'])) {
+            return FALSE;
+        }
+
+        // TODO: Input validation
+        $auth   = Auth::get_instance();
+        $result = $auth->role_delete($postdata['role']);
+
+        if ($result) {
+            return $result;
+        }
+
+        return FALSE;
+    }
+
+    public function role_edit($getdata, $postdata)
+    {
+        //console("role_edit \$postdata", $postdata);
+
+        $role_attributes = $this->parse_input_attributes('role', $postdata);
+        $role            = $postdata['id'];
+
+        $auth   = Auth::get_instance();
+        $result = $auth->role_edit($postdata['id'], $role_attributes, $postdata['type_id']);
+
+        // @TODO: return unique attribute or all attributes as role_add()
+        if ($result) {
+            return true;
+        }
+
+        return false;
+    }
+
+    public function role_effective_rights($getdata, $postdata)
+    {
+        $auth = Auth::get_instance();
+        $conf = Conf::get_instance();
+
+        $unique_attr = $conf->get('unique_attribute');
+        if (empty($unique_attr)) {
+            $unique_attr = 'nsuniqueid';
+        }
+
+        $role_dn = $auth->role_find_by_attribute(Array($unique_attr => $getdata['role']));
+
+        $effective_rights = $auth->list_rights($role_dn);
+
+        return $effective_rights;
+    }
+
+    /**
+     * Role information.
+     *
+     * @param array $get   GET parameters
+     * @param array $post  POST parameters
+     *
+     * @return array|bool Role attributes or False on failure
+     */
+    public function role_info($getdata, $postdata)
+    {
+        //console("api::role.info \$getdata, \$postdata", $getdata, $postdata);
+
+        if (empty($getdata['role'])) {
+            return false;
+        }
+
+        $auth   = Auth::get_instance();
+        $result = $auth->role_info($getdata['role']);
+
+        // normalize result
+        $result = $this->parse_result_attributes('role', $result);
+
+        if ($result) {
+            return $result;
+        }
+
+        return false;
+    }
+
+    /**
+     * Group members listing.
+     *
+     * @param array $get   GET parameters
+     * @param array $post  POST parameters
+     *
+     * @return array List of role members ('list' and 'count' items)
+     */
+    public function role_members_list($getdata, $postdata)
+    {
+        $auth = Auth::get_instance();
+
+        if (empty($getdata['role'])) {
+            //console("Empty \$getdata['role']");
+            return FALSE;
+        }
+
+        $result = $auth->role_members_list($getdata['role'], false);
+
+        return array(
+            'list'  => $result,
+            'count' => count($result),
+        );
+    }
+}
diff --git a/lib/api/kolab_api_service_role_types.php b/lib/api/kolab_api_service_role_types.php
new file mode 100644
index 0000000..9ad1977
--- /dev/null
+++ b/lib/api/kolab_api_service_role_types.php
@@ -0,0 +1,62 @@
+<?php
+/*
+ +--------------------------------------------------------------------------+
+ | This file is part of the Kolab Web Admin Panel                           |
+ |                                                                          |
+ | Copyright (C) 2011-2012, Kolab Systems AG                                |
+ |                                                                          |
+ | This program is free software: you can redistribute it and/or modify     |
+ | it under the terms of the GNU Affero General Public License as published |
+ | by the Free Software Foundation, either version 3 of the License, or     |
+ | (at your option) any later version.                                      |
+ |                                                                          |
+ | This program is distributed in the hope that it will be useful,          |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             |
+ | GNU Affero General Public License for more details.                      |
+ |                                                                          |
+ | You should have received a copy of the GNU Affero General Public License |
+ | along with this program. If not, see <http://www.gnu.org/licenses/>      |
+ +--------------------------------------------------------------------------+
+ | Author: Aleksander Machniak <machniak at kolabsys.com>                      |
+ | Author: Jeroen van Meeuwen <vanmeeuwen at kolabsys.com>                     |
+ +--------------------------------------------------------------------------+
+*/
+
+/**
+ * Service providing role types listing
+ */
+class kolab_api_service_role_types extends kolab_api_service
+{
+    /**
+     * Returns service capabilities.
+     *
+     * @param string $domain Domain name
+     *
+     * @return array Capabilities list
+     */
+    public function capabilities($domain)
+    {
+        return array(
+            'list' => 'r',
+        );
+    }
+
+    /**
+     * Role types listing.
+     *
+     * @param array $get   GET parameters
+     * @param array $post  POST parameters
+     *
+     * @return array List result with 'list' and 'count' items
+     */
+    public function role_types_list($get, $post)
+    {
+        $role_types = $this->object_types('role');
+
+        return array(
+            'list'  => $role_types,
+            'count' => count($role_types),
+        );
+    }
+}


commit 5f657635ab7b38e2b23a96efd657d48e59ae7fa1
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:43:46 2012 +0200

    Disable cache if devel_mode is set

diff --git a/lib/client/kolab_client_task_role.php b/lib/client/kolab_client_task_role.php
index d012abd..979ba43 100644
--- a/lib/client/kolab_client_task_role.php
+++ b/lib/client/kolab_client_task_role.php
@@ -42,7 +42,7 @@ class kolab_client_task_role extends kolab_client_task
     }
 
     /**
-     * Groups list action.
+     * Roles list action.
      */
     public function action_list()
     {
@@ -162,7 +162,7 @@ class kolab_client_task_role extends kolab_client_task
     }
 
     /**
-     * Group information (form) action.
+     * Role information (form) action.
      */
     public function action_info()
     {
@@ -175,7 +175,7 @@ class kolab_client_task_role extends kolab_client_task
     }
 
     /**
-     * Groups adding (form) action.
+     * Roles adding (form) action.
      */
     public function action_add()
     {
@@ -186,7 +186,7 @@ class kolab_client_task_role extends kolab_client_task
     }
 
     /**
-     * Group edit/add form.
+     * Role edit/add form.
      */
     private function role_form($attribs, $data = array())
     {
@@ -205,16 +205,16 @@ class kolab_client_task_role extends kolab_client_task
             'type_id'       => 'system',
             'type_id_name'  => 'system',
             'cn'            => 'system',
-            'gidnumber'     => 'system',
-            'mail'          => 'system',
-            'member'        => 'system',
-            'uniquemember'  => 'system',
-            'memberurl'     => 'system',
+            'description'   => 'system',
         );
 
+        //console("role_form \$data", $data);
+
         // Prepare fields
         list($fields, $types, $type) = $this->form_prepare('role', $data);
 
+        //console("role_form \$types", $types);
+
         $add_mode  = empty($data['id']);
         $accttypes = array();
 
@@ -289,15 +289,19 @@ class kolab_client_task_role extends kolab_client_task
      */
     public function role_types()
     {
-        if (!isset($_SESSION['role_types'])) {
-            $result = $this->api->post('role_types.list');
-            $list   = $result->get('list');
-
-            if (is_array($list)) {
-                $_SESSION['role_types'] = $list;
+        if (!$this->config_get('devel_mode', false)) {
+            if (isset($_SESSION['role_types'])) {
+                return $_SESSION['role_types'];
             }
         }
 
+        $result = $this->api->post('role_types.list');
+        $list   = $result->get('list');
+
+        if (is_array($list)) {
+            $_SESSION['role_types'] = $list;
+        }
+
         return $_SESSION['role_types'];
     }
 


commit 6553c79e6d00168e8118ef69a01999cd05f71d5e
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:43:00 2012 +0200

    Add console message in mail address validation for when it's needed
    Disable the MX check for now

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 4aa7b78..6278c36 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -183,7 +183,7 @@ class kolab_api_service_form_value extends kolab_api_service
      */
     public function validate($getdata, $postdata)
     {
-        console("Executing validate() for \$getdata, \$postdata", $getdata, $postdata);
+        //console("Executing validate() for \$getdata, \$postdata", $getdata, $postdata);
 
         $attribs = $this->object_type_attributes($postdata['object_type'], $postdata['type_id']);
         $result  = array();
@@ -1022,40 +1022,47 @@ class kolab_api_service_form_value extends kolab_api_service
 
             if (strlen($local) < 1 || strlen($local) > 64) {
                 // local part length exceeded
+                //console("Local part of email address is longer than permitted");
                 $valid = false;
 
             } else if (strlen($domain) < 1 || strlen($domain) > 255) {
                 // domain part length exceeded
+                //console("Domain part of email address is longer than permitted");
                 $valid = false;
 
             } else if ($local[0] == '.' || $local[strlen($local)-1] == '.') {
                 // local part starts or ends with '.'
+                //console("Local part of email address starts or ends with '.'");
                 $valid = false;
 
             } else if (preg_match('/\\.\\./', $local)) {
+                //console("Local part contains two consecutive dots");
                 // local part has two consecutive dots
                 $valid = false;
 
             } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
                 // character not valid in domain part
+                //console("Invalid character in domain part");
                 $valid = false;
 
             } else if (preg_match('/\\.\\./', $domain)) {
                 // domain part has two consecutive dots
+                //console("Domain part contains two consecutive dots");
                 $valid = false;
 
             } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) {
                 // character not valid in local part unless
                 // local part is quoted
                 if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) {
+                    //console("Unquoted invalid character in local part");
                     $valid = false;
                 }
             }
 
-            if ($valid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
-                // domain not found in DNS
-                $valid = false;
-            }
+//            if ($valid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
+//                // domain not found in DNS
+//                $valid = false;
+//            }
         }
 
         return $valid;


commit 494c3e2e974a1de5f9a9168b8e7b091558be2442
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Thu Jun 21 11:42:33 2012 +0200

    Add some role functions

diff --git a/lib/Auth.php b/lib/Auth.php
index 6af9f3c..90159d7 100644
--- a/lib/Auth.php
+++ b/lib/Auth.php
@@ -413,6 +413,16 @@ class Auth {
         return $this->_auth[$_SESSION['user']->get_domain()]->resource_members_list($resourcedata, $recurse);
     }
 
+    public function role_find_by_attribute($attribute)
+    {
+        return $this->_auth[$_SESSION['user']->get_domain()]->role_find_by_attribute($attribute);
+    }
+
+    public function role_info($roledata)
+    {
+        return $this->_auth[$_SESSION['user']->get_domain()]->role_info($roledata);
+    }
+
     public function search()
     {
         $this->connect();
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 7007007..9d23dbb 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -820,6 +820,30 @@ class LDAP
         return $this->_list_resource_members($resource_dn, null, $recurse);
     }
 
+    public function role_find_by_attribute($attribute)
+    {
+        //console("Finding role by attribute", $attribute);
+
+        $attribute['objectclass'] = 'ldapsubentry';
+        $result = $this->entry_find_by_attribute($attribute);
+        if (is_array($result) && count($result) == 0) {
+            return key($result);
+        } else {
+            return false;
+        }
+    }
+
+    public function role_info($role, $attributes = array('*'))
+    {
+        $role_dn = $this->entry_dn($role);
+
+        if (!$role_dn) {
+            return false;
+        }
+
+        return self::normalize_result($this->_search($role_dn, '(objectclass=ldapsubentry)', $attributes));
+    }
+
     public function user_add($attrs, $typeid = null)
     {
         if ($typeid == null) {
@@ -1043,7 +1067,7 @@ class LDAP
 
     private function entry_find_by_attribute($attribute, $base_dn = null)
     {
-        if (empty($attribute) || !is_array($attribute) || count($attribute) > 1) {
+        if (empty($attribute) || !is_array($attribute)) {
             return false;
         }
 





More information about the commits mailing list