commit 36e960e: [Rework] Slashing: Distinguish lualibdir, pluginsdir and sharedir

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Dec 27 18:28:14 UTC 2018


Author: Vsevolod Stakhov
Date: 2018-12-26 13:37:05 +0000
URL: https://github.com/rspamd/rspamd/commit/36e960ed741e3b908469e194c8cff1d3dc666220

[Rework] Slashing: Distinguish lualibdir, pluginsdir and sharedir

---
 CMakeLists.txt               | 35 +++++++++++++++-----------
 centos/rspamd.spec           |  2 +-
 conf/common.conf             |  3 ++-
 conf/modules.d/elastic.conf  |  4 +--
 conf/options.inc             |  2 +-
 config.h.in                  |  1 +
 debian/rules                 |  2 +-
 src/libmime/lang_detection.c |  2 +-
 src/libserver/cfg_utils.c    |  6 ++++-
 src/lua/lua_common.c         | 60 ++++++++++++++++++++++++++++++++------------
 src/lua/lua_common.h         |  1 +
 src/plugins/lua/elastic.lua  |  4 +--
 12 files changed, 81 insertions(+), 41 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9fc4fef74..fb907c85e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -119,24 +119,28 @@ IF(NOT LOGDIR)
 	SET(LOGDIR "/var/log/rspamd")
 ENDIF(NOT LOGDIR)
 
+IF(NOT SHAREDIR)
+	SET(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/rspamd")
+ENDIF(NOT SHAREDIR)
+
 IF(NOT EXAMPLESDIR)
 	SET(EXAMPLESDIR "${CMAKE_INSTALL_PREFIX}/share/examples/rspamd")
 ENDIF(NOT EXAMPLESDIR)
 
 IF(NOT PLUGINSDIR)
-	SET(PLUGINSDIR "${CMAKE_INSTALL_PREFIX}/share/rspamd")
+	SET(PLUGINSDIR "${SHAREDIR}/lualib/plugins")
 ENDIF(NOT PLUGINSDIR)
 
 IF(NOT RULESDIR)
-	SET(RULESDIR "${PLUGINSDIR}/rules")
+	SET(RULESDIR "${SHAREDIR}/rules")
 ENDIF(NOT RULESDIR)
 
 IF(NOT LUALIBDIR)
-	SET(LUALIBDIR "${PLUGINSDIR}/lib")
+	SET(LUALIBDIR "${SHAREDIR}/lualib")
 ENDIF(NOT LUALIBDIR)
 
 IF(NOT WWWDIR)
-	SET(WWWDIR "${CMAKE_INSTALL_PREFIX}/share/rspamd/www")
+	SET(WWWDIR "${SHAREDIR}/www")
 ENDIF(NOT WWWDIR)
 
 # Set libdir
@@ -1301,10 +1305,11 @@ ADD_DEFINITIONS("HAVE_CONFIG_H")
 
 # Configs
 INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${CONFDIR})")
+INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${SHAREDIR})")
 INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${EXAMPLESDIR})")
-INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/lua)")
-INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${RULESDIR})")
 INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${LUALIBDIR})")
+INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR})")
+INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${RULESDIR})")
 
 # Install configs only if they are unchanged
 LIST(LENGTH CONFFILES CONFLIST_COUNT)
@@ -1335,22 +1340,22 @@ FILE(GLOB LUA_PLUGINS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/lua"
 	"${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/lua/*.lua" )
 FOREACH(LUA_PLUGIN ${LUA_PLUGINS})
 	GET_FILENAME_COMPONENT(_rp ${LUA_PLUGIN} PATH)
-	INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/lua/${_rp})")
-	INSTALL(FILES "src/plugins/lua/${LUA_PLUGIN}" DESTINATION ${PLUGINSDIR}/lua/${_rp})
+	INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/${_rp})")
+	INSTALL(FILES "src/plugins/lua/${LUA_PLUGIN}" DESTINATION ${PLUGINSDIR}/${_rp})
 ENDFOREACH(LUA_PLUGIN)
 
 
 # Install TLD list
 INSTALL(FILES "contrib/publicsuffix/effective_tld_names.dat" DESTINATION
-	"${PLUGINSDIR}")
+	"${SHAREDIR}")
 
 # Install languages data
-INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${PLUGINSDIR}/languages)")
+INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${SHAREDIR}/languages)")
 FILE(GLOB LANGUAGES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/languages-data/*.json")
 FOREACH(_LANG ${LANGUAGES})
-	INSTALL(FILES "${_LANG}" DESTINATION ${PLUGINSDIR}/languages)
+	INSTALL(FILES "${_LANG}" DESTINATION ${SHAREDIR}/languages)
 ENDFOREACH()
-INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/languages-data/stop_words" DESTINATION ${PLUGINSDIR}/languages)
+INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/languages-data/stop_words" DESTINATION ${SHAREDIR}/languages)
 
 # Lua config
 FILE(GLOB_RECURSE LUA_CONFIGS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/rules"
@@ -1366,8 +1371,8 @@ FILE(GLOB_RECURSE LUA_LIBS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/lualib"
 		"${CMAKE_CURRENT_SOURCE_DIR}/lualib/*.lua")
 FOREACH(LUA_LIB ${LUA_LIBS})
 	GET_FILENAME_COMPONENT(_rp ${LUA_LIB} PATH)
-	INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${LUALIBDIR}/${_rp})")
-	INSTALL(FILES "lualib/${LUA_LIB}" DESTINATION ${LUALIBDIR}/${_rp})
+	INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${LUALIBDIR}/rspamd/${_rp})")
+	INSTALL(FILES "lualib/${LUA_LIB}" DESTINATION ${LUALIBDIR}/rspamd/${_rp})
 ENDFOREACH(LUA_LIB)
 
 # Install lua fun library
@@ -1398,7 +1403,7 @@ IF(INSTALL_WEBUI MATCHES "ON")
 ENDIF(INSTALL_WEBUI MATCHES "ON")
 
 
-INSTALL(DIRECTORY "contrib/elastic/" DESTINATION "${PLUGINSDIR}/elastic" PATTERN ".git" EXCLUDE)
+INSTALL(DIRECTORY "contrib/elastic/" DESTINATION "${SHAREDIR}/elastic" PATTERN ".git" EXCLUDE)
 
 ADD_CUSTOM_TARGET(dist ${CMAKE_SOURCE_DIR}/dist.sh
 	"${CMAKE_BINARY_DIR}/rspamd-${RSPAMD_VERSION}.tar.xz" "${TAR}"
diff --git a/centos/rspamd.spec b/centos/rspamd.spec
index 112569ca8..79e87455a 100644
--- a/centos/rspamd.spec
+++ b/centos/rspamd.spec
@@ -88,7 +88,7 @@ lua.
 %endif
         -DLOGDIR=%{_localstatedir}/log/rspamd \
         -DEXAMPLESDIR=%{_datadir}/examples/rspamd \
-        -DPLUGINSDIR=%{_datadir}/rspamd \
+        -DSHAREDIR=%{_datadir}/rspamd \
         -DLIBDIR=%{_libdir}/rspamd/ \
         -DINCLUDEDIR=%{_includedir} \
         -DNO_SHARED=ON \
diff --git a/conf/common.conf b/conf/common.conf
index 549af73a0..6a537b3e5 100644
--- a/conf/common.conf
+++ b/conf/common.conf
@@ -34,5 +34,6 @@ lua = "$RULESDIR/rspamd.lua"
 .include(try=true,priority=10) "$LOCAL_CONFDIR/rspamd.conf.override"
 
 modules {
-    path = "$PLUGINSDIR/lua/"
+  path = "${PLUGINSDIR}";
+  path = "${SHAREDIR}/lua"; # Legacy path
 }
diff --git a/conf/modules.d/elastic.conf b/conf/modules.d/elastic.conf
index 1753a54b9..665604278 100644
--- a/conf/modules.d/elastic.conf
+++ b/conf/modules.d/elastic.conf
@@ -6,9 +6,9 @@ elastic {
   # Timeout to wait for response (5 seconds if unset)
   timeout = 5;
   # Elasticsearch template file (json format)
-  #template_file = "${PLUGINSDIR}/elastic/rspamd_template.json";
+  #template_file = "${SHAREDIR}/elastic/rspamd_template.json";
   # Kibana prebuild visualizations and dashboard template (json format)
-  #kibana_file = "${PLUGINSDIR}/elastic/kibana.json";
+  #kibana_file = "${SHAREDIR}/elastic/kibana.json";
   # Elasticsearch index name pattern
   index_pattern = "rspamd-%Y.%m.%d";
   # Dump debug information
diff --git a/conf/options.inc b/conf/options.inc
index f8abaa875..51fd7b2dc 100644
--- a/conf/options.inc
+++ b/conf/options.inc
@@ -17,7 +17,7 @@ dns {
     retransmits = 5;
 }
 tempdir = "/tmp";
-url_tld = "${PLUGINSDIR}/effective_tld_names.dat";
+url_tld = "${SHAREDIR}/effective_tld_names.dat";
 classify_headers = [
 	"User-Agent",
 	"X-Mailer",
diff --git a/config.h.in b/config.h.in
index 66f287e03..53f5c3f81 100644
--- a/config.h.in
+++ b/config.h.in
@@ -209,6 +209,7 @@
 
 #endif /* BYTE_ORDER */
 
+#define RSPAMD_SHAREDIR "${SHAREDIR}"
 #define RSPAMD_CONFDIR "${CONFDIR}"
 #define RSPAMD_LOCAL_CONFDIR "${LOCAL_CONFDIR}"
 #define RSPAMD_RUNDIR "${RUNDIR}"
diff --git a/debian/rules b/debian/rules
index 5cde81db5..5dfe45e88 100755
--- a/debian/rules
+++ b/debian/rules
@@ -12,7 +12,7 @@ override_dh_auto_configure:
 		-DRUNDIR=/run/rspamd \
 		-DDBDIR=/var/lib/rspamd \
 		-DLOGDIR=/var/log/rspamd \
-		-DPLUGINSDIR=/usr/share/rspamd \
+		-DSHAREDIR=/usr/share/rspamd \
 		-DEXAMPLESDIR=/usr/share/doc/rspamd/examples \
 		-DLIBDIR=/usr/lib/rspamd \
 		-DINCLUDEDIR=/usr/include \
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"
@@ -1168,6 +1169,9 @@ rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
 	ucl_parser_register_variable (parser,
 			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);
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,


More information about the Commits mailing list