diff options
author | Andrew Lewis <nerf@judo.za.org> | 2016-10-18 11:37:44 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2016-10-18 11:37:44 +0200 |
commit | 72e5434161c94a77d165c4feeac47e383331ded7 (patch) | |
tree | b2f6e571a567bf6521999cebf935f9f84575b82d | |
parent | be3414a88cc7dbd8b34f24b4121ccab5fc9aff7c (diff) | |
download | rspamd-72e5434161c94a77d165c4feeac47e383331ded7.tar.gz rspamd-72e5434161c94a77d165c4feeac47e383331ded7.zip |
[Feature] Support looking up NS records in lua_dns
-rw-r--r-- | src/lua/lua_dns.c | 33 |
1 files changed, 33 insertions, 0 deletions
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) |