-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deny_malformed.go
35 lines (32 loc) · 935 Bytes
/
deny_malformed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package helo
import (
"strings"
"github.com/vodolaz095/msmtpd"
)
// DenyMalformedDomain checks, if domain in HELO request belongs to top list domains like .ru, .su and so on
func DenyMalformedDomain(transaction *msmtpd.Transaction) error {
var pass bool
if transaction.IsFlagSet(IsLocalAddressFlagName) {
transaction.LogDebug("Connecting from local address %s, DenyMalformedDomain check disabled",
transaction.Addr.String())
return nil
}
fixed := strings.ToUpper(transaction.HeloName)
for i := range TopListDomains {
if pass {
continue
}
if strings.HasSuffix(fixed, "."+TopListDomains[i]) {
pass = true
}
if strings.HasSuffix(fixed, "."+TopListDomains[i]+".") {
pass = true
}
}
if !pass {
transaction.LogWarn("HELO/EHLO hostname %s is invalid", transaction.HeloName)
return complain
}
transaction.LogDebug("HELO/EHLO %s seems to be in top domain list", transaction.HeloName)
return nil
}