summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-07-30 12:13:28 +0200
committerAleksander Machniak <alec@alec.pl>2013-07-30 12:13:28 +0200
commitc37ecce722e2c02b8cb3ec53435504ac5c3d3ea5 (patch)
tree32f5b93d4da9379321f0f3ae2916b4343a4b7722 /lib
parentf11818cff39f33021ff1017c1e8a1c6a8b3b093b (diff)
downloadwebadmin-c37ecce722e2c02b8cb3ec53435504ac5c3d3ea5.tar.gz
Fixed uidnumber/gidnumber generation (Bug #2058)
Diffstat (limited to 'lib')
-rw-r--r--lib/Auth.php2
-rw-r--r--lib/api/kolab_api_service_form_value.php77
-rw-r--r--lib/ext/Net/LDAP3.php15
3 files changed, 63 insertions, 31 deletions
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 . ")";
}
}