git » chasquid » commit 41d9605

smtpsrv: Use spf.CheckHostWithSender

author Alberto Bertogli
2019-10-14 18:37:14 UTC
committer Alberto Bertogli
2019-10-14 18:37:14 UTC
parent 35844415497746f88ba62d10cdc1f2fba4b47960

smtpsrv: Use spf.CheckHostWithSender

The spf library has gained support for macros, but to process them
properly, a new function needs to be called with the full sender
address, spf.CheckHostWithSender.

This patch updates chasquid's calls to the new API.

cmd/smtp-check/smtp-check.go +1 -1
cmd/spf-check/spf-check.go +2 -1
internal/smtpsrv/conn.go +2 -2

diff --git a/cmd/smtp-check/smtp-check.go b/cmd/smtp-check/smtp-check.go
index b9215fc..569b424 100644
--- a/cmd/smtp-check/smtp-check.go
+++ b/cmd/smtp-check/smtp-check.go
@@ -72,7 +72,7 @@ func main() {
 			log.Fatal(err)
 		}
 		for _, ip := range ips {
-			result, err := spf.CheckHost(ip, domain)
+			result, err := spf.CheckHostWithSender(ip, domain, "test@"+domain)
 			if result != spf.Pass {
 				log.Printf("SPF check != pass for IP %s: %s - %s",
 					ip, result, err)
diff --git a/cmd/spf-check/spf-check.go b/cmd/spf-check/spf-check.go
index 53e609a..1efdb60 100644
--- a/cmd/spf-check/spf-check.go
+++ b/cmd/spf-check/spf-check.go
@@ -16,7 +16,8 @@ import (
 func main() {
 	flag.Parse()
 
-	r, err := spf.CheckHost(net.ParseIP(flag.Arg(0)), flag.Arg(1))
+	r, err := spf.CheckHostWithSender(
+		net.ParseIP(flag.Arg(0)), "", flag.Arg(1))
 	fmt.Println(r)
 	fmt.Println(err)
 }
diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go
index 29ea5a2..82808cf 100644
--- a/internal/smtpsrv/conn.go
+++ b/internal/smtpsrv/conn.go
@@ -439,8 +439,8 @@ func (c *Conn) checkSPF(addr string) (spf.Result, error) {
 	}
 
 	if tcp, ok := c.conn.RemoteAddr().(*net.TCPAddr); ok {
-		res, err := spf.CheckHost(
-			tcp.IP, envelope.DomainOf(addr))
+		res, err := spf.CheckHostWithSender(
+			tcp.IP, envelope.DomainOf(addr), addr)
 
 		c.tr.Debugf("SPF %v (%v)", res, err)
 		spfResultCount.Add(string(res), 1)