#include "libutil/util.h"
#include "libserver/http/http_connection.h"
#include "libserver/http/http_private.h"
+#include "libserver/cfg_file.h"
#include "rspamdclient.h"
#include "utlist.h"
#include "unix-std.h"
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
-/* Copy to avoid linking with librspamdserver */
-enum rspamd_action_type {
- METRIC_ACTION_REJECT = 0,
- METRIC_ACTION_SOFT_REJECT,
- METRIC_ACTION_REWRITE_SUBJECT,
- METRIC_ACTION_ADD_HEADER,
- METRIC_ACTION_GREYLIST,
- METRIC_ACTION_NOACTION,
- METRIC_ACTION_MAX
-};
-
static void rspamc_symbols_output (FILE *out, ucl_object_t *obj);
static void rspamc_uptime_output (FILE *out, ucl_object_t *obj);
static void rspamc_counters_output (FILE *out, ucl_object_t *obj);
*/
void rspamd_deinit_libs (struct rspamd_external_libs_ctx *ctx);
+/**
+ * Returns TRUE if an address belongs to some local address
+ */
+gboolean rspamd_ip_is_local_cfg (struct rspamd_config *cfg,
+ const rspamd_inet_addr_t *addr);
+
/**
* Configure libraries
*/
g_free (ctx);
}
-}
\ No newline at end of file
+}
+
+gboolean
+rspamd_ip_is_local_cfg (struct rspamd_config *cfg,
+ const rspamd_inet_addr_t *addr)
+{
+ struct rspamd_radix_map_helper *local_addrs = NULL;
+
+ if (cfg && cfg->libs_ctx) {
+ local_addrs = *(struct rspamd_radix_map_helper**)cfg->libs_ctx->local_addrs;
+ }
+
+ if (rspamd_inet_address_is_local (addr)) {
+ return TRUE;
+ }
+
+ if (local_addrs) {
+ if (rspamd_match_radix_map_addr (local_addrs, addr) != NULL) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
#include "config.h"
#include "addr.h"
#include "util.h"
-/*
- * TODO: fix this cross dependency!
- */
-#include "libserver/maps/map_helpers.h"
#include "logger.h"
#include "cryptobox.h"
#include "unix-std.h"
#include <grp.h>
#endif
-static struct rspamd_radix_map_helper *local_addrs;
+static void *local_addrs;
enum {
RSPAMD_IPV6_UNDEFINED = 0,
#endif
gboolean
-rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr,
- gboolean check_laddrs)
+rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr)
{
if (addr == NULL) {
return FALSE;
return TRUE;
}
}
-
- if (check_laddrs && local_addrs) {
- if (rspamd_match_radix_map_addr (local_addrs, addr) != NULL) {
- return TRUE;
- }
- }
}
return FALSE;
}
-struct rspamd_radix_map_helper **
+void **
rspamd_inet_library_init (void)
{
return &local_addrs;
}
+void *
+rspamd_inet_library_get_lib_ctx (void)
+{
+ return local_addrs;
+}
+
void
rspamd_inet_library_destroy (void)
{
*/
typedef struct rspamd_inet_addr_s rspamd_inet_addr_t;
-struct rspamd_radix_map_helper;
-
-struct rspamd_radix_map_helper **rspamd_inet_library_init (void);
-
+/**
+ * Returns pointer storage for global singleton (map for local addresses)
+ * @return
+ */
+void **rspamd_inet_library_init (void);
+/**
+ * Returns local addresses singleton
+ * @return
+ */
+void *rspamd_inet_library_get_lib_ctx (void);
+/**
+ * Cleanup library (currently it does nothing)
+ */
void rspamd_inet_library_destroy (void);
/**
/**
* Returns TRUE if an address belongs to some local address
*/
-gboolean rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr,
- gboolean check_laddrs);
+gboolean rspamd_inet_address_is_local (const rspamd_inet_addr_t *addr);
/**
* Returns size of storage required to store a complete IP address
* limitations under the License.
*/
#include "lua_common.h"
+#include "libserver/maps/map_helpers.h"
/***
* @module rspamd_ip
check_laddrs = lua_toboolean (L, 2);
}
- lua_pushboolean (L, rspamd_inet_address_is_local (ip->addr,
- check_laddrs));
+ if ( rspamd_inet_address_is_local (ip->addr)) {
+ lua_pushboolean (L, true);
+
+ return 1;
+ }
+ else if (check_laddrs) {
+ struct rspamd_radix_map_helper *local_addrs =
+ rspamd_inet_library_get_lib_ctx ();
+ if (local_addrs) {
+ if (rspamd_match_radix_map_addr (local_addrs, ip->addr) != NULL) {
+ lua_pushboolean (L, true);
+
+ return 1;
+ }
+ }
+ }
+
+ lua_pushboolean (L, false);
}
else {
lua_pushnil (L);
/* First check if plugin should be enabled */
if ((!dkim_module_ctx->check_authed && task->user != NULL)
|| (!dkim_module_ctx->check_local &&
- rspamd_inet_address_is_local (task->from_addr, TRUE))) {
+ rspamd_ip_is_local_cfg (task->cfg, task->from_addr))) {
msg_info_task ("skip DKIM checks for local networks and authorized users");
rspamd_symcache_finalize_item (task, item);
guint id;
};
-struct rspamd_radix_map_helper;
-
struct rspamd_external_libs_ctx {
- struct rspamd_radix_map_helper **local_addrs;
+ void **local_addrs;
struct rspamd_cryptobox_library_ctx *crypto_ctx;
struct ottery_config *ottery_cfg;
SSL_CTX *ssl_ctx;
}
if (m->local ||
- rspamd_inet_address_is_local (
- rspamd_upstream_addr_cur (bk_conn->up), FALSE)) {
+ rspamd_inet_address_is_local (rspamd_upstream_addr_cur (bk_conn->up))) {
if (session->fname) {
rspamd_http_message_add_header (msg, "File", session->fname);
if (backend->local ||
rspamd_inet_address_is_local (
rspamd_upstream_addr_cur (
- session->master_conn->up), FALSE)) {
+ session->master_conn->up))) {
if (session->fname) {
rspamd_http_message_add_header (msg, "File", session->fname);
session->ctx = ctx;
session->worker = worker;
- if (ctx->encrypted_only && !rspamd_inet_address_is_local (addr, FALSE)) {
+ if (ctx->encrypted_only && !rspamd_inet_address_is_local (addr)) {
http_opts = RSPAMD_HTTP_REQUIRE_ENCRYPTION;
}