diff -r 79c33038ca14 -r 3e36ebbfe048 inc/dns.inc.php --- a/inc/dns.inc.php Fri Apr 11 11:59:33 2008 +0000 +++ b/inc/dns.inc.php Fri Apr 11 13:33:30 2008 +0000 @@ -19,25 +19,10 @@ * along with this program. If not, see . */ -/* - * Validates an IPv4 IP. - * returns true if valid. - */ -function validate_input($zoneid, $type, &$content, &$name, &$prio, &$ttl) +function validate_input($zid, $type, &$content, &$name, &$prio, &$ttl) { global $db; - - // Has to validate content first then it can do the rest - // Since if content is invalid already it can aswell be just removed - // Check first if content is IPv4, IPv6 or Hostname - // We accomplish this by just running all tests over it - // We start with IPv6 since its not able to have these ip's in domains. - // - // - // The nocheck has to move to the configuration file - // - // - $domain = get_domain_name_from_id($zoneid); + $domain = get_domain_name_from_id($zid); $nocheck = array('SOA', 'HINFO', 'NAPTR', 'URL', 'MBOXFW', 'TXT'); $hostname = false; $ip4 = false; @@ -122,14 +107,8 @@ } } - if ($type == 'SOA') { - $status = is_valid_soa($content, $zoneid); - if($status == -1) { - error(ERR_DNS_SOA_UNIQUE); - } elseif($status == -2) { - error(ERR_DNS_SOA_NUMERIC); - return false; - } + if ($type == 'SOA' && !is_valid_rr_soa($content)) { + return false; } // HINFO and TXT require no validation. @@ -183,18 +162,6 @@ return true; } - - - /**************************************** - * * - * RECORD VALIDATING PART. * - * CHANGES HERE SHOULD BE CONSIDERED * - * THEY REQUIRE KNOWLEDGE ABOUT THE * - * DNS SPECIFICATIONS * - * * - ***************************************/ - - /* * Validatis a CNAME record by the name it will have and its destination * @@ -411,55 +378,113 @@ } -/* - * Function to check the validity of SOA records. - * return values: true if succesful - */ -function is_valid_soa(&$content, $zoneid) -{ +function is_valid_hostname_label($hostname_label) { + + // See . + if (!preg_match('/^[a-z\d]([a-z\d-]*[a-z\d])*$/i',$hostname_label)) { + return false; + } elseif (preg_match('/^[\d]+$/i',$hostname_label)) { + return false; + } elseif ((strlen($hostname_label) < 2) || (strlen($hostname_label) > 63)) { + return false; + } + return true; +} + +function is_valid_hostname_fqdn($hostname) { - /* - * The stored format is: primary hostmaster serial refresh retry expire default_ttl - */ + // See . + global $dns_strict_tld_check; + global $valid_tlds; + + $hostname = ereg_replace("\.$","",$hostname); - $return = get_records_by_type_from_domid("SOA", $zoneid); - if($return->numRows() > 1) { - return -1; + if (strlen($hostname) > 255) { + error(ERR_DNS_HN_TOO_LONG); + return false; + } + + $hostname_labels = explode ('.', $hostname); + $label_count = count($hostname_labels); + + if ($dns_strict_tld_check == "1" && !in_array($hostname_labels[$label_count-1], $valid_tlds)) { + error(ERR_DNS_INV_TLD); + return false; } - $soacontent = preg_split("/\s+/", $content); - - if(is_valid_hostname($soacontent[0])) { + if ($hostname_labels[$label_count-1] == "arpa") { + // FIXME + } else { + foreach ($hostname_labels as $hostname_label) { + if (!is_valid_hostname_label($hostname_label)) { + error(ERR_DNS_HOSTNAME); + return false; + } + } + } + return true; +} + +function is_valid_rr_soa(&$content) { - $totalsoa = $soacontent[0]; - // It doesnt matter what field 2 contains, but lets check if its there - // We assume the 2nd field wont have numbers, otherwise its a TTL field + // TODO move to appropiate location +// $return = get_records_by_type_from_domid("SOA", $zid); +// if($return->numRows() > 1) { +// return false; +// } + + $fields = preg_split("/\s+/", trim($content)); + $field_count = count($fields); + + if ($field_count == 0 || $field_count > 7) { + return false; + } else { + if (!is_valid_hostname_fqdn($fields[0]) || preg_match('/\.arpa\.?$/',$fields[0])) { + return false; + } + $final_soa = $fields[0]; - if(count($soacontent) > 1) { - if(is_numeric($soacontent[1])) { - // its a TTL field, or at least not hostmaster or alike - // Set final string to the default hostmaster addy - global $dns_hostmaster; - $totalsoa .= " ". $dns_hostmaster; - } else { - $totalsoa .= " ".$soacontent[1]; + if (isset($fields[1])) { + $addr_input = $fields[1]; + } else { + global $dns_hostmaster; + $addr_input = $dns_hostmaster; + } + if (!preg_match("/@/", $addr_input)) { + $addr_input = preg_split('/(? 7) --> SOA contained too many fields, should we provide error? } - } else { - error(ERR_DNS_SOA_HOSTNAME); } - $content = $totalsoa; - return 1; + $content = $final_soa; + return true; }