coredns-ldap/handler.go

55 lines
1.3 KiB
Go
Raw Normal View History

package ldap
import (
"context"
"github.com/coredns/coredns/plugin"
2020-06-09 03:01:53 +00:00
"github.com/coredns/coredns/plugin/file"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
// ServeDNS implements the plugin.Handler interface.
func (l Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
2020-06-09 03:01:53 +00:00
// opt := plugin.Options{}
state := request.Request{W: w, Req: r}
2020-06-09 03:01:53 +00:00
zone := plugin.Zones(l.Zones.Names).Matches(state.Name())
if zone == "" {
return plugin.NextOrFailure(l.Name(), l.Next, ctx, w, r)
}
2020-06-09 03:01:53 +00:00
Zone, ok := l.Zones.Z[zone]
if !ok || Zone == nil {
return dns.RcodeServerFailure, nil
}
2020-06-09 03:01:53 +00:00
var result file.Result
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
2020-06-09 03:01:53 +00:00
l.zMu.RLock()
m.Answer, m.Ns, m.Extra, result = Zone.Lookup(ctx, state, state.Name())
l.zMu.RUnlock()
if len(m.Answer) == 0 && result != file.NoData && l.Fall.Through(state.Name()) {
return plugin.NextOrFailure(l.Name(), l.Next, ctx, w, r)
}
2020-06-09 03:01:53 +00:00
switch result {
case file.Success:
case file.NoData:
case file.NameError:
m.Rcode = dns.RcodeNameError
case file.Delegation:
m.Authoritative = false
case file.ServerFailure:
return dns.RcodeServerFailure, nil
}
w.WriteMsg(m)
return dns.RcodeSuccess, nil
}
// Name implements the Handler interface.
2020-06-04 17:41:04 +00:00
func (l Ldap) Name() string { return "ldap" }
2020-06-10 02:54:01 +00:00