]> source.dussan.org Git - rspamd.git/commitdiff
Move PRNG seeding function to the util set.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Dec 2013 21:17:57 +0000 (21:17 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 9 Dec 2013 21:17:57 +0000 (21:17 +0000)
src/main.c
src/util.c
src/util.h

index 11da41921c59829de172180a05dd0871afba02f6..7bbe6319909dfb45d45e96bfaaae2df542b0bf71 100644 (file)
@@ -991,10 +991,6 @@ main (gint argc, gchar **argv, gchar **env)
        GList                           *l;
        worker_t                       **pworker;
        GQuark                           type;
-#ifdef HAVE_OPENSSL
-       gchar                            rand_bytes[sizeof (guint32)];
-       guint32                          rand_seed;
-#endif
 
 #ifdef HAVE_SA_SIGINFO
        signals_info = g_queue_new ();
@@ -1049,21 +1045,13 @@ main (gint argc, gchar **argv, gchar **env)
 #ifdef HAVE_OPENSSL
        ERR_load_crypto_strings ();
 
-       /* Init random generator */
-       if (RAND_bytes (rand_bytes, sizeof (rand_bytes)) != 1) {
-               msg_err ("cannot seed random generator using openssl: %s, using time", ERR_error_string (ERR_get_error (), NULL));
-               g_random_set_seed (time (NULL));
-       }
-       else {
-               memcpy (&rand_seed, rand_bytes, sizeof (guint32));
-               g_random_set_seed (rand_seed);
-       }
-
        OpenSSL_add_all_algorithms ();
        OpenSSL_add_all_digests ();
        OpenSSL_add_all_ciphers ();
 #endif
 
+       rspamd_prng_seed ();
+
        /* First set logger to console logger */
        rspamd_set_logger (RSPAMD_LOG_CONSOLE, type, rspamd_main);
        (void)open_log (rspamd_main->logger);
index bc220657975ff80f4448a7de78ef869fa58b15ed..53d73b53a89224a748be8f96c813ef837e63b468 100644 (file)
 #include "filter.h"
 #include "message.h"
 
+#ifdef HAVE_OPENSSL
+#include <openssl/rand.h>
+#include <openssl/err.h>
+#endif
+
 /* Check log messages intensity once per minute */
 #define CHECK_TIME 60
 /* More than 2 log messages per second */
@@ -2386,6 +2391,30 @@ restart:
        return p - buf;
 #endif
 }
+
+void
+rspamd_prng_seed (void)
+{
+       guint32                          rand_seed = 0;
+#ifdef HAVE_OPENSSL
+       gchar                            rand_bytes[sizeof (guint32)];
+
+       /* Init random generator */
+       if (RAND_bytes (rand_bytes, sizeof (rand_bytes)) != 1) {
+               msg_err ("cannot seed random generator using openssl: %s, using time",
+                               ERR_error_string (ERR_get_error (), NULL));
+               rand_seed = time (NULL);
+       }
+       else {
+               memcpy (&rand_seed, rand_bytes, sizeof (guint32));
+       }
+#else
+       rand_seed = time (NULL);
+#endif
+
+       g_random_set_seed (rand_seed);
+}
+
 /*
  * vi:ts=4
  */
index f2b7132af0151026e2ace210d54ddf7479d674e9..4edf5cb9560a8aea196669cb23b47608cd87ba1a 100644 (file)
@@ -440,16 +440,8 @@ time_t parse_http_date (const gchar *header, gsize len);
 gint rspamd_read_passphrase (gchar *buf, gint size, gint rwflag, gpointer key);
 
 /**
- * Expand path that may contain configuration variables:
- * $CONFDIR - configuration directory
- * $RUNDIR - local states directory
- * $DBDIR - databases dir
- * $LOGDIR - logs dir
- * $PLUGINSDIR - plugins dir
- * $PREFIX - installation prefix
- * $VERSION - rspamd version
- * @param pool to use
- * @param path path to expand
+ * Seed glib prng using openssl if possible
  */
+void rspamd_prng_seed (void);
 
 #endif