commit c371d29: [Minor] Fix issues found
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Dec 2 17:07:11 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-12-02 14:02:44 +0000
URL: https://github.com/rspamd/rspamd/commit/c371d29834610a065c0d41f4b39e04b05dc33f78
[Minor] Fix issues found
---
src/libserver/spf.c | 7 +++----
src/lua/lua_spf.c | 55 ++++++++++++++++++++++++++++++++-----------------
src/plugins/lua/spf.lua | 9 +++++++-
3 files changed, 47 insertions(+), 24 deletions(-)
diff --git a/src/libserver/spf.c b/src/libserver/spf.c
index 5fac43aa1..ec8decb50 100644
--- a/src/libserver/spf.c
+++ b/src/libserver/spf.c
@@ -2436,11 +2436,10 @@ rspamd_spf_resolve (struct rspamd_task *task, spf_cb_t callback,
if (cached) {
cached->flags |= RSPAMD_SPF_FLAG_CACHED;
- }
-
- callback (cached, task, cbdata);
+ callback (cached, task, cbdata);
- return TRUE;
+ return TRUE;
+ }
}
diff --git a/src/lua/lua_spf.c b/src/lua/lua_spf.c
index e6dc579d6..333f51bbf 100644
--- a/src/lua/lua_spf.c
+++ b/src/lua/lua_spf.c
@@ -54,6 +54,7 @@ static luaL_reg rspamd_spf_record_m[] = {
struct rspamd_lua_spf_cbdata {
struct rspamd_task *task;
lua_State *L;
+ struct rspamd_symcache_item *item;
gint cbref;
ref_entry_t ref;
};
@@ -153,6 +154,10 @@ lua_spf_dtor (struct rspamd_lua_spf_cbdata *cbd)
{
if (cbd) {
luaL_unref (cbd->L, LUA_REGISTRYINDEX, cbd->cbref);
+ if (cbd->item) {
+ rspamd_symcache_item_async_dec_check (cbd->task, cbd->item,
+ "lua_spf");
+ }
}
}
@@ -162,26 +167,36 @@ spf_lua_lib_callback (struct spf_resolved *record, struct rspamd_task *task,
{
struct rspamd_lua_spf_cbdata *cbd = (struct rspamd_lua_spf_cbdata *)ud;
- if (record && (record->flags & RSPAMD_SPF_RESOLVED_NA)) {
- lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_NA, record,
- "no record found");
- }
- else if (record && record->elts->len == 0 && (record->flags & RSPAMD_SPF_RESOLVED_TEMP_FAILED)) {
- lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_TEMP_FAILED, record,
- "temporary resolution error");
- }
- else if (record && record->elts->len == 0 && (record->flags & RSPAMD_SPF_RESOLVED_PERM_FAILED)) {
- lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_PERM_FAILED, record,
- "permanent resolution error");
- }
- else if (record && record->elts->len == 0) {
- lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_PERM_FAILED, record,
- "record is empty");
+ if (record) {
+ if ((record->flags & RSPAMD_SPF_RESOLVED_NA)) {
+ lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_NA, record,
+ "no record found");
+ }
+ else if (record->elts->len == 0 && (record->flags & RSPAMD_SPF_RESOLVED_TEMP_FAILED)) {
+ lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_TEMP_FAILED, record,
+ "temporary resolution error");
+ }
+ else if (record->elts->len == 0 && (record->flags & RSPAMD_SPF_RESOLVED_PERM_FAILED)) {
+ lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_PERM_FAILED, record,
+ "permanent resolution error");
+ }
+ else if (record->elts->len == 0) {
+ lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_PERM_FAILED, record,
+ "record is empty");
+ }
+ else if (record->domain) {
+ spf_record_ref (record);
+ lua_spf_push_result (cbd, record->flags, record, NULL);
+ spf_record_unref (record);
+ }
+ else {
+ lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_PERM_FAILED, record,
+ "internal error: non empty record for no domain");
+ }
}
- else if (record && record->domain) {
- spf_record_ref (record);
- lua_spf_push_result (cbd, record->flags, record, NULL);
- spf_record_unref (record);
+ else {
+ lua_spf_push_result (cbd, RSPAMD_SPF_RESOLVED_PERM_FAILED, NULL,
+ "internal error: no record");
}
REF_RELEASE (cbd);
@@ -209,6 +224,8 @@ lua_spf_resolve (lua_State * L)
cbd->cbref = luaL_ref (L, LUA_REGISTRYINDEX);
/* TODO: make it as an optional parameter */
spf_cred = rspamd_spf_get_cred (task);
+ cbd->item = rspamd_symcache_get_cur_item (task);
+ rspamd_symcache_item_async_inc (task, cbd->item, "lua_spf");
REF_INIT_RETAIN (cbd, lua_spf_dtor);
if (!rspamd_spf_resolve (task, spf_lua_lib_callback, cbd, spf_cred)) {
diff --git a/src/plugins/lua/spf.lua b/src/plugins/lua/spf.lua
index 26a47fdd8..2e4492b33 100644
--- a/src/plugins/lua/spf.lua
+++ b/src/plugins/lua/spf.lua
@@ -101,8 +101,15 @@ local function spf_check_callback(task)
end
local function spf_resolved_cb(record, flags, err)
+ lua_util.debugm(N, task, 'got spf results: %s flags, %s err',
+ flags, err)
if record then
- local result, flag_or_policy, error_or_addr = record:check_ip(task:get_from_ip())
+ local ip = task:get_from_ip()
+ local result, flag_or_policy, error_or_addr = record:check_ip(ip)
+
+ lua_util.debugm(N, task,
+ 'checked ip %s: result=%s, flag_or_policy=%s, error_or_addr=%s',
+ ip, flags, err, error_or_addr)
if result then
local sym,code = policy_decode(flag_or_policy)
More information about the Commits
mailing list