#include "fmt/core.h"
#include "libutil/cxx/util.hxx"
#include "libutil/cxx/file_util.hxx"
+#include "frozen/unordered_set.h"
+#include "frozen/string.h"
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
return rspamd_rcl_section_parse_defaults(cfg, *section, pool, obj, cfg, err);
}
-
+constexpr const auto known_worker_attributes = frozen::make_unordered_set<frozen::string>({
+ "bind_socket",
+ "listen",
+ "bind",
+ "count",
+ "max_files",
+ "max_core",
+ "enabled",
+});
static gboolean
rspamd_rcl_worker_handler(rspamd_mempool_t *pool, const ucl_object_t *obj,
const gchar *key, gpointer ud,
}
}
}
- else {
+ else if (known_worker_attributes.find(std::string_view{ucl_object_key(cur)}) == known_worker_attributes.end()) {
msg_warn_config("unknown worker attribute: %s; worker type: %s", ucl_object_key(cur), worker_type);
}
}
auto *cfg = static_cast<rspamd_config *>(ud);
auto lua_src = fs::path{ucl_object_tostring(obj)};
auto *L = RSPAMD_LUA_CFG_STATE(cfg);
- std::error_code ec1, ec2;
+ std::error_code ec1;
auto lua_dir = fs::weakly_canonical(lua_src.parent_path(), ec1);
- auto lua_file = fs::weakly_canonical(lua_src.filename(), ec2);
+ auto lua_file = lua_src.filename();
- if (ec1 && ec2 && !lua_dir.empty() && !lua_file.empty()) {
+ if (!ec1 && !lua_dir.empty() && !lua_file.empty()) {
auto cur_dir = fs::current_path(ec1);
- if (ec1 && !cur_dir.empty() && ::chdir(lua_dir.c_str()) != -1) {
+ if (!ec1 && !cur_dir.empty() && ::chdir(lua_dir.c_str()) != -1) {
/* Push traceback function */
lua_pushcfunction(L, &rspamd_lua_traceback);
auto err_idx = lua_gettop(L);
g_set_error(err, CFG_RCL_ERROR, ENOENT, "cannot chdir to %s: %s",
lua_dir.c_str(), strerror(errno));
if (::chdir(cur_dir.c_str()) == -1) {
- msg_err_config("cannot chdir to %s: %s", cur_dir.c_str(), strerror(errno));
+ msg_err_config("cannot chdir back to %s: %s", cur_dir.c_str(), strerror(errno));
}
return FALSE;
}
if (::chdir(cur_dir.c_str()) == -1) {
- msg_err_config("cannot chdir to %s: %s", cur_dir.c_str(), strerror(errno));
+ msg_err_config("cannot chdir back to %s: %s", cur_dir.c_str(), strerror(errno));
}
}
else {
auto add_single_file = [&](const fs::path &fpath) -> bool {
auto fname = fpath.filename();
+ auto modname = fname.string();
+
+ if (fname.has_extension()) {
+ modname = modname.substr(0, modname.size() - fname.extension().native().size());
+ }
auto *cur_mod = rspamd_mempool_alloc_type(cfg->cfg_pool,
struct script_module);
cur_mod->path = rspamd_mempool_strdup(cfg->cfg_pool, fpath.c_str());
- cur_mod->name = rspamd_mempool_strdup(cfg->cfg_pool, fname.c_str());
+ cur_mod->name = rspamd_mempool_strdup(cfg->cfg_pool, modname.c_str());
- if (sections->lua_modules_seen.contains(fname.string())) {
+ if (sections->lua_modules_seen.contains(modname)) {
msg_info_config("already seen module %s, skip %s",
cur_mod->name, cur_mod->path);
return false;
else {
/* Handle directory */
for (const auto &p: fs::recursive_directory_iterator(dir, ec)) {
- auto fpath = std::string_view{p.path().string()};
+ auto fpath = p.path().string();
if (p.is_regular_file() && fpath.ends_with(".lua")) {
add_single_file(p.path());
}
/* Section has been already processed */
return TRUE;
}
+
g_assert(obj != nullptr);
g_assert(sec.handler != nullptr);
- /* Set processed flag */
- sec.processed = true;
if (sec.key_attr) {
it = ucl_object_iterate_new(obj);
return;
}
- auto nhandler = handler_it.first->second;
+ auto &nhandler = handler_it.first->second;
nhandler.parser.flags = flags;
nhandler.parser.offset = offset;
nhandler.parser.user_struct = target;
{"symbols_scores_params", {RSPAMD_LOG_SYMBOLS, RSPAMD_LOG_FMT_FLAG_SYMBOLS_PARAMS | RSPAMD_LOG_FMT_FLAG_SYMBOLS_SCORES}},
{"groups", {RSPAMD_LOG_GROUPS, 0}},
{"public_groups", {RSPAMD_LOG_PUBLIC_GROUPS, 0}},
+ {"is_spam", {RSPAMD_LOG_ISSPAM, 0}},
});
static gboolean
if (opts & RSPAMD_CONFIG_INIT_SYMCACHE) {
/* Init config cache */
- ret &= rspamd_symcache_init(cfg->cache);
+ ret = rspamd_symcache_init(cfg->cache) && ret;
/* Init re cache */
rspamd_re_cache_init(cfg->re_cache, cfg);
if (opts & RSPAMD_CONFIG_INIT_LIBS) {
/* Config other libraries */
- ret &= rspamd_config_libs(cfg->libs_ctx, cfg);
+ ret = rspamd_config_libs(cfg->libs_ctx, cfg) && ret;
+
+ if (!ret) {
+ msg_err_config("cannot configure libraries, fatal error");
+ return FALSE;
+ }
}
/* Validate cache */
" Rspamd features will be broken");
}
- ret &= rspamd_symcache_validate(cfg->cache, cfg, FALSE);
+ ret = rspamd_symcache_validate(cfg->cache, cfg, FALSE) && ret;
}
if (opts & RSPAMD_CONFIG_INIT_POST_LOAD_LUA) {
if (wcf) {
struct rspamd_worker_bind_conf *cnf, *tmp;
- LL_FOREACH_SAFE(wcf->bind_conf, cnf, tmp)
- {
- g_ptr_array_free(cnf->addrs, TRUE);
- }
-
ucl_object_unref(wcf->options);
g_queue_free(wcf->active_workers);
g_hash_table_unref(wcf->params);
if (ctx != nullptr) {
if (cfg->local_addrs) {
+ GError *err = nullptr;
ret = rspamd_config_radix_from_ucl(cfg, cfg->local_addrs,
"Local addresses",
(struct rspamd_radix_map_helper **) ctx->local_addrs,
- nullptr,
+ &err,
nullptr, "local addresses");
+
+ if (!ret) {
+ msg_err_config("cannot load local addresses: %e", err);
+ g_error_free(err);
+
+ return ret;
+ }
}
rspamd_free_zstd_dictionary(ctx->in_dict);
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
if (*addrs == NULL) {
*addrs = g_ptr_array_new_full(1,
- (GDestroyNotify) rspamd_inet_address_free);
+ pool == NULL ? NULL : (GDestroyNotify) rspamd_inet_address_free);
if (pool != NULL) {
rspamd_mempool_add_destructor(pool,
}
if (v4_any) {
- cur_addr = rspamd_inet_addr_create(AF_INET, pool);
+ cur_addr = rspamd_inet_addr_create(AF_INET, NULL);
rspamd_parse_inet_address_ip4("0.0.0.0",
sizeof("0.0.0.0") - 1, &su.s4.sin_addr);
memcpy(&cur_addr->u.in.addr.s4.sin_addr, &su.s4.sin_addr,
g_ptr_array_add(*addrs, cur_addr);
}
if (v6_any) {
- cur_addr = rspamd_inet_addr_create(AF_INET6, pool);
+ cur_addr = rspamd_inet_addr_create(AF_INET6, NULL);
rspamd_parse_inet_address_ip6("::",
sizeof("::") - 1, &su.s6.sin6_addr);
memcpy(&cur_addr->u.in.addr.s6.sin6_addr, &su.s6.sin6_addr,