Esempio n. 1
0
// transferParse parses transfer statements: 'transfer to [address...]'.
func transferParse(c *Controller) (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] != "*" {
					if x := net.ParseIP(tos[i]); x == nil {
						return nil, nil, fmt.Errorf("must specify an IP addres: `%s'", tos[i])
					}
					tos[i] = middleware.Addr(tos[i]).Normalize()
				}
			}
		}
		if value == "from" {
			froms = c.RemainingArgs()
			for i, _ := range froms {
				if froms[i] != "*" {
					if x := net.ParseIP(froms[i]); x == nil {
						return nil, nil, fmt.Errorf("must specify an IP addres: `%s'", froms[i])
					}
					froms[i] = middleware.Addr(froms[i]).Normalize()
				} else {
					return nil, nil, fmt.Errorf("can't use '*' in transfer from")
				}
			}
		}
	}
	return
}
Esempio n. 2
0
// isNotify checks if state is a notify message and if so, will *also* check if it
// is from one of the configured masters. If not it will not be a valid notify
// message. If the zone z is not a secondary zone the message will also be ignored.
func (z *Zone) isNotify(state middleware.State) bool {
	if state.Req.Opcode != dns.OpcodeNotify {
		return false
	}
	if len(z.TransferFrom) == 0 {
		return false
	}
	remote := middleware.Addr(state.IP()).Normalize()
	for _, from := range z.TransferFrom {
		if from == remote {
			return true
		}
	}
	return false
}