NETCUP: Handle CNAMEs with a single @ as destination correctly (#1947)

This commit is contained in:
Kordian Bruck 2023-01-17 16:56:29 +01:00 committed by GitHub
parent b4cbd1299f
commit 261961c5b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,6 +71,17 @@ type responseLogin struct {
SessionID string `json:"apisessionid"`
}
// addTailingDot adds a dot if it's missing from what the netcup api has returned to us.
func addTailingDot(destination string) string {
if destination == "@" || len(destination) == 0 {
return destination
}
if destination[len(destination)-1:] != "." {
return destination + "."
}
return destination
}
func toRecordConfig(domain string, r *record) *models.RecordConfig {
priority, _ := strconv.ParseUint(r.Priority, 10, 16)
@ -89,7 +100,7 @@ func toRecordConfig(domain string, r *record) *models.RecordConfig {
case "TXT":
_ = rc.SetTargetTXT(r.Destination)
case "NS", "ALIAS", "CNAME", "MX":
_ = rc.SetTarget(dnsutil.AddOrigin(r.Destination+".", domain))
_ = rc.SetTarget(dnsutil.AddOrigin(addTailingDot(r.Destination), domain))
case "SRV":
parts := strings.Split(r.Destination, " ")
priority, _ := strconv.ParseUint(parts[0], 10, 16)
@ -108,7 +119,6 @@ func toRecordConfig(domain string, r *record) *models.RecordConfig {
default:
_ = rc.SetTarget(r.Destination)
}
return rc
}