From: Andrew Lewis Date: Tue, 18 Oct 2016 09:37:44 +0000 (+0200) Subject: [Feature] Support looking up NS records in lua_dns X-Git-Tag: 1.4.0~235^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1051%2Fhead;p=rspamd.git [Feature] Support looking up NS records in lua_dns --- diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index 3593518cf..1d8943c56 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -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)