Skip to content

Commit 6a2e0ad

Browse files
committed
check/spf: Use context.Context and custom resolver interface
Closes #354.
1 parent 66cb717 commit 6a2e0ad

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/foxcpp/maddy
33
go 1.14
44

55
require (
6-
blitiri.com.ar/go/spf v1.1.1
6+
blitiri.com.ar/go/spf v1.2.0
77
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962
88
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
99
github.com/emersion/go-imap v1.0.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
blitiri.com.ar/go/spf v1.1.1 h1:H5MKnEe5feN4NjtPDK/vFkkS0fI+ecTIsOfLNCR+6yI=
2-
blitiri.com.ar/go/spf v1.1.1/go.mod h1:HLmgHxdrsqbBgi5omEopdAKm18PypvUKJGkF/j7BO0w=
1+
blitiri.com.ar/go/spf v1.2.0 h1:aPpeEVKz5Ue4xb4SEt4AzScCSyES7/pol6znzZGle3A=
2+
blitiri.com.ar/go/spf v1.2.0/go.mod h1:HLmgHxdrsqbBgi5omEopdAKm18PypvUKJGkF/j7BO0w=
33
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
44
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
55
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

internal/check/spf/spf.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ type Check struct {
5656
permerrAction modconfig.FailAction
5757
temperrAction modconfig.FailAction
5858

59-
log log.Logger
59+
log log.Logger
60+
resolver dns.Resolver
6061
}
6162

6263
func New(_, instName string, _, _ []string) (module.Module, error) {
6364
return &Check{
6465
instName: instName,
6566
log: log.Logger{Name: modName},
67+
resolver: dns.DefaultResolver(),
6668
}, nil
6769
}
6870

@@ -243,7 +245,7 @@ func (s *state) relyOnDMARC(ctx context.Context, hdr textproto.Header) bool {
243245
return false
244246
}
245247

246-
policyDomain, record, err := maddydmarc.FetchRecord(ctx, dns.DefaultResolver(), fromDomain)
248+
policyDomain, record, err := maddydmarc.FetchRecord(ctx, s.c.resolver, fromDomain)
247249
if err != nil {
248250
s.log.Error("DMARC fetch", err, "from_domain", fromDomain)
249251
return false
@@ -323,7 +325,8 @@ func (s *state) CheckConnection(ctx context.Context) module.CheckResult {
323325

324326
if s.c.enforceEarly {
325327
res, err := spf.CheckHostWithSender(ip.IP,
326-
dns.FQDN(s.msgMeta.Conn.Hostname), mailFrom)
328+
dns.FQDN(s.msgMeta.Conn.Hostname), mailFrom,
329+
spf.WithContext(ctx), spf.WithResolver(s.c.resolver))
327330
s.log.Debugf("result: %s (%v)", res, err)
328331
return s.spfResult(res, err)
329332
}
@@ -344,7 +347,8 @@ func (s *state) CheckConnection(ctx context.Context) module.CheckResult {
344347

345348
defer trace.StartRegion(ctx, "check.spf/CheckConnection (Async)").End()
346349

347-
res, err := spf.CheckHostWithSender(ip.IP, dns.FQDN(s.msgMeta.Conn.Hostname), mailFrom)
350+
res, err := spf.CheckHostWithSender(ip.IP, dns.FQDN(s.msgMeta.Conn.Hostname), mailFrom,
351+
spf.WithContext(ctx), spf.WithResolver(s.c.resolver))
348352
s.log.Debugf("result: %s (%v)", res, err)
349353
s.spfFetch <- spfRes{res, err}
350354
}()

0 commit comments

Comments
 (0)