aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-26 14:21:47 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-12-26 15:00:02 +0000
commite96cab20b996c1555ba0e5748057649c5ab82d8d (patch)
tree9523cbe6a0668cc1506c5698cea224fe8cc65c55 /src
parent36e960ed741e3b908469e194c8cff1d3dc666220 (diff)
downloadrspamd-e96cab20b996c1555ba0e5748057649c5ab82d8d.tar.gz
rspamd-e96cab20b996c1555ba0e5748057649c5ab82d8d.zip
[Rework] Another paths rework
Diffstat (limited to 'src')
-rw-r--r--src/libserver/cfg_rcl.c95
-rw-r--r--src/libserver/cfg_rcl.h1
-rw-r--r--src/lua/lua_common.c9
-rw-r--r--src/rspamadm/confighelp.c2
4 files changed, 84 insertions, 23 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index d6aadc03e..bb807d932 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -794,22 +794,31 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
gboolean
rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
const gchar *path,
+ GHashTable *modules_seen,
GError **err)
{
struct stat st;
- struct script_module *cur_mod;
+ struct script_module *cur_mod, *seen_mod;
GPtrArray *paths;
gchar *fname, *ext_pos;
guint i;
if (stat (path, &st) == -1) {
- g_set_error (err,
- CFG_RCL_ERROR,
- errno,
- "cannot stat path %s, %s",
- path,
- strerror (errno));
- return FALSE;
+
+ if (errno != ENOENT) {
+ g_set_error (err,
+ CFG_RCL_ERROR,
+ errno,
+ "cannot stat path %s, %s",
+ path,
+ strerror (errno));
+ return FALSE;
+ }
+ else {
+ msg_info_config ("plugins path %s is absent, skip it", path);
+
+ return TRUE;
+ }
}
/* Handle directory */
@@ -834,6 +843,16 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
*ext_pos = '\0';
}
+ if (modules_seen) {
+ seen_mod = g_hash_table_lookup (modules_seen, cur_mod->name);
+
+ if (seen_mod != NULL) {
+ msg_info_config ("already seen module %s at %s, skip %s",
+ cur_mod->name, seen_mod->path, cur_mod->path);
+ continue;
+ }
+ }
+
if (cfg->script_modules == NULL) {
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
@@ -844,6 +863,10 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
}
+
+ if (modules_seen) {
+ g_hash_table_insert (modules_seen, cur_mod->name, cur_mod);
+ }
}
g_ptr_array_free (paths, TRUE);
@@ -862,6 +885,17 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
*ext_pos = '\0';
}
+ if (modules_seen) {
+ seen_mod = g_hash_table_lookup (modules_seen, cur_mod->name);
+
+ if (seen_mod != NULL) {
+ msg_info_config ("already seen module %s at %s, skip %s",
+ cur_mod->name, seen_mod->path, cur_mod->path);
+
+ return TRUE;
+ }
+ }
+
if (cfg->script_modules == NULL) {
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
@@ -873,6 +907,10 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
}
+
+ if (modules_seen) {
+ g_hash_table_insert (modules_seen, cur_mod->name, cur_mod);
+ }
}
return TRUE;
@@ -888,21 +926,48 @@ rspamd_rcl_modules_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
const gchar *data;
if (obj->type == UCL_OBJECT) {
+ GHashTable *mods_seen = g_hash_table_new (rspamd_strcase_hash,
+ rspamd_strcase_equal);
val = ucl_object_lookup (obj, "path");
- LL_FOREACH (val, cur)
- {
- if (ucl_object_tostring_safe (cur, &data)) {
- if (!rspamd_rcl_add_lua_plugins_path (cfg,
- rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
- return FALSE;
+ if (val) {
+ LL_FOREACH (val, cur) {
+ if (ucl_object_tostring_safe (cur, &data)) {
+ if (!rspamd_rcl_add_lua_plugins_path (cfg,
+ rspamd_mempool_strdup (cfg->cfg_pool, data),
+ mods_seen,
+ err)) {
+ return FALSE;
+ }
+ }
+ }
+ }
+ else {
+ g_set_error (err,
+ CFG_RCL_ERROR,
+ EINVAL,
+ "path attribute is missing");
+ return FALSE;
+ }
+
+ val = ucl_object_lookup (obj, "fallback_path");
+
+ if (val) {
+ LL_FOREACH (val, cur) {
+ if (ucl_object_tostring_safe (cur, &data)) {
+ if (!rspamd_rcl_add_lua_plugins_path (cfg,
+ rspamd_mempool_strdup (cfg->cfg_pool, data),
+ mods_seen,
+ err)) {
+ return FALSE;
+ }
}
}
}
}
else if (ucl_object_tostring_safe (obj, &data)) {
if (!rspamd_rcl_add_lua_plugins_path (cfg,
- rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
+ rspamd_mempool_strdup (cfg->cfg_pool, data), NULL, err)) {
return FALSE;
}
}
diff --git a/src/libserver/cfg_rcl.h b/src/libserver/cfg_rcl.h
index b14b98f8b..830a1bfe3 100644
--- a/src/libserver/cfg_rcl.h
+++ b/src/libserver/cfg_rcl.h
@@ -445,6 +445,7 @@ ucl_object_t *rspamd_rcl_add_doc_by_example (struct rspamd_config *cfg,
*/
gboolean rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
const gchar *path,
+ GHashTable *modules_seen,
GError **err);
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index db1f5357e..a5ae37e2e 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -332,14 +332,11 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars
"%s/?.lua;"
"%s/?.lua;"
"%s/?/init.lua;"
- "%s/rspamd/?.lua;"
"%s;"
"%s",
RSPAMD_CONFDIR,
rulesdir,
lualibdir, lualibdir,
- /* Rspamd specific: lualib/rspamd */
- lualibdir,
additional_path, old_path);
}
else {
@@ -348,12 +345,10 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars
"%s/?.lua;"
"%s/?.lua;"
"%s/?/init.lua;"
- "%s/rspamd/?.lua;"
"%s",
- RSPAMD_CONFDIR, rulesdir,
+ RSPAMD_CONFDIR,
+ rulesdir,
lualibdir, lualibdir,
- /* Rspamd specific: lualib/rspamd */
- lualibdir,
old_path);
}
diff --git a/src/rspamadm/confighelp.c b/src/rspamadm/confighelp.c
index d3461489e..a414545db 100644
--- a/src/rspamadm/confighelp.c
+++ b/src/rspamadm/confighelp.c
@@ -234,7 +234,7 @@ rspamadm_confighelp (gint argc, gchar **argv, const struct rspamadm_command *cmd
rspamd_rcl_config_init (cfg, NULL);
lua_pushboolean (cfg->lua_state, true);
lua_setglobal (cfg->lua_state, "confighelp");
- rspamd_rcl_add_lua_plugins_path (cfg, plugins_path, NULL);
+ rspamd_rcl_add_lua_plugins_path (cfg, plugins_path, NULL, NULL);
/* Init modules to get documentation strings */
i = 0;