mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
chasquid: Track and enforce the HELO/EHLO address
HELO and EHLO both take a mandatory parameter, which also should be used in the Received header. This patch tracks and enforces that parameter, and also updates the Received header generation to use it. https://tools.ietf.org/html/rfc5321#section-4.4
This commit is contained in:
20
chasquid.go
20
chasquid.go
@@ -422,6 +422,9 @@ type Conn struct {
|
|||||||
// TLS configuration.
|
// TLS configuration.
|
||||||
tlsConfig *tls.Config
|
tlsConfig *tls.Config
|
||||||
|
|
||||||
|
// Address given at HELO/EHLO, used for tracing purposes.
|
||||||
|
ehloAddress string
|
||||||
|
|
||||||
// Envelope.
|
// Envelope.
|
||||||
mailFrom string
|
mailFrom string
|
||||||
rcptTo []string
|
rcptTo []string
|
||||||
@@ -565,6 +568,11 @@ loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) HELO(params string) (code int, msg string) {
|
func (c *Conn) HELO(params string) (code int, msg string) {
|
||||||
|
if len(strings.TrimSpace(params)) == 0 {
|
||||||
|
return 501, "Invisible customers are not welcome!"
|
||||||
|
}
|
||||||
|
c.ehloAddress = strings.Fields(params)[0]
|
||||||
|
|
||||||
types := []string{
|
types := []string{
|
||||||
"general store", "used armor dealership", "second-hand bookstore",
|
"general store", "used armor dealership", "second-hand bookstore",
|
||||||
"liquor emporium", "antique weapons outlet", "delicatessen",
|
"liquor emporium", "antique weapons outlet", "delicatessen",
|
||||||
@@ -577,6 +585,11 @@ func (c *Conn) HELO(params string) (code int, msg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) EHLO(params string) (code int, msg string) {
|
func (c *Conn) EHLO(params string) (code int, msg string) {
|
||||||
|
if len(strings.TrimSpace(params)) == 0 {
|
||||||
|
return 501, "Invisible customers are not welcome!"
|
||||||
|
}
|
||||||
|
c.ehloAddress = strings.Fields(params)[0]
|
||||||
|
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
fmt.Fprintf(buf, c.hostname+" - Your hour of destiny has come.\n")
|
fmt.Fprintf(buf, c.hostname+" - Your hour of destiny has come.\n")
|
||||||
fmt.Fprintf(buf, "8BITMIME\n")
|
fmt.Fprintf(buf, "8BITMIME\n")
|
||||||
@@ -767,6 +780,9 @@ func (c *Conn) RCPT(params string) (code int, msg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) DATA(params string) (code int, msg string) {
|
func (c *Conn) DATA(params string) (code int, msg string) {
|
||||||
|
if c.ehloAddress == "" {
|
||||||
|
return 503, "Invisible customers are not welcome!"
|
||||||
|
}
|
||||||
if c.mailFrom == "" {
|
if c.mailFrom == "" {
|
||||||
return 503, "sender not yet given"
|
return 503, "sender not yet given"
|
||||||
}
|
}
|
||||||
@@ -832,10 +848,10 @@ func (c *Conn) addReceivedHeader() {
|
|||||||
|
|
||||||
if c.completedAuth {
|
if c.completedAuth {
|
||||||
v += fmt.Sprintf("from %s (authenticated as %s@%s)\n",
|
v += fmt.Sprintf("from %s (authenticated as %s@%s)\n",
|
||||||
envelope.DomainOf(c.mailFrom), c.authUser, c.authDomain)
|
c.ehloAddress, c.authUser, c.authDomain)
|
||||||
} else {
|
} else {
|
||||||
v += fmt.Sprintf("from %s (%s)\n",
|
v += fmt.Sprintf("from %s (%s)\n",
|
||||||
envelope.DomainOf(c.mailFrom), c.netconn.RemoteAddr().String())
|
c.ehloAddress, c.netconn.RemoteAddr().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
v += fmt.Sprintf("by %s (chasquid)\n", c.hostname)
|
v += fmt.Sprintf("by %s (chasquid)\n", c.hostname)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ Delivery to the following recipient(s) failed permanently:
|
|||||||
|
|
||||||
----- Original message -----
|
----- Original message -----
|
||||||
|
|
||||||
Received: from testserver (authenticated as user@testserver)
|
Received: from localhost (authenticated as user@testserver)
|
||||||
by testserver (chasquid)
|
by testserver (chasquid)
|
||||||
(over *
|
(over *
|
||||||
(envelope from "user@testserver")
|
(envelope from "user@testserver")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
EHLO
|
EHLO localhost
|
||||||
MAIL FROM: <>
|
MAIL FROM: <>
|
||||||
RCPT TO: user@testserver
|
RCPT TO: user@testserver
|
||||||
DATA
|
DATA
|
||||||
|
|||||||
Reference in New Issue
Block a user