Browse Source

[Rework] Another paths rework

tags/1.9.0
Vsevolod Stakhov 5 years ago
parent
commit
e96cab20b9
6 changed files with 92 additions and 31 deletions
  1. 7
    7
      CMakeLists.txt
  2. 1
    1
      conf/common.conf
  3. 80
    15
      src/libserver/cfg_rcl.c
  4. 1
    0
      src/libserver/cfg_rcl.h
  5. 2
    7
      src/lua/lua_common.c
  6. 1
    1
      src/rspamadm/confighelp.c

+ 7
- 7
CMakeLists.txt View File

@@ -127,18 +127,18 @@ IF(NOT EXAMPLESDIR)
SET(EXAMPLESDIR "${CMAKE_INSTALL_PREFIX}/share/examples/rspamd")
ENDIF(NOT EXAMPLESDIR)

IF(NOT LUALIBDIR)
SET(LUALIBDIR "${SHAREDIR}/lualib")
ENDIF(NOT LUALIBDIR)

IF(NOT PLUGINSDIR)
SET(PLUGINSDIR "${SHAREDIR}/lualib/plugins")
SET(PLUGINSDIR "${SHAREDIR}/plugins")
ENDIF(NOT PLUGINSDIR)

IF(NOT RULESDIR)
SET(RULESDIR "${SHAREDIR}/rules")
ENDIF(NOT RULESDIR)

IF(NOT LUALIBDIR)
SET(LUALIBDIR "${SHAREDIR}/lualib")
ENDIF(NOT LUALIBDIR)

IF(NOT WWWDIR)
SET(WWWDIR "${SHAREDIR}/www")
ENDIF(NOT WWWDIR)
@@ -1371,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}/rspamd/${_rp})")
INSTALL(FILES "lualib/${LUA_LIB}" DESTINATION ${LUALIBDIR}/rspamd/${_rp})
INSTALL(CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${LUALIBDIR}/${_rp})")
INSTALL(FILES "lualib/${LUA_LIB}" DESTINATION ${LUALIBDIR}/${_rp})
ENDFOREACH(LUA_LIB)

# Install lua fun library

+ 1
- 1
conf/common.conf View File

@@ -35,5 +35,5 @@ lua = "$RULESDIR/rspamd.lua"

modules {
path = "${PLUGINSDIR}";
path = "${SHAREDIR}/lua"; # Legacy path
fallback_path = "${SHAREDIR}/lua"; # Legacy path
}

+ 80
- 15
src/libserver/cfg_rcl.c View File

@@ -794,22 +794,31 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
gboolean
rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
const gchar *path,
GHashTable *modules_seen,
GError **err)
{
struct stat st;
struct script_module *cur_mod;
struct script_module *cur_mod, *seen_mod;
GPtrArray *paths;
gchar *fname, *ext_pos;
guint i;

if (stat (path, &st) == -1) {
g_set_error (err,
CFG_RCL_ERROR,
errno,
"cannot stat path %s, %s",
path,
strerror (errno));
return FALSE;

if (errno != ENOENT) {
g_set_error (err,
CFG_RCL_ERROR,
errno,
"cannot stat path %s, %s",
path,
strerror (errno));
return FALSE;
}
else {
msg_info_config ("plugins path %s is absent, skip it", path);

return TRUE;
}
}

/* Handle directory */
@@ -834,6 +843,16 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
*ext_pos = '\0';
}

if (modules_seen) {
seen_mod = g_hash_table_lookup (modules_seen, cur_mod->name);

if (seen_mod != NULL) {
msg_info_config ("already seen module %s at %s, skip %s",
cur_mod->name, seen_mod->path, cur_mod->path);
continue;
}
}

if (cfg->script_modules == NULL) {
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
@@ -844,6 +863,10 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
}

if (modules_seen) {
g_hash_table_insert (modules_seen, cur_mod->name, cur_mod);
}
}

