Add hook for EXTERNAL authentication mechanism

This commit is contained in:
Ian Kent 2014-11-22 19:26:11 +00:00
parent 256849f2c6
commit 2b58b571cb
2 changed files with 16 additions and 6 deletions

View file

@ -27,6 +27,7 @@ type Protocol struct {
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()

View file

@ -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")