diff --git a/config.go b/config.go index 483689c..fb37552 100644 --- a/config.go +++ b/config.go @@ -24,10 +24,10 @@ type logOut struct { func logOutput(m *config.Map, node config.Node) (interface{}, error) { if len(node.Args) == 0 { - return nil, m.MatchErr("expected at least 1 argument") + return nil, config.NodeErr(node, "expected at least 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, config.NodeErr(node, "can't declare block here") } return LogOutputOption(node.Args) diff --git a/internal/auth/sasl.go b/internal/auth/sasl.go index 0b8600d..4377fd2 100644 --- a/internal/auth/sasl.go +++ b/internal/auth/sasl.go @@ -104,7 +104,7 @@ func (s *SASLAuth) AddProvider(m *config.Map, node config.Node) error { } if !hasAny { - return m.MatchErr("auth: specified module does not provide any SASL mechanism") + return config.NodeErr(node, "auth: specified module does not provide any SASL mechanism") } return nil } diff --git a/internal/check/action.go b/internal/check/action.go index 8918509..36775ef 100644 --- a/internal/check/action.go +++ b/internal/check/action.go @@ -40,12 +40,12 @@ type FailAction struct { func FailActionDirective(m *config.Map, node config.Node) (interface{}, error) { if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, config.NodeErr(node, "can't declare block here") } val, err := ParseActionDirective(node.Args) if err != nil { - return nil, m.MatchErr("%v", err) + return nil, config.NodeErr(node, "%v", err) } return val, nil } diff --git a/internal/config/map.go b/internal/config/map.go index d6c6db0..1a56a69 100644 --- a/internal/config/map.go +++ b/internal/config/map.go @@ -2,14 +2,11 @@ package config import ( "errors" - "fmt" "reflect" "strconv" "strings" "time" "unicode" - - parser "github.com/foxcpp/maddy/pkg/cfgparser" ) type matcher struct { @@ -38,10 +35,6 @@ func (m *matcher) assign(val interface{}) { type Map struct { allowUnknown bool - // Set to currently processed node when defaultVal or mapper functions are - // called. - curNode *Node - // All values saved by Map during processing. Values map[string]interface{} @@ -57,17 +50,6 @@ func NewMap(globals map[string]interface{}, block Node) *Map { return &Map{Globals: globals, Block: block} } -// MatchErr returns error with formatted message, if called from defaultVal or -// mapper functions - message will be prepended with information about -// processed config node. -func (m *Map) MatchErr(format string, args ...interface{}) error { - if m.curNode != nil { - return parser.NodeErr(*m.curNode, format, args...) - } else { - return fmt.Errorf(format, args...) - } -} - // AllowUnknown makes config.Map skip unknown configuration directives instead // of failing. func (m *Map) AllowUnknown() { @@ -85,10 +67,10 @@ func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed []stri return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare a block here") + return nil, NodeErr(node, "can't declare a block here") } if len(node.Args) == 0 { - return nil, m.MatchErr("expected at least one argument") + return nil, NodeErr(node, "expected at least one argument") } for _, arg := range node.Args { @@ -99,7 +81,7 @@ func (m *Map) EnumList(name string, inheritGlobal, required bool, allowed []stri } } if !isAllowed { - return nil, m.MatchErr("invalid argument, valid values are: %v", allowed) + return nil, NodeErr(node, "invalid argument, valid values are: %v", allowed) } } @@ -118,10 +100,10 @@ func (m *Map) Enum(name string, inheritGlobal, required bool, allowed []string, return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare a block here") + return nil, NodeErr(node, "can't declare a block here") } if len(node.Args) != 1 { - return nil, m.MatchErr("expected exactly one argument") + return nil, NodeErr(node, "expected exactly one argument") } for _, str := range allowed { @@ -130,7 +112,7 @@ func (m *Map) Enum(name string, inheritGlobal, required bool, allowed []string, } } - return nil, m.MatchErr("invalid argument, valid values are: %v", allowed) + return nil, NodeErr(node, "invalid argument, valid values are: %v", allowed) }, store) } @@ -150,20 +132,20 @@ func (m *Map) Duration(name string, inheritGlobal, required bool, defaultVal tim return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } if len(node.Args) == 0 { - return nil, m.MatchErr("at least one argument is required") + return nil, NodeErr(node, "at least one argument is required") } durationStr := strings.Join(node.Args, "") dur, err := time.ParseDuration(durationStr) if err != nil { - return nil, m.MatchErr("%v", err) + return nil, NodeErr(node, "%v", err) } if dur < 0 { - return nil, m.MatchErr("duration must not be negative") + return nil, NodeErr(node, "duration must not be negative") } return dur, nil @@ -236,16 +218,16 @@ func (m *Map) DataSize(name string, inheritGlobal, required bool, defaultVal int return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } if len(node.Args) == 0 { - return nil, m.MatchErr("at least one argument is required") + return nil, NodeErr(node, "at least one argument is required") } durationStr := strings.Join(node.Args, " ") dur, err := ParseDataSize(durationStr) if err != nil { - return nil, m.MatchErr("%v", err) + return nil, NodeErr(node, "%v", err) } return dur, nil @@ -264,14 +246,14 @@ func (m *Map) Bool(name string, inheritGlobal, defaultVal bool, store *bool) { return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } if len(node.Args) == 0 { return true, nil } if len(node.Args) != 1 { - return nil, m.MatchErr("expected exactly 1 argument") + return nil, NodeErr(node, "expected exactly 1 argument") } switch strings.ToLower(node.Args[0]) { @@ -280,7 +262,7 @@ func (m *Map) Bool(name string, inheritGlobal, defaultVal bool, store *bool) { case "0", "false", "off", "no": return false, nil } - return nil, m.MatchErr("bool argument should be 'yes' or 'no'") + return nil, NodeErr(node, "bool argument should be 'yes' or 'no'") }, store) } @@ -297,10 +279,10 @@ func (m *Map) StringList(name string, inheritGlobal, required bool, defaultVal [ return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) == 0 { - return nil, m.MatchErr("expected at least one argument") + return nil, NodeErr(node, "expected at least one argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } return node.Args, nil @@ -319,10 +301,10 @@ func (m *Map) String(name string, inheritGlobal, required bool, defaultVal strin return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } return node.Args[0], nil @@ -341,15 +323,15 @@ func (m *Map) Int(name string, inheritGlobal, required bool, defaultVal int, sto return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } i, err := strconv.Atoi(node.Args[0]) if err != nil { - return nil, m.MatchErr("invalid integer: %s", node.Args[0]) + return nil, NodeErr(node, "invalid integer: %s", node.Args[0]) } return i, nil }, store) @@ -367,15 +349,15 @@ func (m *Map) UInt(name string, inheritGlobal, required bool, defaultVal uint, s return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } i, err := strconv.ParseUint(node.Args[0], 10, 32) if err != nil { - return nil, m.MatchErr("invalid integer: %s", node.Args[0]) + return nil, NodeErr(node, "invalid integer: %s", node.Args[0]) } return uint(i), nil }, store) @@ -393,15 +375,15 @@ func (m *Map) Int32(name string, inheritGlobal, required bool, defaultVal int32, return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } i, err := strconv.ParseInt(node.Args[0], 10, 32) if err != nil { - return nil, m.MatchErr("invalid integer: %s", node.Args[0]) + return nil, NodeErr(node, "invalid integer: %s", node.Args[0]) } return int32(i), nil }, store) @@ -419,15 +401,15 @@ func (m *Map) UInt32(name string, inheritGlobal, required bool, defaultVal uint3 return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } i, err := strconv.ParseUint(node.Args[0], 10, 32) if err != nil { - return nil, m.MatchErr("invalid integer: %s", node.Args[0]) + return nil, NodeErr(node, "invalid integer: %s", node.Args[0]) } return uint32(i), nil }, store) @@ -445,15 +427,15 @@ func (m *Map) Int64(name string, inheritGlobal, required bool, defaultVal int64, return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } i, err := strconv.ParseInt(node.Args[0], 10, 64) if err != nil { - return nil, m.MatchErr("invalid integer: %s", node.Args[0]) + return nil, NodeErr(node, "invalid integer: %s", node.Args[0]) } return i, nil }, store) @@ -471,15 +453,15 @@ func (m *Map) UInt64(name string, inheritGlobal, required bool, defaultVal uint6 return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare block here") + return nil, NodeErr(node, "can't declare block here") } i, err := strconv.ParseUint(node.Args[0], 10, 64) if err != nil { - return nil, m.MatchErr("invalid integer: %s", node.Args[0]) + return nil, NodeErr(node, "invalid integer: %s", node.Args[0]) } return i, nil }, store) @@ -497,12 +479,12 @@ func (m *Map) Float(name string, inheritGlobal, required bool, defaultVal float6 return defaultVal, nil }, func(m *Map, node Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 1 argument") + return nil, NodeErr(node, "expected 1 argument") } f, err := strconv.ParseFloat(node.Args[0], 64) if err != nil { - return nil, m.MatchErr("invalid float: %s", node.Args[0]) + return nil, NodeErr(node, "invalid float: %s", node.Args[0]) } return f, nil }, store) @@ -594,12 +576,10 @@ func (m *Map) ProcessWith(globalCfg map[string]interface{}, block Node) (unknown m.Values = make(map[string]interface{}) for _, subnode := range block.Children { - m.curNode = &subnode - matcher, ok := m.entries[subnode.Name] if !ok { if !m.allowUnknown { - return nil, m.MatchErr("unexpected directive: %s", subnode.Name) + return nil, NodeErr(subnode, "unexpected directive: %s", subnode.Name) } unknown = append(unknown, subnode) continue @@ -614,7 +594,7 @@ func (m *Map) ProcessWith(globalCfg map[string]interface{}, block Node) (unknown } if matched[subnode.Name] { - return nil, m.MatchErr("duplicate directive: %s", subnode.Name) + return nil, NodeErr(subnode, "duplicate directive: %s", subnode.Name) } matched[subnode.Name] = true @@ -627,7 +607,6 @@ func (m *Map) ProcessWith(globalCfg map[string]interface{}, block Node) (unknown matcher.assign(val) } } - m.curNode = &block for _, matcher := range m.entries { if matched[matcher.name] { @@ -651,7 +630,7 @@ func (m *Map) ProcessWith(globalCfg map[string]interface{}, block Node) (unknown return nil, err } } else { - return nil, m.MatchErr("missing required directive: %s", matcher.name) + return nil, NodeErr(block, "missing required directive: %s", matcher.name) } // If we put zero values into map then code that checks globalCfg diff --git a/internal/config/tls_general.go b/internal/config/tls_general.go index bb7f881..ec129c5 100644 --- a/internal/config/tls_general.go +++ b/internal/config/tls_general.go @@ -56,21 +56,21 @@ func TLSVersionsDirective(m *Map, node Node) (interface{}, error) { case 1: value, ok := strVersionsMap[node.Args[0]] if !ok { - return nil, m.MatchErr("invalid TLS version value: %s", node.Args[0]) + return nil, NodeErr(node, "invalid TLS version value: %s", node.Args[0]) } return [2]uint16{value, value}, nil case 2: minValue, ok := strVersionsMap[node.Args[0]] if !ok { - return nil, m.MatchErr("invalid TLS version value: %s", node.Args[0]) + return nil, NodeErr(node, "invalid TLS version value: %s", node.Args[0]) } maxValue, ok := strVersionsMap[node.Args[1]] if !ok { - return nil, m.MatchErr("invalid TLS version value: %s", node.Args[1]) + return nil, NodeErr(node, "invalid TLS version value: %s", node.Args[1]) } return [2]uint16{minValue, maxValue}, nil default: - return nil, m.MatchErr("expected 1 or 2 arguments") + return nil, NodeErr(node, "expected 1 or 2 arguments") } } @@ -80,14 +80,14 @@ func TLSVersionsDirective(m *Map, node Node) (interface{}, error) { // It returns list of []uint16 with corresponding cipher IDs. func TLSCiphersDirective(m *Map, node Node) (interface{}, error) { if len(node.Args) == 0 { - return nil, m.MatchErr("expected at least 1 argument, got 0") + return nil, NodeErr(node, "expected at least 1 argument, got 0") } res := make([]uint16, 0, len(node.Args)) for _, arg := range node.Args { cipherId, ok := strCiphersMap[arg] if !ok { - return nil, m.MatchErr("unknown cipher: %s", arg) + return nil, NodeErr(node, "unknown cipher: %s", arg) } res = append(res, cipherId) } @@ -101,14 +101,14 @@ func TLSCiphersDirective(m *Map, node Node) (interface{}, error) { // It returns []tls.CurveID. func TLSCurvesDirective(m *Map, node Node) (interface{}, error) { if len(node.Args) == 0 { - return nil, m.MatchErr("expected at least 1 argument, got 0") + return nil, NodeErr(node, "expected at least 1 argument, got 0") } res := make([]tls.CurveID, 0, len(node.Args)) for _, arg := range node.Args { curveId, ok := strCurvesMap[arg] if !ok { - return nil, m.MatchErr("unknown curve: %s", arg) + return nil, NodeErr(node, "unknown curve: %s", arg) } res = append(res, curveId) } diff --git a/internal/config/tls_server.go b/internal/config/tls_server.go index 938723d..bdd2730 100644 --- a/internal/config/tls_server.go +++ b/internal/config/tls_server.go @@ -60,7 +60,7 @@ func (cfg *TLSConfig) read(m *Map, node Node, generateSelfSig bool) error { return nil default: log.Println(node.Name, node.Args) - return m.MatchErr("unexpected argument (%s), want 'off' or 'self_signed'", node.Args[0]) + return NodeErr(node, "unexpected argument (%s), want 'off' or 'self_signed'", node.Args[0]) } case 2: tlsCfg, err := readTLSBlock(m, node) @@ -70,7 +70,7 @@ func (cfg *TLSConfig) read(m *Map, node Node, generateSelfSig bool) error { cfg.cfg = tlsCfg return nil default: - return m.MatchErr("expected 1 or 2 arguments") + return NodeErr(node, "expected 1 or 2 arguments") } } @@ -124,7 +124,7 @@ func readTLSBlock(m *Map, blockNode Node) (*tls.Config, error) { var tlsVersions [2]uint16 if len(blockNode.Args) != 2 { - return nil, m.MatchErr("two arguments required") + return nil, NodeErr(blockNode, "two arguments required") } certPath := blockNode.Args[0] keyPath := blockNode.Args[1] diff --git a/internal/endpoint/smtp/smtp.go b/internal/endpoint/smtp/smtp.go index 300a393..ad87486 100644 --- a/internal/endpoint/smtp/smtp.go +++ b/internal/endpoint/smtp/smtp.go @@ -149,12 +149,12 @@ func autoBufferMode(maxSize int, dir string) func(io.Reader) (buffer.Buffer, err func bufferModeDirective(m *config.Map, node config.Node) (interface{}, error) { if len(node.Args) < 1 { - return nil, m.MatchErr("at least one argument required") + return nil, config.NodeErr(node, "at least one argument required") } switch node.Args[0] { case "ram": if len(node.Args) > 1 { - return nil, m.MatchErr("no additional arguments for 'ram' mode") + return nil, config.NodeErr(node, "no additional arguments for 'ram' mode") } return buffer.BufferInMemory, nil case "fs": @@ -168,7 +168,7 @@ func bufferModeDirective(m *config.Map, node config.Node) (interface{}, error) { return buffer.BufferInFile(r, path) }, nil default: - return nil, m.MatchErr("too many arguments for 'fs' mode") + return nil, config.NodeErr(node, "too many arguments for 'fs' mode") } case "auto": path := filepath.Join(config.StateDirectory, "buffer") @@ -185,16 +185,16 @@ func bufferModeDirective(m *config.Map, node config.Node) (interface{}, error) { var err error maxSize, err = config.ParseDataSize(node.Args[1]) if err != nil { - return nil, m.MatchErr("%v", err) + return nil, config.NodeErr(node, "%v", err) } fallthrough case 1: return autoBufferMode(maxSize, path), nil default: - return nil, m.MatchErr("too many arguments for 'auto' mode") + return nil, config.NodeErr(node, "too many arguments for 'auto' mode") } default: - return nil, m.MatchErr("unknown buffer mode: %v", node.Args[0]) + return nil, config.NodeErr(node, "unknown buffer mode: %v", node.Args[0]) } } diff --git a/internal/limits/limits.go b/internal/limits/limits.go index 648d027..03ca5f2 100644 --- a/internal/limits/limits.go +++ b/internal/limits/limits.go @@ -53,9 +53,9 @@ func (g *Group) Init(cfg *config.Map) error { ) switch kind := child.Args[0]; kind { case "rate": - ctor, err = rateCtor(cfg, child.Args[1:]) + ctor, err = rateCtor(child, child.Args[1:]) case "concurrency": - ctor, err = concurrencyCtor(cfg, child.Args[1:]) + ctor, err = concurrencyCtor(child, child.Args[1:]) default: return config.NodeErr(child, "unknown limit kind: %v", kind) } @@ -111,7 +111,7 @@ func (g *Group) Init(cfg *config.Map) error { return nil } -func rateCtor(cfg *config.Map, args []string) (func() limiters.L, error) { +func rateCtor(node config.Node, args []string) (func() limiters.L, error) { period := 1 * time.Second burst := 0 @@ -120,16 +120,16 @@ func rateCtor(cfg *config.Map, args []string) (func() limiters.L, error) { var err error period, err = time.ParseDuration(args[1]) if err != nil { - return nil, cfg.MatchErr("%v", err) + return nil, config.NodeErr(node, "%v", err) } case 1: var err error burst, err = strconv.Atoi(args[0]) if err != nil { - return nil, cfg.MatchErr("%v", err) + return nil, config.NodeErr(node, "%v", err) } case 0: - return nil, cfg.MatchErr("at least burst size is needed") + return nil, config.NodeErr(node, "at least burst size is needed") } return func() limiters.L { @@ -137,13 +137,13 @@ func rateCtor(cfg *config.Map, args []string) (func() limiters.L, error) { }, nil } -func concurrencyCtor(cfg *config.Map, args []string) (func() limiters.L, error) { +func concurrencyCtor(node config.Node, args []string) (func() limiters.L, error) { if len(args) != 1 { - return nil, cfg.MatchErr("max concurrency value is needed") + return nil, config.NodeErr(node, "max concurrency value is needed") } max, err := strconv.Atoi(args[0]) if err != nil { - return nil, cfg.MatchErr("%v", err) + return nil, config.NodeErr(node, "%v", err) } return func() limiters.L { return limiters.NewSemaphore(max) diff --git a/internal/storage/sql/sql.go b/internal/storage/sql/sql.go index 10d0d76..df4c728 100644 --- a/internal/storage/sql/sql.go +++ b/internal/storage/sql/sql.go @@ -221,7 +221,7 @@ func (store *Storage) Init(cfg *config.Map) error { return "messages", nil }, func(m *config.Map, node config.Node) (interface{}, error) { if len(node.Args) != 1 { - return nil, m.MatchErr("expected 0 or 1 arguments") + return nil, config.NodeErr(node, "expected 0 or 1 arguments") } return node.Args[0], nil }, &fsstoreLocation) diff --git a/internal/target/remote/policy_group.go b/internal/target/remote/policy_group.go index 0b8371d..a9bcccc 100644 --- a/internal/target/remote/policy_group.go +++ b/internal/target/remote/policy_group.go @@ -35,7 +35,7 @@ func (pg *PolicyGroup) Init(cfg *config.Map) error { for _, block := range other { if _, ok := pg.pols[block.Name]; ok { - return cfg.MatchErr("duplicate policy block: %v", block.Name) + return config.NodeErr(block, "duplicate policy block: %v", block.Name) } policy, err := policyFromNode(debugLog, cfg, block) diff --git a/internal/target/remote/security.go b/internal/target/remote/security.go index 08c5037..5c70dc7 100644 --- a/internal/target/remote/security.go +++ b/internal/target/remote/security.go @@ -766,7 +766,7 @@ func (l localPolicy) CheckConn(ctx context.Context, mxLevel MXLevel, tlsLevel TL func policyFromNode(debugLog bool, m *config.Map, node config.Node) (Policy, error) { if len(node.Args) != 0 { - return nil, m.MatchErr("no arguments allowed") + return nil, config.NodeErr(node, "no arguments allowed") } var ( @@ -778,12 +778,12 @@ func policyFromNode(debugLog bool, m *config.Map, node config.Node) (Policy, err policy, err = NewMTASTSPolicy(net.DefaultResolver, log.DefaultLogger.Debug, config.NewMap(m.Globals, node)) case "dane": if node.Children != nil { - return nil, m.MatchErr("policy offers no additional configuration") + return nil, config.NodeErr(node, "policy offers no additional configuration") } policy = NewDANEPolicy(debugLog) case "dnssec": if node.Children != nil { - return nil, m.MatchErr("policy offers no additional configuration") + return nil, config.NodeErr(node, "policy offers no additional configuration") } policy = &dnssecPolicy{} case "sts_preload": @@ -792,7 +792,7 @@ func policyFromNode(debugLog bool, m *config.Map, node config.Node) (Policy, err case "local_policy": policy, err = NewLocalPolicy(config.NewMap(m.Globals, node)) default: - return nil, m.MatchErr("unknown policy module: %v", node.Name) + return nil, config.NodeErr(node, "unknown policy module: %v", node.Name) } if err != nil { return nil, err diff --git a/internal/target/smtp_downstream/sasl.go b/internal/target/smtp_downstream/sasl.go index b7930a8..a8a88b5 100644 --- a/internal/target/smtp_downstream/sasl.go +++ b/internal/target/smtp_downstream/sasl.go @@ -15,17 +15,17 @@ type saslClientFactory = func(msgMeta *module.MsgMetadata) (sasl.Client, error) // Authentication information of the current client should be passed in arguments. func saslAuthDirective(m *config.Map, node config.Node) (interface{}, error) { if len(node.Children) != 0 { - return nil, m.MatchErr("can't declare a block here") + return nil, config.NodeErr(node, "can't declare a block here") } if len(node.Args) == 0 { - return nil, m.MatchErr("at least one argument required") + return nil, config.NodeErr(node, "at least one argument required") } switch node.Args[0] { case "off": return nil, nil case "forward": if len(node.Args) > 1 { - return nil, m.MatchErr("no additional arguments required") + return nil, config.NodeErr(node, "no additional arguments required") } return func(msgMeta *module.MsgMetadata) (sasl.Client, error) { if msgMeta.Conn == nil || msgMeta.Conn.AuthUser == "" || msgMeta.Conn.AuthPassword == "" { @@ -42,19 +42,19 @@ func saslAuthDirective(m *config.Map, node config.Node) (interface{}, error) { }, nil case "plain": if len(node.Args) != 3 { - return nil, m.MatchErr("two additional arguments are required (username, password)") + return nil, config.NodeErr(node, "two additional arguments are required (username, password)") } return func(*module.MsgMetadata) (sasl.Client, error) { return sasl.NewPlainClient("", node.Args[1], node.Args[2]), nil }, nil case "external": if len(node.Args) > 1 { - return nil, m.MatchErr("no additional arguments required") + return nil, config.NodeErr(node, "no additional arguments required") } return func(*module.MsgMetadata) (sasl.Client, error) { return sasl.NewExternalClient(""), nil }, nil default: - return nil, m.MatchErr("unknown authentication mechanism: %s", node.Args[0]) + return nil, config.NodeErr(node, "unknown authentication mechanism: %s", node.Args[0]) } }