Skip to content

Commit 1f30586

Browse files
committed
Drop Server.AuthDisabled
This is the default for servers not implementing AuthSession now.
1 parent 968926f commit 1f30586

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

conn.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ func (c *Conn) handle(cmd string, arg string) {
141141
c.writeResponse(221, EnhancedCode{2, 0, 0}, "Bye")
142142
c.Close()
143143
case "AUTH":
144-
if c.server.AuthDisabled {
145-
c.protocolError(500, EnhancedCode{5, 5, 2}, "Syntax error, AUTH command unrecognized")
146-
} else {
147-
c.handleAuth(arg)
148-
}
144+
c.handleAuth(arg)
149145
case "STARTTLS":
150146
c.handleStartTLS()
151147
default:
@@ -207,7 +203,7 @@ func (c *Conn) Conn() net.Conn {
207203

208204
func (c *Conn) authAllowed() bool {
209205
_, isTLS := c.TLSConnectionState()
210-
return !c.server.AuthDisabled && (isTLS || c.server.AllowInsecureAuth)
206+
return isTLS || c.server.AllowInsecureAuth
211207
}
212208

213209
// protocolError writes errors responses and closes the connection once too many

server.go

-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ type Server struct {
5959
// Should be used only if backend supports it.
6060
EnableDSN bool
6161

62-
// If set, the AUTH command will not be advertised and authentication
63-
// attempts will be rejected. This setting overrides AllowInsecureAuth.
64-
AuthDisabled bool
65-
6662
// The server backend.
6763
Backend Backend
6864

server_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type message struct {
2525
}
2626

2727
type backend struct {
28+
authDisabled bool
29+
2830
messages []*message
2931
anonmsgs []*message
3032

@@ -70,10 +72,16 @@ type session struct {
7072
var _ smtp.AuthSession = (*session)(nil)
7173

7274
func (s *session) AuthMechanisms() []string {
75+
if s.backend.authDisabled {
76+
return nil
77+
}
7378
return []string{sasl.Plain}
7479
}
7580

7681
func (s *session) Auth(mech string) (sasl.Server, error) {
82+
if s.backend.authDisabled {
83+
return nil, smtp.ErrAuthUnsupported
84+
}
7785
return sasl.NewPlainServer(func(identity, username, password string) error {
7886
if identity != "" && identity != username {
7987
return errors.New("Invalid identity")
@@ -217,7 +225,7 @@ type serverConfigureFunc func(*smtp.Server)
217225

218226
var (
219227
authDisabled = func(s *smtp.Server) {
220-
s.AuthDisabled = true
228+
s.Backend.(*backend).authDisabled = true
221229
}
222230
)
223231

@@ -698,7 +706,7 @@ func TestServer_authDisabled(t *testing.T) {
698706

699707
io.WriteString(c, "AUTH PLAIN\r\n")
700708
scanner.Scan()
701-
if scanner.Text() != "500 5.5.2 Syntax error, AUTH command unrecognized" {
709+
if scanner.Text() != "502 5.7.0 Authentication not supported" {
702710
t.Fatal("Invalid AUTH response with auth disabled:", scanner.Text())
703711
}
704712
}

0 commit comments

Comments
 (0)