Fully separate authentication from IMAP access

Now imapsql module does not handle authentication. (it was not doing it so well
anyway)

sql_table module was introduced and used in the default configuration as
a replacement for functionality that was implemented by imapsql before.

Parts of maddyctl code were rewritten to make it work transparently with
any IMAP backend or credentials store.

Closes #212.
This commit is contained in:
fox.cpp 2020-04-13 23:01:17 +03:00
parent 609a8fd235
commit e19d21dfcb
No known key found for this signature in database
GPG key ID: E76D97CCEDE90B6C
29 changed files with 867 additions and 473 deletions

View file

@ -420,28 +420,7 @@ func prepareUsername(username string) (string, error) {
return mbox + "@" + domain, nil
}
func (store *Storage) AuthPlain(username, password string) error {
// TODO: Pass session context there.
defer trace.StartRegion(context.Background(), "imapsql/AuthPlain").End()
accountName, err := prepareUsername(username)
if err != nil {
return err
}
password, err = precis.OpaqueString.CompareKey(password)
if err != nil {
return err
}
// TODO(GH foxcpp/go-imap-sql#30): Make go-imap-sql CheckPlain return an actual error.
if !store.Back.CheckPlain(accountName, password) {
return module.ErrUnknownCredentials
}
return nil
}
func (store *Storage) GetOrCreateUser(username string) (backend.User, error) {
func (store *Storage) GetOrCreateIMAPAcct(username string) (backend.User, error) {
accountName, err := prepareUsername(username)
if err != nil {
return nil, backend.ErrInvalidCredentials