Made detection of login mechanisms work correctly
This commit is contained in:
parent
ff35d6f004
commit
9f015b99c1
|
@ -22,10 +22,9 @@ var DatabaseBackend = smtp.DatabaseBackend{
|
||||||
|
|
||||||
// AuthenticationBackend is a smtp.AuthenticationBackend implementation that always returns a fixed address for Authenticate.
|
// AuthenticationBackend is a smtp.AuthenticationBackend implementation that always returns a fixed address for Authenticate.
|
||||||
var AuthenticationBackend = smtp.AuthenticationBackend{
|
var AuthenticationBackend = smtp.AuthenticationBackend{
|
||||||
Authenticate: func(initial string, conn *textproto.Conn) (*smtp.Address, error) {
|
Authenticate: func(initial string, conn *textproto.Conn) (smtp.CheckAddress, error) {
|
||||||
return &smtp.Address{
|
return func(address *smtp.Address) (bool, error) {
|
||||||
Name: "test",
|
return true, nil
|
||||||
Address: "example.org",
|
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
22
smtp.go
22
smtp.go
|
@ -58,7 +58,8 @@ type DatabaseBackend struct {
|
||||||
|
|
||||||
// AuthenticationBackend is a struct that represents an authentication backend
|
// AuthenticationBackend is a struct that represents an authentication backend
|
||||||
type AuthenticationBackend struct {
|
type AuthenticationBackend struct {
|
||||||
Authenticate func(initial string, conn *textproto.Conn) (CheckAddress, error)
|
Authenticate func(initial string, conn *textproto.Conn) (CheckAddress, error)
|
||||||
|
SupportedMechanisms []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type CheckAddress func(*Address) (bool, error)
|
type CheckAddress func(*Address) (bool, error)
|
||||||
|
@ -211,10 +212,9 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Connection from", conn.RemoteAddr().String())
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
line, err := textProto.ReadLine()
|
line, err := textProto.ReadLine()
|
||||||
|
fmt.Println(line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = textProto.PrintfLine("421 4.7.0 Temporary server error")
|
_ = textProto.PrintfLine("421 4.7.0 Temporary server error")
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
|
@ -283,6 +283,9 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
||||||
if fr.enforceTLS {
|
if fr.enforceTLS {
|
||||||
capabilities = append(capabilities, "250-REQUIRETLS")
|
capabilities = append(capabilities, "250-REQUIRETLS")
|
||||||
}
|
}
|
||||||
|
if fr.auth.SupportedMechanisms != nil {
|
||||||
|
capabilities = append(capabilities, "250-AUTH "+strings.Join(fr.auth.SupportedMechanisms, " "))
|
||||||
|
}
|
||||||
capabilities = append(capabilities, defaultCapabilities...)
|
capabilities = append(capabilities, defaultCapabilities...)
|
||||||
state.HELO = true
|
state.HELO = true
|
||||||
err = speakMultiLine(textProto, capabilities)
|
err = speakMultiLine(textProto, capabilities)
|
||||||
|
@ -293,6 +296,8 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case strings.HasPrefix(line, "AUTH"):
|
case strings.HasPrefix(line, "AUTH"):
|
||||||
|
fmt.Println("It's about time")
|
||||||
|
|
||||||
if !isSubmission {
|
if !isSubmission {
|
||||||
err = textProto.PrintfLine("503 5.5.1 AUTH only allowed on submission port")
|
err = textProto.PrintfLine("503 5.5.1 AUTH only allowed on submission port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -714,10 +719,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
code, line, err = textConn.ReadCodeLine(0)
|
code, line, err = textConn.ReadCodeLine(0)
|
||||||
fmt.Println(code, line, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// For some reason the EHLO stuff ends up here
|
|
||||||
fmt.Println("5")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,9 +734,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
code, line, err = textConn.ReadCodeLine(0)
|
code, line, err = textConn.ReadCodeLine(0)
|
||||||
fmt.Println(code, line, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("6")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,9 +749,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
code, line, err = textConn.ReadCodeLine(0)
|
code, line, err = textConn.ReadCodeLine(0)
|
||||||
fmt.Println(code, line, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("7")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -771,9 +769,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
code, line, err = textConn.ReadCodeLine(0)
|
code, line, err = textConn.ReadCodeLine(0)
|
||||||
fmt.Println(code, line, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("8")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -787,9 +783,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
code, line, err = textConn.ReadCodeLine(0)
|
code, line, err = textConn.ReadCodeLine(0)
|
||||||
fmt.Println(code, line, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("9")
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue