lib/api lib/Auth.php lib/ext

Aleksander Machniak machniak at kolabsys.com
Tue Jul 30 12:14:10 CEST 2013


 lib/Auth.php                             |    2 
 lib/api/kolab_api_service_form_value.php |   77 ++++++++++++++++++++-----------
 lib/ext/Net/LDAP3.php                    |   15 ++++--
 3 files changed, 63 insertions(+), 31 deletions(-)

New commits:
commit c37ecce722e2c02b8cb3ec53435504ac5c3d3ea5
Author: Aleksander Machniak <alec at alec.pl>
Date:   Tue Jul 30 12:13:28 2013 +0200

    Fixed uidnumber/gidnumber generation (Bug #2058)

diff --git a/lib/Auth.php b/lib/Auth.php
index b342783..0c5ef5b 100644
--- a/lib/Auth.php
+++ b/lib/Auth.php
@@ -297,7 +297,7 @@ class Auth {
 
     public function list_users($domain = NULL, $attributes = array(), $search = array(), $params = array())
     {
-        return $this->auth_instance()->list_users($attributes, $search, $params);
+        return $this->auth_instance($domain)->list_users($attributes, $search, $params);
     }
 
     public function list_groups($domain = NULL, $attributes = array(), $search = array(), $params = array())
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index d781358..b51529c 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -485,31 +485,42 @@ class kolab_api_service_form_value extends kolab_api_service
             // TODO: Take a policy to use a known group ID, a known group (by name?)
             // and/or create user private groups.
 
-            $search = Array(
-                    'params' => Array(
-                            'objectclass' => Array(
-                                    'type' => 'exact',
-                                    'value' => 'posixgroup',
-                                ),
-                        ),
-                );
-
-            $groups = $auth->list_groups(NULL, Array('gidnumber'), $search);
+            // groups search parameters
+            $params = array('page_size' => 200);
+            $search = array(
+                'operator' => 'AND',
+                'params' => array(
+                    'objectclass' => array(
+                        'type'  => 'exact',
+                        'value' => 'posixgroup',
+                    ),
+                    'gidnumber' => array(
+                        'type'  => '>=',
+                    )
+                ),
+            );
 
             $highest_gidnumber = $conf->get('gidnumber_lower_barrier');
             if (!$highest_gidnumber) {
                 $highest_gidnumber = 999;
             }
 
-            foreach ($groups['list'] as $dn => $attributes) {
-                if (!array_key_exists('gidnumber', $attributes)) {
-                    continue;
-                }
+            do {
+                $search['params']['gidnumber']['value'] = $highest_gidnumber;
+
+                $groups = $auth->list_groups(NULL, array('gidnumber'), $search, $params);
+
+                foreach ($groups['list'] as $dn => $attributes) {
+                    if (!array_key_exists('gidnumber', $attributes)) {
+                        continue;
+                    }
 
-                if ($attributes['gidnumber'] > $highest_gidnumber) {
-                    $highest_gidnumber = $attributes['gidnumber'];
+                    if ($attributes['gidnumber'] > $highest_gidnumber) {
+                        $highest_gidnumber = $attributes['gidnumber'];
+                    }
                 }
             }
+            while ($groups['count'] == $params['page_size']);
 
             $gidnumber = ($highest_gidnumber + 1);
             $postdata['gidnumber'] = $gidnumber;
@@ -830,33 +841,45 @@ class kolab_api_service_form_value extends kolab_api_service
     private function generate_uidnumber($postdata, $attribs = array())
     {
         if (isset($attribs['auto_form_fields']) && isset($attribs['auto_form_fields']['uidnumber'])) {
+            $auth = Auth::get_instance($_SESSION['user']->get_domain());
+            $conf = Conf::get_instance();
+
+            // users search parameters
+            $params = array('page_size' => 200);
             $search = array(
-                'params' => array(
+                'operator' => 'AND',
+                'params'   => array(
                     'objectclass' => array(
                         'type'  => 'exact',
                         'value' => 'posixaccount',
                     ),
+                    'uidnumber' => array(
+                        'type' => '>=',
+                    ),
                 ),
             );
 
-            $auth  = Auth::get_instance($_SESSION['user']->get_domain());
-            $conf  = Conf::get_instance();
-            $users = $auth->list_users(NULL, Array('uidnumber'), $search);
-
             $highest_uidnumber = $conf->get('uidnumber_lower_barrier');
             if (!$highest_uidnumber) {
                 $highest_uidnumber = 999;
             }
 
-            foreach ($users['list'] as $dn => $attributes) {
-                if (!array_key_exists('uidnumber', $attributes)) {
-                    continue;
-                }
+            do {
+                $search['params']['uidnumber']['value'] = $highest_uidnumber;
 
-                if ($attributes['uidnumber'] > $highest_uidnumber) {
-                    $highest_uidnumber = $attributes['uidnumber'];
+                $users = $auth->list_users(NULL, array('uidnumber'), $search, $params);
+
+                foreach ($users['list'] as $dn => $attributes) {
+                    if (!array_key_exists('uidnumber', $attributes)) {
+                        continue;
+                    }
+
+                    if ($attributes['uidnumber'] > $highest_uidnumber) {
+                        $highest_uidnumber = $attributes['uidnumber'];
+                    }
                 }
             }
+            while ($users['count'] == $params['page_size']);
 
             $uidnumber = ($highest_uidnumber + 1);
             $postdata['uidnumber'] = $uidnumber;
diff --git a/lib/ext/Net/LDAP3.php b/lib/ext/Net/LDAP3.php
index 1f04d1a..64d7db4 100644
--- a/lib/ext/Net/LDAP3.php
+++ b/lib/ext/Net/LDAP3.php
@@ -1598,7 +1598,9 @@ class Net_LDAP3
             return null;
         }
 
-        $filter = '';
+        $operators = array('=', '>', '<', '>=', '<=');
+        $filter    = '';
+
         foreach ((array) $search['params'] as $field => $param) {
             switch ((string)$param['type']) {
                 case 'prefix':
@@ -1610,6 +1612,11 @@ class Net_LDAP3
                     $suffix = '';
                     break;
                 case 'exact':
+                case '=':
+                case '>':
+                case '<':
+                case '>=':
+                case '<=':
                     $prefix = '';
                     $suffix = '';
                     break;
@@ -1620,17 +1627,19 @@ class Net_LDAP3
                     break;
             }
 
+            $operator = $param['type'] && in_array($param['type'], $operators) ? $param['type'] : '=';
+
             if (is_array($param['value'])) {
                 $val_filter = array();
                 foreach ($param['value'] as $val) {
                     $value = self::_quote_string($val);
-                    $val_filter[] = "($field=$prefix" . $value . "$suffix)";
+                    $val_filter[] = "(" . $field . $operator . $prefix . $value . $suffix . ")";
                 }
                 $filter .= "(|" . implode($val_filter, '') . ")";
             }
             else {
                 $value = self::_quote_string($param['value']);
-                $filter .= "($field=$prefix" . $value . "$suffix)";
+                $filter .= "(" . $field . $operator . $prefix . $value . $suffix . ")";
             }
         }
 




More information about the commits mailing list