]> source.dussan.org Git - rspamd.git/commitdiff
Add external libraries context
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 12 Nov 2015 15:14:35 +0000 (15:14 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 12 Nov 2015 15:14:35 +0000 (15:14 +0000)
src/libserver/cfg_file.h
src/libutil/util.c
src/libutil/util.h
src/rspamd.c
src/rspamd.h

index 7036fd5526cf57e500d635eb2ecbde6b5808da9a..06e8372a019a900cade0a92423d4e87ae031291b 100644 (file)
@@ -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                                             */
 };
 
 
index 816d794dcf8ba3e3adabf3f3e4a7b54c3e6ae21e..1a70f1b6f676c4d92af1e91304eecb26ef7bada9 100644 (file)
@@ -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
index 31e68a80a8baa321f1c20e93f2d7a1ae7811e631..f2156c60a29ff9b5509f6584dce4fc7f690bdee9 100644 (file)
@@ -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
index a079ab603236a521f813a4ebd88d667fa1dc5ab3..edaa5a52fa416a44ac394950fe28583dc0145dc9 100644 (file)
@@ -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));
index 970046eb57ded4faba40f6074e3f4596310d248e..701efb9f8118333868e3f872ef2e7c1ce02a3704 100644 (file)
@@ -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