#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}"
* @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
#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"
/* 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");
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 */
}
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;
cur = g_list_next (cur);
}
- return rspamd_init_lua_filters (cfg, 0);
+ return rspamd_init_lua_filters (cfg, 0, vars);
}
static void
}
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");
}
}
+ 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);
}
}
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;
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) {
* 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
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);
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);
/* 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;
}
}
/* 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 ++) {
/* 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;
}
}
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 ++) {
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;
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,
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;
rspamd_lua_post_load_config (cfg);
if (init_modules) {
- rspamd_init_filters (cfg, reload);
+ rspamd_init_filters (cfg, reload, vars);
}
/* Do post-load actions */
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);
}
/* 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);
}
}
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);