function validate_input($rid, $zid, $type, &$content, &$name, &$prio, &$ttl)
{
    $zone = get_zone_name_from_id($zid);
    // TODO check for return
    if (!preg_match("/{$zone}\$/i", $name)) {
        if (isset($name) && $name != "") {
            $name = $name . "." . $zone;
        } else {
            $name = $zone;
        }
    }
    switch ($type) {
        case "A":
            if (!is_valid_ipv4($content)) {
                return false;
            }
            if (!is_valid_rr_cname_exists($name, $rid)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case "AAAA":
            if (!is_valid_ipv6($content)) {
                return false;
            }
            if (!is_valid_rr_cname_exists($name, $rid)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case "CNAME":
            if (!is_valid_rr_cname_name($name)) {
                return false;
            }
            if (!is_valid_rr_cname_unique($name, $rid)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            break;
        case "HINFO":
            if (!is_valid_rr_hinfo_content($content)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case "MX":
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_non_alias_target($content)) {
                return false;
            }
            break;
        case "NS":
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_non_alias_target($content)) {
                return false;
            }
            break;
        case "PTR":
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case "SOA":
            if (!is_valid_rr_soa_name($name, $zone)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_rr_soa_content($content)) {
                return false;
            }
            break;
        case "SRV":
            if (!is_valid_rr_srv_name($name)) {
                return false;
            }
            if (!is_valid_rr_srv_content($content)) {
                return false;
            }
            break;
        case "TXT":
            if (!is_valid_printable($name)) {
                return false;
            }
            if (!is_valid_printable($content)) {
                return false;
            }
            break;
        case "CURL":
        case "MBOXFW":
        case "NAPTR":
        case "SPF":
            /*
            Validate SPF entry
            */
            if (!is_valid_spf($content)) {
                return false;
            }
        case "SSHFP":
        case "URL":
            // These types are supported by PowerDNS, but there is not
            // yet code for validation. Validation needs to be added
            // for these types. One Day Real Soon Now. [tm]
            break;
        case "LOC":
            if (!is_valid_loc($content)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        default:
            error(ERR_DNS_RR_TYPE);
            return false;
    }
    if (!is_valid_rr_prio($prio, $type)) {
        return false;
    }
    if (!is_valid_rr_ttl($ttl)) {
        return false;
    }
    return true;
}
Ejemplo n.º 2
0
/** Validate DNS record input
 *
 * @param int $rid Record ID
 * @param int $zid Zone ID
 * @param string $type Record Type
 * @param mixed $content content part of record
 * @param mixed $name Name part of record
 * @param mixed $prio Priority
 * @param mixed $ttl TTL
 *
 * @return boolean true on success, false otherwise
 */
function validate_input($rid, $zid, $type, &$content, &$name, &$prio, &$ttl)
{
    $zone = get_zone_name_from_id($zid);
    // TODO check for return
    if (!preg_match("/{$zone}\$/i", $name)) {
        if (isset($name) && $name != "") {
            $name = $name . "." . $zone;
        } else {
            $name = $zone;
        }
    }
    switch ($type) {
        case "A":
            if (!is_valid_ipv4($content)) {
                return false;
            }
            if (!is_valid_rr_cname_exists($name, $rid)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case "AAAA":
            if (!is_valid_ipv6($content)) {
                return false;
            }
            if (!is_valid_rr_cname_exists($name, $rid)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case "AFSDB":
            // TODO: implement validation.
            break;
        case "CERT":
            // TODO: implement validation.
            break;
        case "CNAME":
            if (!is_valid_rr_cname_name($name)) {
                return false;
            }
            if (!is_valid_rr_cname_unique($name, $rid)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            if (!is_not_empty_cname_rr($name, $zone)) {
                return false;
            }
            break;
        case 'DHCID':
            // TODO: implement validation
            break;
        case 'DLV':
            // TODO: implement validation
            break;
        case 'DNSKEY':
            // TODO: implement validation
            break;
        case 'DS':
            // TODO: implement validation
            break;
        case 'EUI48':
            // TODO: implement validation
            break;
        case 'EUI64':
            // TODO: implement validation
            break;
        case "HINFO":
            if (!is_valid_rr_hinfo_content($content)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case 'IPSECKEY':
            // TODO: implement validation
            break;
        case 'KEY':
            // TODO: implement validation
            break;
        case 'KX':
            // TODO: implement validation
            break;
        case "LOC":
            if (!is_valid_loc($content)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case 'MINFO':
            // TODO: implement validation
            break;
        case 'MR':
            // TODO: implement validation
            break;
        case "MX":
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_non_alias_target($content)) {
                return false;
            }
            break;
        case 'NAPTR':
            // TODO: implement validation
            break;
        case "NS":
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_non_alias_target($content)) {
                return false;
            }
            break;
        case 'NSEC':
            // TODO: implement validation
            break;
        case 'NSEC3':
            // TODO: implement validation
            break;
        case 'NSEC3PARAM':
            // TODO: implement validation
            break;
        case 'OPT':
            // TODO: implement validation
            break;
        case "PTR":
            if (!is_valid_hostname_fqdn($content, 0)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            break;
        case 'RKEY':
            // TODO: implement validation
            break;
        case 'RP':
            // TODO: implement validation
            break;
        case 'RRSIG':
            // TODO: implement validation
            break;
        case "SOA":
            if (!is_valid_rr_soa_name($name, $zone)) {
                return false;
            }
            if (!is_valid_hostname_fqdn($name, 1)) {
                return false;
            }
            if (!is_valid_rr_soa_content($content)) {
                error(ERR_DNS_CONTENT);
                return false;
            }
            break;
        case "SPF":
            if (!is_valid_spf($content)) {
                return false;
            }
            break;
        case "SRV":
            if (!is_valid_rr_srv_name($name)) {
                return false;
            }
            if (!is_valid_rr_srv_content($content)) {
                return false;
            }
            break;
        case 'SSHFP':
            // TODO: implement validation
            break;
        case 'TLSA':
            // TODO: implement validation
            break;
        case 'TSIG':
            // TODO: implement validation
            break;
        case "TXT":
            if (!is_valid_printable($name)) {
                return false;
            }
            if (!is_valid_printable($content)) {
                return false;
            }
            break;
        case 'WKS':
            // TODO: implement validation
            break;
        case "CURL":
        case "MBOXFW":
        case "URL":
            // TODO: implement validation?
            // Fancy types are not supported anymore in PowerDNS
            break;
        default:
            error(ERR_DNS_RR_TYPE);
            return false;
    }
    if (!is_valid_rr_prio($prio, $type)) {
        return false;
    }
    if (!is_valid_rr_ttl($ttl)) {
        return false;
    }
    return true;
}