diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-06-11 11:32:43 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-06-11 11:32:43 +0100 |
commit | 0e654a69f908ae3abe19663dc192f1dbc45d8ed0 (patch) | |
tree | e6802c0328f8a352dbfb1bd5986b66902a9294ba | |
parent | a028e5973813023f29c740a0b857fa32ce1c51fb (diff) | |
download | rspamd-0e654a69f908ae3abe19663dc192f1dbc45d8ed0.tar.gz rspamd-0e654a69f908ae3abe19663dc192f1dbc45d8ed0.zip |
[Feature] Improve error reporting for DKIM key access issues
-rw-r--r-- | rules/rspamd.lua | 17 | ||||
-rw-r--r-- | src/lua/lua_util.c | 15 | ||||
-rw-r--r-- | src/plugins/lua/arc.lua | 10 | ||||
-rw-r--r-- | src/plugins/lua/dkim_signing.lua | 10 |
4 files changed, 32 insertions, 20 deletions
diff --git a/rules/rspamd.lua b/rules/rspamd.lua index 6b53828ee..a193eb495 100644 --- a/rules/rspamd.lua +++ b/rules/rspamd.lua @@ -23,6 +23,7 @@ rspamd_maps = {} -- Global maps local local_conf = rspamd_paths['CONFDIR'] local local_rules = rspamd_paths['RULESDIR'] +local rspamd_util = require "rspamd_util" dofile(local_rules .. '/regexp/headers.lua') dofile(local_rules .. '/regexp/misc.lua') @@ -36,26 +37,16 @@ dofile(local_rules .. '/http_headers.lua') dofile(local_rules .. '/forwarding.lua') dofile(local_rules .. '/mid.lua') -local function file_exists(filename) - local file = io.open(filename) - if file then - io.close(file) - return true - else - return false - end -end - -if file_exists(local_conf .. '/rspamd.local.lua') then +if rspamd_util.file_exists(local_conf .. '/rspamd.local.lua') then dofile(local_conf .. '/rspamd.local.lua') else -- Legacy lua/rspamd.local.lua - if file_exists(local_conf .. '/lua/rspamd.local.lua') then + if rspamd_util.file_exists(local_conf .. '/lua/rspamd.local.lua') then dofile(local_conf .. '/lua/rspamd.local.lua') end end -if file_exists(local_rules .. '/rspamd.classifiers.lua') then +if rspamd_util.file_exists(local_rules .. '/rspamd.classifiers.lua') then dofile(local_rules .. '/rspamd.classifiers.lua') end diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index f99ae7d1f..063a7aab7 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -414,7 +414,7 @@ LUA_FUNCTION_DEF (util, readpassphrase); /*** * @function util.file_exists(file) * Checks if a specified file exists and is available for reading - * @return {boolean} true if file exists + * @return {boolean,string} true if file exists + string error if not */ LUA_FUNCTION_DEF (util, file_exists); @@ -2399,15 +2399,24 @@ static gint lua_util_file_exists (lua_State *L) { const gchar *fname = luaL_checkstring (L, 1); + gint serrno; if (fname) { - lua_pushboolean (L, access (fname, R_OK) != -1); + if (access (fname, R_OK) == -1) { + serrno = errno; + lua_pushboolean (L, false); + lua_pushstring (L, strerror (serrno)); + } + else { + lua_pushboolean (L, true); + lua_pushnil (L); + } } else { return luaL_error (L, "invalid arguments"); } - return 1; + return 2; } static gint diff --git a/src/plugins/lua/arc.lua b/src/plugins/lua/arc.lua index b240b3b3c..83b02c32e 100644 --- a/src/plugins/lua/arc.lua +++ b/src/plugins/lua/arc.lua @@ -510,10 +510,16 @@ local function arc_signing_cb(task) else if (p.key and p.selector) then p.key = lua_util.template(p.key, {domain = p.domain, selector = p.selector}) - if not rspamd_util.file_exists(p.key) then - rspamd_logger.debugm(N, task, 'file %s does not exists', p.key) + local exists,err = rspamd_util.file_exists(p.key) + if not exists then + if err and err == 'No such file or directory' then + rspamd_logger.debugm(N, task, 'cannot read key from %s: %s', p.key, err) + else + rspamd_logger.warnx(N, task, 'cannot read key from %s: %s', p.key, err) + end return false end + local dret, hdr = dkim_sign(task, p) if dret then return arc_sign_seal(task, p, hdr) diff --git a/src/plugins/lua/dkim_signing.lua b/src/plugins/lua/dkim_signing.lua index 9b8f0a047..5e057cf9e 100644 --- a/src/plugins/lua/dkim_signing.lua +++ b/src/plugins/lua/dkim_signing.lua @@ -117,10 +117,16 @@ local function dkim_signing_cb(task) else if (p.key and p.selector) then p.key = lutil.template(p.key, {domain = p.domain, selector = p.selector}) - if not rspamd_util.file_exists(p.key) then - rspamd_logger.debugm(N, task, 'file %s does not exists', p.key) + local exists,err = rspamd_util.file_exists(p.key) + if not exists then + if err and err == 'No such file or directory' then + rspamd_logger.debugm(N, task, 'cannot read key from %s: %s', p.key, err) + else + rspamd_logger.warnx(N, task, 'cannot read key from %s: %s', p.key, err) + end return false end + local sret, _ = sign_func(task, p) return sret else |