1
0
mirror of https://github.com/chylex/SMTP-Relay.git synced 2025-04-09 08:15:44 +02:00

Check sender email against auth file when user is authenticated

This commit is contained in:
Bernhard Froehlich 2018-12-28 15:30:55 +00:00
parent 76a04a2001
commit a82b0faf96
No known key found for this signature in database
GPG Key ID: 4DD88C3F9F3B8333
3 changed files with 27 additions and 2 deletions

View File

@ -25,5 +25,5 @@ produces mail.
* Authentication support with file (LOGIN, PLAIN)
* Enforce encryption for authentication
* Forwards all mail to a smarthost (GMail, MailGun or any other SMTP server)
* Small codebase (smtp-proxy ~250 LoC, chrj/smtpd ~1200 LoC)
* Small codebase (smtp-proxy ~300 LoC, chrj/smtpd ~1200 LoC)
* IPv6 support

25
main.go
View File

@ -63,6 +63,31 @@ func connectionChecker(peer smtpd.Peer) error {
}
func senderChecker(peer smtpd.Peer, addr string) error {
// check sender address from auth file if user is authenticated
if *allowedUsers != "" && peer.Username != "" {
file, err := os.Open(*allowedUsers)
if err != nil {
log.Printf("User file not found %v", err)
return smtpd.Error{Code: 451, Message: "Bad sender address"}
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
parts := strings.Fields(scanner.Text())
if len(parts) != 3 {
continue
}
if peer.Username == parts[0] {
if strings.ToLower(addr) != strings.ToLower(parts[2]) {
return smtpd.Error{Code: 451, Message: "Bad sender address"}
}
}
}
}
if *allowedSender == "" {
return nil
}

View File

@ -37,7 +37,7 @@
; File which contains username and password used for
; authentication before they can send mail.
; File format: username bcrypt-hash
; File format: username bcrypt-hash email
;allowed_users =
; Relay all mails to this SMTP server