Skip to content

Commit

Permalink
[Minor] Archives: Distinguish compressed headers and encrypted archives
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed May 22, 2019
1 parent 83dfe58 commit 77d0030
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/libmime/archives.c
Expand Up @@ -1590,7 +1590,8 @@ rspamd_7zip_read_next_section (struct rspamd_task *task,
* In fact, headers are just packed, but we assume it as
* encrypted to distinguish from the normal archives
*/
arch->flags |= RSPAMD_ARCHIVE_ENCRYPTED;
msg_debug_archive ("7zip: encoded header, needs to be uncompressed");
arch->flags |= RSPAMD_ARCHIVE_CANNOT_READ;
p = NULL; /* Cannot get anything useful */
break;
case kArchiveProperties:
Expand Down
1 change: 1 addition & 0 deletions src/libmime/archives.h
Expand Up @@ -27,6 +27,7 @@ enum rspamd_archive_type {

enum rspamd_archive_flags {
RSPAMD_ARCHIVE_ENCRYPTED = (1u << 0u),
RSPAMD_ARCHIVE_CANNOT_READ = (1u << 1u),
};

enum rspamd_archive_file_flags {
Expand Down
18 changes: 18 additions & 0 deletions src/lua/lua_task.c
Expand Up @@ -1171,6 +1171,7 @@ LUA_FUNCTION_DEF (archive, get_type);
LUA_FUNCTION_DEF (archive, get_files);
LUA_FUNCTION_DEF (archive, get_files_full);
LUA_FUNCTION_DEF (archive, is_encrypted);
LUA_FUNCTION_DEF (archive, is_unreadable);
LUA_FUNCTION_DEF (archive, get_filename);
LUA_FUNCTION_DEF (archive, get_size);

Expand All @@ -1179,6 +1180,7 @@ static const struct luaL_reg archivelib_m[] = {
LUA_INTERFACE_DEF (archive, get_files),
LUA_INTERFACE_DEF (archive, get_files_full),
LUA_INTERFACE_DEF (archive, is_encrypted),
LUA_INTERFACE_DEF (archive, is_unreadable),
LUA_INTERFACE_DEF (archive, get_filename),
LUA_INTERFACE_DEF (archive, get_size),
{"__tostring", rspamd_lua_class_tostring},
Expand Down Expand Up @@ -5935,6 +5937,22 @@ lua_archive_is_encrypted (lua_State *L)
return 1;
}

static gint
lua_archive_is_unreadable (lua_State *L)
{
LUA_TRACE_POINT;
struct rspamd_archive *arch = lua_check_archive (L);

if (arch != NULL) {
lua_pushboolean (L, (arch->flags & RSPAMD_ARCHIVE_CANNOT_READ) ? true : false);
}
else {
return luaL_error (L, "invalid arguments");
}

return 1;
}

static gint
lua_archive_get_size (lua_State *L)
{
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/lua/mime_types.lua
Expand Up @@ -1037,13 +1037,20 @@ local function check_mime_type(task)
if ext and settings.archive_exceptions[ext] then
check = false
logger.debugm("mime_types", task, "skip checking of %s as archive, %s is whitelisted",
filename, ext)
filename, ext)
end
end
local arch = p:get_archive()

if arch:is_encrypted() then
task:insert_result(settings['symbol_encrypted_archive'], 1.0, filename)
task:insert_result(settings.symbol_encrypted_archive, 1.0, filename)
task:insert_result('MIME_TRACE', 0.0,
string.format("%s:%s", p:get_id(), '-'))
elseif arch:is_unreadable() then
task:insert_result(settings.symbol_encrypted_archive, 0.5, {
'compressed header',
filename,
})
task:insert_result('MIME_TRACE', 0.0,
string.format("%s:%s", p:get_id(), '-'))
end
Expand Down

0 comments on commit 77d0030

Please sign in to comment.