g_ptr_array_free (paths, TRUE);
@@ -862,6 +885,17 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
*ext_pos = '\0';
}

if (modules_seen) {
seen_mod = g_hash_table_lookup (modules_seen, cur_mod->name);

if (seen_mod != NULL) {
msg_info_config ("already seen module %s at %s, skip %s",
cur_mod->name, seen_mod->path, cur_mod->path);

return TRUE;
}
}

if (cfg->script_modules == NULL) {
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
@@ -873,6 +907,10 @@ rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
cfg->script_modules = g_list_append (cfg->script_modules,
cur_mod);
}

if (modules_seen) {
g_hash_table_insert (modules_seen, cur_mod->name, cur_mod);
}
}

return TRUE;
@@ -888,21 +926,48 @@ rspamd_rcl_modules_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
const gchar *data;

if (obj->type == UCL_OBJECT) {
GHashTable *mods_seen = g_hash_table_new (rspamd_strcase_hash,
rspamd_strcase_equal);
val = ucl_object_lookup (obj, "path");

LL_FOREACH (val, cur)
{
if (ucl_object_tostring_safe (cur, &data)) {
if (!rspamd_rcl_add_lua_plugins_path (cfg,
rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
if (val) {
LL_FOREACH (val, cur) {
if (ucl_object_tostring_safe (cur, &data)) {
if (!rspamd_rcl_add_lua_plugins_path (cfg,
rspamd_mempool_strdup (cfg->cfg_pool, data),
mods_seen,
err)) {
return FALSE;
}
}
}
}
else {
g_set_error (err,
CFG_RCL_ERROR,
EINVAL,
"path attribute is missing");
return FALSE;
}

val = ucl_object_lookup (obj, "fallback_path");

if (val) {
LL_FOREACH (val, cur) {
if (ucl_object_tostring_safe (cur, &data)) {
if (!rspamd_rcl_add_lua_plugins_path (cfg,
rspamd_mempool_strdup (cfg->cfg_pool, data),
mods_seen,
err)) {
return FALSE;
}
}
}
}
}
else if (ucl_object_tostring_safe (obj, &data)) {
if (!rspamd_rcl_add_lua_plugins_path (cfg,
rspamd_mempool_strdup (cfg->cfg_pool, data), err)) {
rspamd_mempool_strdup (cfg->cfg_pool, data), NULL, err)) {
return FALSE;
}
}

+ 1
- 0
src/libserver/cfg_rcl.h View File

@@ -445,6 +445,7 @@ ucl_object_t *rspamd_rcl_add_doc_by_example (struct rspamd_config *cfg,
*/
gboolean rspamd_rcl_add_lua_plugins_path (struct rspamd_config *cfg,
const gchar *path,
GHashTable *modules_seen,
GError **err);



+ 2
- 7
src/lua/lua_common.c View File

@@ -332,14 +332,11 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars
"%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 {
@@ -348,12 +345,10 @@ rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, GHashTable *vars
"%s/?.lua;"
"%s/?.lua;"
"%s/?/init.lua;"
"%s/rspamd/?.lua;"
"%s",
RSPAMD_CONFDIR, rulesdir,
RSPAMD_CONFDIR,
rulesdir,
lualibdir, lualibdir,
/* Rspamd specific: lualib/rspamd */
lualibdir,
old_path);
}


+ 1
- 1
src/rspamadm/confighelp.c View File

@@ -234,7 +234,7 @@ rspamadm_confighelp (gint argc, gchar **argv, const struct rspamadm_command *cmd
rspamd_rcl_config_init (cfg, NULL);
lua_pushboolean (cfg->lua_state, true);
lua_setglobal (cfg->lua_state, "confighelp");
rspamd_rcl_add_lua_plugins_path (cfg, plugins_path, NULL);
rspamd_rcl_add_lua_plugins_path (cfg, plugins_path, NULL, NULL);

/* Init modules to get documentation strings */
i = 0;

Loading…
Cancel
Save