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')
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
/***
* @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);
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
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)
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