From: bert hubert Date: Thu, 20 Mar 2014 11:38:25 +0000 (+0100) Subject: implement CNAME following when requested from Lua. X-Git-Tag: rec-3.6.0-rc1~8^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1c8b825ef0d2e20901ffe72bbfd8833dbcc3fa2;p=thirdparty%2Fpdns.git implement CNAME following when requested from Lua. --- diff --git a/pdns/lua-pdns.cc b/pdns/lua-pdns.cc index 41e96e42b9..25e9348b8b 100644 --- a/pdns/lua-pdns.cc +++ b/pdns/lua-pdns.cc @@ -161,6 +161,7 @@ int getLuaTableLength(lua_State* lua, int depth) #endif } +// expects a table at offset 2, and, importantly DOES NOT POP IT from the stack - only the contents void popResourceRecordsTable(lua_State *lua, const string &query, vector& ret) { /* get the result */ @@ -169,10 +170,7 @@ void popResourceRecordsTable(lua_State *lua, const string &query, vector& r void popResourceRecordsTable(lua_State *lua, const string &query, vector& ret); void pushSyslogSecurityLevelTable(lua_State *lua); int getLuaTableLength(lua_State* lua, int depth); +void luaStackDump (lua_State *L); #endif diff --git a/pdns/lua-recursor.cc b/pdns/lua-recursor.cc index cfda9ea7fd..4ac6bdd99b 100644 --- a/pdns/lua-recursor.cc +++ b/pdns/lua-recursor.cc @@ -58,6 +58,32 @@ RecursorLua::RecursorLua(const std::string &fname) // empty } +int followCNAMERecords(vector& ret, const QType& qtype) +{ + vector resolved; + string target; + BOOST_FOREACH(DNSResourceRecord& rr, ret) { + if(rr.qtype.getCode() == QType::CNAME) { + target=rr.content; + break; + } + } + if(target.empty()) + return 0; + + if(target[target.size()-1]!='.') + target.append(1, '.'); + + int rcode=directResolve(target, qtype, 1, resolved); // 1 == class + + BOOST_FOREACH(const DNSResourceRecord& rr, resolved) + { + ret.push_back(rr); + } + return rcode; + +} + int getFakeAAAARecords(const std::string& qname, const std::string& prefix, vector& ret) { int rcode=directResolve(qname, QType(QType::A), 1, ret); @@ -158,26 +184,37 @@ bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, co extraParameter+=2; } - if(lua_pcall(d_lua, 3 + extraParameter, 3, 0)) { + if(lua_pcall(d_lua, 3 + extraParameter, 3, 0)) { // NOTE! Means we always get 3 stack entries back! string error=string("lua error in '"+func+"' while processing query for '"+query+"|"+qtype.getName()+": ")+lua_tostring(d_lua, -1); lua_pop(d_lua, 1); throw runtime_error(error); return false; } - + *variable |= d_variable; if(!lua_isnumber(d_lua, 1)) { string tocall = lua_tostring(d_lua,1); - string luaqname = lua_tostring(d_lua,2); - string luaprefix = lua_tostring(d_lua, 3); - lua_pop(d_lua, 3); - // cerr<<"should call '"<