From: cajus Date: Tue, 20 Mar 2007 08:51:21 +0000 (+0000) Subject: Merged ID generation from branches/2.5 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5c145ba027a1ebacc9a06434c4a1bb7c0012704c;p=gosa.git Merged ID generation from branches/2.5 git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5831 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/Changelog b/Changelog index cf1ac23a8..bddb0b560 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 diff --git a/include/functions.inc b/include/functions.inc index 5b35af77f..65c9fa53a 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2148,6 +2148,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 8858285e8..644873ed3 100644 --- a/plugins/admin/groups/class_groupGeneric.inc +++ b/plugins/admin/groups/class_groupGeneric.inc @@ -597,7 +597,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); } } @@ -800,7 +800,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(); @@ -819,7 +819,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); } diff --git a/plugins/personal/posix/class_posixAccount.inc b/plugins/personal/posix/class_posixAccount.inc index 4df29ad4a..340e6f301 100644 --- a/plugins/personal/posix/class_posixAccount.inc +++ b/plugins/personal/posix/class_posixAccount.inc @@ -765,11 +765,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); } } @@ -1091,7 +1091,6 @@ class posixAccount extends plugin } } - function convertToSeconds($val) { if ($val != 0){ @@ -1104,7 +1103,7 @@ class posixAccount extends plugin } - function get_next_id($attrib) + function get_next_id($attrib, $dn) { $ids= array(); $ldap= $this->config->get_ldap_link(); @@ -1123,13 +1122,13 @@ class posixAccount extends plugin } /* Add the nobody id */ - $ids[]= 65534; + $ids[]= 65534; /* get the ranges */ $tmp = array('0'=> 1000); if (preg_match('/posixAccount/', $oc) && isset($this->config->current['UIDBASE'])) { $tmp= split('-',$this->config->current['UIDBASE']); - } elseif(isset($this->config->current['UIDBASE'])) { + } elseif(isset($this->config->current['GIDBASE'])){ $tmp= split('-',$this->config->current['GIDBASE']); } @@ -1142,7 +1141,13 @@ class posixAccount extends plugin } /* Find out next free id near to UID_BASE */ - for ($id=$lwm; $id++; $id<$hwm){ + if (!isset($this->config->current['BASE_HOOK'])){ + $base= $lwm; + } 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); } @@ -1311,8 +1316,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); }