Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth check for mail, from, data commands #216 #217

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backendutil/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func TestServer_tooLongMessage(t *testing.T) {

func TestServer_anonymousUserOK(t *testing.T) {
be, s, c, scanner, _ := testServerEhlo(t)
s.AuthDisabled = true
defer s.Close()
defer c.Close()

Expand Down
6 changes: 6 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func (c *Conn) handle(cmd string, arg string) {
}

cmd = strings.ToUpper(cmd)
// Auth should be checked for mail, rcpt, data commands.
if (cmd == "MAIL" || cmd == "RCPT" || cmd == "DATA") && !c.server.AuthDisabled && !c.didAuth {
c.writeResponse(502, EnhancedCode{5, 7, 0}, "Please authenticate first")
return
}

switch cmd {
case "SEND", "SOML", "SAML", "EXPN", "HELP", "TURN":
// These commands are not implemented in any state
Expand Down
4 changes: 4 additions & 0 deletions lmtp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func sendLHLO(t *testing.T, scanner *bufio.Scanner, c io.Writer) {
func TestServer_LMTP(t *testing.T) {
be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
s.LMTP = true
s.AuthDisabled = true
be := s.Backend.(*backend)
be.implementLMTPData = true
be.lmtpStatus = []struct {
Expand Down Expand Up @@ -82,6 +83,7 @@ func TestServer_LMTP_Early(t *testing.T) {

be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
s.LMTP = true
s.AuthDisabled = true
be := s.Backend.(*backend)
be.implementLMTPData = true
be.lmtpStatusSync = lmtpStatusSync
Expand Down Expand Up @@ -126,6 +128,7 @@ func TestServer_LMTP_Expand(t *testing.T) {

be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
s.LMTP = true
s.AuthDisabled = true
})
defer s.Close()
defer c.Close()
Expand All @@ -149,6 +152,7 @@ func TestServer_LMTP_Expand(t *testing.T) {
func TestServer_LMTP_DuplicatedRcpt(t *testing.T) {
be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
s.LMTP = true
s.AuthDisabled = true
be := s.Backend.(*backend)
be.implementLMTPData = true
be.lmtpStatus = []struct {
Expand Down
2 changes: 2 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ func TestServer_anonymousUserError(t *testing.T) {

func TestServer_anonymousUserOK(t *testing.T) {
be, s, c, scanner, _ := testServerEhlo(t)
s.AuthDisabled = true
defer s.Close()
defer c.Close()

Expand All @@ -780,6 +781,7 @@ func TestServer_anonymousUserOK(t *testing.T) {

func TestServer_authParam(t *testing.T) {
be, s, c, scanner, _ := testServerEhlo(t)
s.AuthDisabled = true
defer s.Close()
defer c.Close()

Expand Down