mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-27 16:24:04 +00:00
Add hook for EXTERNAL authentication mechanism
This commit is contained in:
parent
256849f2c6
commit
2b58b571cb
2 changed files with 16 additions and 6 deletions
|
@ -23,10 +23,11 @@ type Protocol struct {
|
||||||
message *data.SMTPMessage
|
message *data.SMTPMessage
|
||||||
hostname string
|
hostname string
|
||||||
|
|
||||||
LogHandler func(message string, args ...interface{})
|
LogHandler func(message string, args ...interface{})
|
||||||
MessageReceivedHandler func(*data.Message) (string, error)
|
MessageReceivedHandler func(*data.Message) (string, error)
|
||||||
ValidateSenderHandler func(from string) bool
|
ValidateSenderHandler func(from string) bool
|
||||||
ValidateRecipientHandler func(to string) bool
|
ValidateRecipientHandler func(to string) bool
|
||||||
|
ValidateAuthenticationHandler func(mechanism string, args ...string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProtocol returns a new SMTP state machine in INVALID state
|
// NewProtocol returns a new SMTP state machine in INVALID state
|
||||||
|
@ -182,6 +183,11 @@ func (proto *Protocol) Command(command *Command) (reply *Reply) {
|
||||||
return ReplyAuthResponse("PDQxOTI5NDIzNDEuMTI4Mjg0NzJAc291cmNlZm91ci5hbmRyZXcuY211LmVkdT4=")
|
return ReplyAuthResponse("PDQxOTI5NDIzNDEuMTI4Mjg0NzJAc291cmNlZm91ci5hbmRyZXcuY211LmVkdT4=")
|
||||||
case strings.HasPrefix(command.args, "EXTERNAL "):
|
case strings.HasPrefix(command.args, "EXTERNAL "):
|
||||||
proto.logf("Got EXTERNAL authentication: %s", strings.TrimPrefix(command.args, "EXTERNAL "))
|
proto.logf("Got EXTERNAL authentication: %s", strings.TrimPrefix(command.args, "EXTERNAL "))
|
||||||
|
if proto.ValidateAuthenticationHandler != nil {
|
||||||
|
if !proto.ValidateAuthenticationHandler("EXTERNAL", command.args) {
|
||||||
|
// TODO error reply
|
||||||
|
}
|
||||||
|
}
|
||||||
return ReplyAuthOk()
|
return ReplyAuthOk()
|
||||||
default:
|
default:
|
||||||
return ReplyUnsupportedAuth()
|
return ReplyUnsupportedAuth()
|
||||||
|
|
|
@ -28,9 +28,10 @@ func Accept(conn *net.TCPConn, conf *config.Config) {
|
||||||
proto := protocol.NewProtocol()
|
proto := protocol.NewProtocol()
|
||||||
session := &Session{conn, proto, conf, false, ""}
|
session := &Session{conn, proto, conf, false, ""}
|
||||||
proto.LogHandler = session.logf
|
proto.LogHandler = session.logf
|
||||||
proto.MessageReceivedHandler = session.acceptMessageHandler
|
proto.MessageReceivedHandler = session.acceptMessage
|
||||||
proto.ValidateSenderHandler = session.validateSender
|
proto.ValidateSenderHandler = session.validateSender
|
||||||
proto.ValidateRecipientHandler = session.validateRecipient
|
proto.ValidateRecipientHandler = session.validateRecipient
|
||||||
|
proto.ValidateAuthenticationHandler = session.validateAuthentication
|
||||||
|
|
||||||
session.logf("Starting session")
|
session.logf("Starting session")
|
||||||
session.Write(proto.Start(conf.Hostname))
|
session.Write(proto.Start(conf.Hostname))
|
||||||
|
@ -39,6 +40,9 @@ func Accept(conn *net.TCPConn, conf *config.Config) {
|
||||||
session.logf("Session ended")
|
session.logf("Session ended")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Session) validateAuthentication(mechanism string, args ...string) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
func (c *Session) validateRecipient(to string) bool {
|
func (c *Session) validateRecipient(to string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -47,7 +51,7 @@ func (c *Session) validateSender(from string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Session) acceptMessageHandler(msg *data.Message) (id string, err error) {
|
func (c *Session) acceptMessage(msg *data.Message) (id string, err error) {
|
||||||
switch c.conf.Storage.(type) {
|
switch c.conf.Storage.(type) {
|
||||||
case *storage.MongoDB:
|
case *storage.MongoDB:
|
||||||
c.logf("Storing message using MongoDB")
|
c.logf("Storing message using MongoDB")
|
||||||
|
|
Loading…
Reference in a new issue