Browse Source

[Feature] Implement more strict configuration tests

tags/1.8.3
Vsevolod Stakhov 5 years ago
parent
commit
2bcf327219
4 changed files with 150 additions and 14 deletions
  1. 68
    0
      src/libserver/cfg_rcl.c
  2. 15
    4
      src/libserver/cfg_utils.c
  3. 66
    9
      src/plugins/regexp.c
  4. 1
    1
      src/rspamadm/configtest.c

+ 68
- 0
src/libserver/cfg_rcl.c View File

@@ -381,40 +381,108 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
nshots = cfg->default_max_shots;

if ((elt = ucl_object_lookup (obj, "one_shot")) != NULL) {
if (ucl_object_type (elt) != UCL_BOOLEAN) {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"one_shot attribute is not boolean for symbol: '%s'",
key);

return FALSE;
}
if (ucl_object_toboolean (elt)) {
nshots = 1;
}
}

if ((elt = ucl_object_lookup (obj, "any_shot")) != NULL) {
if (ucl_object_type (elt) != UCL_BOOLEAN) {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"any_shot attribute is not boolean for symbol: '%s'",
key);

return FALSE;
}
if (ucl_object_toboolean (elt)) {
nshots = -1;
}
}

if ((elt = ucl_object_lookup (obj, "one_param")) != NULL) {
if (ucl_object_type (elt) != UCL_BOOLEAN) {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"one_param attribute is not boolean for symbol: '%s'",
key);

return FALSE;
}

if (ucl_object_toboolean (elt)) {
flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
}
}

if ((elt = ucl_object_lookup (obj, "ignore")) != NULL) {
if (ucl_object_type (elt) != UCL_BOOLEAN) {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"ignore attribute is not boolean for symbol: '%s'",
key);

return FALSE;
}

if (ucl_object_toboolean (elt)) {
flags |= RSPAMD_SYMBOL_FLAG_IGNORE;
}
}

if ((elt = ucl_object_lookup (obj, "nshots")) != NULL) {
if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"nshots attribute is not numeric for symbol: '%s'",
key);

return FALSE;
}

nshots = ucl_object_toint (elt);
}

elt = ucl_object_lookup_any (obj, "score", "weight", NULL);
if (elt) {
if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"score attribute is not numeric for symbol: '%s'",
key);

return FALSE;
}

score = ucl_object_todouble (elt);
}

elt = ucl_object_lookup (obj, "priority");
if (elt) {
if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"priority attribute is not numeric for symbol: '%s'",
key);

return FALSE;
}

priority = ucl_object_toint (elt);
}
else {

+ 15
- 4
src/libserver/cfg_utils.c View File

@@ -1470,6 +1470,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
module_t *mod, **pmod;
guint i = 0;
struct module_ctx *mod_ctx, *cur_ctx;
gboolean ret = TRUE;

/* Init all compiled modules */

@@ -1504,11 +1505,19 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
mod_ctx->enabled = rspamd_config_is_module_enabled (cfg, mod->name);

if (reconfig) {
(void)mod->module_reconfig_func (cfg);
msg_info_config ("reconfig of %s", mod->name);
if (!mod->module_reconfig_func (cfg)) {
msg_err_config ("reconfig of %s failed!", mod->name);
}
else {
msg_info_config ("reconfig of %s", mod->name);
}

}
else {
(void)mod->module_config_func (cfg);
if (!mod->module_config_func (cfg)) {
msg_info_config ("config of %s failed!", mod->name);
ret = FALSE;
}
}
}

@@ -1519,7 +1528,9 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
cur = g_list_next (cur);
}

return rspamd_init_lua_filters (cfg, 0);
ret = rspamd_init_lua_filters (cfg, 0) && ret;

return ret;
}

static void

+ 66
- 9
src/plugins/regexp.c View File

@@ -279,39 +279,96 @@ regexp_module_config (struct rspamd_config *cfg)
elt = ucl_object_lookup (value, "score");

if (elt) {
score = ucl_object_todouble (elt);
if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
msg_err_config (
"score attribute is not numeric for symbol: '%s'",
cur_item->symbol);

res = FALSE;
}
else {
score = ucl_object_todouble (elt);
}
}

elt = ucl_object_lookup (value, "one_shot");

if (elt) {
if (ucl_object_toboolean (elt)) {
nshots = 1;
if (ucl_object_type (elt) != UCL_BOOLEAN) {
msg_err_config (
"one_shot attribute is not numeric for symbol: '%s'",
cur_item->symbol);

res = FALSE;
}
else {
if (ucl_object_toboolean (elt)) {
nshots = 1;
}
}
}

if ((elt = ucl_object_lookup (value, "any_shot")) != NULL) {
if (ucl_object_toboolean (elt)) {
nshots = -1;
if (ucl_object_type (elt) != UCL_BOOLEAN) {
msg_err_config (
"any_shot attribute is not numeric for symbol: '%s'",
cur_item->symbol);

res = FALSE;
}
else {
if (ucl_object_toboolean (elt)) {
nshots = -1;
}
}
}

if ((elt = ucl_object_lookup (value, "nshots")) != NULL) {
nshots = ucl_object_toint (elt);
if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
msg_err_config (
"nshots attribute is not numeric for symbol: '%s'",
cur_item->symbol);

res = FALSE;
}
else {
nshots = ucl_object_toint (elt);
}
}

elt = ucl_object_lookup (value, "one_param");

if (elt) {
if (ucl_object_toboolean (elt)) {
flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
if (ucl_object_type (elt) != UCL_BOOLEAN) {
msg_err_config (
"one_param attribute is not numeric for symbol: '%s'",
cur_item->symbol);

res = FALSE;
}
else {
if (ucl_object_toboolean (elt)) {
flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
}
}
}

elt = ucl_object_lookup (value, "priority");

if (elt) {
priority = ucl_object_toint (elt);
if (ucl_object_type (elt) != UCL_FLOAT && ucl_object_type (elt) != UCL_INT) {
msg_err_config (
"priority attribute is not numeric for symbol: '%s'",
cur_item->symbol);

res = FALSE;
}
else {
priority = ucl_object_toint (elt);
}
}
else {
priority = ucl_object_get_priority (value) + 1;
}

rspamd_config_add_symbol (cfg, cur_item->symbol,

+ 1
- 1
src/rspamadm/configtest.c View File

@@ -156,7 +156,7 @@ rspamadm_configtest (gint argc, gchar **argv, const struct rspamadm_command *cmd
ret = rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE);
}

if (!rspamd_symcache_validate (rspamd_main->cfg->cache,
if (ret && !rspamd_symcache_validate (rspamd_main->cfg->cache,
rspamd_main->cfg,
FALSE)) {
ret = FALSE;

Loading…
Cancel
Save