1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

config: Support "" values for drop_characters and suffix_separators

If the `drop_characters` or `suffix_separators` options are set to "",
currently instead of the empty string, their default value is used instead.

This is a bug, and it also happens on other config options, but because
the others have to be set in order for chasquid to function, it's not a
problem in practice.

Thanks Björn Busse (bbusse@github) for finding and reporting this
problem, on irc and in https://github.com/albertito/chasquid/issues/25.

This patch fixes the problem by marking these fields explicitly
optional, which enables presence testing, as described in the protobuf
documentation:
https://github.com/protocolbuffers/protobuf/blob/master/docs/field_presence.md.
This commit is contained in:
Alberto Bertogli
2022-01-14 01:13:31 +00:00
parent 4f595ce3d2
commit fa1db7d81a
6 changed files with 64 additions and 46 deletions

View File

@@ -2,7 +2,7 @@
package config
// Generate the config protobuf.
//go:generate protoc --go_out=. --go_opt=paths=source_relative config.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --experimental_allow_proto3_optional config.proto
import (
"fmt"
@@ -27,8 +27,8 @@ var defaultConfig = &Config{
DataDir: "/var/lib/chasquid",
SuffixSeparators: "+",
DropCharacters: ".",
SuffixSeparators: proto.String("+"),
DropCharacters: proto.String("."),
MailLogPath: "<syslog>",
}
@@ -104,10 +104,10 @@ func override(c, o *Config) {
c.DataDir = o.DataDir
}
if o.SuffixSeparators != "" {
if o.SuffixSeparators != nil {
c.SuffixSeparators = o.SuffixSeparators
}
if o.DropCharacters != "" {
if o.DropCharacters != nil {
c.DropCharacters = o.DropCharacters
}
if o.MailLogPath != "" {
@@ -140,8 +140,16 @@ func LogConfig(c *Config) {
log.Infof(" Monitoring address: %s", c.MonitoringAddress)
log.Infof(" MDA: %s %v", c.MailDeliveryAgentBin, c.MailDeliveryAgentArgs)
log.Infof(" Data directory: %s", c.DataDir)
log.Infof(" Suffix separators: %s", c.SuffixSeparators)
log.Infof(" Drop characters: %s", c.DropCharacters)
if c.SuffixSeparators == nil {
log.Infof(" Suffix separators: nil")
} else {
log.Infof(" Suffix separators: %s", *c.SuffixSeparators)
}
if c.DropCharacters == nil {
log.Infof(" Drop characters: nil")
} else {
log.Infof(" Drop characters: %s", *c.DropCharacters)
}
log.Infof(" Mail log: %s", c.MailLogPath)
log.Infof(" Dovecot auth: %v (%q, %q)",
c.DovecotAuth, c.DovecotUserdbPath, c.DovecotClientPath)