git » chasquid » commit 0ae5798

dovecot: Support dovecot-side username changes

author Alberto Bertogli
2018-03-02 18:52:25 UTC
committer Alberto Bertogli
2018-03-02 19:08:00 UTC
parent d39d3aaff4df7655b9a1434b3f1d8ce83121903f

dovecot: Support dovecot-side username changes

Dovecot has options for changing the formatting of usernames; for
example, dropping the domain part, or replacing characters.

chasquid's implementation, however, fails to handle this well, as it
expects the reply to contain the username exactly as requested.

This patch fixes the problem by making chasquid ignoring the returned
username, which is unused anyway. The protocol is unambiguous enough.

Tests are also amended to always exercise this case.

internal/dovecot/dovecot.go +1 -1
test/t-11-dovecot/config/dovecot.conf.in +4 -0
test/t-11-dovecot/config/passwd +1 -1

diff --git a/internal/dovecot/dovecot.go b/internal/dovecot/dovecot.go
index 9a7f26e..855cfee 100644
--- a/internal/dovecot/dovecot.go
+++ b/internal/dovecot/dovecot.go
@@ -118,7 +118,7 @@ func (a *Auth) Exists(user string) (bool, error) {
 	resp, err := conn.ReadLine()
 	if err != nil {
 		return false, fmt.Errorf("error receiving response: %v", err)
-	} else if strings.HasPrefix(resp, "USER\t1\t"+user+"\t") {
+	} else if strings.HasPrefix(resp, "USER\t1\t") {
 		return true, nil
 	} else if strings.HasPrefix(resp, "NOTFOUND\t") {
 		return false, nil
diff --git a/test/t-11-dovecot/config/dovecot.conf.in b/test/t-11-dovecot/config/dovecot.conf.in
index d770287..3f59a86 100644
--- a/test/t-11-dovecot/config/dovecot.conf.in
+++ b/test/t-11-dovecot/config/dovecot.conf.in
@@ -5,6 +5,10 @@ ssl = no
 default_internal_user = $USER
 default_login_user = $USER
 
+# Before auth checks, rename "u@d" to "u-AT-d". This exercises that chasquid
+# handles well the case where the returned user information does not match the
+# requested user.
+auth_username_format = "%n-AT-%d"
 
 passdb {
 	driver = passwd-file
diff --git a/test/t-11-dovecot/config/passwd b/test/t-11-dovecot/config/passwd
index 0182c1a..2ceb0ee 100644
--- a/test/t-11-dovecot/config/passwd
+++ b/test/t-11-dovecot/config/passwd
@@ -1 +1 @@
-user@srv:{plain}password:1000:1000::/home/user
+user-AT-srv:{plain}password:1000:1000::/home/user