diff --git a/dovecot/dict.go b/dovecot/dict.go index 4082f6dfa55bf36f809da6f45eb71ab395cb20b5..50835edd28283dac6ee062b25551095e98ddb6d1 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 }