summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-13 13:46:30 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-13 13:46:30 +0100
commit90905903ebed01788d2b196ebcdac99d5f4d7d00 (patch)
treee75d57b090b707381c1d0db4191f2cd52ce47c4d
parent0ea784ef25ed92cd55ba2958c9dd3b5c9140108e (diff)
downloadrspamd-90905903ebed01788d2b196ebcdac99d5f4d7d00.tar.gz
rspamd-90905903ebed01788d2b196ebcdac99d5f4d7d00.zip
Fix generic DNS request in lua.
-rw-r--r--src/lua/lua_dns.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c
index df16c75eb..713ec81b5 100644
--- a/src/lua/lua_dns.c
+++ b/src/lua/lua_dns.c
@@ -96,16 +96,42 @@ struct lua_dns_cbdata {
static int
lua_dns_get_type (lua_State *L, int argno)
{
- int type;
+ int type = RDNS_REQUEST_A;
+ const gchar *strtype;
- lua_pushvalue (L, argno);
- lua_gettable (L, lua_upvalueindex (1));
+ if (lua_type (L, argno) != LUA_TSTRING) {
+ lua_pushvalue (L, argno);
+ lua_gettable (L, lua_upvalueindex (1));
- type = lua_tonumber (L, -1);
- lua_pop (L, 1);
- if (type == 0) {
- rspamd_lua_typerror (L, argno, "dns_request_type");
+ type = lua_tonumber (L, -1);
+ lua_pop (L, 1);
+ if (type == 0) {
+ rspamd_lua_typerror (L, argno, "dns_request_type");
+ }
+ }
+ else {
+ strtype = lua_tostring (L, argno);
+
+ if (g_ascii_strcasecmp (strtype, "a") == 0) {
+ type = RDNS_REQUEST_A;
+ }
+ else if (g_ascii_strcasecmp (strtype, "aaaa") == 0) {
+ type = RDNS_REQUEST_AAAA;
+ }
+ else if (g_ascii_strcasecmp (strtype, "mx") == 0) {
+ type = RDNS_REQUEST_MX;
+ }
+ else if (g_ascii_strcasecmp (strtype, "txt") == 0) {
+ type = RDNS_REQUEST_TXT;
+ }
+ else if (g_ascii_strcasecmp (strtype, "ptr") == 0) {
+ type = RDNS_REQUEST_PTR;
+ }
+ else {
+ msg_err ("bad DNS type: %s", strtype);
+ }
}
+
return type;
}