aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-07-30 16:08:15 +0600
committerGitHub <noreply@github.com>2024-07-30 16:08:15 +0600
commite4e393aa663268fad7b1634e48524c0d800bdac9 (patch)
tree212d1f37bbfb45bc86d19ead98f73571e541cfa7 /src/libserver
parent7fc185c25b87e5059a15640cc2b23d829bf1871f (diff)
parent9395e3c03727a0a5902dccb49f49788bff9027d9 (diff)
downloadrspamd-vstakhov-fuzzy-tcp.tar.gz
rspamd-vstakhov-fuzzy-tcp.zip
Merge branch 'master' into vstakhov-fuzzy-tcpvstakhov-fuzzy-tcp
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/cfg_rcl.cxx11
-rw-r--r--src/libserver/cfg_utils.cxx52
-rw-r--r--src/libserver/spf.c5
-rw-r--r--src/libserver/spf.h2
4 files changed, 46 insertions, 24 deletions
diff --git a/src/libserver/cfg_rcl.cxx b/src/libserver/cfg_rcl.cxx
index ce3df4010..8a479fa6d 100644
--- a/src/libserver/cfg_rcl.cxx
+++ b/src/libserver/cfg_rcl.cxx
@@ -3623,7 +3623,8 @@ rspamd_config_parse_ucl(struct rspamd_config *cfg,
auto &cfg_file = cfg_file_maybe.value();
/* Try to load keyfile if available */
- rspamd::util::raii_file::open(fmt::format("{}.key", filename), O_RDONLY).map([&](const auto &keyfile) {
+ auto keyfile_name = fmt::format("{}.key", filename);
+ rspamd::util::raii_file::open(keyfile_name, O_RDONLY).map([&](const auto &keyfile) {
auto *kp_parser = ucl_parser_new(0);
if (ucl_parser_add_fd(kp_parser, keyfile.get_fd())) {
auto *kp_obj = ucl_parser_get_object(kp_parser);
@@ -3632,8 +3633,8 @@ rspamd_config_parse_ucl(struct rspamd_config *cfg,
decrypt_keypair = rspamd_keypair_from_ucl(kp_obj);
if (decrypt_keypair == nullptr) {
- msg_err_config_forced("cannot load keypair from %s.key: invalid keypair",
- filename);
+ msg_err_config_forced("cannot load keypair from %s: invalid keypair",
+ keyfile_name.c_str());
}
else {
/* Add decryption support to UCL */
@@ -3645,8 +3646,8 @@ rspamd_config_parse_ucl(struct rspamd_config *cfg,
ucl_object_unref(kp_obj);
}
else {
- msg_err_config_forced("cannot load keypair from %s.key: %s",
- filename, ucl_parser_get_error(kp_parser));
+ msg_err_config_forced("cannot load keypair from %s: %s",
+ keyfile_name.c_str(), ucl_parser_get_error(kp_parser));
}
ucl_parser_free(kp_parser);
});
diff --git a/src/libserver/cfg_utils.cxx b/src/libserver/cfg_utils.cxx
index dd85eddfb..1344bc4f9 100644
--- a/src/libserver/cfg_utils.cxx
+++ b/src/libserver/cfg_utils.cxx
@@ -57,7 +57,7 @@
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
-#include <math.h>
+#include <cmath>
#include "libserver/composites/composites.h"
#include "blas-config.h"
@@ -69,6 +69,7 @@
#include "cxx/util.hxx"
#include "frozen/unordered_map.h"
#include "frozen/string.h"
+#include "contrib/expected/expected.hpp"
#include "contrib/ankerl/unordered_dense.h"
#define DEFAULT_SCORE 10.0
@@ -135,14 +136,14 @@ struct rspamd_actions_list {
void sort()
{
std::sort(actions.begin(), actions.end(), [](const action_ptr &a1, const action_ptr &a2) -> bool {
- if (!isnan(a1->threshold) && !isnan(a2->threshold)) {
+ if (!std::isnan(a1->threshold) && !std::isnan(a2->threshold)) {
return a1->threshold < a2->threshold;
}
- if (isnan(a1->threshold) && isnan(a2->threshold)) {
+ if (std::isnan(a1->threshold) && std::isnan(a2->threshold)) {
return false;
}
- else if (isnan(a1->threshold)) {
+ else if (std::isnan(a1->threshold)) {
return true;
}
@@ -826,8 +827,7 @@ gboolean
rspamd_config_post_load(struct rspamd_config *cfg,
enum rspamd_post_load_options opts)
{
-
- auto ret = TRUE;
+ auto ret = tl::expected<void, std::string>{};
rspamd_adjust_clocks_resolution(cfg);
rspamd_logger_configure_modules(cfg->debug_modules);
@@ -867,14 +867,15 @@ rspamd_config_post_load(struct rspamd_config *cfg,
else {
if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
msg_err_config("no url_tld option has been specified");
- ret = FALSE;
+ ret = tl::make_unexpected(std::string{"no url_tld option has been specified"});
}
}
}
else {
if (access(cfg->tld_file, R_OK) == -1) {
if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
- ret = FALSE;
+ ret = tl::make_unexpected(fmt::format("cannot access tld file {}: {}",
+ cfg->tld_file, strerror(errno)));
msg_err_config("cannot access tld file %s: %s", cfg->tld_file,
strerror(errno));
}
@@ -905,13 +906,17 @@ rspamd_config_post_load(struct rspamd_config *cfg,
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_VALIDATE) {
- ret = FALSE;
+ ret = tl::make_unexpected(std::string{"cannot parse log format"});
}
}
if (opts & RSPAMD_CONFIG_INIT_SYMCACHE) {
/* Init config cache */
- ret = rspamd_symcache_init(cfg->cache) && ret;
+ auto symcache_ret = rspamd_symcache_init(cfg->cache);
+
+ if (!symcache_ret) {
+ ret = tl::make_unexpected(std::string{"symcache init failed"});
+ }
/* Init re cache */
rspamd_re_cache_init(cfg->re_cache, cfg);
@@ -928,9 +933,9 @@ rspamd_config_post_load(struct rspamd_config *cfg,
if (opts & RSPAMD_CONFIG_INIT_LIBS) {
/* Config other libraries */
- ret = rspamd_config_libs(cfg->libs_ctx, cfg) && ret;
+ auto libs_ret = rspamd_config_libs(cfg->libs_ctx, cfg);
- if (!ret) {
+ if (!libs_ret) {
msg_err_config("cannot configure libraries, fatal error");
return FALSE;
}
@@ -959,7 +964,11 @@ rspamd_config_post_load(struct rspamd_config *cfg,
" Rspamd features will be broken");
}
- ret = rspamd_symcache_validate(cfg->cache, cfg, FALSE) && ret;
+ auto val_ret = rspamd_symcache_validate(cfg->cache, cfg, FALSE);
+
+ if (!val_ret) {
+ ret = tl::make_unexpected(std::string{"symcache validation failed"});
+ }
}
if (opts & RSPAMD_CONFIG_INIT_POST_LOAD_LUA) {
@@ -970,7 +979,14 @@ rspamd_config_post_load(struct rspamd_config *cfg,
rspamd_map_preload(cfg);
}
- return ret;
+ if (ret) {
+ return true;
+ }
+ else {
+ msg_err_config("error on post-init stage: %s", ret.error().c_str());
+
+ return false;
+ }
}
struct rspamd_classifier_config *
@@ -1525,7 +1541,7 @@ rspamd_config_new_symbol(struct rspamd_config *cfg, const char *symbol,
rspamd_mempool_alloc0_type(cfg->cfg_pool, struct rspamd_symbol);
score_ptr = rspamd_mempool_alloc_type(cfg->cfg_pool, double);
- if (isnan(score)) {
+ if (std::isnan(score)) {
/* In fact, it could be defined later */
msg_debug_config("score is not defined for symbol %s, set it to zero",
symbol);
@@ -1636,7 +1652,7 @@ rspamd_config_add_symbol(struct rspamd_config *cfg,
}
if (sym_def->priority > priority &&
- (isnan(score) || !(sym_def->flags & RSPAMD_SYMBOL_FLAG_UNSCORED))) {
+ (std::isnan(score) || !(sym_def->flags & RSPAMD_SYMBOL_FLAG_UNSCORED))) {
msg_debug_config("symbol %s has been already registered with "
"priority %ud, do not override (new priority: %ud)",
symbol,
@@ -1657,7 +1673,7 @@ rspamd_config_add_symbol(struct rspamd_config *cfg,
}
else {
- if (!isnan(score)) {
+ if (!std::isnan(score)) {
msg_debug_config("symbol %s has been already registered with "
"priority %ud, override it with new priority: %ud, "
"old score: %.2f, new score: %.2f",
@@ -1997,7 +2013,7 @@ rspamd_config_action_from_ucl(struct rspamd_config *cfg,
/* TODO: add lua references support */
- if (isnan(threshold) && !(flags & RSPAMD_ACTION_NO_THRESHOLD)) {
+ if (std::isnan(threshold) && !(flags & RSPAMD_ACTION_NO_THRESHOLD)) {
msg_err_config("action %s has no threshold being set and it is not"
" a no threshold action",
act->name);
diff --git a/src/libserver/spf.c b/src/libserver/spf.c
index 32c020bf3..562222042 100644
--- a/src/libserver/spf.c
+++ b/src/libserver/spf.c
@@ -451,6 +451,9 @@ rspamd_spf_process_reference(struct spf_resolved *target,
target->flags |= RSPAMD_SPF_RESOLVED_NA;
continue;
}
+ if (cur->flags & RSPAMD_SPF_FLAG_PLUSALL) {
+ target->flags |= RSPAMD_SPF_RESOLVED_PLUSALL;
+ }
if (cur->flags & RSPAMD_SPF_FLAG_INVALID) {
/* Ignore invalid elements */
continue;
@@ -1418,7 +1421,7 @@ parse_spf_all(struct spf_record *rec, struct spf_addr *addr)
/* Disallow +all */
if (addr->mech == SPF_PASS) {
- addr->flags |= RSPAMD_SPF_FLAG_INVALID;
+ addr->flags |= RSPAMD_SPF_FLAG_PLUSALL;
msg_notice_spf("domain %s allows any SPF (+all), ignore SPF record completely",
rec->sender_domain);
}
diff --git a/src/libserver/spf.h b/src/libserver/spf.h
index cc0ee4c05..b89dc4d0e 100644
--- a/src/libserver/spf.h
+++ b/src/libserver/spf.h
@@ -77,6 +77,7 @@ typedef enum spf_action_e {
#define RSPAMD_SPF_FLAG_PERMFAIL (1u << 10u)
#define RSPAMD_SPF_FLAG_RESOLVED (1u << 11u)
#define RSPAMD_SPF_FLAG_CACHED (1u << 12u)
+#define RSPAMD_SPF_FLAG_PLUSALL (1u << 13u)
/** Default SPF limits for avoiding abuse **/
#define SPF_MAX_NESTING 10
@@ -104,6 +105,7 @@ enum rspamd_spf_resolved_flags {
RSPAMD_SPF_RESOLVED_TEMP_FAILED = (1u << 0u),
RSPAMD_SPF_RESOLVED_PERM_FAILED = (1u << 1u),
RSPAMD_SPF_RESOLVED_NA = (1u << 2u),
+ RSPAMD_SPF_RESOLVED_PLUSALL = (1u << 3u),
};
struct spf_resolved {