From 56698453a1fb1c377b2b38d158064bb673da8c4c Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Tue, 24 Jan 2017 11:57:59 -0500 Subject: [PATCH] validate.go: Remove "_" warning if CNAME is a _domainkey. * "_" is permitted in label, if we suspect the target is a TXT. * Improve warning text if "." is required at end of target. * Move common factor assert_no_enddot(label) outside of case statement. --- normalize/validate.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/normalize/validate.go b/normalize/validate.go index e18cbd558..5fdd5f0d3 100644 --- a/normalize/validate.go +++ b/normalize/validate.go @@ -59,7 +59,7 @@ func assert_valid_target(target string) error { } // If it containts a ".", it must end in a ".". if strings.ContainsRune(target, '.') && target[len(target)-1] != '.' { - return fmt.Errorf("WARNING: target (%v) includes a (.), must end with a (.)", target) + return fmt.Errorf("WARNING: target (%v) must end with a (.) [Required if target is not single label]", target) } return nil } @@ -91,25 +91,31 @@ func validateTargets(rec *models.RecordConfig, domain_name string) (errs []error errs = append(errs, e) } } + check(assert_no_enddot(label)) switch rec.Type { case "A": - check(assert_no_enddot(label)) check(assert_no_underscores(label)) check(assert_valid_ipv4(target)) case "AAAA": - check(assert_no_enddot(label)) check(assert_no_underscores(label)) check(assert_valid_ipv6(target)) case "CNAME": - check(assert_no_enddot(label)) - check(assert_no_underscores(label)) + // NOTE(tlim): In theory a CNAME's label should abide by the assertions + // of the record type it points to. + // i.e. a If the CNAME target points at an MX record, the label should + // be validated as if it is an MX record. + // However, that's rather difficult to do, and impossible if the CNAME + // points at a record outside of dnscontrol's control. Therefore we do + // simple hacks to guess the target type. + // Assumption: If the label contains "._domainkey", this is an TXT. check(assert_valid_target(target)) + if !strings.Contains(label, "._domainkey") { + check(assert_no_underscores(label)) + } case "MX": - check(assert_no_enddot(label)) check(assert_no_underscores(label)) check(assert_valid_target(target)) case "NS": - check(assert_no_enddot(label)) check(assert_no_underscores(label)) check(assert_valid_target(target)) if label == "@" {