change "mox setaccountpassword" to use an account name as parameter, not email address

because with the name you would expect an account name.
and the email-resolving behaviour is surprising: with wildcard addresses you
can use any address, including a typo. you would change the password of the
address with the wildcard, without any warning. accounts are more precise and
less error-prone.

for issue #68 by x8x
This commit is contained in:
Mechiel Lukkien 2023-09-23 17:18:49 +02:00
parent 8c2814df89
commit f1f3135135
No known key found for this signature in database
7 changed files with 19 additions and 15 deletions

6
ctl.go
View file

@ -355,15 +355,15 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
case "setaccountpassword": case "setaccountpassword":
/* protocol: /* protocol:
> "setaccountpassword" > "setaccountpassword"
> address > account
> password > password
< "ok" or error < "ok" or error
*/ */
addr := ctl.xread() account := ctl.xread()
pw := ctl.xread() pw := ctl.xread()
acc, _, err := store.OpenEmail(addr) acc, err := store.OpenAccount(account)
ctl.xcheck(err, "open account") ctl.xcheck(err, "open account")
defer func() { defer func() {
if acc != nil { if acc != nil {

View file

@ -61,7 +61,7 @@ func TestCtl(t *testing.T) {
// "setaccountpassword" // "setaccountpassword"
testctl(func(ctl *ctl) { testctl(func(ctl *ctl) {
ctlcmdSetaccountpassword(ctl, "mjl@mox.example", "test4321") ctlcmdSetaccountpassword(ctl, "mjl", "test4321")
}) })
err := queue.Init() err := queue.Init()

8
doc.go
View file

@ -16,7 +16,7 @@ low-maintenance self-hosted email.
mox serve mox serve
mox quickstart [-existing-webserver] [-hostname host] user@domain [user | uid] mox quickstart [-existing-webserver] [-hostname host] user@domain [user | uid]
mox stop mox stop
mox setaccountpassword address mox setaccountpassword account
mox setadminpassword mox setadminpassword
mox loglevels [level [pkg]] mox loglevels [level [pkg]]
mox queue list mox queue list
@ -156,9 +156,11 @@ password itself, are stored in the account database. The stored secrets are for
authentication with: scram-sha-256, scram-sha-1, cram-md5, plain text (bcrypt authentication with: scram-sha-256, scram-sha-1, cram-md5, plain text (bcrypt
hash). hash).
Any email address configured for the account can be used. The parameter is an account name, as configured under Accounts in domains.conf
and as present in the data/accounts/ directory, not a configured email address
for an account.
usage: mox setaccountpassword address usage: mox setaccountpassword account
# mox setadminpassword # mox setadminpassword

View file

@ -10,7 +10,7 @@ services:
- ./testdata/imaptest/imaptest.mbox:/mox/imaptest.mbox - ./testdata/imaptest/imaptest.mbox:/mox/imaptest.mbox
working_dir: /mox working_dir: /mox
tty: true # For job control with set -m. tty: true # For job control with set -m.
command: sh -c 'set -m; mox serve & sleep 1; echo testtest | mox setaccountpassword mjl@mox.example; fg' command: sh -c 'set -m; mox serve & sleep 1; echo testtest | mox setaccountpassword mjl; fg'
healthcheck: healthcheck:
test: netstat -nlt | grep ':1143 ' test: netstat -nlt | grep ':1143 '
interval: 1s interval: 1s

12
main.go
View file

@ -681,7 +681,7 @@ func ctlcmdConfigAccountAdd(ctl *ctl, account, address string) {
ctl.xwrite(account) ctl.xwrite(account)
ctl.xwrite(address) ctl.xwrite(address)
ctl.xreadok() ctl.xreadok()
fmt.Printf("account added, set a password with \"mox setaccountpassword %s\"\n", address) fmt.Printf("account added, set a password with \"mox setaccountpassword %s\"\n", account)
} }
func cmdConfigAccountRemove(c *cmd) { func cmdConfigAccountRemove(c *cmd) {
@ -1136,7 +1136,7 @@ pick a random, unguessable password, preferably at least 12 characters.
} }
func cmdSetaccountpassword(c *cmd) { func cmdSetaccountpassword(c *cmd) {
c.params = "address" c.params = "account"
c.help = `Set new password an account. c.help = `Set new password an account.
The password is read from stdin. Secrets derived from the password, but not the The password is read from stdin. Secrets derived from the password, but not the
@ -1144,7 +1144,9 @@ password itself, are stored in the account database. The stored secrets are for
authentication with: scram-sha-256, scram-sha-1, cram-md5, plain text (bcrypt authentication with: scram-sha-256, scram-sha-1, cram-md5, plain text (bcrypt
hash). hash).
Any email address configured for the account can be used. The parameter is an account name, as configured under Accounts in domains.conf
and as present in the data/accounts/ directory, not a configured email address
for an account.
` `
args := c.Parse() args := c.Parse()
if len(args) != 1 { if len(args) != 1 {
@ -1157,9 +1159,9 @@ Any email address configured for the account can be used.
ctlcmdSetaccountpassword(xctl(), args[0], pw) ctlcmdSetaccountpassword(xctl(), args[0], pw)
} }
func ctlcmdSetaccountpassword(ctl *ctl, address, password string) { func ctlcmdSetaccountpassword(ctl *ctl, account, password string) {
ctl.xwrite("setaccountpassword") ctl.xwrite("setaccountpassword")
ctl.xwrite(address) ctl.xwrite(account)
ctl.xwrite(password) ctl.xwrite(password)
ctl.xreadok() ctl.xreadok()
} }

View file

@ -33,7 +33,7 @@ CURL_CA_BUNDLE=/integration/tls/ca.pem curl -o /integration/tmp-pebble-ca.pem ht
mox -checkconsistency serve & mox -checkconsistency serve &
while true; do while true; do
if test -e data/ctl; then if test -e data/ctl; then
echo -n accountpass1234 | mox setaccountpassword moxtest1@mox1.example echo -n accountpass1234 | mox setaccountpassword moxtest1
break break
fi fi
sleep 0.1 sleep 0.1

View file

@ -29,7 +29,7 @@ unbound-control -s 172.28.1.30 reload # reload unbound with zone file changes
mox -checkconsistency serve & mox -checkconsistency serve &
while true; do while true; do
if test -e data/ctl; then if test -e data/ctl; then
echo -n accountpass4321 | mox setaccountpassword moxtest2@mox2.example echo -n accountpass4321 | mox setaccountpassword moxtest2
break break
fi fi
sleep 0.1 sleep 0.1