commit e4fcd0f: [Minor] Allow to skip IDN checks in rdns

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Sep 23 11:21:08 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-09-23 12:05:36 +0100
URL: https://github.com/rspamd/rspamd/commit/e4fcd0fcda0d192b068dc28eb317e09dc0eb3a12

[Minor] Allow to skip IDN checks in rdns

---
 contrib/librdns/dns_private.h |  1 +
 contrib/librdns/packet.c      | 18 +++++++++++-------
 contrib/librdns/rdns.h        |  7 ++++++-
 contrib/librdns/resolver.c    | 15 ++++++++-------
 src/libserver/dns.c           |  3 ++-
 5 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/contrib/librdns/dns_private.h b/contrib/librdns/dns_private.h
index 3f0bee437..76bfba8fe 100644
--- a/contrib/librdns/dns_private.h
+++ b/contrib/librdns/dns_private.h
@@ -151,6 +151,7 @@ struct rdns_resolver {
 	bool async_binded;
 	bool initialized;
 	bool enable_dnssec;
+	int flags;
 	ref_entry_t ref;
 };
 
diff --git a/contrib/librdns/packet.c b/contrib/librdns/packet.c
index 35f4a9601..cdb524705 100644
--- a/contrib/librdns/packet.c
+++ b/contrib/librdns/packet.c
@@ -105,21 +105,25 @@ rdns_format_dns_name (struct rdns_resolver *resolver, const char *in,
 	}
 
 	/* Check for non-ascii characters */
-	while (p != end) {
-		if (*p >= 0x80) {
-			need_encode = true;
-		}
-		else if (*p == '.') {
-			labels ++;
+	if (!(resolver->flags & RDNS_RESOLVER_NOIDN)) {
+		while (p != end) {
+			if (*p >= 0x80) {
+				need_encode = true;
+			}
+			else if (*p == '.') {
+				labels++;
+			}
+			p++;
 		}
-		p ++;
 	}
 
 	if (!need_encode) {
 		*out = malloc (inlen + 1);
+
 		if (*out == NULL) {
 			return false;
 		}
+
 		o = *out;
 		memcpy (o, in, inlen);
 		o[inlen] = '\0';
diff --git a/contrib/librdns/rdns.h b/contrib/librdns/rdns.h
index 5ea8f5952..4df1991fd 100644
--- a/contrib/librdns/rdns.h
+++ b/contrib/librdns/rdns.h
@@ -233,10 +233,15 @@ struct rdns_request_name {
  * RDNS API
  */
 
+enum rdns_resolver_flags {
+	RDNS_RESOLVER_DEFAULT,
+	RDNS_RESOLVER_NOIDN = (1u << 0u),
+};
+
 /**
  * Create DNS resolver structure
  */
-struct rdns_resolver *rdns_resolver_new (void);
+struct rdns_resolver *rdns_resolver_new (int flags);
 
 /**
  * Bind resolver to specified async context
diff --git a/contrib/librdns/resolver.c b/contrib/librdns/resolver.c
index 98807f38e..3dd44012e 100644
--- a/contrib/librdns/resolver.c
+++ b/contrib/librdns/resolver.c
@@ -1049,18 +1049,19 @@ rdns_resolver_free (struct rdns_resolver *resolver)
 
 
 struct rdns_resolver *
-rdns_resolver_new (void)
+rdns_resolver_new (int flags)
 {
-	struct rdns_resolver     *new;
+	struct rdns_resolver     *new_resolver;
 
-	new = calloc (1, sizeof (struct rdns_resolver));
+	new_resolver = calloc (1, sizeof (struct rdns_resolver));
 
-	REF_INIT_RETAIN (new, rdns_resolver_free);
+	REF_INIT_RETAIN (new_resolver, rdns_resolver_free);
 
-	new->logger = rdns_logger_internal;
-	new->log_data = new;
+	new_resolver->logger = rdns_logger_internal;
+	new_resolver->log_data = new_resolver;
+	new_resolver->flags = flags;
 
-	return new;
+	return new_resolver;
 }
 
 void
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index cbbed4aa8..e5ec9d729 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -884,7 +884,8 @@ rspamd_dns_resolver_init (rspamd_logger_t *logger,
 		dns_resolver->max_retransmits = 2;
 	}
 
-	dns_resolver->r = rdns_resolver_new ();
+	/* IDN translation is performed in Rspamd now */
+	dns_resolver->r = rdns_resolver_new (RDNS_RESOLVER_NOIDN);
 
 	UErrorCode uc_err = U_ZERO_ERROR;
 


More information about the Commits mailing list