summaryrefslogtreecommitdiffstats
path: root/.github
diff options
context:
space:
mode:
authorMichaIng <micha@dietpi.com>2022-03-04 00:38:00 +0100
committerGitHub <noreply@github.com>2022-03-04 00:38:00 +0100
commitfdf4024ccb2971c5a2755ce77307d0f24e8a9cd0 (patch)
tree2131e7d94ef92f109394e6ab749c1c8ead5ce406 /.github
parentaec2e0fdc49b7b9aa9e9c6c10421bf1f13edb5dc (diff)
parentf63eb4261fd3f7591774b12a08a5e83d41f4bf36 (diff)
downloadnextcloud-server-fdf4024ccb2971c5a2755ce77307d0f24e8a9cd0.tar.gz
nextcloud-server-fdf4024ccb2971c5a2755ce77307d0f24e8a9cd0.zip
Merge pull request #31415 from knox/fix-opcache-permitted-path
Fix "Nextcloud is not allowed to use the OPcache API" warning
Diffstat (limited to '.github')
0 files changed, 0 insertions, 0 deletions
> { if (!(cfg->libs_ctx->crypto_ctx->cpu_config & CPUID_SSSE3)) { msg_warn_config ("CPU doesn't have SSSE3 instructions set " "required for hyperscan, disable it"); cfg->disable_hyperscan = TRUE; } } #endif if (opts & RSPAMD_CONFIG_INIT_URL) { if (cfg->tld_file == NULL) { /* Try to guess tld file */ GString *fpath = g_string_new (NULL); rspamd_printf_gstring (fpath, "%s%c%s", RSPAMD_PLUGINSDIR, G_DIR_SEPARATOR, "effective_tld_names.dat"); if (access (fpath->str, R_OK) != -1) { msg_debug_config ("url_tld option is not specified but %s is available," " therefore this file is assumed as TLD file for URL" " extraction", fpath->str); cfg->tld_file = rspamd_mempool_strdup (cfg->cfg_pool, fpath->str); } else { if (opts & RSPAMD_CONFIG_INIT_VALIDATE) { msg_err_config ("no url_tld option has been specified"); ret = FALSE; } } g_string_free (fpath, TRUE); } else { if (access (cfg->tld_file, R_OK) == -1) { if (opts & RSPAMD_CONFIG_INIT_VALIDATE) { ret = FALSE; msg_err_config ("cannot access tld file %s: %s", cfg->tld_file, strerror (errno)); } else { msg_debug_config ("cannot access tld file %s: %s", cfg->tld_file, strerror (errno)); cfg->tld_file = NULL; } } } if (opts & RSPAMD_CONFIG_INIT_NO_TLD) { rspamd_url_init (NULL); } else { rspamd_url_init (cfg->tld_file); } } init_dynamic_config (cfg); /* Insert classifiers symbols */ rspamd_config_insert_classify_symbols (cfg); /* Parse format string that we have */ if (!rspamd_config_parse_log_format (cfg)) { msg_err_config ("cannot parse log format, task logging will not be available"); } if (opts & RSPAMD_CONFIG_INIT_SYMCACHE) { lua_State *L = cfg->lua_state; int err_idx; /* Process squeezed Lua rules */ lua_pushcfunction (L, &rspamd_lua_traceback); err_idx = lua_gettop (L); if (rspamd_lua_require_function (cfg->lua_state, "lua_squeeze_rules", "squeeze_init")) { if (lua_pcall (L, 0, 0, err_idx) != 0) { GString *tb = lua_touserdata (L, -1); msg_err_config ("call to squeeze_init script failed: %v", tb); if (tb) { g_string_free (tb, TRUE); } } } lua_settop (L, err_idx - 1); /* Init config cache */ rspamd_symbols_cache_init (cfg->cache); /* Init re cache */ rspamd_re_cache_init (cfg->re_cache, cfg); } if (opts & RSPAMD_CONFIG_INIT_LIBS) { /* Config other libraries */ rspamd_config_libs (cfg->libs_ctx, cfg); } /* Validate cache */ if (opts & RSPAMD_CONFIG_INIT_VALIDATE) { /* Check for actions sanity */ int i, prev_act = 0; gdouble prev_score = NAN; gboolean seen_controller = FALSE; GList *cur; struct rspamd_worker_conf *wcf; for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i ++) { if (!isnan (prev_score) && !isnan (cfg->actions[i].score)) { if (prev_score <= isnan (cfg->actions[i].score)) { msg_warn_config ("incorrect metrics scores: action %s" " has lower score: %.2f than action %s: %.2f", rspamd_action_to_str (prev_act), prev_score, rspamd_action_to_str (i), cfg->actions[i].score); ret = FALSE; } } if (!isnan (cfg->actions[i].score)) { prev_score = cfg->actions[i].score; prev_act = i; } } cur = cfg->workers; while (cur) { wcf = cur->data; if (wcf->type == g_quark_from_static_string ("controller")) { seen_controller = TRUE; break; } cur = g_list_next (cur); } if (!seen_controller) { msg_warn_config ("controller worker is unconfigured: learning," " periodic scripts, maps watching and many other" " Rspamd features will be broken"); ret = FALSE; } return rspamd_symbols_cache_validate (cfg->cache, cfg, FALSE) && ret; } return ret; } #if 0 void parse_err (const gchar *fmt, ...) { va_list aq; gchar logbuf[BUFSIZ], readbuf[32]; gint r; va_start (aq, fmt); rspamd_strlcpy (readbuf, yytext, sizeof (readbuf)); r = snprintf (logbuf, sizeof (logbuf), "config file parse error! line: %d, text: %s, reason: ", yylineno, readbuf); r += vsnprintf (logbuf + r, sizeof (logbuf) - r, fmt, aq); va_end (aq); g_critical ("%s", logbuf); } void parse_warn (const gchar *fmt, ...) { va_list aq; gchar logbuf[BUFSIZ], readbuf[32]; gint r; va_start (aq, fmt); rspamd_strlcpy (readbuf, yytext, sizeof (readbuf)); r = snprintf (logbuf, sizeof (logbuf), "config file parse warning! line: %d, text: %s, reason: ", yylineno, readbuf); r += vsnprintf (logbuf + r, sizeof (logbuf) - r, fmt, aq); va_end (aq); g_warning ("%s", logbuf); } #endif void rspamd_config_unescape_quotes (gchar *line) { gchar *c = line, *t; while (*c) { if (*c == '\\' && *(c + 1) == '"') { t = c; while (*t) { *t = *(t + 1); t++; } } c++; } } GList * rspamd_config_parse_comma_list (rspamd_mempool_t * pool, const gchar *line) { GList *res = NULL; const gchar *c, *p; gchar *str; c = line; p = c; while (*p) { if (*p == ',' && *c != *p) { str = rspamd_mempool_alloc (pool, p - c + 1); rspamd_strlcpy (str, c, p - c + 1); res = g_list_prepend (res, str); /* Skip spaces */ while (g_ascii_isspace (*(++p))) ; c = p; continue; } p++; } if (res != NULL) { rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_list_free, res); } return res; } struct rspamd_classifier_config * rspamd_config_new_classifier (struct rspamd_config *cfg, struct rspamd_classifier_config *c) { if (c == NULL) { c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_classifier_config)); } if (c->labels == NULL) { c->labels = g_hash_table_new_full (rspamd_str_hash, rspamd_str_equal, NULL, (GDestroyNotify)g_list_free); rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, c->labels); } return c; } struct rspamd_statfile_config * rspamd_config_new_statfile (struct rspamd_config *cfg, struct rspamd_statfile_config *c) { if (c == NULL) { c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_statfile_config)); } return c; } void rspamd_config_init_metric (struct rspamd_config *cfg) { int i; cfg->grow_factor = 1.0; cfg->symbols = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); cfg->groups = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i++) { cfg->actions[i].score = NAN; cfg->actions[i].action = i; cfg->actions[i].priority = 0; } cfg->subject = SPAM_SUBJECT; rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, cfg->symbols); rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, cfg->groups); } struct rspamd_symbols_group * rspamd_config_new_group (struct rspamd_config *cfg, const gchar *name) { struct rspamd_symbols_group *gr; gr = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*gr)); gr->symbols = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_unref, gr->symbols); gr->name = rspamd_mempool_strdup (cfg->cfg_pool, name); g_hash_table_insert (cfg->groups, gr->name, gr); return gr; } static void rspamd_worker_conf_dtor (struct rspamd_worker_conf *wcf) { if (wcf) { ucl_object_unref (wcf->options); g_queue_free (wcf->active_workers); g_hash_table_unref (wcf->params); g_free (wcf); } } static void rspamd_worker_conf_cfg_fin (gpointer d) { struct rspamd_worker_conf *wcf = d; REF_RELEASE (wcf); } struct rspamd_worker_conf * rspamd_config_new_worker (struct rspamd_config *cfg, struct rspamd_worker_conf *c) { if (c == NULL) { c = g_malloc0 (sizeof (struct rspamd_worker_conf)); c->params = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); c->active_workers = g_queue_new (); #ifdef HAVE_SC_NPROCESSORS_ONLN c->count = MIN (DEFAULT_MAX_WORKERS, MAX (1, sysconf (_SC_NPROCESSORS_ONLN) - 2)); #else c->count = DEFAULT_MAX_WORKERS; #endif c->rlimit_nofile = 0; c->rlimit_maxcore = 0; c->enabled = TRUE; REF_INIT_RETAIN (c, rspamd_worker_conf_dtor); rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_worker_conf_cfg_fin, c); } return c; } static bool rspamd_include_map_handler (const guchar *data, gsize len, const ucl_object_t *args, void * ud) { struct rspamd_config *cfg = (struct rspamd_config *)ud; struct rspamd_ucl_map_cbdata *cbdata, **pcbdata; gchar *map_line; map_line = rspamd_mempool_alloc (cfg->cfg_pool, len + 1); rspamd_strlcpy (map_line, data, len + 1); cbdata = g_malloc (sizeof (struct rspamd_ucl_map_cbdata)); pcbdata = g_malloc (sizeof (struct rspamd_ucl_map_cbdata *)); cbdata->buf = NULL; cbdata->cfg = cfg; *pcbdata = cbdata; return rspamd_map_add (cfg, map_line, "ucl include", rspamd_ucl_read_cb, rspamd_ucl_fin_cb, (void **)pcbdata); } /* * Variables: * $CONFDIR - configuration directory * $LOCAL_CONFDIR - local configuration directory * $RUNDIR - local states directory * $DBDIR - databases dir * $LOGDIR - logs dir * $PLUGINSDIR - pluggins dir * $PREFIX - installation prefix * $VERSION - rspamd version */ #define RSPAMD_CONFDIR_MACRO "CONFDIR" #define RSPAMD_LOCAL_CONFDIR_MACRO "LOCAL_CONFDIR" #define RSPAMD_RUNDIR_MACRO "RUNDIR" #define RSPAMD_DBDIR_MACRO "DBDIR" #define RSPAMD_LOGDIR_MACRO "LOGDIR" #define RSPAMD_PLUGINSDIR_MACRO "PLUGINSDIR" #define RSPAMD_RULESDIR_MACRO "RULESDIR" #define RSPAMD_WWWDIR_MACRO "WWWDIR" #define RSPAMD_PREFIX_MACRO "PREFIX" #define RSPAMD_VERSION_MACRO "VERSION" #define RSPAMD_VERSION_MAJOR_MACRO "VERSION_MAJOR" #define RSPAMD_VERSION_MINOR_MACRO "VERSION_MINOR" #define RSPAMD_VERSION_PATCH_MACRO "VERSION_PATCH" #define RSPAMD_BRANCH_VERSION_MACRO "BRANCH_VERSION" void rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars) { GHashTableIter it; gpointer k, v; ucl_parser_register_variable (parser, RSPAMD_CONFDIR_MACRO, RSPAMD_CONFDIR); ucl_parser_register_variable (parser, RSPAMD_LOCAL_CONFDIR_MACRO, RSPAMD_LOCAL_CONFDIR); ucl_parser_register_variable (parser, RSPAMD_RUNDIR_MACRO, RSPAMD_RUNDIR); ucl_parser_register_variable (parser, RSPAMD_DBDIR_MACRO, RSPAMD_DBDIR); ucl_parser_register_variable (parser, RSPAMD_LOGDIR_MACRO, RSPAMD_LOGDIR); ucl_parser_register_variable (parser, RSPAMD_PLUGINSDIR_MACRO, RSPAMD_PLUGINSDIR); ucl_parser_register_variable (parser, RSPAMD_RULESDIR_MACRO, RSPAMD_RULESDIR); ucl_parser_register_variable (parser, RSPAMD_WWWDIR_MACRO, RSPAMD_WWWDIR); ucl_parser_register_variable (parser, RSPAMD_PREFIX_MACRO, RSPAMD_PREFIX); ucl_parser_register_variable (parser, RSPAMD_VERSION_MACRO, RVERSION); ucl_parser_register_variable (parser, RSPAMD_VERSION_MAJOR_MACRO, RSPAMD_VERSION_MAJOR); ucl_parser_register_variable (parser, RSPAMD_VERSION_MINOR_MACRO, RSPAMD_VERSION_MINOR); ucl_parser_register_variable (parser, RSPAMD_VERSION_PATCH_MACRO, RSPAMD_VERSION_PATCH); ucl_parser_register_variable (parser, RSPAMD_BRANCH_VERSION_MACRO, RSPAMD_VERSION_BRANCH); #if defined(WITH_TORCH) && defined(WITH_LUAJIT) && defined(__x86_64__) ucl_parser_register_variable (parser, "HAS_TORCH", "yes"); #else ucl_parser_register_variable (parser, "HAS_TORCH", "no"); #endif if (vars != NULL) { g_hash_table_iter_init (&it, vars); while (g_hash_table_iter_next (&it, &k, &v)) { ucl_parser_register_variable (parser, k, v); } } } void rspamd_ucl_add_conf_macros (struct ucl_parser *parser, struct rspamd_config *cfg) { ucl_parser_register_macro (parser, "include_map", rspamd_include_map_handler, cfg); } static void symbols_classifiers_callback (gpointer key, gpointer value, gpointer ud) { struct rspamd_config *cfg = ud; /* Actually, statistics should act like any ordinary symbol */ rspamd_symbols_cache_add_symbol (cfg->cache, key, 0, NULL, NULL, SYMBOL_TYPE_CLASSIFIER|SYMBOL_TYPE_NOSTAT, -1); } void rspamd_config_insert_classify_symbols (struct rspamd_config *cfg) { g_hash_table_foreach (cfg->classifiers_symbols, symbols_classifiers_callback, cfg); } struct rspamd_classifier_config * rspamd_config_find_classifier (struct rspamd_config *cfg, const gchar *name) { GList *cur; struct rspamd_classifier_config *cf; if (name == NULL) { return NULL; } cur = cfg->classifiers; while (cur) { cf = cur->data; if (g_ascii_strcasecmp (cf->name, name) == 0) { return cf; } cur = g_list_next (cur); } return NULL; } gboolean rspamd_config_check_statfiles (struct rspamd_classifier_config *cf) { struct rspamd_statfile_config *st; gboolean has_other = FALSE, res = FALSE, cur_class; GList *cur; /* First check classes directly */ cur = cf->statfiles; while (cur) { st = cur->data; if (!has_other) { cur_class = st->is_spam; has_other = TRUE; } else { if (cur_class != st->is_spam) { return TRUE; } } cur = g_list_next (cur); } if (!has_other) { /* We have only one statfile */ return FALSE; } /* We have not detected any statfile that has different class, so turn on euristic based on symbol's name */ has_other = FALSE; cur = cf->statfiles; while (cur) { st = cur->data; if (rspamd_substring_search_caseless (st->symbol, strlen (st->symbol),"spam", 4) != -1) { st->is_spam = TRUE; } else if (rspamd_substring_search_caseless (st->symbol, strlen (st->symbol),"ham", 3) != -1) { st->is_spam = FALSE; } if (!has_other) { cur_class = st->is_spam; has_other = TRUE; } else { if (cur_class != st->is_spam) { res = TRUE; } } cur = g_list_next (cur); } return res; } static gchar * rspamd_ucl_read_cb (gchar * chunk, gint len, struct map_cb_data *data, gboolean final) { struct rspamd_ucl_map_cbdata *cbdata = data->cur_data, *prev; if (cbdata == NULL) { cbdata = g_malloc (sizeof (struct rspamd_ucl_map_cbdata)); prev = data->prev_data; cbdata->buf = g_string_sized_new (BUFSIZ); cbdata->cfg = prev->cfg; data->cur_data = cbdata; } g_string_append_len (cbdata->buf, chunk, len); /* Say not to copy any part of this buffer */ return NULL; } static void rspamd_ucl_fin_cb (struct map_cb_data *data) { struct rspamd_ucl_map_cbdata *cbdata = data->cur_data, *prev = data->prev_data; ucl_object_t *obj; struct ucl_parser *parser; ucl_object_iter_t it = NULL; const ucl_object_t *cur; struct rspamd_config *cfg = data->map->cfg; if (prev != NULL) { if (prev->buf != NULL) { g_string_free (prev->buf, TRUE); } g_free (prev); } if (cbdata == NULL) { msg_err_config ("map fin error: new data is NULL"); return; } /* New data available */ parser = ucl_parser_new (0); if (!ucl_parser_add_chunk (parser, cbdata->buf->str, cbdata->buf->len)) { msg_err_config ("cannot parse map %s: %s", data->map->name, ucl_parser_get_error (parser)); ucl_parser_free (parser); } else { obj = ucl_parser_get_object (parser); ucl_parser_free (parser); it = NULL; while ((cur = ucl_object_iterate (obj, &it, true))) { ucl_object_replace_key (cbdata->cfg->rcl_obj, (ucl_object_t *)cur, cur->key, cur->keylen, false); } ucl_object_unref (obj); } } gboolean rspamd_check_module (struct rspamd_config *cfg, module_t *mod) { gboolean ret = TRUE; if (mod != NULL) { if (mod->module_version != RSPAMD_CUR_MODULE_VERSION) { msg_err_config ("module %s has incorrect version %xd (%xd expected)", mod->name, (gint)mod->module_version, RSPAMD_CUR_MODULE_VERSION); ret = FALSE; } if (ret && mod->rspamd_version != RSPAMD_VERSION_NUM) { msg_err_config ("module %s has incorrect rspamd version %xL (%xL expected)", mod->name, mod->rspamd_version, RSPAMD_VERSION_NUM); ret = FALSE; } if (ret && strcmp (mod->rspamd_features, RSPAMD_FEATURES) != 0) { msg_err_config ("module %s has incorrect rspamd features '%s' ('%s' expected)", mod->name, mod->rspamd_features, RSPAMD_FEATURES); ret = FALSE; } } else { ret = FALSE; } return ret; } gboolean rspamd_check_worker (struct rspamd_config *cfg, worker_t *wrk) { gboolean ret = TRUE; if (wrk != NULL) { if (wrk->worker_version != RSPAMD_CUR_WORKER_VERSION) { msg_err_config ("worker %s has incorrect version %xd (%xd expected)", wrk->name, wrk->worker_version, RSPAMD_CUR_WORKER_VERSION); ret = FALSE; } if (ret && wrk->rspamd_version != RSPAMD_VERSION_NUM) { msg_err_config ("worker %s has incorrect rspamd version %xL (%xL expected)", wrk->name, wrk->rspamd_version, RSPAMD_VERSION_NUM); ret = FALSE; } if (ret && strcmp (wrk->rspamd_features, RSPAMD_FEATURES) != 0) { msg_err_config ("worker %s has incorrect rspamd features '%s' ('%s' expected)", wrk->name, wrk->rspamd_features, RSPAMD_FEATURES); ret = FALSE; } } else { ret = FALSE; } return ret; } gboolean rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) { GList *cur; module_t *mod, **pmod; struct module_ctx *mod_ctx; /* Init all compiled modules */ if (!reconfig) { for (pmod = cfg->compiled_modules; pmod != NULL && *pmod != NULL; pmod ++) { mod = *pmod; if (rspamd_check_module (cfg, mod)) { mod_ctx = g_malloc0 (sizeof (struct module_ctx)); if (mod->module_init_func (cfg, &mod_ctx) == 0) { g_hash_table_insert (cfg->c_modules, (gpointer) mod->name, mod_ctx); mod_ctx->mod = mod; } } } } /* Now check what's enabled */ cur = g_list_first (cfg->filters); while (cur) { /* Perform modules configuring */ mod_ctx = g_hash_table_lookup (cfg->c_modules, cur->data); if (mod_ctx) { mod = mod_ctx->mod; mod_ctx->enabled = rspamd_config_is_module_enabled (cfg, mod->name); if (reconfig) { (void)mod->module_reconfig_func (cfg); msg_info_config ("reconfig of %s", mod->name); } else { (void)mod->module_config_func (cfg); } } if (mod_ctx == NULL) { msg_warn_config ("requested unknown module %s", cur->data); } cur = g_list_next (cur); } return rspamd_init_lua_filters (cfg, 0); } static void rspamd_config_new_symbol (struct rspamd_config *cfg, const gchar *symbol, gdouble score, const gchar *description, const gchar *group, guint flags, guint priority, gint nshots) { struct rspamd_symbols_group *sym_group; struct rspamd_symbol *sym_def; gdouble *score_ptr; sym_def = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_symbol)); score_ptr = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (gdouble)); *score_ptr = score; sym_def->score = score; sym_def->weight_ptr = score_ptr; sym_def->name = rspamd_mempool_strdup (cfg->cfg_pool, symbol); sym_def->priority = priority; sym_def->flags = flags; sym_def->nshots = nshots; if (description) { sym_def->description = rspamd_mempool_strdup (cfg->cfg_pool, description); } msg_debug_config ("registered symbol %s with weight %.2f in and group %s", sym_def->name, score, group); g_hash_table_insert (cfg->symbols, sym_def->name, sym_def); /* Search for symbol group */ if (group == NULL) { group = "ungrouped"; } if (strcmp (group, "ungrouped") == 0) { sym_def->flags |= RSPAMD_SYMBOL_FLAG_UNGROUPPED; } sym_group = g_hash_table_lookup (cfg->groups, group); if (sym_group == NULL) { /* Create new group */ sym_group = rspamd_config_new_group (cfg, group); } sym_def->gr = sym_group; g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def); } gboolean rspamd_config_add_symbol (struct rspamd_config *cfg, const gchar *symbol, gdouble score, const gchar *description, const gchar *group, guint flags, guint priority, gint nshots) { struct rspamd_symbol *sym_def; g_assert (cfg != NULL); g_assert (symbol != NULL); struct rspamd_symbols_group *sym_group; sym_def = g_hash_table_lookup (cfg->symbols, symbol); if (sym_def != NULL) { if (sym_def->flags & RSPAMD_SYMBOL_FLAG_UNGROUPPED && group != NULL) { /* Non-empty group has a priority over non-groupped one */ sym_group = g_hash_table_lookup (cfg->groups, group); if (sym_group == NULL) { /* Create new group */ sym_group = rspamd_config_new_group (cfg, group); } sym_def->gr = sym_group; g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def); sym_def->flags &= ~(RSPAMD_SYMBOL_FLAG_UNGROUPPED); } if (sym_def->priority > priority) { msg_debug_config ("symbol %s has been already registered with " "priority %ud, do not override (new priority: %ud)", symbol, sym_def->priority, priority); /* But we can still add description */ if (!sym_def->description && description) { sym_def->description = rspamd_mempool_strdup (cfg->cfg_pool, description); } return FALSE; } else { msg_debug_config ("symbol %s has been already registered with " "priority %ud, override it with new priority: %ud, " "old score: %.2f, new score: %.2f", symbol, sym_def->priority, priority, sym_def->score, score); *sym_def->weight_ptr = score; sym_def->score = score; sym_def->flags = flags; sym_def->nshots = nshots; if (description) { sym_def->description = rspamd_mempool_strdup (cfg->cfg_pool, description); } sym_def->priority = priority; /* We also check group information in this case */ if (group != NULL && sym_def->gr != NULL && strcmp (group, sym_def->gr->name) != 0) { msg_debug_config ("move symbol %s from group %s to %s", sym_def->gr->name, group); g_hash_table_remove (sym_def->gr->symbols, sym_def->name); sym_group = g_hash_table_lookup (cfg->groups, group); if (sym_group == NULL) { /* Create new group */ sym_group = rspamd_config_new_group (cfg, group); } sym_def->gr = sym_group; g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def); } return TRUE; } } rspamd_config_new_symbol (cfg, symbol, score, description, group, flags, priority, nshots); return TRUE; } gboolean rspamd_config_is_module_enabled (struct rspamd_config *cfg, const gchar *module_name) { gboolean is_c = FALSE; const ucl_object_t *conf, *enabled; GList *cur; struct rspamd_symbols_group *gr; lua_State *L = cfg->lua_state; if (g_hash_table_lookup (cfg->c_modules, module_name)) { is_c = TRUE; } if (g_hash_table_lookup (cfg->explicit_modules, module_name) != NULL) { /* Always load module */ rspamd_plugins_table_push_elt (L, "enabled", module_name); return TRUE; } if (is_c) { gboolean found = FALSE; cur = g_list_first (cfg->filters); while (cur) { if (strcmp (cur->data, module_name) == 0) { found = TRUE; break; } cur = g_list_next (cur); } if (!found) { msg_info_config ("internal module %s is disable in `filters` line", module_name); rspamd_plugins_table_push_elt (L, "disabled_explicitly", module_name); return FALSE; } } conf = ucl_object_lookup (cfg->rcl_obj, module_name); if (conf == NULL) { rspamd_plugins_table_push_elt (L, "disabled_unconfigured", module_name); msg_info_config ("%s module %s is enabled but has not been configured", is_c ? "internal" : "lua", module_name); if (!is_c) { msg_info_config ("%s disabling unconfigured lua module", module_name); return FALSE; } } else { enabled = ucl_object_lookup (conf, "enabled"); if (enabled) { if (ucl_object_type (enabled) == UCL_BOOLEAN) { if (!ucl_object_toboolean (enabled)) { rspamd_plugins_table_push_elt (L, "disabled_explicitly", module_name); msg_info_config ( "%s module %s is disabled in the configuration", is_c ? "internal" : "lua", module_name); return FALSE; } } else if (ucl_object_type (enabled) == UCL_STRING) { gint ret; ret = rspamd_config_parse_flag (ucl_object_tostring (enabled), 0); if (ret == 0) { rspamd_plugins_table_push_elt (L, "disabled_explicitly", module_name); msg_info_config ( "%s module %s is disabled in the configuration", is_c ? "internal" : "lua", module_name); return FALSE; } else if (ret == -1) { rspamd_plugins_table_push_elt (L, "disabled_failed", module_name); msg_info_config ( "%s module %s has wrong enabled flag (%s) in the configuration", is_c ? "internal" : "lua", module_name, ucl_object_tostring (enabled)); return FALSE; } } } } /* Now we check symbols group */ gr = g_hash_table_lookup (cfg->groups, module_name); if (gr) { if (gr->disabled) { rspamd_plugins_table_push_elt (L, "disabled_explicitly", module_name); msg_info_config ("%s module %s is disabled in the configuration as " "its group has been disabled", is_c ? "internal" : "lua", module_name); return FALSE; } } rspamd_plugins_table_push_elt (L, "enabled", module_name); return TRUE; } gboolean rspamd_config_set_action_score (struct rspamd_config *cfg, const gchar *action_name, gdouble score, guint priority) { struct rspamd_action *act; gint act_num; g_assert (cfg != NULL); g_assert (action_name != NULL); if (!rspamd_action_from_str (action_name, &act_num)) { msg_err_config ("invalid action name: %s", action_name); return FALSE; } g_assert (act_num >= METRIC_ACTION_REJECT && act_num < METRIC_ACTION_MAX); act = &cfg->actions[act_num]; if (isnan (act->score)) { act->score = score; act->priority = priority; } else { if (act->priority > priority) { msg_info_config ("action %s has been already registered with " "priority %ud, do not override (new priority: %ud)", action_name, act->priority, priority); return FALSE; } else { msg_info_config ("action %s has been already registered with " "priority %ud, override it with new priority: %ud, " "old score: %.2f, new score: %.2f", action_name, act->priority, priority, act->score, score); act->score = score; act->priority = priority; } } return TRUE; } gboolean rspamd_config_radix_from_ucl (struct rspamd_config *cfg, const ucl_object_t *obj, const gchar *description, struct rspamd_radix_map_helper **target, GError **err) { ucl_type_t type; ucl_object_iter_t it = NULL; const ucl_object_t *cur, *cur_elt; const gchar *str; LL_FOREACH (obj, cur_elt) { type = ucl_object_type (cur_elt); switch (type) { case UCL_STRING: /* Either map or a list of IPs */ str = ucl_object_tostring (cur_elt); if (rspamd_map_is_map (str)) { if (rspamd_map_add_from_ucl (cfg, cur_elt, description, rspamd_radix_read, rspamd_radix_fin, (void **)target) == NULL) { g_set_error (err, g_quark_from_static_string ("rspamd-config"), EINVAL, "bad map definition %s for %s", str, ucl_object_key (obj)); return FALSE; } } else { /* Just a list */ *target = rspamd_map_helper_new_radix (NULL); rspamd_map_helper_insert_radix_resolve (*target, str, ""); } break; case UCL_OBJECT: /* Should be a map description */ if (rspamd_map_add_from_ucl (cfg, cur_elt, description, rspamd_radix_read, rspamd_radix_fin, (void **)target) == NULL) { g_set_error (err, g_quark_from_static_string ("rspamd-config"), EINVAL, "bad map object for %s", ucl_object_key (obj)); return FALSE; } break; case UCL_ARRAY: /* List of IP addresses */ it = ucl_object_iterate_new (cur_elt); while ((cur = ucl_object_iterate_safe (it, true)) != NULL) { str = ucl_object_tostring (cur); if (!*target) { *target = rspamd_map_helper_new_radix (NULL); } rspamd_map_helper_insert_radix_resolve (*target, str, ""); } ucl_object_iterate_free (it); break; default: g_set_error (err, g_quark_from_static_string ("rspamd-config"), EINVAL, "bad map type %s for %s", ucl_object_type_to_string (type), ucl_object_key (obj)); return FALSE; } } return TRUE; } gboolean rspamd_action_from_str (const gchar *data, gint *result) { guint64 h; h = rspamd_cryptobox_fast_hash_specific (RSPAMD_CRYPTOBOX_XXHASH64, data, strlen (data), 0xdeadbabe); switch (h) { case 0x9917BFDB46332B8CULL: /* reject */ *result = METRIC_ACTION_REJECT; break; case 0x7130EE37D07B3715ULL: /* greylist */ *result = METRIC_ACTION_GREYLIST; break; case 0xCA6087E05480C60CULL: /* add_header */ case 0x87A3D27783B16241ULL: /* add header */ *result = METRIC_ACTION_ADD_HEADER; break; case 0x4963374ED8B90449ULL: /* rewrite_subject */ case 0x5C9FC4679C025948ULL: /* rewrite subject */ *result = METRIC_ACTION_REWRITE_SUBJECT; break; case 0xFC7D6502EE71FDD9ULL: /* soft reject */ case 0x73576567C262A82DULL: /* soft_reject */ *result = METRIC_ACTION_SOFT_REJECT; break; case 0x207091B927D1EC0DULL: /* no action */ case 0xB7D92D002CD46325ULL: /* no_action */ case 0x167C0DF4BAA9BCECULL: /* accept */ *result = METRIC_ACTION_NOACTION; break; default: return FALSE; } return TRUE; } const gchar * rspamd_action_to_str (enum rspamd_action_type action) { switch (action) { case METRIC_ACTION_REJECT: return "reject"; case METRIC_ACTION_SOFT_REJECT: return "soft reject"; case METRIC_ACTION_REWRITE_SUBJECT: return "rewrite subject"; case METRIC_ACTION_ADD_HEADER: return "add header"; case METRIC_ACTION_GREYLIST: return "greylist"; case METRIC_ACTION_NOACTION: return "no action"; case METRIC_ACTION_MAX: return "invalid max action"; } return "unknown action"; } const gchar * rspamd_action_to_str_alt (enum rspamd_action_type action) { switch (action) { case METRIC_ACTION_REJECT: return "reject"; case METRIC_ACTION_SOFT_REJECT: return "soft_reject"; case METRIC_ACTION_REWRITE_SUBJECT: return "rewrite_subject"; case METRIC_ACTION_ADD_HEADER: return "add_header"; case METRIC_ACTION_GREYLIST: return "greylist"; case METRIC_ACTION_NOACTION: return "no action"; case METRIC_ACTION_MAX: return "invalid max action"; } return "unknown action"; }