aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-22 14:56:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-22 14:56:37 +0100
commit98d22d8bd5da4c7aa427c1a62b05c026f7a202f8 (patch)
tree0a719c4c54e674875b9a314e5baae11715a44626
parent75591b77cec803d35447d7636f8719feedd219b7 (diff)
downloadrspamd-98d22d8bd5da4c7aa427c1a62b05c026f7a202f8.tar.gz
rspamd-98d22d8bd5da4c7aa427c1a62b05c026f7a202f8.zip
[Feature] Rework confighelp to load Lua plugins
-rw-r--r--src/libserver/cfg_rcl.c20
-rw-r--r--src/libserver/cfg_rcl.h11
-rw-r--r--src/libserver/cfg_utils.c2
-rw-r--r--src/lua/lua_common.c10
-rw-r--r--src/lua/lua_common.h3
-rw-r--r--src/lua/lua_config.c20
-rw-r--r--src/plugins/lua/dcc.lua10
-rw-r--r--src/rspamadm/confighelp.c12
-rw-r--r--src/rspamadm/confighelp.lua2
9 files changed, 66 insertions, 24 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index b6adc61a8..ae6657064 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -1029,10 +1029,10 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
return TRUE;
}
-static gboolean
-rspamd_rcl_add_module_path (struct rspamd_config *cfg,
- const gchar *path,
- GError **err)
+gboolean
+rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
+ const gchar *path,
+ GError **err)
{
struct stat st;
struct script_module *cur_mod;
@@ -1145,16 +1145,16 @@ rspamd_rcl_modules_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
LL_FOREACH (val, cur)
{
if (ucl_object_tostring_safe (cur, &data)) {
- if (!rspamd_rcl_add_module_path (cfg,
- rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_lua_plugins_path (cfg,
+ rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
}
}
else if (ucl_object_tostring_safe (obj, &data)) {
- if (!rspamd_rcl_add_module_path (cfg,
- rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_lua_plugins_path (cfg,
+ rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
@@ -3869,7 +3869,7 @@ rspamd_rcl_add_doc_from_comments (struct rspamd_config *cfg,
ucl_object_t *top_doc, const ucl_object_t *obj,
const ucl_object_t *comments, gboolean is_top)
{
- ucl_object_iter_t it;
+ ucl_object_iter_t it = NULL;
const ucl_object_t *cur, *cmt;
ucl_object_t *cur_doc;
@@ -3927,7 +3927,7 @@ rspamd_rcl_add_doc_by_example (struct rspamd_config *cfg,
top_doc = rspamd_rcl_add_doc_by_path (cfg, root_path, doc_string,
doc_name, ucl_object_type (top), NULL, 0, NULL, FALSE);
ucl_object_insert_key (top_doc,
- ucl_object_fromlstring (example_data, example_len),
+ ucl_object_fromstring_common (example_data, example_len, 0),
"example", 0, false);
rspamd_rcl_add_doc_from_comments (cfg, top_doc, top, comments, TRUE);
diff --git a/src/libserver/cfg_rcl.h b/src/libserver/cfg_rcl.h
index a83e9698f..d1ec26b2b 100644
--- a/src/libserver/cfg_rcl.h
+++ b/src/libserver/cfg_rcl.h
@@ -446,4 +446,15 @@ ucl_object_t *rspamd_rcl_add_doc_by_example (struct rspamd_config *cfg,
const gchar *doc_string,
const gchar *doc_name,
const gchar *example_data, gsize example_len);
+
+/**
+ * Add lua modules path
+ * @param cfg
+ * @param path
+ * @param err
+ * @return
+ */
+gboolean rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
+ const gchar *path,
+ GError **err);
#endif /* CFG_RCL_H_ */
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index c97db53fb..e8abcd9e6 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -1376,7 +1376,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig)
cur = g_list_next (cur);
}
- return rspamd_init_lua_filters (cfg);
+ return rspamd_init_lua_filters (cfg, 0);
}
static void
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 7f4cea7b7..4f494971b 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -340,7 +340,7 @@ rspamd_free_lua_locked (struct lua_locked_state *st)
}
gboolean
-rspamd_init_lua_filters (struct rspamd_config *cfg)
+rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load)
{
struct rspamd_config **pcfg;
GList *cur;
@@ -355,9 +355,11 @@ rspamd_init_lua_filters (struct rspamd_config *cfg)
while (cur) {
module = cur->data;
if (module->path) {
- if (!rspamd_config_is_module_enabled (cfg, module->name)) {
- cur = g_list_next (cur);
- continue;
+ if (!force_load) {
+ if (!rspamd_config_is_module_enabled (cfg, module->name)) {
+ cur = g_list_next (cur);
+ continue;
+ }
}
lua_pushcfunction (L, &rspamd_lua_traceback);
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index 394798fb8..a4d212fc5 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -162,7 +162,8 @@ lua_State *rspamd_lua_init (void);
/**
* Load and initialize lua plugins
*/
-gboolean rspamd_init_lua_filters (struct rspamd_config *cfg);
+gboolean
+rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load);
/**
* Initialize new locked lua_State structure
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index e59595447..0eea492ca 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -2603,18 +2603,22 @@ static gint
lua_config_add_doc (lua_State *L)
{
struct rspamd_config *cfg;
- const gchar *path, *option, *doc_string;
+ const gchar *path = NULL, *option, *doc_string;
const gchar *type_str = NULL, *default_value = NULL;
ucl_type_t type = UCL_NULL;
gboolean required = FALSE;
GError *err = NULL;
cfg = lua_check_config (L, 1);
- path = luaL_checkstring (L, 2);
+
+ if (lua_type (L, 2 ) == LUA_TSTRING) {
+ path = luaL_checkstring (L, 2);
+ }
+
option = luaL_checkstring (L, 3);
doc_string = luaL_checkstring (L, 4);
- if (cfg && path && option && doc_string) {
+ if (cfg && option && doc_string) {
if (lua_type (L, 5) == LUA_TTABLE) {
if (!rspamd_lua_parse_table_arguments (L, 2, &err,
"type=S;default=S;required=B",
@@ -2647,16 +2651,20 @@ static gint
lua_config_add_example (lua_State *L)
{
struct rspamd_config *cfg;
- const gchar *path, *option, *doc_string, *example;
+ const gchar *path = NULL, *option, *doc_string, *example;
gsize example_len;
cfg = lua_check_config (L, 1);
- path = luaL_checkstring (L, 2);
+
+ if (lua_type (L, 2 ) == LUA_TSTRING) {
+ path = luaL_checkstring (L, 2);
+ }
+
option = luaL_checkstring (L, 3);
doc_string = luaL_checkstring (L, 4);
example = luaL_checklstring (L, 5, &example_len);
- if (cfg && path && option && doc_string && example) {
+ if (cfg && option && doc_string && example) {
rspamd_rcl_add_doc_by_example (cfg, path, doc_string, option,
example, example_len);
diff --git a/src/plugins/lua/dcc.lua b/src/plugins/lua/dcc.lua
index bde9e7983..cf44c3224 100644
--- a/src/plugins/lua/dcc.lua
+++ b/src/plugins/lua/dcc.lua
@@ -128,3 +128,13 @@ if opts and opts['host'] then
else
logger.infox('DCC module not configured');
end
+
+rspamd_config:add_example(nil, 'dcc',
+ "Check messages for 'bulkiness' using DCC",
+[[
+dcc {
+ host = "/var/dcc/dccifd"; # Unix socket or hostname
+ port = 1234 # Port to use (needed for TCP socket)
+ timeout = 2s; # Timeout to wait for checks
+}
+]]) \ No newline at end of file
diff --git a/src/rspamadm/confighelp.c b/src/rspamadm/confighelp.c
index 010ebb834..591f68652 100644
--- a/src/rspamadm/confighelp.c
+++ b/src/rspamadm/confighelp.c
@@ -25,6 +25,7 @@
static gboolean json = FALSE;
static gboolean compact = FALSE;
static gboolean keyword = FALSE;
+static const gchar *plugins_path = RSPAMD_PLUGINSDIR;
extern struct rspamd_main *rspamd_main;
/* Defined in modules.c */
extern module_t *modules[];
@@ -48,6 +49,8 @@ static GOptionEntry entries[] = {
"Output compacted", NULL},
{"keyword", 'k', 0, G_OPTION_ARG_NONE, &keyword,
"Search by keyword", NULL},
+ {"plugins", 'P', 0, G_OPTION_ARG_STRING, &plugins_path,
+ "Use the following plugin path (" RSPAMD_PLUGINSDIR ")", NULL},
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
};
@@ -63,7 +66,8 @@ rspamadm_confighelp_help (gboolean full_help)
"-c: output compacted JSON\n"
"-j: output pretty formatted JSON\n"
"-k: search by keyword in doc string\n"
- "--color: show colored output\n"
+ "-P: use specific Lua plugins path\n"
+ "--no-color: show colored output\n"
"--short: show only option names\n"
"--no-examples: do not show examples (impied by --short)\n"
"--help: shows available options and commands";
@@ -224,6 +228,9 @@ rspamadm_confighelp (gint argc, gchar **argv)
cfg->compiled_workers = workers;
rspamd_rcl_config_init (cfg);
+ lua_pushboolean (cfg->lua_state, true);
+ lua_setglobal (cfg->lua_state, "confighelp");
+ rspamd_rcl_add_lua_plugins_path (cfg, plugins_path, NULL);
/* Init modules to get documentation strings */
for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod++) {
@@ -242,6 +249,9 @@ rspamadm_confighelp (gint argc, gchar **argv)
(*pworker)->worker_init_func (cfg);
}
+ /* Init lua modules */
+ rspamd_init_lua_filters (cfg, TRUE);
+
if (argc > 1) {
for (i = 1; i < argc; i ++) {
if (argv[i][0] != '-') {
diff --git a/src/rspamadm/confighelp.lua b/src/rspamadm/confighelp.lua
index 0d61bf394..91da3177d 100644
--- a/src/rspamadm/confighelp.lua
+++ b/src/rspamadm/confighelp.lua
@@ -12,7 +12,7 @@ local known_attrs = {
local function maybe_print_color(key)
- if opts['color'] then
+ if not opts['no-color'] then
return ansicolors.white .. key .. ansicolors.reset
else
return key