when opening an account by email address, such as during login attempts, and address is an alias, fail with proper error "no such credentials" instead of with error "no such account", which printing a stack trace

was encountered during smtp session. but could also happen for imapserver and
webmail.

in smtpserver, we now log error messages for smtp errors that cause us to print
a stack trace. would have made logging output more helpful (without having to
turn on trace-level logging).

hopefully solves issue #238 by mwyvr, thanks for reporting!
This commit is contained in:
Mechiel Lukkien 2024-11-10 23:13:38 +01:00
parent 0e338b0530
commit 3d4cd00430
No known key found for this signature in database
3 changed files with 12 additions and 1 deletions

View file

@ -63,7 +63,10 @@ func LookupAddress(localpart smtp.Localpart, domain dns.Domain, allowPostmaster,
canonical := smtp.NewAddress(localpart, domain).String() canonical := smtp.NewAddress(localpart, domain).String()
accAddr, alias, ok := Conf.AccountDestination(canonical) accAddr, alias, ok := Conf.AccountDestination(canonical)
if ok && alias != nil && allowAlias { if ok && alias != nil {
if !allowAlias {
return "", nil, "", config.Destination{}, ErrAddressNotFound
}
return "", alias, canonical, config.Destination{}, nil return "", alias, canonical, config.Destination{}, nil
} else if !ok { } else if !ok {
if accAddr, alias, ok = Conf.AccountDestination("@" + domain.Name()); !ok || alias != nil { if accAddr, alias, ok = Conf.AccountDestination("@" + domain.Name()); !ok || alias != nil {

View file

@ -1,6 +1,7 @@
package smtpserver package smtpserver
import ( import (
"errors"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
@ -62,6 +63,12 @@ func TestAliasSubmitMsgFromDenied(t *testing.T) {
ts := newTestServer(t, filepath.FromSlash("../testdata/smtp/mox.conf"), dns.MockResolver{}) ts := newTestServer(t, filepath.FromSlash("../testdata/smtp/mox.conf"), dns.MockResolver{})
defer ts.close() defer ts.close()
// Trying to open account by alias should result in proper error.
_, _, err := store.OpenEmail(pkglog, "public@mox.example")
if err == nil || !errors.Is(err, store.ErrUnknownCredentials) {
t.Fatalf("opening alias, got err %v, expected store.ErrUnknownCredentials", err)
}
acc, err := store.OpenAccount(pkglog, "☺") acc, err := store.OpenAccount(pkglog, "☺")
tcheck(t, err, "open account") tcheck(t, err, "open account")
err = acc.SetPassword(pkglog, password0) err = acc.SetPassword(pkglog, password0)

View file

@ -751,6 +751,7 @@ func command(c *conn) {
if errors.As(err, &serr) { if errors.As(err, &serr) {
c.writecodeline(serr.code, serr.secode, fmt.Sprintf("%s (%s)", serr.errmsg, mox.ReceivedID(c.cid)), serr.err) c.writecodeline(serr.code, serr.secode, fmt.Sprintf("%s (%s)", serr.errmsg, mox.ReceivedID(c.cid)), serr.err)
if serr.printStack { if serr.printStack {
c.log.Errorx("smtp error", serr.err, slog.Int("code", serr.code), slog.String("secode", serr.secode))
debug.PrintStack() debug.PrintStack()
} }
} else { } else {