diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-18 16:32:26 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-18 16:40:48 +0100 |
commit | 37f250e80e9e9aee06e4a333b4f8a0ab6d8a3aba (patch) | |
tree | 7a5e42407744295be5a279e1845def3e60a27cf0 | |
parent | 61b2a08f5de3d72ee84dddb8d3ee23b66c821380 (diff) | |
download | rspamd-37f250e80e9e9aee06e4a333b4f8a0ab6d8a3aba.tar.gz rspamd-37f250e80e9e9aee06e4a333b4f8a0ab6d8a3aba.zip |
[Rework] Propagate ucl variables from the command line
-rw-r--r-- | config.h.in | 1 | ||||
-rw-r--r-- | src/libserver/cfg_file.h | 3 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 4 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 4 | ||||
-rw-r--r-- | src/lua/lua_common.c | 40 | ||||
-rw-r--r-- | src/lua/lua_common.h | 6 | ||||
-rw-r--r-- | src/lua/lua_util.c | 2 | ||||
-rw-r--r-- | src/rspamadm/configdump.c | 2 | ||||
-rw-r--r-- | src/rspamadm/confighelp.c | 2 | ||||
-rw-r--r-- | src/rspamadm/configtest.c | 2 | ||||
-rw-r--r-- | src/rspamadm/lua_repl.c | 2 | ||||
-rw-r--r-- | src/rspamd.c | 16 | ||||
-rw-r--r-- | test/rspamd_lua_test.c | 2 |
13 files changed, 61 insertions, 25 deletions
diff --git a/config.h.in b/config.h.in index d9be4fedf..9e2ccb9fd 100644 --- a/config.h.in +++ b/config.h.in @@ -193,6 +193,7 @@ #define RSPAMD_DBDIR "${DBDIR}" #define RSPAMD_EXAMPLESDIR "${EXAMPLESDIR}" #define RSPAMD_PLUGINSDIR "${PLUGINSDIR}" +#define RSPAMD_LUALIBDIR "${LUALIBDIR}" #define RSPAMD_RULESDIR "${RULESDIR}" #define RSPAMD_WWWDIR "${WWWDIR}" #define RSPAMD_PREFIX "${CMAKE_INSTALL_PREFIX}" diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 2db607075..89f4f0fde 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -581,7 +581,8 @@ void rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars) * @param reconfig * @return */ -gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig); +gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig, + GHashTable *vars); /** * Add new symbol to the metric diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index aa0282d5b..d8fc1c764 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -705,6 +705,7 @@ rspamd_rcl_worker_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, #define RSPAMD_LOGDIR_INDEX "LOGDIR" #define RSPAMD_PLUGINSDIR_INDEX "PLUGINSDIR" #define RSPAMD_RULESDIR_INDEX "RULESDIR" +#define RSPAMD_LUALIBDIR_INDEX "LUALIBDIR" #define RSPAMD_WWWDIR_INDEX "WWWDIR" #define RSPAMD_PREFIX_INDEX "PREFIX" #define RSPAMD_VERSION_INDEX "VERSION" @@ -902,7 +903,7 @@ rspamd_rcl_set_lua_globals (struct rspamd_config *cfg, lua_State *L, /* Clear stack from globals */ lua_pop (L, 4); - rspamd_lua_set_path (L, cfg); + rspamd_lua_set_path (L, cfg, vars); /* Set known paths as rspamd_paths global */ lua_getglobal (L, "rspamd_paths"); @@ -915,6 +916,7 @@ rspamd_rcl_set_lua_globals (struct rspamd_config *cfg, lua_State *L, rspamd_lua_table_set (L, RSPAMD_WWWDIR_INDEX, RSPAMD_WWWDIR); rspamd_lua_table_set (L, RSPAMD_PLUGINSDIR_INDEX, RSPAMD_PLUGINSDIR); rspamd_lua_table_set (L, RSPAMD_RULESDIR_INDEX, RSPAMD_RULESDIR); + rspamd_lua_table_set (L, RSPAMD_LUALIBDIR_INDEX, RSPAMD_LUALIBDIR); rspamd_lua_table_set (L, RSPAMD_PREFIX_INDEX, RSPAMD_PREFIX); /* Override from vars if needed */ diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 354e9f082..982415fdb 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -1331,7 +1331,7 @@ rspamd_check_worker (struct rspamd_config *cfg, worker_t *wrk) } gboolean -rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) +rspamd_init_filters (struct rspamd_config *cfg, bool reconfig, GHashTable *vars) { GList *cur; module_t *mod, **pmod; @@ -1383,7 +1383,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) cur = g_list_next (cur); } - return rspamd_init_lua_filters (cfg, 0); + return rspamd_init_lua_filters (cfg, 0, vars); } static void diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 634f7c569..2af506f13 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -202,10 +202,14 @@ lua_add_actions_global (lua_State *L) } void -rspamd_lua_set_path (lua_State *L, struct rspamd_config *cfg) +rspamd_lua_set_path (lua_State *L, struct rspamd_config *cfg, GHashTable *vars) { const gchar *old_path, *additional_path = NULL; const ucl_object_t *opts; + const gchar *pluginsdir = RSPAMD_PLUGINSDIR, + *rulesdir = RSPAMD_RULESDIR, + *lualibdir = RSPAMD_LUALIBDIR; + gchar path_buf[PATH_MAX]; lua_getglobal (L, "package"); @@ -228,16 +232,37 @@ rspamd_lua_set_path (lua_State *L, struct rspamd_config *cfg) } } + if (vars) { + gchar *t; + + t = g_hash_table_lookup (vars, "PLUGINSDIR"); + if (t) { + pluginsdir = t; + } + + t = g_hash_table_lookup (vars, "RULESDIR"); + if (t) { + rulesdir = t; + } + + t = g_hash_table_lookup (vars, "LUALIBDIR"); + if (t) { + lualibdir = t; + } + } + if (additional_path) { rspamd_snprintf (path_buf, sizeof (path_buf), - "%s/lua/?.lua;%s/lua/?.lua;%s/?.lua;%s;%s", - RSPAMD_PLUGINSDIR, RSPAMD_CONFDIR, RSPAMD_RULESDIR, + "%s/lua/?.lua;%s/lua/?.lua;%s/?.lua;%s/?.lua;%s/?.so;%s;%s", + pluginsdir, RSPAMD_CONFDIR, rulesdir, + lualibdir, lualibdir, additional_path, old_path); } else { rspamd_snprintf (path_buf, sizeof (path_buf), - "%s/lua/?.lua;%s/lua/?.lua;%s/?.lua;%s", - RSPAMD_PLUGINSDIR, RSPAMD_CONFDIR, RSPAMD_RULESDIR, + "%s/lua/?.lua;%s/lua/?.lua;%s/?.lua;%s/?.lua;%s/?.so;%s", + pluginsdir, RSPAMD_CONFDIR, rulesdir, + lualibdir, lualibdir, old_path); } @@ -340,7 +365,8 @@ rspamd_free_lua_locked (struct lua_locked_state *st) } gboolean -rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) +rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load, + GHashTable *vars) { struct rspamd_config **pcfg; GList *cur; @@ -349,7 +375,7 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) GString *tb; gint err_idx; - rspamd_lua_set_path (L, cfg); + rspamd_lua_set_path (L, cfg, vars); cur = g_list_first (cfg->script_modules); while (cur) { diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index a4d212fc5..82957d3a1 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -163,7 +163,8 @@ lua_State *rspamd_lua_init (void); * Load and initialize lua plugins */ gboolean -rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load); +rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load, + GHashTable *vars); /** * Initialize new locked lua_State structure @@ -279,7 +280,8 @@ gboolean rspamd_lua_check_condition (struct rspamd_config *cfg, void rspamd_lua_dumpstack (lua_State *L); /* Set lua path according to the configuration */ -void rspamd_lua_set_path (lua_State *L, struct rspamd_config *cfg); +void rspamd_lua_set_path (lua_State *L, struct rspamd_config *cfg, + GHashTable *vars); struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L, gint pos); struct rspamd_config * lua_check_config (lua_State * L, gint pos); diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index afa5da371..fc051814b 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -648,7 +648,7 @@ lua_util_process_message (lua_State *L) if (cfg != NULL && message != NULL) { base = event_init (); - rspamd_init_filters (cfg, FALSE); + rspamd_init_filters (cfg, FALSE, NULL); task = rspamd_task_new (NULL, cfg); task->ev_base = base; task->msg.begin = rspamd_mempool_alloc (task->task_pool, mlen); diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c index 355437b9c..720d6bf51 100644 --- a/src/rspamadm/configdump.c +++ b/src/rspamadm/configdump.c @@ -286,7 +286,7 @@ rspamadm_configdump (gint argc, gchar **argv) /* Do post-load actions */ rspamd_lua_post_load_config (cfg); - if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) { + if (!rspamd_init_filters (rspamd_main->cfg, FALSE, ucl_vars)) { ret = FALSE; } diff --git a/src/rspamadm/confighelp.c b/src/rspamadm/confighelp.c index 591f68652..26251937e 100644 --- a/src/rspamadm/confighelp.c +++ b/src/rspamadm/confighelp.c @@ -250,7 +250,7 @@ rspamadm_confighelp (gint argc, gchar **argv) } /* Init lua modules */ - rspamd_init_lua_filters (cfg, TRUE); + rspamd_init_lua_filters (cfg, TRUE, ucl_vars); if (argc > 1) { for (i = 1; i < argc; i ++) { diff --git a/src/rspamadm/configtest.c b/src/rspamadm/configtest.c index 59f466de2..3a15b976b 100644 --- a/src/rspamadm/configtest.c +++ b/src/rspamadm/configtest.c @@ -146,7 +146,7 @@ rspamadm_configtest (gint argc, gchar **argv) /* Do post-load actions */ rspamd_lua_post_load_config (cfg); - if (!rspamd_init_filters (rspamd_main->cfg, FALSE)) { + if (!rspamd_init_filters (rspamd_main->cfg, FALSE, ucl_vars)) { ret = FALSE; } diff --git a/src/rspamadm/lua_repl.c b/src/rspamadm/lua_repl.c index e3656e8c9..d7d7721a8 100644 --- a/src/rspamadm/lua_repl.c +++ b/src/rspamadm/lua_repl.c @@ -676,7 +676,7 @@ rspamadm_lua (gint argc, gchar **argv) } L = rspamd_lua_init (); - rspamd_lua_set_path (L, NULL); + rspamd_lua_set_path (L, NULL, ucl_vars); if (paths) { for (elt = paths; *elt != NULL; elt ++) { diff --git a/src/rspamd.c b/src/rspamd.c index 1a08c938f..828720cae 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -68,7 +68,8 @@ static gboolean load_rspamd_config (struct rspamd_main *rspamd_main, struct rspamd_config *cfg, gboolean init_modules, enum rspamd_post_load_options opts, - gboolean reload); + gboolean reload, + GHashTable *vars); /* Control socket */ static gint control_fd; @@ -287,7 +288,8 @@ reread_config (struct rspamd_main *rspamd_main) rspamd_main->cfg = tmp_cfg; if (!load_rspamd_config (rspamd_main, tmp_cfg, TRUE, - RSPAMD_CONFIG_INIT_VALIDATE|RSPAMD_CONFIG_INIT_SYMCACHE, TRUE)) { + RSPAMD_CONFIG_INIT_VALIDATE|RSPAMD_CONFIG_INIT_SYMCACHE, + TRUE, ucl_vars)) { rspamd_main->cfg = old_cfg; rspamd_log_close_priv (rspamd_main->logger, rspamd_main->workers_uid, @@ -825,7 +827,8 @@ static gboolean load_rspamd_config (struct rspamd_main *rspamd_main, struct rspamd_config *cfg, gboolean init_modules, enum rspamd_post_load_options opts, - gboolean reload) + gboolean reload, + GHashTable *vars) { cfg->compiled_modules = modules; cfg->compiled_workers = workers; @@ -854,7 +857,7 @@ load_rspamd_config (struct rspamd_main *rspamd_main, rspamd_lua_post_load_config (cfg); if (init_modules) { - rspamd_init_filters (cfg, reload); + rspamd_init_filters (cfg, reload, vars); } /* Do post-load actions */ @@ -1220,7 +1223,8 @@ main (gint argc, gchar **argv, gchar **env) rspamd_main->workers_gid); if (config_test || dump_cache) { - if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, FALSE, 0, FALSE)) { + if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, FALSE, 0, + FALSE, ucl_vars)) { exit (EXIT_FAILURE); } @@ -1243,7 +1247,7 @@ main (gint argc, gchar **argv, gchar **env) /* Load config */ if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, TRUE, - RSPAMD_CONFIG_LOAD_ALL, FALSE)) { + RSPAMD_CONFIG_LOAD_ALL, FALSE, ucl_vars)) { exit (EXIT_FAILURE); } diff --git a/test/rspamd_lua_test.c b/test/rspamd_lua_test.c index baad40ed7..0c785e9e6 100644 --- a/test/rspamd_lua_test.c +++ b/test/rspamd_lua_test.c @@ -106,7 +106,7 @@ rspamd_lua_test_func (void) } lua_setglobal (L, "tests_list"); - rspamd_lua_set_path (L, NULL); + rspamd_lua_set_path (L, NULL, NULL); lua_pushcfunction (L, traceback); luaL_loadfile (L, rp); |