diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-14 16:52:33 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-14 16:52:33 +0100 |
commit | 7238b9cfe41d73d90979902f600e55d89908c831 (patch) | |
tree | 98d6bd55c6ecb1e8ef2d2abd49e72cff331861fb | |
parent | 98a7518f0b8f5bec20b5995ffcfde079b3fc8138 (diff) | |
download | rspamd-7238b9cfe41d73d90979902f600e55d89908c831.tar.gz rspamd-7238b9cfe41d73d90979902f600e55d89908c831.zip |
[Fix] Some fixes to libmagic initialization
-rw-r--r-- | src/controller.c | 1 | ||||
-rw-r--r-- | src/libserver/cfg_file.h | 2 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 8 | ||||
-rw-r--r-- | src/libutil/addr.c | 6 | ||||
-rw-r--r-- | src/libutil/addr.h | 2 | ||||
-rw-r--r-- | src/libutil/radix.c | 2 | ||||
-rw-r--r-- | src/libutil/util.c | 5 | ||||
-rw-r--r-- | src/lua/lua_ip.c | 8 | ||||
-rw-r--r-- | src/plugins/spf.c | 2 | ||||
-rw-r--r-- | src/rspamd.c | 4 |
10 files changed, 28 insertions, 12 deletions
diff --git a/src/controller.c b/src/controller.c index 13835ae77..1144441fd 100644 --- a/src/controller.c +++ b/src/controller.c @@ -2046,6 +2046,7 @@ rspamd_controller_handle_stat_common ( struct rspamd_task *task; struct rspamd_stat_cbdata *cbdata; + memset (&mem_st, 0, sizeof (mem_st)); rspamd_mempool_stat (&mem_st); memcpy (&stat_copy, session->ctx->worker->srv->stat, sizeof (stat_copy)); stat = &stat_copy; diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 9e946bfca..a44c2fc4a 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -370,6 +370,8 @@ struct rspamd_config { gchar * hs_cache_dir; /**< directory to save hyperscan databases */ + gchar * magic_file; /**< file to initialize libmagic */ + gdouble dns_timeout; /**< timeout in milliseconds for waiting for dns reply */ guint32 dns_retransmits; /**< maximum retransmits count */ guint32 dns_throttling_errors; /**< maximum errors for starting resolver throttling */ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index b4201fdd9..a099ccda3 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -93,7 +93,7 @@ rspamd_rcl_logging_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, GError **err) { const ucl_object_t *val; - const gchar *facility, *log_type, *log_level; + const gchar *facility = NULL, *log_type = NULL, *log_level = NULL; struct rspamd_config *cfg = ud; val = ucl_object_lookup (obj, "type"); @@ -1940,6 +1940,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg) G_STRUCT_OFFSET (struct rspamd_config, ssl_ciphers), 0, "List of ssl ciphers (e.g. HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4)"); + rspamd_rcl_add_default_handler (sub, + "magic_file", + rspamd_rcl_parse_struct_string, + G_STRUCT_OFFSET (struct rspamd_config, magic_file), + 0, + "Path to a custom libmagic file"); /* New DNS configuration */ ssub = rspamd_rcl_add_section_doc (&sub->subsections, "dns", NULL, NULL, UCL_OBJECT, FALSE, TRUE, diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 5d96472a0..a6aa8a878 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -1194,7 +1194,7 @@ rspamd_parse_host_port_priority (const gchar *str, } guchar* -rspamd_inet_address_get_radix_key (const rspamd_inet_addr_t *addr, guint *klen) +rspamd_inet_address_get_hash_key (const rspamd_inet_addr_t *addr, guint *klen) { guchar *res = NULL; static struct in_addr local = {INADDR_LOOPBACK}; @@ -1214,6 +1214,10 @@ rspamd_inet_address_get_radix_key (const rspamd_inet_addr_t *addr, guint *klen) *klen = sizeof (struct in_addr); res = (guchar *)&local; } + else { + *klen = 0; + res = NULL; + } return res; } diff --git a/src/libutil/addr.h b/src/libutil/addr.h index 1d400c5e4..e648a2b07 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -136,7 +136,7 @@ gint rspamd_inet_address_get_af (const rspamd_inet_addr_t *addr); * @param klen * @return */ -guchar * rspamd_inet_address_get_radix_key (const rspamd_inet_addr_t *addr, guint *klen); +guchar * rspamd_inet_address_get_hash_key (const rspamd_inet_addr_t *addr, guint *klen); /** * Receive data from an unconnected socket and fill the inet_addr structure if needed diff --git a/src/libutil/radix.c b/src/libutil/radix.c index 14ef21fbd..b165401f7 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -129,7 +129,7 @@ radix_find_compressed_addr (radix_compressed_t *tree, return RADIX_NO_VALUE; } - key = rspamd_inet_address_get_radix_key (addr, &klen); + key = rspamd_inet_address_get_hash_key (addr, &klen); if (key && klen) { return radix_find_compressed (tree, key, klen); diff --git a/src/libutil/util.c b/src/libutil/util.c index f87971980..6a60f854a 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -2069,7 +2069,6 @@ rspamd_init_libs (void) #endif ctx->libmagic = magic_open (MAGIC_MIME|MAGIC_NO_CHECK_COMPRESS| MAGIC_NO_CHECK_ELF|MAGIC_NO_CHECK_TAR); - magic_load (ctx->libmagic, NULL); ctx->local_addrs = rspamd_inet_library_init (); REF_INIT_RETAIN (ctx, rspamd_deinit_libs); @@ -2113,6 +2112,10 @@ rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, SSL_CTX_set_cipher_list (ctx->ssl_ctx, secure_ciphers); } } + + if (ctx->libmagic) { + magic_load (ctx->libmagic, cfg->magic_file); + } } } diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index 5dd85f4a8..97f75ddda 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -224,7 +224,7 @@ lua_ip_to_table (lua_State *L) if (ip != NULL && ip->addr) { lua_newtable (L); - ptr = rspamd_inet_address_get_radix_key (ip->addr, &max); + ptr = rspamd_inet_address_get_hash_key (ip->addr, &max); for (i = 1; i <= max; i++, ptr++) { lua_pushnumber (L, *ptr); @@ -250,7 +250,7 @@ lua_ip_str_octets (lua_State *L) if (ip != NULL && ip->addr) { lua_newtable (L); af = rspamd_inet_address_get_af (ip->addr); - ptr = rspamd_inet_address_get_radix_key (ip->addr, &max); + ptr = rspamd_inet_address_get_hash_key (ip->addr, &max); for (i = 1; i <= max; i++, ptr++) { if (af == AF_INET) { @@ -289,7 +289,7 @@ lua_ip_inversed_str_octets (lua_State *L) if (ip != NULL && ip->addr) { lua_newtable (L); - ptr = rspamd_inet_address_get_radix_key (ip->addr, &max); + ptr = rspamd_inet_address_get_hash_key (ip->addr, &max); af = rspamd_inet_address_get_af (ip->addr); ptr += max - 1; @@ -379,7 +379,7 @@ lua_ip_to_number (lua_State *L) guchar *ptr; if (ip != NULL && ip->addr) { - ptr = rspamd_inet_address_get_radix_key (ip->addr, &max); + ptr = rspamd_inet_address_get_hash_key (ip->addr, &max); for (i = 0; i < max / sizeof (c); i ++) { memcpy (&c, ptr + i * sizeof (c), sizeof (c)); diff --git a/src/plugins/spf.c b/src/plugins/spf.c index ec7540895..5dbc535e4 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -279,7 +279,7 @@ spf_check_element (struct spf_addr *addr, struct rspamd_task *task) /* Basic comparing algorithm */ if (((addr->flags & RSPAMD_SPF_FLAG_IPV6) && af == AF_INET6) || ((addr->flags & RSPAMD_SPF_FLAG_IPV4) && af == AF_INET)) { - d = rspamd_inet_address_get_radix_key (task->from_addr, &addrlen); + d = rspamd_inet_address_get_hash_key (task->from_addr, &addrlen); if (af == AF_INET6) { s = (const guint8 *)addr->addr6; diff --git a/src/rspamd.c b/src/rspamd.c index b45fa0229..c4aba793d 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -432,7 +432,7 @@ static inline uintptr_t make_listen_key (struct rspamd_worker_bind_conf *cf) { rspamd_cryptobox_fast_hash_state_t st; - guint i, keylen; + guint i, keylen = 0; guint8 *key; rspamd_inet_addr_t *addr; guint16 port; @@ -446,7 +446,7 @@ make_listen_key (struct rspamd_worker_bind_conf *cf) rspamd_cryptobox_fast_hash_update (&st, cf->name, strlen (cf->name)); for (i = 0; i < cf->cnt; i ++) { addr = g_ptr_array_index (cf->addrs, i); - key = rspamd_inet_address_get_radix_key ( + key = rspamd_inet_address_get_hash_key ( addr, &keylen); rspamd_cryptobox_fast_hash_update (&st, key, keylen); port = rspamd_inet_address_get_port (addr); |