From c304dcacac9ec77608c256a339c09c22da5206d4 Mon Sep 17 00:00:00 2001 From: cajus Date: Mon, 13 Nov 2006 13:31:24 +0000 Subject: [PATCH] Merged dns edit fixes from zeph git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5086 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_ldap.inc | 14 ++++ include/functions_dns.inc | 77 +++++++++++++------ .../admin/systems/class_servDNSeditZone.inc | 4 +- plugins/admin/systems/class_termDNS.inc | 3 +- 4 files changed, 71 insertions(+), 27 deletions(-) diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 504a470d4..c5f376e4e 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -1161,6 +1161,20 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec } } } + + /* added by Guido Serra aka Zeph */ + function getCn($dn){ + $simple= split(",", $dn); + + foreach($simple as $piece) { + $partial= split("=", $piece); + + if($partial[0] == "cn"){ + return $partial[1]; + } + } + + } } diff --git a/include/functions_dns.inc b/include/functions_dns.inc index 1eeba0c35..162caeca7 100644 --- a/include/functions_dns.inc +++ b/include/functions_dns.inc @@ -349,18 +349,25 @@ function getDNSHostEntries($config,$name,$silent = false) */ $foundIn = array(); $zones = getAvailableZones($config); - foreach($zones as $zone){ - $zoneDn = getDNSZoneDN($config,$zone); - $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=".$name.")(!(relativeDomainName=@)))", $zoneDn,$attrs = array("*")); - while($attrs = $ldap->fetch()){ - $foundIn [] = $attrs['dn']; - } + + $zonesArr = array(); + foreach($zones as $zoneMix){ + $zoneIndex = split("/",$zoneMix); + if(!array_key_exists($zoneIndex[0],$zonesArr)) $zonesArr[$zoneIndex[0]] = array(); + array_push($zonesArr[$zoneIndex[0]],$zoneIndex[1]); } - - /* Alert if there is more than one zone with an entry named like $name - */ - if((count($foundIn) > 1) && (!$silent)) { - print_red(sprintf(_("Found more than one dns zone which contains an entry named '%s'. Aborting getting dns informations for this device."),$name)); + + foreach($zonesArr as $nameServer => $nameServerArr){ + $foundInTmp = array(); + foreach($nameServerArr as $zoneArr => $zone){ + $zoneMix = $nameServer."/".$zone; + $zoneDn = getDNSZoneDN($config,$zoneMix); + $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=".$name.")(!(relativeDomainName=@)))", $zoneDn,$attrs = array("*")); + while($attrs = $ldap->fetch()){ + $foundInTmp [] = $attrs['dn']; + $foundIn [] = $attrs['dn']; + } + } } /* No zone found which contains an entry for us @@ -426,16 +433,17 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName) $zones = getAvailableZones($config); $specialAttributes = array("cNAMERecord","pTRRecord"); $newRecords = array(); // Used to remember which records are removed - $zoneName = $newEntry['zoneName']; - $zoneDn = getDNSZoneDN($config,$zoneName); + $zoneNameMix = $newEntry['zoneName']; + $zoneDn = getDNSZoneDN($config,$zoneNameMix); $tmp = array_flip($zones); + $zoneName = getNameFromMix($zoneNameMix); /* If reverseZone can't be resolved ... this * can't be a valid entry, so remove this account */ - if(isset($tmp[$zoneName])){ - $reverseName = $tmp[$zoneName]; - $reverseDn = getDNSZoneDN($config,$reverseName); + if(isset($tmp[$zoneNameMix])){ + $reverseNameMix = $tmp[$zoneNameMix]; + $reverseDn = getDNSZoneDN($config,$reverseNameMix); if(empty($reverseDn)){ $newEntry['exists'] = false; } @@ -467,7 +475,7 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName) /* Check if zoneName has changed */ if(count($newEntry['RECORDS'])){ - if($oldEntry['zoneName'] != $newEntry['zoneName']){ + if($oldEntry['zoneName'] != $zoneName){ $oldzoneDn = getDNSZoneDN($config,$oldEntry['zoneName']); $dn = "relativeDomainName=".$oldName.",".$oldzoneDn; $dn2= "relativeDomainName=".$oldName.",".$zoneDn; @@ -553,17 +561,18 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName) if($rec['type'] == "pTRRecord"){ $PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn; $ptrObj = $baseObj; + $reverseName = getNameFromMix($reverseNameMix); $ptrObj['zoneName'] = $reverseName; - $ptrObj['pTRRecord'] = $newName.".".$zoneName; + $ptrObj['pTRRecord'] = $newName.".".$zoneName."."; $ptrObj['relativeDomainName'] = $rec['value']; - + $add[$PTRdn] = $ptrObj; }else if($rec['type'] == "cNAMERecord"){ $PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn; $ptrObj = $baseObj; - $ptrObj['zoneName'] = $reverseName; - $ptrObj['cNAMERecord'] = $newName.".".$zoneName; + $ptrObj['zoneName'] = $zoneName; + $ptrObj['cNAMERecord'] = $newName; $ptrObj['relativeDomainName'] = $rec['value']; $add[$PTRdn] = $ptrObj; @@ -578,18 +587,37 @@ function getDNSHostEntriesDiff($config,$oldName,$newEntry,$newName) return($ret); } +function getNameFromMix($zoneMix){ + $ret = ""; + if(!strstr($zoneMix, '/')) return($ret); + $zoneIndex = split("/",$zoneMix); + return($zoneIndex[1]); +} /* returns the dn for a specified zone */ -function getDNSZoneDN($config,$zoneName){ +function getDNSZoneDN($config,$zoneNameMix){ $ret = ""; + if(!strstr($zoneNameMix, '/')) return($ret); + $zoneNameIndex = split("/",$zoneNameMix); + $zoneName = $zoneNameIndex[1]; + $nameServer = strtolower($zoneNameIndex[0]); $ldap = $config->get_ldap_link(); + + /* search for the nameserver */ $ldap-> cd($config->current['BASE']); + $ldap->search("(&(objectClass=goServer)(cn=".$nameServer."))",array("cn")); + if($ldap->count()){ + $attr = $ldap->fetch(); + } else return($ret); + + $ldap-> cd($attr['dn']); $ldap->search("(&(objectClass=dNSZone)(sOARecord=*)(zoneName=".$zoneName."))",array("zoneName")); if($ldap->count()){ $attr = $ldap->fetch(); return($attr['dn']); } + return($ret); } @@ -625,9 +653,10 @@ function getAvailableZones($config) */ foreach($ReverseZones as $Rdn => $Robj ){ if(preg_match("/".$dn."/",$Rdn)){ - $zones[$Robj['zoneName'][0]] = $obj['zoneName'][0]; + $zones[strtoupper($ldap->getCn($dn))."/".$Robj['zoneName'][0]] = + strtoupper($ldap->getCn($dn))."/".$obj['zoneName'][0]; } - } + } } return($zones); } diff --git a/plugins/admin/systems/class_servDNSeditZone.inc b/plugins/admin/systems/class_servDNSeditZone.inc index 7fcef3aa0..f8866b2de 100644 --- a/plugins/admin/systems/class_servDNSeditZone.inc +++ b/plugins/admin/systems/class_servDNSeditZone.inc @@ -347,12 +347,12 @@ class servdnseditZone extends plugin /* Check if zoneName is already in use */ $usedZones = $this->getUsedZoneNames(); if(($this->isNew == true)||($this->zoneName != $this->InitialzoneName)||($this->ReverseZone != $this->InitialReverseZone)){ - if((isset($usedZones[$this->zoneName]))&&($this->zoneName != $this->InitialzoneName)){ +/* if((isset($usedZones[$this->zoneName]))&&($this->zoneName != $this->InitialzoneName)){ $message[] =_("This zoneName is already in use"); } if((in_array($this->ReverseZone,$usedZones))&&($this->ReverseZone != $this->InitialReverseZone)){ $message[] =_("This reverse zone is already in use"); - } + }*/ } if(empty($this->zoneName)){ diff --git a/plugins/admin/systems/class_termDNS.inc b/plugins/admin/systems/class_termDNS.inc index fc55c61d7..93642535e 100644 --- a/plugins/admin/systems/class_termDNS.inc +++ b/plugins/admin/systems/class_termDNS.inc @@ -323,7 +323,8 @@ class termDNS extends plugin $checkArray = array(); $onlyOnce = array(); - $onlyOnce['cNAMERecord'] = 0; + // There can be many CNAME records + //$onlyOnce['cNAMERecord'] = 0; /* Walk through all entries and detect duplicates or mismatches */ -- 2.30.2