diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-12-26 13:37:05 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-12-26 15:00:02 +0000 |
commit | 36e960ed741e3b908469e194c8cff1d3dc666220 (patch) | |
tree | 4c8c85f8de227fce52abb5198a68b72930559891 /src | |
parent | 263ae1f2809372170751719c5288fffae6993375 (diff) | |
download | rspamd-36e960ed741e3b908469e194c8cff1d3dc666220.tar.gz rspamd-36e960ed741e3b908469e194c8cff1d3dc666220.zip |
[Rework] Slashing: Distinguish lualibdir, pluginsdir and sharedir
Diffstat (limited to 'src')
-rw-r--r-- | src/libmime/lang_detection.c | 2 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 6 | ||||
-rw-r--r-- | src/lua/lua_common.c | 60 | ||||
-rw-r--r-- | src/lua/lua_common.h | 1 | ||||
-rw-r--r-- | src/plugins/lua/elastic.lua | 4 |
5 files changed, 53 insertions, 20 deletions
diff --git a/src/libmime/lang_detection.c b/src/libmime/lang_detection.c index 82e5fc2ff..72964a93a 100644 --- a/src/libmime/lang_detection.c +++ b/src/libmime/lang_detection.c @@ -33,7 +33,7 @@ static const gsize default_short_text_limit = 20; static const gsize default_words = 80; static const gdouble update_prob = 0.6; -static const gchar *default_languages_path = RSPAMD_PLUGINSDIR "/languages"; +static const gchar *default_languages_path = RSPAMD_SHAREDIR "/languages"; #undef EXTRA_LANGDET_DEBUG diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 2125a2854..a15bb9b8a 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -731,7 +731,7 @@ rspamd_config_post_load (struct rspamd_config *cfg, /* Try to guess tld file */ GString *fpath = g_string_new (NULL); - rspamd_printf_gstring (fpath, "%s%c%s", RSPAMD_PLUGINSDIR, + rspamd_printf_gstring (fpath, "%s%c%s", RSPAMD_SHAREDIR, G_DIR_SEPARATOR, "effective_tld_names.dat"); if (access (fpath->str, R_OK) != -1) { @@ -1135,6 +1135,7 @@ rspamd_include_map_handler (const guchar *data, gsize len, #define RSPAMD_DBDIR_MACRO "DBDIR" #define RSPAMD_LOGDIR_MACRO "LOGDIR" #define RSPAMD_PLUGINSDIR_MACRO "PLUGINSDIR" +#define RSPAMD_SHAREDIR_MACRO "SHAREDIR" #define RSPAMD_RULESDIR_MACRO "RULESDIR" #define RSPAMD_WWWDIR_MACRO "WWWDIR" #define RSPAMD_PREFIX_MACRO "PREFIX" @@ -1169,6 +1170,9 @@ rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars) RSPAMD_PLUGINSDIR_MACRO, RSPAMD_PLUGINSDIR); ucl_parser_register_variable (parser, + RSPAMD_SHAREDIR_MACRO, + RSPAMD_SHAREDIR); + ucl_parser_register_variable (parser, RSPAMD_RULESDIR_MACRO, RSPAMD_RULESDIR); ucl_parser_register_variable (parser, RSPAMD_WWWDIR_MACRO, diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 01d5dc869..db1f5357e 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -237,7 +237,8 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars const gchar *pluginsdir = RSPAMD_PLUGINSDIR, *rulesdir = RSPAMD_RULESDIR, *lualibdir = RSPAMD_LUALIBDIR, - *libdir = RSPAMD_LIBDIR; + *libdir = RSPAMD_LIBDIR, + *sharedir = RSPAMD_SHAREDIR; const gchar *t; gchar path_buf[PATH_MAX]; @@ -246,7 +247,7 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars lua_getfield (L, -1, "path"); old_path = luaL_checkstring (L, -1); - if (strstr (old_path, RSPAMD_PLUGINSDIR) != NULL) { + if (strstr (old_path, RSPAMD_LUALIBDIR) != NULL) { /* Path has been already set, do not touch it */ lua_pop (L, 2); return; @@ -263,6 +264,11 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars } /* Try environment */ + t = getenv ("SHAREDIR"); + if (t) { + sharedir = t; + } + t = getenv ("PLUGINSDIR"); if (t) { pluginsdir = t; @@ -294,6 +300,11 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars pluginsdir = t; } + t = g_hash_table_lookup (vars, "SHAREDIR"); + if (t) { + sharedir = t; + } + t = g_hash_table_lookup (vars, "RULESDIR"); if (t) { rulesdir = t; @@ -318,26 +329,31 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars if (additional_path) { rspamd_snprintf (path_buf, sizeof (path_buf), "%s/lua/?.lua;" - "%s/lua/?.lua;" - "%s/?.lua;" - "%s/?.lua;" - "%s/?/init.lua;" - "%s;" - "%s", - pluginsdir, RSPAMD_CONFDIR, rulesdir, + "%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 { rspamd_snprintf (path_buf, sizeof (path_buf), "%s/lua/?.lua;" - "%s/lua/?.lua;" - "%s/?.lua;" - "%s/?.lua;" - "%s/?/init.lua;" - "%s", - pluginsdir, RSPAMD_CONFDIR, rulesdir, + "%s/?.lua;" + "%s/?.lua;" + "%s/?/init.lua;" + "%s/rspamd/?.lua;" + "%s", + RSPAMD_CONFDIR, rulesdir, lualibdir, lualibdir, + /* Rspamd specific: lualib/rspamd */ + lualibdir, old_path); } @@ -592,10 +608,16 @@ rspamd_lua_set_globals (struct rspamd_config *cfg, lua_State *L, *pluginsdir = RSPAMD_PLUGINSDIR, *rulesdir = RSPAMD_RULESDIR, *lualibdir = RSPAMD_LUALIBDIR, - *prefix = RSPAMD_PREFIX; + *prefix = RSPAMD_PREFIX, + *sharedir = RSPAMD_SHAREDIR; const gchar *t; /* Try environment */ + t = getenv ("SHAREDIR"); + if (t) { + sharedir = t; + } + t = getenv ("PLUGINSDIR"); if (t) { pluginsdir = t; @@ -643,6 +665,11 @@ rspamd_lua_set_globals (struct rspamd_config *cfg, lua_State *L, if (vars) { + t = g_hash_table_lookup (vars, "SHAREDIR"); + if (t) { + sharedir = t; + } + t = g_hash_table_lookup (vars, "PLUGINSDIR"); if (t) { pluginsdir = t; @@ -691,6 +718,7 @@ rspamd_lua_set_globals (struct rspamd_config *cfg, lua_State *L, lua_createtable (L, 0, 9); + rspamd_lua_table_set (L, RSPAMD_SHAREDIR_INDEX, sharedir); rspamd_lua_table_set (L, RSPAMD_CONFDIR_INDEX, confdir); rspamd_lua_table_set (L, RSPAMD_LOCAL_CONFDIR_INDEX, local_confdir); rspamd_lua_table_set (L, RSPAMD_RUNDIR_INDEX, rundir); diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 4c82be640..cb9390a1d 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -464,6 +464,7 @@ gint rspamd_lua_push_words (lua_State *L, GArray *words, #define RSPAMD_DBDIR_INDEX "DBDIR" #define RSPAMD_LOGDIR_INDEX "LOGDIR" #define RSPAMD_PLUGINSDIR_INDEX "PLUGINSDIR" +#define RSPAMD_SHAREDIR_INDEX "SHAREDIR" #define RSPAMD_RULESDIR_INDEX "RULESDIR" #define RSPAMD_LUALIBDIR_INDEX "LUALIBDIR" #define RSPAMD_WWWDIR_INDEX "WWWDIR" diff --git a/src/plugins/lua/elastic.lua b/src/plugins/lua/elastic.lua index d613d335f..a223756e4 100644 --- a/src/plugins/lua/elastic.lua +++ b/src/plugins/lua/elastic.lua @@ -39,8 +39,8 @@ local enabled = true local settings = { limit = 500, index_pattern = 'rspamd-%Y.%m.%d', - template_file = rspamd_paths['PLUGINSDIR'] .. '/elastic/rspamd_template.json', - kibana_file = rspamd_paths['PLUGINSDIR'] ..'/elastic/kibana.json', + template_file = rspamd_paths['SHAREDIR'] .. '/elastic/rspamd_template.json', + kibana_file = rspamd_paths['SHAREDIR'] ..'/elastic/kibana.json', key_prefix = 'elastic-', expire = 3600, timeout = 5.0, |