aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-12 09:48:39 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-12 09:48:39 +0000
commit1a82c5b056ead9a2ce36a01bd816c192257cacab (patch)
tree23c8dce2935f926780a9e5db5614ce52b6692538 /src/plugins
parent9e778d2623681675b55438fa8b3778b16a972274 (diff)
downloadrspamd-1a82c5b056ead9a2ce36a01bd816c192257cacab.tar.gz
rspamd-1a82c5b056ead9a2ce36a01bd816c192257cacab.zip
[Minor] Add full_domain option to surbl
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/surbl.c115
1 files changed, 73 insertions, 42 deletions
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 71f07a604..e5080b864 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -73,6 +73,7 @@ static const gchar *M = "surbl";
#define SURBL_OPTION_RESOLVEIP (1 << 1)
#define SURBL_OPTION_CHECKIMAGES (1 << 2)
#define SURBL_OPTION_CHECKDKIM (1 << 3)
+#define SURBL_OPTION_FULLDOMAIN (1 << 4)
#define MAX_LEVELS 10
struct surbl_ctx {
@@ -599,6 +600,15 @@ surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
0,
NULL,
0);
+ rspamd_rcl_add_doc_by_path (cfg,
+ "surbl.rule",
+ "Check full domain name instead of eSLD",
+ "full_domain",
+ UCL_BOOLEAN,
+ NULL,
+ 0,
+ NULL,
+ 0);
return 0;
}
@@ -805,6 +815,13 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg)
}
}
+ cur = ucl_object_lookup (cur_rule, "full_domain");
+ if (cur != NULL && cur->type == UCL_BOOLEAN) {
+ if (ucl_object_toboolean (cur)) {
+ new_suffix->options |= SURBL_OPTION_FULLDOMAIN;
+ }
+ }
+
if ((new_suffix->options & (SURBL_OPTION_RESOLVEIP | SURBL_OPTION_NOIP))
== (SURBL_OPTION_NOIP | SURBL_OPTION_RESOLVEIP)) {
/* Mutually exclusive options */
@@ -1279,62 +1296,76 @@ format_surbl_request (rspamd_mempool_t * pool,
else {
/* Not a numeric url */
result = rspamd_mempool_alloc (pool, len);
- /* Now we should try to check for exceptions */
- if (!forced && surbl_module_ctx->exceptions) {
- for (i = MAX_LEVELS - 1; i >= 0; i--) {
- t = surbl_module_ctx->exceptions[i];
- if (t != NULL && dots_num >= i + 1) {
- f.begin = dots[dots_num - i - 1] + 1;
- f.len = hostname->len -
- (dots[dots_num - i - 1] - hostname->begin + 1);
- if (g_hash_table_lookup (t, &f) != NULL) {
- level = dots_num - i - 1;
- found_exception = TRUE;
- break;
+
+ if (suffix->options & SURBL_OPTION_FULLDOMAIN) {
+ /* Full domain case */
+ r = rspamd_snprintf (result,
+ len,
+ "%*s",
+ url->hostlen,
+ url->host);
+ }
+ else {
+ /* Now we should try to check for exceptions */
+ if (!forced && surbl_module_ctx->exceptions) {
+ for (i = MAX_LEVELS - 1; i >= 0; i--) {
+ t = surbl_module_ctx->exceptions[i];
+ if (t != NULL && dots_num >= i + 1) {
+ f.begin = dots[dots_num - i - 1] + 1;
+ f.len = hostname->len -
+ (dots[dots_num - i - 1] - hostname->begin + 1);
+ if (g_hash_table_lookup (t, &f) != NULL) {
+ level = dots_num - i - 1;
+ found_exception = TRUE;
+ break;
+ }
}
}
}
- }
- if (found_exception || url->tldlen == 0) {
- if (level != MAX_LEVELS) {
- if (level == 0) {
+ if (found_exception || url->tldlen == 0) {
+ if (level != MAX_LEVELS) {
+ if (level == 0) {
+ r = rspamd_snprintf (result,
+ len,
+ "%T",
+ hostname);
+ }
+ else {
+ r = rspamd_snprintf (result, len, "%*s",
+ (gint) (hostname->len -
+ (dots[level - 1] - hostname->begin + 1)),
+ dots[level - 1] + 1);
+ }
+ }
+ else if (dots_num >= 2) {
+ r = rspamd_snprintf (result, len, "%*s",
+ (gint) (hostname->len -
+ (dots[dots_num - 2] - hostname->begin + 1)),
+ dots[dots_num - 2] + 1);
+ }
+ else {
r = rspamd_snprintf (result,
len,
"%T",
hostname);
}
- else {
- r = rspamd_snprintf (result, len, "%*s",
- (gint)(hostname->len -
- (dots[level - 1] - hostname->begin + 1)),
- dots[level - 1] + 1);
- }
- }
- else if (dots_num >= 2) {
- r = rspamd_snprintf (result, len, "%*s",
- (gint)(hostname->len -
- (dots[dots_num - 2] - hostname->begin + 1)),
- dots[dots_num - 2] + 1);
}
else {
+ /* No exception */
r = rspamd_snprintf (result,
len,
- "%T",
- hostname);
- }
- }
- else {
- r = rspamd_snprintf (result,
- len,
"%*s",
url->tldlen,
url->tld);
+ }
}
}
- url->surbl = result;
- url->surbllen = r;
+ if (url->surbl == NULL) {
+ url->surbl = result;
+ url->surbllen = r;
+ }
if (!forced &&
rspamd_match_hash_map (surbl_module_ctx->whitelist, result) != NULL) {
@@ -1383,11 +1414,11 @@ format_surbl_request (rspamd_mempool_t * pool,
}
msg_debug_pool ("request: %s, dots: %d, level: %d, orig: %*s",
- result,
- dots_num,
- level,
- (gint)hostname->len,
- hostname->begin);
+ result,
+ dots_num,
+ level,
+ (gint)hostname->len,
+ hostname->begin);
return result;
}