From 28be0f906dd20b3a2d468464885595bd0b59fdcb Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Tue, 29 Aug 2023 10:33:47 +0100 Subject: [PATCH] Implement check for compatible client protocol version Fixes issue #5. --- dovecot/dict.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dovecot/dict.go b/dovecot/dict.go index 4082f6df..50835edd 100644 --- a/dovecot/dict.go +++ b/dovecot/dict.go @@ -5,7 +5,9 @@ import ( "context" "encoding/json" "errors" + "fmt" "log" + "strconv" "git.autistici.org/ai3/go-common/unix" ) @@ -15,6 +17,8 @@ var ( noMatchResponse = []byte{'N', '\n'} ) +const supportedDictProtocolVersion = 2 + // DictDatabase is an interface to a key/value store by way of the Lookup // method. type DictDatabase interface { @@ -55,7 +59,16 @@ func (p *DictProxyServer) ServeLine(ctx context.Context, lw unix.LineResponseWri } func (p *DictProxyServer) handleHello(ctx context.Context, lw unix.LineResponseWriter, arg []byte) error { - // TODO: parse the hello line and extract useful information. + fields := bytes.Split(arg, []byte{'\t'}) + if len(fields) < 1 { + return errors.New("could not parse HELLO") + } + + majorVersion, _ := strconv.Atoi(string(fields[0])) + if majorVersion != supportedDictProtocolVersion { + return fmt.Errorf("unsupported protocol version %d", majorVersion) + } + return nil } -- GitLab