commit 1d5c1d7: [Minor] Core: Pass server name when doing DNS request

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Dec 27 18:28:14 UTC 2018


Author: Vsevolod Stakhov
Date: 2018-12-27 09:21:10 +0000
URL: https://github.com/rspamd/rspamd/commit/1d5c1d7b7f12803e12230260cd517d980bf30ca1

[Minor] Core: Pass server name when doing DNS request

---
 contrib/librdns/rdns.h     |  8 ++++++++
 contrib/librdns/util.c     | 10 ++++++++++
 src/lua/lua_dns_resolver.c | 12 +++++++++++-
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/contrib/librdns/rdns.h b/contrib/librdns/rdns.h
index 016903ba6..647f0f1b1 100644
--- a/contrib/librdns/rdns.h
+++ b/contrib/librdns/rdns.h
@@ -435,6 +435,14 @@ bool rdns_request_has_type (struct rdns_request *req, enum rdns_request_type typ
 const struct rdns_request_name* rdns_request_get_name (struct rdns_request *req,
 		unsigned int *count);
 
+/**
+ * Return a DNS server name associated with the request
+ * @param req request object
+ * @return name of a DNS server
+ */
+const char* rdns_request_get_server (struct rdns_request *req);
+
+
 /**
  * Return PTR string for a request (ipv4 or ipv6) addresses
  * @param str string representation of IP address
diff --git a/contrib/librdns/util.c b/contrib/librdns/util.c
index c9480beb6..b793b9077 100644
--- a/contrib/librdns/util.c
+++ b/contrib/librdns/util.c
@@ -663,6 +663,16 @@ rdns_request_get_name (struct rdns_request *req, unsigned int *count)
 	return req->requested_names;
 }
 
+const char*
+rdns_request_get_server (struct rdns_request *req)
+{
+	if (req && req->io) {
+		return req->io->srv->name;
+	}
+
+	return NULL;
+}
+
 char *
 rdns_generate_ptr_from_str (const char *str)
 {
diff --git a/src/lua/lua_dns_resolver.c b/src/lua/lua_dns_resolver.c
index ffc4cd738..d108744e1 100644
--- a/src/lua/lua_dns_resolver.c
+++ b/src/lua/lua_dns_resolver.c
@@ -172,6 +172,7 @@ lua_dns_resolver_callback (struct rdns_reply *reply, gpointer arg)
 	 * 4 - error | nil
 	 * 5 - user_str
 	 * 6 - reply->authenticated
+	 * 7 - server
 	 */
 	if (reply->code != RDNS_RC_NOERROR) {
 		lua_pushnil (L);
@@ -186,12 +187,21 @@ lua_dns_resolver_callback (struct rdns_reply *reply, gpointer arg)
 
 	lua_pushboolean (L, reply->authenticated);
 
+	const gchar *servname = rdns_request_get_server (reply->request);
+
+	if (servname) {
+		lua_pushstring (L, servname);
+	}
+	else {
+		lua_pushnil (L);
+	}
+
 	if (cd->item) {
 		/* We also need to restore the item in case there are some chains */
 		rspamd_symcache_set_cur_item (cd->task, cd->item);
 	}
 
-	if (lua_pcall (L, 6, 0, err_idx) != 0) {
+	if (lua_pcall (L, 7, 0, err_idx) != 0) {
 		tb = lua_touserdata (L, -1);
 
 		if (tb) {


More information about the Commits mailing list