Fix the IsSubDomain issue

This commit is contained in:
Miek Gieben 2012-08-09 21:05:20 +02:00
parent 1dffbeeee1
commit 939fd83e83
3 changed files with 11 additions and 3 deletions

View File

@ -20,13 +20,16 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
if z == nil {
panic("fksd: no zone")
}
//logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr())
logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr())
// Ds Handling
// Referral
// if we find something with NonAuth = true, it means
// we need to return referral
nss := z.Predecessor(req.Question[0].Name)
m := new(dns.Msg)
if nss != nil {
println("found", nss.RR[dns.TypeNS][0].String())
}
if nss != nil && nss.NonAuth {
m.SetReply(req)
m.Ns = nss.RR[dns.TypeNS]
@ -98,6 +101,9 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
return
} else { // NoData reply or CNAME
m.SetReply(req)
if cname, ok := node.RR[dns.TypeCNAME]; ok {
m.Answer = cname // tODO
}
m.Ns = apex.RR[dns.TypeSOA]
ednsFromRequest(req, m)
w.Write(m)

View File

@ -14,7 +14,9 @@ func (c *Config) ReadZoneFile(origin, file string) error {
z := dns.NewZone(origin)
for rr := range dns.ParseZone(f, origin, file) {
if rr.Error == nil {
z.Insert(rr.RR)
if e := z.Insert(rr.RR); e != nil {
logPrintf("failed to insert record: %s\n", e.Error())
}
} else {
logPrintf("failed to parse: %s\n", rr.Error.Error())
}

View File

@ -52,7 +52,7 @@ func NewZone(origin string) *Zone {
// Insert inserts an RR into the zone. Duplicate data overwrites the old data.
func (z *Zone) Insert(r RR) error {
if !IsSubDomain(r.Header().Name, z.Origin) {
if !IsSubDomain(z.Origin, r.Header().Name) {
return &Error{Err: "out of zone data", Name: r.Header().Name}
}