]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support looking up NS records in lua_dns 1051/head
authorAndrew Lewis <nerf@judo.za.org>
Tue, 18 Oct 2016 09:37:44 +0000 (11:37 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 18 Oct 2016 09:37:44 +0000 (11:37 +0200)
src/lua/lua_dns.c

index 3593518cfcc0831dfe10dc04a0b374413d763bf2..1d8943c56a8b313dfe40b03da50efa8fe3c9a1a2 100644 (file)
@@ -50,6 +50,7 @@ LUA_FUNCTION_DEF (dns_resolver, resolve_a);
 LUA_FUNCTION_DEF (dns_resolver, resolve_ptr);
 LUA_FUNCTION_DEF (dns_resolver, resolve_txt);
 LUA_FUNCTION_DEF (dns_resolver, resolve_mx);
+LUA_FUNCTION_DEF (dns_resolver, resolve_ns);
 LUA_FUNCTION_DEF (dns_resolver, resolve);
 
 static const struct luaL_reg dns_resolverlib_f[] = {
@@ -62,6 +63,7 @@ static const struct luaL_reg dns_resolverlib_m[] = {
        LUA_INTERFACE_DEF (dns_resolver, resolve_ptr),
        LUA_INTERFACE_DEF (dns_resolver, resolve_txt),
        LUA_INTERFACE_DEF (dns_resolver, resolve_mx),
+       LUA_INTERFACE_DEF (dns_resolver, resolve_ns),
        LUA_INTERFACE_DEF (dns_resolver, resolve),
        {"__tostring", rspamd_lua_class_tostring},
        {NULL, NULL}
@@ -163,6 +165,10 @@ lua_dns_callback (struct rdns_reply *reply, gpointer arg)
                                rspamd_inet_address_destroy (addr);
                                lua_rawseti (cd->L, -2, ++i);
                                break;
+                       case RDNS_REQUEST_NS:
+                               lua_pushstring (cd->L, elt->content.ns.name);
+                               lua_rawseti (cd->L, -2, ++i);
+                               break;
                        case RDNS_REQUEST_PTR:
                                lua_pushstring (cd->L, elt->content.ptr.name);
                                lua_rawseti (cd->L, -2, ++i);
@@ -480,6 +486,33 @@ lua_dns_resolver_resolve_mx (lua_State *L)
        return 1;
 }
 
+/***
+ * @method resolver:resolve_ns(session, pool, host, callback)
+ * Resolve NS records for a specified host.
+ * @param {async_session} session asynchronous session normally associated with rspamd task (`task:get_session()`)
+ * @param {mempool} pool memory pool for storing intermediate data
+ * @param {string} host name to get NS records for
+ * @param {function} callback callback function to be called upon name resolution is finished; must be of type `function (resolver, to_resolve, results, err)`
+ * @return {boolean} `true` if DNS request has been scheduled
+ */
+static int
+lua_dns_resolver_resolve_ns (lua_State *L)
+{
+       struct rspamd_dns_resolver *dns_resolver = lua_check_dns_resolver (L);
+
+       if (dns_resolver) {
+               return lua_dns_resolver_resolve_common (L,
+                                  dns_resolver,
+                                  RDNS_REQUEST_NS,
+                                  2);
+       }
+       else {
+               lua_pushnil (L);
+       }
+
+       return 1;
+}
+
 /* XXX: broken currently */
 static int
 lua_dns_resolver_resolve (lua_State *L)