mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 18:53:43 -04:00
middleware/file: correctly parse the stanza (#658)
* middleware/file: correctly parse the stanza Parsing the file stanza would give precedence to 'transfer' and ignore other bits if it wasn't specified. This change fixes the parsing. The actually external CNAME retrieval is working fine (once the upstream is correctly parsed). This wasn't caught in tests, because we lack a parsing test for this. Fixes #657 * Add tests
This commit is contained in:
@@ -92,12 +92,17 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||
|
||||
noReload := false
|
||||
prxy := proxy.Proxy{}
|
||||
t := []string{}
|
||||
var e error
|
||||
|
||||
for c.NextBlock() {
|
||||
t, _, e := TransferParse(c, false)
|
||||
if e != nil {
|
||||
return Zones{}, e
|
||||
}
|
||||
switch c.Val() {
|
||||
case "transfer":
|
||||
t, _, e = TransferParse(c, false)
|
||||
if e != nil {
|
||||
return Zones{}, e
|
||||
}
|
||||
|
||||
case "no_reload":
|
||||
noReload = true
|
||||
|
||||
@@ -128,40 +133,37 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||
|
||||
// TransferParse parses transfer statements: 'transfer to [address...]'.
|
||||
func TransferParse(c *caddy.Controller, secondary bool) (tos, froms []string, err error) {
|
||||
what := c.Val()
|
||||
if !c.NextArg() {
|
||||
return nil, nil, c.ArgErr()
|
||||
}
|
||||
value := c.Val()
|
||||
switch what {
|
||||
case "transfer":
|
||||
if value == "to" {
|
||||
tos = c.RemainingArgs()
|
||||
for i := range tos {
|
||||
if tos[i] != "*" {
|
||||
normalized, err := dnsutil.ParseHostPort(tos[i], "53")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
tos[i] = normalized
|
||||
switch value {
|
||||
case "to":
|
||||
tos = c.RemainingArgs()
|
||||
for i := range tos {
|
||||
if tos[i] != "*" {
|
||||
normalized, err := dnsutil.ParseHostPort(tos[i], "53")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
tos[i] = normalized
|
||||
}
|
||||
}
|
||||
if value == "from" {
|
||||
if !secondary {
|
||||
return nil, nil, fmt.Errorf("can't use `transfer from` when not being a secondary")
|
||||
}
|
||||
froms = c.RemainingArgs()
|
||||
for i := range froms {
|
||||
if froms[i] != "*" {
|
||||
normalized, err := dnsutil.ParseHostPort(froms[i], "53")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
froms[i] = normalized
|
||||
} else {
|
||||
return nil, nil, fmt.Errorf("can't use '*' in transfer from")
|
||||
|
||||
case "from":
|
||||
if !secondary {
|
||||
return nil, nil, fmt.Errorf("can't use `transfer from` when not being a secondary")
|
||||
}
|
||||
froms = c.RemainingArgs()
|
||||
for i := range froms {
|
||||
if froms[i] != "*" {
|
||||
normalized, err := dnsutil.ParseHostPort(froms[i], "53")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
froms[i] = normalized
|
||||
} else {
|
||||
return nil, nil, fmt.Errorf("can't use '*' in transfer from")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user