From: hickert Date: Fri, 14 May 2010 09:27:07 +0000 (+0000) Subject: Updated gathering of FAI objects X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0f6e2fe0ee7febbfe37a29ef42282695f5dfc6f5;p=gosa.git Updated gathering of FAI objects git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18472 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/fai/admin/fai/class_FAI.inc b/gosa-plugins/fai/admin/fai/class_FAI.inc index 6bb494aec..e23adcb7a 100644 --- a/gosa-plugins/fai/admin/fai/class_FAI.inc +++ b/gosa-plugins/fai/admin/fai/class_FAI.inc @@ -145,16 +145,26 @@ class FAI /* Return all relevant FAI departments */ static function get_FAI_departments($suffix = "") { - $arr = array("hooks","scripts","disk","packages","profiles","templates","variables"); + global $config; + $arr = array( + $config->get_cfg_value('faiScript', 'faiScriptRDN'), + $config->get_cfg_value('faiHook', 'faiHookRDN'), + $config->get_cfg_value('faiTemplate', 'faiTemplateRDN'), + $config->get_cfg_value('faiVariable', 'faiVariableRDN'), + $config->get_cfg_value('faiProfile', 'faiProfileRDN'), + $config->get_cfg_value('faiPartitionTable', 'faiPartitionRDN'), + $config->get_cfg_value('faiPackage', 'faiPackageRDN') + ); + $tmp = array(); if(preg_match("/^,/",$suffix)){ $suffix = preg_replace("/^,/","",$suffix); } foreach($arr as $name){ if(empty($suffix)){ - $tmp[$name] = "ou=".$name; + $tmp[$name] = $name; }else{ - $tmp[$name] = "ou=".$name.",".$suffix; + $tmp[$name] = $name.$suffix; } } return($tmp); diff --git a/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc b/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc index b832513b3..be91061ff 100644 --- a/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc +++ b/gosa-plugins/fai/admin/fai/migration/class_migrateFaiRDN.inc @@ -35,9 +35,11 @@ class migrateFaiRDN extends migrateRDN implements propertyMigration $initialValue = $this->prefix.$this->property->getValue().$this->suffix; $targetValue = $this->prefix.$this->property->getValue(TRUE).$this->suffix; + $prefix = $this->config->get_cfg_value('faiManagement','faiBaseRDN'); + $dnMatch = ""; - if(!empty($initialValue)){ - foreach(preg_split("/,/", $initialValue) as $rdnPart){ + if(!empty($initialValue) || !empty($prefix)){ + foreach(preg_split("/,/", $initialValue.$prefix) as $rdnPart){ if(empty($rdnPart)) continue; list($namingAttrs, $container) = preg_split("/=/",$rdnPart,2); $container = trim($container,', '); @@ -45,6 +47,15 @@ class migrateFaiRDN extends migrateRDN implements propertyMigration } } + // Collect all FAI releases - this is nescessary to detect the release part + // of the dn + $ldap->cd($this->config->current['BASE']); + $releases = array(); + $ldap->search("(objectClass=FAIbranch)",array('dn')); + while($attrs = $ldap->fetch()){ + $releases[$attrs['dn']] = $attrs['dn']; + } + // Search for users $filter = sprintf($this->filter,$dnMatch); $ldap->search($filter,array('dn')); @@ -53,53 +64,46 @@ class migrateFaiRDN extends migrateRDN implements propertyMigration $dn = $attrs['dn']; $dnTo = $dn; - // If there intially was no userDN given then just add the new userRDN to the user dns - // and create the new container objects. - if(empty($initialValue)){ - list($namingAttrs, $container) = preg_split("/=/",$targetValue,2); - list($name, $container) = preg_split("/,/",$dn,2); - - // Ensure that we handle a valid gosaDepartment container. - while(!isset($this->config->idepartments[$container])){ - $container = preg_replace("/^[^,]*+,/","",$container); - } + // Detect the releaes part of the dn. + $releasePart = $dn; + while(!isset($releases[$releasePart]) && preg_match("/,/", $releasePart)){ + $releasePart = preg_replace("/^[^,]*+,/","",$releasePart); + } + if(!isset($releases[$releasePart])){ + // Release not found; + continue; + } - // Queue new containuer to be created. - if(!preg_match("/^".preg_quote($targetValue,'/i')."/", $container)){ - $dnTo = $name.",".$targetValue.$container; - if(!$ldap->dn_exists($targetValue.$container)){ - $this->found['add'][$targetValue.$container] = array(); - } - if($dn != $dnTo){ - $this->found['move'][] = array('from' => $dn, 'to' => $dnTo); - $found = TRUE; - } - } + // Detect the base part of the releasePart + $basePart = $releasePart; + while(!isset($this->config->idepartments[$basePart]) && preg_match("/,/", $basePart)){ + $basePart = preg_replace("/^[^,]*+,/","",$basePart); + } + if(!isset($this->config->idepartments[$basePart])){ + // Base not found; + continue; } - // If there intially was a userDN given then replace it with the new one. - if(!empty($initialValue)){ + $releaseRDN = substr($releasePart,0,strlen($releasePart) - strlen($basePart)); - list($name, $container) = preg_split("/,/",$dn,2); - if(preg_match("/^".preg_quote($initialValue,'/i')."/", $container)){ - $container = preg_replace("/^".preg_quote($initialValue,'/')."/",$targetValue,$container); + // Now remove the faiBaseRDN from the release DN. + $releaseRDN = preg_replace("/".preg_quote($prefix,'/')."/","", $releaseRDN); - // Ensure that we handle a valid gosaDepartment container. - while(!isset($this->config->idepartments[$container])){ - $container = preg_replace("/^[^,]*+,/","",$container); - } + // Remove all parts from the dn to geht the objects name. + $name = substr($dn,0, (strlen($dn) - strlen($initialValue.$releaseRDN.$prefix.$basePart))); + // Build new container name and check if it exists. + $newContainer = $targetValue.$releaseRDN.$prefix.$basePart; + if(!$ldap->dn_exists($newContainer)){ + $this->found['add'][$newContainer] = array(); + } - $dnTo = $name.",".$targetValue.$container; - if(!empty($targetValue) && !$ldap->dn_exists($targetValue.$container)){ - $this->found['add'][$targetValue.$container] = array(); - } - if($dn != $dnTo){ - $this->found['move'][] = array('from' => $dn, 'to' => $dnTo); - $found = TRUE; - } - } - } + // Check if the target name has changed. + $dnTo = $name.$newContainer; + if($dn != $dnTo){ + $this->found['move'][] = array('from' => $dn, 'to' => $dnTo); + $found = TRUE; + } } return($found); }