]> source.dussan.org Git - rspamd.git/commitdiff
Add local addrs extension available in the conviguration
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 3 Jan 2016 17:00:56 +0000 (17:00 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 3 Jan 2016 17:13:24 +0000 (17:13 +0000)
src/libserver/cfg_file.h
src/libserver/cfg_utils.c
src/libutil/addr.c
src/libutil/addr.h
src/libutil/util.c
src/libutil/util.h
src/rspamd.h

index 96c4fb10b8e77467236a1b34015edd9cf01e31be..1dfd3419e257961185454ae62b15d3737e54897a 100644 (file)
@@ -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
index 07d9ae44dde721277f5d3ce3dd939d84c9dfc242..32651dd20d2f4a09d019ba243a4d9c564f962748 100644 (file)
@@ -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);
index f301c724e3b19a5e1541453054214abb8ddaf9e6..d8dec0b97929f997230df87b1ef3bbd5c80db854 100644 (file)
@@ -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);
+       }
+}
index 36f9910fdcf5b99edda1fc1aa42a1c52e7dfe295..b2075f7f0dd488cd68fb1c3a3e7d0ad3e7c9a324 100644 (file)
@@ -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
index a3b89131ccc3b9424da441eba3ad4e6e9614468c..994f475b9b1d1b34c7223d21325cfae9fdecede7 100644 (file)
@@ -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 ();
        }
 }
 
index ab1d205c10f51d4c11957cdb72b6fa9b326b8498..28a6827b2278693b2d03a78b70789f313e19d8e4 100644 (file)
@@ -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
index a2a442a1f2fcdf49e500b96025683426778c68ba..6126b17a765ab89a1e188563923f07c16a735866 100644 (file)
@@ -191,6 +191,7 @@ struct controller_session {
 
 struct rspamd_external_libs_ctx {
        magic_t libmagic;
+       void **local_addrs;
        ref_entry_t ref;
 };