]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Check for plugin configuration errors on `configtest`
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 7 Aug 2023 12:32:48 +0000 (13:32 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 7 Aug 2023 12:32:48 +0000 (13:32 +0100)
lualib/lua_cfg_utils.lua
src/rspamadm/configtest.c

index 141b497bcded6d6e078cd30d1c35df4e15086cb9..e07a3ae051a55ef6a51163d6ea3298ca075bccd5 100644 (file)
@@ -19,6 +19,7 @@ limitations under the License.
 -- This module contains utility functions for configuration of Rspamd modules
 --]]
 
+local rspamd_logger = require "rspamd_logger"
 local exports = {}
 
 --[[[
@@ -64,4 +65,20 @@ exports.push_config_error = function(module, err)
   table.insert(rspamd_plugins_state.config_errors[module], err)
 end
 
+exports.check_configuration_errors = function()
+  local ret = true
+
+  if type(rspamd_plugins_state.config_errors) == 'table' then
+    -- We have some errors found during the configuration, so we need to show them
+    for m, errs in pairs(rspamd_plugins_state.config_errors) do
+      for _, err in ipairs(errs) do
+        rspamd_logger.errx(rspamd_config, 'configuration error: module %s: %s', m, err)
+        ret = false
+      end
+    end
+  end
+
+  return ret
+end
+
 return exports
\ No newline at end of file
index bfad1984e8c578334fae6ec926191e26b1b7f440..8f1482fc13fabde6626efc817aff70a8ef8287df 100644 (file)
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *   http://www.apache.org/licenses/LICENSE-2.0
+ *    http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -150,6 +150,23 @@ rspamadm_configtest(gint argc, gchar **argv, const struct rspamadm_command *cmd)
                                                                                         FALSE)) {
                        ret = FALSE;
                }
+
+               if (ret) {
+                       if (rspamd_lua_require_function(cfg->lua_state, "lua_cfg_utils", "check_configuration_errors")) {
+                               GError *err = NULL;
+
+                               if (!rspamd_lua_universal_pcall(cfg->lua_state, -1, G_STRLOC, 1, "", &err)) {
+                                       msg_err_config("call to lua function failed: %s",
+                                                                  lua_tostring(cfg->lua_state, -1));
+                                       lua_pop(cfg->lua_state, 2);
+                                       ret = FALSE;
+                               }
+                               else {
+                                       ret = lua_toboolean(cfg->lua_state, -1);
+                                       lua_pop(cfg->lua_state, 2);
+                               }
+                       }
+               }
        }
 
        if (strict && ret) {