commit 99692da: [Minor] Print module digest and path when loading modules

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jun 24 15:35:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-24 15:37:18 +0100
URL: https://github.com/rspamd/rspamd/commit/99692da96eeb415bed39fa3116df582a7b9e2e27

[Minor] Print module digest and path when loading modules

---
 src/libserver/cfg_file.h |  5 +++--
 src/lua/lua_common.c     | 35 ++++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index f6b1adad6..5f70ccda8 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -84,8 +84,9 @@ struct rspamd_worker_log_pipe {
  * script module list item
  */
 struct script_module {
-	gchar *name;                                    /**< name of module                                     */
-	gchar *path;                                    /**< path to module										*/
+	gchar *name;                                    /**< name of module   */
+	gchar *path;                                    /**< path to module   */
+	gchar *digest;
 };
 
 /**
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 689dcd1c4..68373c0a9 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -1062,10 +1062,36 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 			lua_pushcfunction (L, &rspamd_lua_traceback);
 			err_idx = lua_gettop (L);
 
-			if (luaL_loadfile (L, module->path) != 0) {
+			gsize fsize;
+			guint8 *data = rspamd_file_xmap (module->path,
+					PROT_READ, &fsize, TRUE);
+			guchar digest[rspamd_cryptobox_HASHBYTES];
+
+			if (data == NULL) {
+				msg_err_config ("cannot mmap %s failed: %s", module->path,
+						strerror (errno));
+
+				lua_settop (L, err_idx - 1); /*  Error function */
+
+				rspamd_plugins_table_push_elt (L, "disabled_failed",
+						module->name);
+
+				cur = g_list_next (cur);
+				continue;
+			}
+
+			module->digest = rspamd_mempool_alloc (cfg->cfg_pool,
+				rspamd_cryptobox_HASHBYTES * 2 + 1);
+			rspamd_cryptobox_hash (digest, data, fsize, NULL, 0);
+			rspamd_encode_hex_buf (digest, sizeof (digest),
+					module->digest, rspamd_cryptobox_HASHBYTES * 2 + 1);
+			module->digest[rspamd_cryptobox_HASHBYTES * 2] = '\0';
+
+
+			if (luaL_loadbuffer (L, data, fsize, module->path) != 0) {
 				msg_err_config ("load of %s failed: %s", module->path,
 					lua_tostring (L, -1));
-				lua_pop (L, 1); /*  Error function */
+				lua_settop (L, err_idx - 1); /*  Error function */
 
 				rspamd_plugins_table_push_elt (L, "disabled_failed",
 						module->name);
@@ -1094,7 +1120,10 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
 			}
 
 			if (!force_load) {
-				msg_info_config ("init lua module %s", module->name);
+				msg_info_config ("init lua module %s from %s; digest: %*s",
+						module->name,
+						module->path,
+						10, module->digest);
 			}
 
 			lua_pop (L, 1); /* Error function */


More information about the Commits mailing list