diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-12 15:14:35 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-12 15:14:35 +0000 |
commit | 56fdb79c495ab76cbde7cc7b12d3751b662fb9c4 (patch) | |
tree | 43fde227600ce7cd3036e12eb9799108fde399bd | |
parent | 7ea334cd83f09d7c7ad7f1795cbf702fd137979c (diff) | |
download | rspamd-56fdb79c495ab76cbde7cc7b12d3751b662fb9c4.tar.gz rspamd-56fdb79c495ab76cbde7cc7b12d3751b662fb9c4.zip |
Add external libraries context
-rw-r--r-- | src/libserver/cfg_file.h | 3 | ||||
-rw-r--r-- | src/libutil/util.c | 9 | ||||
-rw-r--r-- | src/libutil/util.h | 3 | ||||
-rw-r--r-- | src/rspamd.c | 3 | ||||
-rw-r--r-- | src/rspamd.h | 5 |
5 files changed, 20 insertions, 3 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 7036fd552..06e8372a0 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -25,6 +25,7 @@ struct tokenizer; struct rspamd_stat_classifier; struct module_s; struct worker_s; +struct rspamd_external_libs_ctx; enum { VAL_UNDEF=0, VAL_TRUE, VAL_FALSE }; @@ -314,6 +315,8 @@ struct rspamd_config { struct worker_s **compiled_workers; /**< list of compiled C modules */ struct rspamd_log_format *log_format; /**< parsed log format */ gchar *log_format_str; /**< raw log format string */ + + struct rspamd_external_libs_ctx *libs_ctx; /**< context for external libraries */ }; diff --git a/src/libutil/util.c b/src/libutil/util.c index 816d794dc..1a70f1b6f 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -1906,11 +1906,13 @@ rspamd_gstring_free_soft (gpointer p) g_string_free (ar, FALSE); } -void +struct rspamd_external_libs_ctx * rspamd_init_libs (void) { struct rlimit rlim; + struct rspamd_external_libs_ctx *ctx; + ctx = g_slice_alloc0 (sizeof (*ctx)); rspamd_cryptobox_init (); ottery_init (NULL); @@ -1949,6 +1951,11 @@ rspamd_init_libs (void) #else g_mime_init (0); #endif + ctx->libmagic = magic_open (MAGIC_MIME|MAGIC_NO_CHECK_COMPRESS| + MAGIC_NO_CHECK_ELF|MAGIC_NO_CHECK_TAR|MAGIC_NO_CHECK_TEXT); + magic_compile (ctx->libmagic, NULL); + + return ctx; } guint64 diff --git a/src/libutil/util.h b/src/libutil/util.h index 31e68a80a..f2156c60a 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -385,10 +385,11 @@ void rspamd_gstring_free_hard (gpointer p); */ void rspamd_gstring_free_soft (gpointer p); +struct rspamd_external_libs_ctx; /** * Initialize rspamd libraries */ -void rspamd_init_libs (void); +struct rspamd_external_libs_ctx* rspamd_init_libs (void); /** * Returns some statically initialized random hash seed diff --git a/src/rspamd.c b/src/rspamd.c index a079ab603..edaa5a52f 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -271,6 +271,7 @@ reread_config (struct rspamd_main *rspamd_main) tmp_cfg = (struct rspamd_config *)g_malloc0 (sizeof (struct rspamd_config)); tmp_cfg->c_modules = g_hash_table_ref (rspamd_main->cfg->c_modules); + tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx; rspamd_set_logger (tmp_cfg, g_quark_try_string ("main"), rspamd_main); rspamd_init_cfg (tmp_cfg, TRUE); cfg_file = rspamd_mempool_strdup (tmp_cfg->cfg_pool, @@ -817,7 +818,7 @@ main (gint argc, gchar **argv, gchar **env) init_title (argc, argv, env); #endif - rspamd_init_libs (); + rspamd_main->cfg->libs_ctx = rspamd_init_libs (); rspamd_init_cfg (rspamd_main->cfg, TRUE); memset (&signals, 0, sizeof (struct sigaction)); diff --git a/src/rspamd.h b/src/rspamd.h index 970046eb5..701efb9f8 100644 --- a/src/rspamd.h +++ b/src/rspamd.h @@ -19,6 +19,7 @@ #include "libserver/events.h" #include "libserver/roll_history.h" #include "libserver/task.h" +#include <magic.h> /* Default values */ @@ -229,6 +230,10 @@ struct controller_session { struct event_base *ev_base; /**< Event base */ }; +struct rspamd_external_libs_ctx { + magic_t libmagic; +}; + /** * Register custom controller function |