Code

Merged dns edit fixes from zeph
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 13 Nov 2006 13:31:24 +0000 (13:31 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 13 Nov 2006 13:31:24 +0000 (13:31 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5086 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_ldap.inc
include/functions_dns.inc
plugins/admin/systems/class_servDNSeditZone.inc
plugins/admin/systems/class_termDNS.inc

index 504a470d45dca1630fe747bb3ba5395e17a1fd67..c5f376e4e99cb2912308602e10a5e225a9f4ab6b 100644 (file)
@@ -1161,6 +1161,20 @@ function gen_xls ($dn, $filter= "(objectClass=*)", $attributes= array('*'), $rec
       }
     }
   }
+  
+  /* added by Guido Serra aka Zeph <zeph@purotesto.it> */
+  function getCn($dn){
+    $simple= split(",", $dn);
+
+    foreach($simple as $piece) {
+      $partial= split("=", $piece);
+
+      if($partial[0] == "cn"){
+        return $partial[1];
+      }
+    }
+
+  }
 
 
 }
index 1eeba0c359f2dd7ab00bb277ed32162e8b8f42bb..162caeca7123317ad71c30cb84cffa5fdef327b0 100644 (file)
@@ -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);
 }
index 7fcef3aa0e0f1e601189aed6e9f507385ac5fdaa..f8866b2defa0f5970a56d455ec87748b6178d77f 100644 (file)
@@ -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)){
index fc55c61d73bbc67e2f7765b787c92accb2f5b258..93642535eb921faf95564c20bd51f187bcead5f6 100644 (file)
@@ -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
        */