add config options to disable a domain and to disable logins for an account

to facilitate migrations from/to other mail setups.

a domain can be added in "disabled" mode (or can be disabled/enabled later on).
you can configure a disabled domain, but incoming/outgoing messages involving
the domain are rejected with temporary error codes (as this may occur during a
migration, remote servers will try again, hopefully to the correct machine or
after this machine has been configured correctly). also, no acme tls certs will
be requested for disabled domains (the autoconfig/mta-sts dns records may still
point to the current/previous machine). accounts with addresses at disabled
domains can still login, unless logins are disabled for their accounts.

an account now has an option to disable logins. you can specify an error
message to show. this will be shown in smtp, imap and the web interfaces. it
could contain a message about migrations, and possibly a URL to a page with
information about how to migrate. incoming/outgoing email involving accounts
with login disabled are still accepted/delivered as normal (unless the domain
involved in the messages is disabled too). account operations by the admin,
such as importing/exporting messages still works.

in the admin web interface, listings of domains/accounts show if they are disabled.
domains & accounts can be enabled/disabled through the config file, cli
commands and admin web interface.

for issue #175 by RobSlgm
This commit is contained in:
Mechiel Lukkien
2025-01-25 20:39:20 +01:00
parent 132efdd9fb
commit 2d3d726f05
67 changed files with 1078 additions and 231 deletions

93
ctl.go
View File

@ -328,7 +328,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
*/
to := ctl.xread()
a, addr, err := store.OpenEmail(log, to)
a, addr, err := store.OpenEmail(log, to, false)
ctl.xcheck(err, "lookup destination address")
msgFile, err := store.CreateMessageTemp(log, "ctl-deliver")
@ -367,7 +367,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
account := ctl.xread()
pw := ctl.xread()
acc, err := store.OpenAccount(log, account)
acc, err := store.OpenAccount(log, account, false)
ctl.xcheck(err, "open account")
defer func() {
if acc != nil {
@ -965,17 +965,28 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
case "domainadd":
/* protocol:
> "domainadd"
> disabled as "true" or "false"
> domain
> account
> localpart
< "ok" or error
*/
var disabled bool
switch s := ctl.xread(); s {
case "true":
disabled = true
case "false":
disabled = false
default:
ctl.xcheck(fmt.Errorf("invalid value %q", s), "parsing disabled boolean")
}
domain := ctl.xread()
account := ctl.xread()
localpart := ctl.xread()
d, err := dns.ParseDomain(domain)
ctl.xcheck(err, "parsing domain")
err = admin.DomainAdd(ctx, d, account, smtp.Localpart(localpart))
err = admin.DomainAdd(ctx, disabled, d, account, smtp.Localpart(localpart))
ctl.xcheck(err, "adding domain")
ctl.xwriteok()
@ -992,6 +1003,30 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
ctl.xcheck(err, "removing domain")
ctl.xwriteok()
case "domaindisabled":
/* protocol:
> "domaindisabled"
> "true" or "false"
> domain
< "ok" or error
*/
domain := ctl.xread()
var disabled bool
switch s := ctl.xread(); s {
case "true":
disabled = true
case "false":
disabled = false
default:
ctl.xerror("bad boolean value")
}
err := admin.DomainSave(ctx, domain, func(d *config.Domain) error {
d.Disabled = disabled
return nil
})
ctl.xcheck(err, "saving domain")
ctl.xwriteok()
case "accountadd":
/* protocol:
> "accountadd"
@ -1016,6 +1051,46 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
ctl.xcheck(err, "removing account")
ctl.xwriteok()
case "accountdisabled":
/* protocol:
> "accountdisabled"
> account
> message (if empty, then enabled)
< "ok" or error
*/
account := ctl.xread()
message := ctl.xread()
acc, err := store.OpenAccount(log, account, false)
ctl.xcheck(err, "open account")
defer func() {
err := acc.Close()
log.Check(err, "closing account")
}()
err = admin.AccountSave(ctx, account, func(acc *config.Account) {
acc.LoginDisabled = message
})
ctl.xcheck(err, "saving account")
err = acc.SessionsClear(ctx, ctl.log)
ctl.xcheck(err, "clearing active web sessions")
ctl.xwriteok()
case "accountenable":
/* protocol:
> "accountenable"
> account
< "ok" or error
*/
account := ctl.xread()
err := admin.AccountSave(ctx, account, func(acc *config.Account) {
acc.LoginDisabled = ""
})
ctl.xcheck(err, "enabling account")
ctl.xwriteok()
case "tlspubkeylist":
/* protocol:
> "tlspubkeylist"
@ -1079,7 +1154,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
if name != "" {
tlspubkey.Name = name
}
acc, _, err := store.OpenEmail(ctl.log, loginAddress)
acc, _, err := store.OpenEmail(ctl.log, loginAddress, false)
ctl.xcheck(err, "open account for address")
defer func() {
err := acc.Close()
@ -1341,7 +1416,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
account := ctl.xread()
xretrain := func(name string) {
acc, err := store.OpenAccount(log, name)
acc, err := store.OpenAccount(log, name, false)
ctl.xcheck(err, "open account")
defer func() {
if acc != nil {
@ -1417,7 +1492,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
< stream
*/
account := ctl.xread()
acc, err := store.OpenAccount(log, account)
acc, err := store.OpenAccount(log, account, false)
ctl.xcheck(err, "open account")
defer func() {
if acc != nil {
@ -1492,7 +1567,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
const batchSize = 10000
xfixmsgsize := func(accName string) {
acc, err := store.OpenAccount(log, accName)
acc, err := store.OpenAccount(log, accName, false)
ctl.xcheck(err, "open account")
defer func() {
err := acc.Close()
@ -1627,7 +1702,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
const batchSize = 100
xreparseAccount := func(accName string) {
acc, err := store.OpenAccount(log, accName)
acc, err := store.OpenAccount(log, accName, false)
ctl.xcheck(err, "open account")
defer func() {
err := acc.Close()
@ -1703,7 +1778,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
w := ctl.writer()
xreassignThreads := func(accName string) {
acc, err := store.OpenAccount(log, accName)
acc, err := store.OpenAccount(log, accName, false)
ctl.xcheck(err, "open account")
defer func() {
err := acc.Close()