Add authors helper function
This commit is contained in:
parent
6058dce1db
commit
88902fc943
|
@ -158,6 +158,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
dns.HandleFunc(".", handleReflect)
|
dns.HandleFunc(".", handleReflect)
|
||||||
|
dns.HandleFunc("authors.bind.", dns.HandleAuthors)
|
||||||
|
dns.HandleFunc("authors.server.", dns.HandleAuthors)
|
||||||
go serve("tcp", name, secret)
|
go serve("tcp", name, secret)
|
||||||
go serve("udp", name, secret)
|
go serve("udp", name, secret)
|
||||||
sig := make(chan os.Signal)
|
sig := make(chan os.Signal)
|
||||||
|
|
48
server.go
48
server.go
|
@ -81,16 +81,50 @@ func (f HandlerFunc) ServeDNS(w ResponseWriter, r *Msg) {
|
||||||
f(w, r)
|
f(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failed is a helper handler that returns an answer with
|
// FailedHandler returns a HandlerFunc
|
||||||
// RCODE = servfail for every request.
|
// returns SERVFAIL for every request it gets.
|
||||||
func Failed(w ResponseWriter, r *Msg) {
|
func HandleFailed(w ResponseWriter, r *Msg) {
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
m.SetRcode(r, RcodeServerFailure)
|
m.SetRcode(r, RcodeServerFailure)
|
||||||
|
// does not matter if this write fails
|
||||||
w.Write(m)
|
w.Write(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FailedHandler returns HandlerFunc with Failed.
|
// AuthorHandler returns a HandlerFunc that returns the authors
|
||||||
func FailedHandler() Handler { return HandlerFunc(Failed) }
|
// of Go DNS for 'authors.bind' or 'authors.server' queries in the
|
||||||
|
// CHAOS Class.
|
||||||
|
func HandleAuthors(w ResponseWriter, r *Msg) {
|
||||||
|
if len(r.Question) != 1 {
|
||||||
|
HandleFailed(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.Question[0].Qtype != ClassCHAOS && r.Question[0].Qtype != TypeTXT {
|
||||||
|
HandleFailed(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.Question[0].Name != "authors.server." && r.Question[0].Name != "authors.bind." {
|
||||||
|
HandleFailed(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// primary author
|
||||||
|
m := new(Msg)
|
||||||
|
m.SetReply(r)
|
||||||
|
for _, author := range []string{"Miek Gieben"} {
|
||||||
|
h := RR_Header{r.Question[0].Name, TypeTXT, ClassCHAOS, 0, 0}
|
||||||
|
m.Answer = append(m.Answer, &RR_TXT{h, []string{author}})
|
||||||
|
}
|
||||||
|
// from git:
|
||||||
|
// git log |grep '^Author' | sort -u | sed 's/^Author: //' | sed 's/<.*>//'
|
||||||
|
// But only if I have a firstname and lastname
|
||||||
|
for _, author := range []string{"Ask Bjorn Hansen", "Dave Cheney", "Dusty Wilson", "Peter van Dijk"} {
|
||||||
|
h := RR_Header{r.Question[0].Name, TypeTXT, ClassCHAOS, 0, 0}
|
||||||
|
m.Extra = append(m.Extra, &RR_TXT{h, []string{author}})
|
||||||
|
}
|
||||||
|
w.Write(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func authorHandler() Handler { return HandlerFunc(HandleAuthors) }
|
||||||
|
func failedHandler() Handler { return HandlerFunc(HandleFailed) }
|
||||||
|
|
||||||
// Start a server on addresss and network speficied. Invoke handler
|
// Start a server on addresss and network speficied. Invoke handler
|
||||||
// for any incoming queries.
|
// for any incoming queries.
|
||||||
|
@ -147,10 +181,10 @@ func (mux *ServeMux) HandleRemove(pattern string) {
|
||||||
func (mux *ServeMux) ServeDNS(w ResponseWriter, request *Msg) {
|
func (mux *ServeMux) ServeDNS(w ResponseWriter, request *Msg) {
|
||||||
var h Handler
|
var h Handler
|
||||||
if len(request.Question) != 1 {
|
if len(request.Question) != 1 {
|
||||||
h = FailedHandler()
|
h = failedHandler()
|
||||||
} else {
|
} else {
|
||||||
if h = mux.match(request.Question[0].Name, request.Question[0].Qtype); h == nil {
|
if h = mux.match(request.Question[0].Name, request.Question[0].Qtype); h == nil {
|
||||||
h = FailedHandler()
|
h = failedHandler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.ServeDNS(w, request)
|
h.ServeDNS(w, request)
|
||||||
|
|
Loading…
Reference in New Issue