From b7c865932ad37a74d6c628c84ef55929cd11a454 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 13 Jan 2018 11:59:25 +0000
Subject: [PATCH] Handle dovecot dict key lookup prefix properly

---
 dovecot/keyproxy.go | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/dovecot/keyproxy.go b/dovecot/keyproxy.go
index bd896401..f140cea2 100644
--- a/dovecot/keyproxy.go
+++ b/dovecot/keyproxy.go
@@ -80,17 +80,17 @@ func NewKeyLookupProxy(config *Config) (*KeyLookupProxy, error) {
 // Lookup a key using the dovecot dict proxy interface.
 //
 // We can be sent a userdb lookup, or a passdb lookup, and we can tell
-// them apart from the structure of the key:
-//
-// If it contains passwordSep, then it's a passdb lookup and the key
-// consists of 'username' and 'password'. Otherwise, it's a userdb
-// lookup and the key is simply the username.
+// them apart with the key prefix (passdb/ or userdb/).
 func (s *KeyLookupProxy) Lookup(ctx context.Context, key string) (interface{}, bool) {
-	if strings.Contains(key, passwordSep) {
-		kparts := strings.SplitN(key, passwordSep, 2)
+	switch {
+	case strings.HasPrefix(key, "passdb/"):
+		kparts := strings.SplitN(key[7:], passwordSep, 2)
 		return s.lookupPassdb(ctx, kparts[0], kparts[1])
+	case strings.HasPrefix(key, "userdb/"):
+		return s.lookupUserdb(ctx, key[7:])
+	default:
+		return nil, false
 	}
-	return s.lookupUserdb(ctx, key)
 }
 
 func (s *KeyLookupProxy) lookupUserdb(ctx context.Context, username string) (interface{}, bool) {
-- 
GitLab