2021-03-08 02:19:22 +08:00
|
|
|
package namedotcom
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-07-18 22:30:19 +08:00
|
|
|
"strings"
|
|
|
|
|
2021-03-08 02:19:22 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/models"
|
2022-08-12 05:24:47 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/pkg/rejectif"
|
2021-03-08 02:19:22 +08:00
|
|
|
)
|
|
|
|
|
2022-08-12 05:24:47 +08:00
|
|
|
// AuditRecords returns a list of errors corresponding to the records
|
|
|
|
// that aren't supported by this provider. If all records are
|
|
|
|
// supported, an empty list is returned.
|
|
|
|
func AuditRecords(records []*models.RecordConfig) []error {
|
|
|
|
a := rejectif.Auditor{}
|
2021-03-08 02:19:22 +08:00
|
|
|
|
2022-09-08 02:08:06 +08:00
|
|
|
a.Add("MX", rejectif.MxNull) // Last verified 2020-12-28
|
|
|
|
|
|
|
|
a.Add("SRV", rejectif.SrvHasNullTarget) // Last verified 2020-12-28
|
|
|
|
|
2022-08-12 05:24:47 +08:00
|
|
|
a.Add("TXT", MaxLengthNDC) // Last verified 2021-03-01
|
2021-03-08 02:19:22 +08:00
|
|
|
|
2022-08-12 05:24:47 +08:00
|
|
|
a.Add("TXT", rejectif.TxtIsEmpty) // Last verified 2021-03-01
|
2021-03-08 02:19:22 +08:00
|
|
|
|
2022-08-12 05:24:47 +08:00
|
|
|
return a.Audit(records)
|
2021-03-08 02:19:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// MaxLengthNDC returns and error if the sum of the strings
|
2022-07-18 22:30:19 +08:00
|
|
|
// are longer than permitted by NDC. Sadly their
|
2021-03-08 02:19:22 +08:00
|
|
|
// length limit is undocumented. This seems to work.
|
2022-08-12 05:24:47 +08:00
|
|
|
func MaxLengthNDC(rc *models.RecordConfig) error {
|
|
|
|
if len(rc.TxtStrings) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sum := 2 // Count the start and end quote.
|
|
|
|
// Add the length of each segment.
|
|
|
|
for _, segment := range rc.TxtStrings {
|
|
|
|
sum += len(segment) // The length of each segment
|
|
|
|
sum += strings.Count(segment, `"`) // Add 1 for any char to be escaped
|
|
|
|
}
|
|
|
|
// Add 3 (quote space quote) for each interior join.
|
|
|
|
sum += 3 * (len(rc.TxtStrings) - 1)
|
2021-03-08 02:19:22 +08:00
|
|
|
|
2022-08-12 05:24:47 +08:00
|
|
|
if sum > 512 {
|
|
|
|
return fmt.Errorf("encoded txt too long")
|
2021-03-08 02:19:22 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|