Do not share Server instance with multiple listeners

to avoid mixing TLS and non TLS configurations in the same server.
This commit is contained in:
Bernhard Froehlich
2018-12-11 15:30:12 +00:00
parent 5a67f917af
commit b53d620dd5
2 changed files with 8 additions and 9 deletions

14
main.go
View File

@@ -41,18 +41,17 @@ func main() {
iniflags.Parse()
server := &smtpd.Server{
Hostname: *hostName,
WelcomeMessage: *welcomeMsg,
Handler: handler,
ForceTLS: *localForceTLS,
}
listeners := strings.Split(*listen, " ")
for i := range(listeners) {
listener := listeners[i]
server := &smtpd.Server{
Hostname: *hostName,
WelcomeMessage: *welcomeMsg,
Handler: handler,
}
if strings.Index(listeners[i], "://") == -1 {
;
} else if strings.HasPrefix(listeners[i], "tls://") || strings.HasPrefix(listeners[i], "starttls://") {
@@ -69,6 +68,7 @@ func main() {
log.Fatal(err)
}
server.ForceTLS = *localForceTLS
server.TLSConfig = &tls.Config {
Certificates: [] tls.Certificate{cert},
}

View File

@@ -18,8 +18,7 @@
;local_key = smtpd.key
; Enforce encrypted connection on STARTTLS ports before
; accepting mails from client. Cannot be used with plain
; non encrypted listeners.
; accepting mails from client.
;local_forcetls = false
; Relay all mails to this SMTP server