@@ -221,6 +221,7 @@ struct rspamd_config { | |||
gchar *pid_file; /**< name of pid file */ | |||
gchar *temp_dir; /**< dir for temp files */ | |||
gchar *control_socket_path; /**< path to the control socket */ | |||
gchar *local_addrs; /**< tree of local addresses */ | |||
#ifdef WITH_GPERF_TOOLS | |||
gchar *profile_path; | |||
#endif |
@@ -681,6 +681,9 @@ rspamd_config_post_load (struct rspamd_config *cfg, gboolean validate_cache) | |||
/* Init re cache */ | |||
rspamd_re_cache_init (cfg->re_cache, cfg); | |||
/* Config other libraries */ | |||
rspamd_config_libs (cfg->libs_ctx, cfg); | |||
/* Validate cache */ | |||
if (validate_cache) { | |||
return rspamd_symbols_cache_validate (cfg->cache, cfg, FALSE); |
@@ -26,7 +26,7 @@ | |||
#include "util.h" | |||
#include "logger.h" | |||
#include "xxhash.h" | |||
#include "radix.h" | |||
#include "unix-std.h" | |||
/* pwd and grp */ | |||
#ifdef HAVE_PWD_H | |||
@@ -37,6 +37,7 @@ | |||
#include <grp.h> | |||
#endif | |||
static radix_compressed_t *local_addrs; | |||
enum { | |||
RSPAMD_IPV6_UNDEFINED = 0, | |||
@@ -1355,7 +1356,27 @@ rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr) | |||
return TRUE; | |||
} | |||
} | |||
if (local_addrs) { | |||
if (radix_find_compressed_addr (local_addrs, addr) != RADIX_NO_VALUE) { | |||
return TRUE; | |||
} | |||
} | |||
} | |||
return FALSE; | |||
} | |||
void ** | |||
rspamd_inet_library_init (void) | |||
{ | |||
return (void **)&local_addrs; | |||
} | |||
void | |||
rspamd_inet_library_destroy (void) | |||
{ | |||
if (local_addrs != NULL) { | |||
radix_destroy_compressed (local_addrs); | |||
} | |||
} |
@@ -46,6 +46,9 @@ | |||
*/ | |||
typedef struct rspamd_inet_addr_s rspamd_inet_addr_t; | |||
void **rspamd_inet_library_init (void); | |||
void rspamd_inet_library_destroy (void); | |||
/** | |||
* Create new inet address structure based on the address familiy and opaque init pointer | |||
* @param af |
@@ -32,6 +32,7 @@ | |||
#include "xxhash.h" | |||
#include "ottery.h" | |||
#include "cryptobox.h" | |||
#include "libutil/map.h" | |||
#ifdef HAVE_OPENSSL | |||
#include <openssl/rand.h> | |||
@@ -1979,11 +1980,29 @@ rspamd_init_libs (void) | |||
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); | |||
return ctx; | |||
} | |||
void | |||
rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, | |||
struct rspamd_config *cfg) | |||
{ | |||
g_assert (ctx != NULL); | |||
g_assert (cfg != NULL); | |||
if (cfg->local_addrs) { | |||
if (!rspamd_map_add (cfg, cfg->local_addrs, | |||
"Local addresses", rspamd_radix_read, rspamd_radix_fin, | |||
(void **) ctx->local_addrs)) { | |||
radix_add_generic_iplist (cfg->local_addrs, | |||
(radix_compressed_t **)ctx->local_addrs); | |||
} | |||
} | |||
} | |||
void | |||
rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx) | |||
{ | |||
@@ -2000,6 +2019,7 @@ rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx) | |||
EVP_cleanup (); | |||
ERR_free_strings (); | |||
#endif | |||
rspamd_inet_library_destroy (); | |||
} | |||
} | |||
@@ -393,7 +393,13 @@ struct rspamd_external_libs_ctx; | |||
/** | |||
* Initialize rspamd libraries | |||
*/ | |||
struct rspamd_external_libs_ctx* rspamd_init_libs (void); | |||
struct rspamd_external_libs_ctx* rspamd_init_libs (); | |||
/** | |||
* Configure libraries | |||
*/ | |||
void rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, | |||
struct rspamd_config *cfg); | |||
/** | |||
* Destroy external libraries context |
@@ -191,6 +191,7 @@ struct controller_session { | |||
struct rspamd_external_libs_ctx { | |||
magic_t libmagic; | |||
void **local_addrs; | |||
ref_entry_t ref; | |||
}; | |||