From: cajus Date: Mon, 19 Mar 2007 16:49:08 +0000 (+0000) Subject: Added script for dynamic user bases X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=76a8857bf8b26c2afaff54cb5ac02a93b19033cc;p=gosa.git Added script for dynamic user bases git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5827 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/Changelog b/Changelog index a8807ab19..aeb125327 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,9 @@ GOsa2 changelog =============== + +* gosa 2.5.10 + - Added hook for dynamic uid-bases + * gosa 2.5.9 - Fixed ldap tls connections when schema check was being used - Updated italian translation diff --git a/include/functions.inc b/include/functions.inc index 3f6025ecb..e78c2f874 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2156,5 +2156,39 @@ function is_php4() } +function get_base_from_hook($dn, $attrib) +{ + global $config; + + if (isset($config->current['BASE_HOOK'])){ + + /* Call hook script - if present */ + $command= $config->current['BASE_HOOK']; + + if ($command != ""){ + $command.= " '$dn' $attrib"; + if (check_command($command)){ + @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); + exec($command, $output); + if (preg_match("/^[0-9]+$/", $output)){ + return ($output[0]); + } else { + print_red(_("Warning - base_hook is not avialable. Using default base.")); + return ($config->current['UIDBASE']); + } + } else { + print_red(_("Warning - base_hook is not avialable. Using default base.")); + return ($config->current['UIDBASE']); + } + + } else { + + print_red(_("Warning - no base_hook defined. Using default base.")); + return ($config->current['UIDBASE']); + + } + } +} + // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/groups/class_groupGeneric.inc b/plugins/admin/groups/class_groupGeneric.inc index 63e2579f6..26bf2169f 100644 --- a/plugins/admin/groups/class_groupGeneric.inc +++ b/plugins/admin/groups/class_groupGeneric.inc @@ -580,7 +580,7 @@ class group extends plugin } } add_lock ("uidnumber", "gosa"); - $this->gidNumber= $this->get_next_id("gidNumber"); + $this->gidNumber= $this->get_next_id("gidNumber", $this->dn); } } @@ -791,7 +791,7 @@ class group extends plugin return ($message); } - function get_next_id($attrib) + function get_next_id($attrib, $dn) { $ids= array(); $ldap= $this->config->get_ldap_link(); @@ -810,7 +810,13 @@ class group extends plugin } /* Find out next free id near to UID_BASE */ - for ($id= $this->config->current['UIDBASE']; $id++; $id < pow(2,32)){ + if (!isset($this->config->current['BASE_HOOK'])){ + $base= $this->config->current['UIDBASE']; + } else { + /* Call base hook */ + $base= get_base_from_hook($dn, $attrib); + } + for ($id= $base; $id++; $id < pow(2,32)){ if (!in_array($id, $ids)){ return ($id); } @@ -818,7 +824,7 @@ class group extends plugin /* check if id reached maximum of 32 bit*/ if ($id >= pow(2,32)){ - echo _("Too many users, can't allocate a free ID!"); + echo _("Too many groups, can't allocate a free ID!"); exit; } } diff --git a/plugins/personal/posix/class_posixAccount.inc b/plugins/personal/posix/class_posixAccount.inc index cd34a0036..fa1a3821e 100644 --- a/plugins/personal/posix/class_posixAccount.inc +++ b/plugins/personal/posix/class_posixAccount.inc @@ -758,11 +758,11 @@ class posixAccount extends plugin } add_lock ("uidnumber", "gosa"); - $this->uidNumber= $this->get_next_id("uidNumber"); + $this->uidNumber= $this->get_next_id("uidNumber", $this->dn); if ($this->savedGidNumber != ""){ $this->gidNumber= $this->savedGidNumber; } else { - $this->gidNumber= $this->get_next_id("gidNumber"); + $this->gidNumber= $this->get_next_id("gidNumber", $this->dn); } } @@ -1077,7 +1077,7 @@ class posixAccount extends plugin } } - function get_next_id($attrib) + function get_next_id($attrib, $dn) { $ids= array(); $ldap= $this->config->get_ldap_link(); @@ -1096,10 +1096,16 @@ class posixAccount extends plugin } /* Add the nobody id */ - $ids[]= 65534; + $ids[]= 65534; /* Find out next free id near to UID_BASE */ - for ($id= $this->config->current['UIDBASE']; $id++; $id < pow(2,32)){ + if (!isset($this->config->current['BASE_HOOK'])){ + $base= $this->config->current['UIDBASE']; + } else { + /* Call base hook */ + $base= get_base_from_hook($dn, $attrib); + } + for ($id= $base; $id++; $id < pow(2,32)){ if (!in_array($id, $ids)){ return ($id); } @@ -1267,8 +1273,8 @@ class posixAccount extends plugin plugin::PrepareForCopyPaste($source); /* Avoid using the same gid/uid number as source user */ - $this->savedUidNumber = $this->get_next_id("gidNumber"); - $this->savedGidNumber = $this->get_next_id("uidNumber"); + $this->savedUidNumber = $this->get_next_id("gidNumber", $this->dn); + $this->savedGidNumber = $this->get_next_id("uidNumber", $this->dn); } function convertToSeconds($val)