]> granicus.if.org Git - pdns/commitdiff
lua-auth: Remove unused sources
authorAki Tuomi <cmouse@cmouse.fi>
Sun, 11 Jun 2017 21:37:08 +0000 (00:37 +0300)
committerAki Tuomi <cmouse@cmouse.fi>
Mon, 18 Dec 2017 10:53:58 +0000 (12:53 +0200)
pdns/Makefile.am
pdns/lua-auth.cc [deleted file]
pdns/lua-auth.hh [deleted file]
pdns/lua-iputils.cc [deleted file]
pdns/lua-pdns.cc [deleted file]
pdns/lua-pdns.hh [deleted file]
pdns/packethandler.hh
pdns/slavecommunicator.cc

index 29c26dd259e5abd1cdd2252220b4b91aafced065..8dff3d1f1feac6368af46200888d6ae18358d0a9 100644 (file)
@@ -180,9 +180,7 @@ pdns_server_SOURCES = \
        lock.hh \
        logger.cc logger.hh \
        lua-base4.cc lua-base4.hh \
-       lua-auth.cc lua-auth.hh \
        lua-auth4.cc lua-auth4.hh \
-       lua-pdns.cc lua-pdns.hh lua-iputils.cc \
        mastercommunicator.cc \
        md5.hh \
        misc.cc misc.hh \
diff --git a/pdns/lua-auth.cc b/pdns/lua-auth.cc
deleted file mode 100644 (file)
index 55bf4bf..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * This file is part of PowerDNS or dnsdist.
- * Copyright -- PowerDNS.COM B.V. and its contributors
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * In addition, for the avoidance of any doubt, permission is granted to
- * link this program with OpenSSL and to (re)distribute the binaries
- * produced as the result of such linking.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "lua-auth.hh"
-
-#if !defined(HAVE_LUA)
-
-AuthLua::AuthLua(const std::string &fname)
-  : PowerDNSLua(fname)
-{
-  // empty
-}
-
-#else
-
-
-extern "C" {
-#undef L
-/* Include the Lua API header files. */
-#include <lua.h>
-#include <lauxlib.h>
-#include <lualib.h>
-}
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string>
-#include <vector>
-#include <stdexcept>
-
-#include "logger.hh"
-#include "namespaces.hh"
-
-AuthLua::AuthLua(const std::string &fname)
-  : PowerDNSLua(fname)
-{
-  registerLuaDNSPacket();
-  pthread_mutex_init(&d_lock,0);
-}
-
-struct LuaDNSPacket
-{
-  DNSPacket *d_p;
-};
-
-static DNSPacket* ldp_checkDNSPacket(lua_State *L) {
-  void *ud = luaL_checkudata(L, 1, "LuaDNSPacket");
-  luaL_argcheck(L, ud != NULL, 1, "`LuaDNSPacket' expected");
-  return ((LuaDNSPacket *)ud)->d_p;
-}
-
-static int ldp_setRcode(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-#if LUA_VERSION_NUM < 503
-  int rcode = luaL_checkint(L, 2);
-#else
-  int rcode = (int)luaL_checkinteger(L, 2);
-#endif
-  p->setRcode(rcode);
-  return 0;
-}
-
-static int ldp_getQuestion(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  lua_pushstring(L, p->qdomain.toString().c_str());
-  lua_pushnumber(L, p->qtype.getCode());
-  return 2;
-}
-
-static int ldp_getWild(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  if(p->qdomainwild.empty())
-    lua_pushnil(L);
-  else
-    lua_pushstring(L, p->qdomainwild.toString().c_str());
-  return 1;
-}
-
-static int ldp_getZone(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  if(p->qdomainzone.empty())
-    lua_pushnil(L);
-  else
-    lua_pushstring(L, p->qdomainzone.toString().c_str());
-  return 1;
-}
-
-static int ldp_addRecords(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  vector<DNSRecord> rrs;
-  popResourceRecordsTable(L, DNSName("BOGUS"), rrs);
-  for(const DNSRecord& dr :  rrs) {
-    DNSZoneRecord dzr;
-    dzr.dr=dr;
-    dzr.auth=true; // LET'S HOPE THIS IS TRUE XXX
-    p->addRecord(dzr);
-  }
-  return 0;
-}
-
-static int ldp_getRemote(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  lua_pushstring(L, p->getRemote().toString().c_str());
-  return 1;
-}
-
-static int ldp_getRemoteRaw(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  const ComboAddress& ca=p->getRemote();
-  if(ca.sin4.sin_family == AF_INET) {
-    lua_pushlstring(L, (const char*)&ca.sin4.sin_addr.s_addr, 4);
-  }
-  else {
-    lua_pushlstring(L, (const char*)&ca.sin6.sin6_addr.s6_addr, 16);
-  }
-  return 1;
-}
-
-static int ldp_getRcode(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  lua_pushnumber(L, p->d.rcode);
-  return 1;
-}
-
-static int ldp_getSize(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  lua_pushnumber(L, p->getString().size());
-  return 1;
-}
-
-static int ldp_getRRCounts(lua_State *L) {
-  DNSPacket *p=ldp_checkDNSPacket(L);
-  lua_pushnumber(L, ntohs(p->d.ancount));
-  lua_pushnumber(L, ntohs(p->d.nscount));
-  lua_pushnumber(L, ntohs(p->d.arcount));
-  return 3;
-}
-
-// these functions are used for PowerDNS recursor regression testing against auth,
-// and for the Lua Policy Engine. The Lua 5.2 implementation is untested.
-static const struct luaL_Reg ldp_methods [] = {
-      {"setRcode", ldp_setRcode},
-      {"getQuestion", ldp_getQuestion},
-      {"getWild", ldp_getWild},
-      {"getZone", ldp_getZone},
-      {"addRecords", ldp_addRecords},
-      {"getRemote", ldp_getRemote},
-      {"getRemoteRaw", ldp_getRemoteRaw},
-      {"getSize", ldp_getSize},
-      {"getRRCounts", ldp_getRRCounts},
-      {"getRcode", ldp_getRcode},
-      {NULL, NULL}
-    };
-
-#if LUA_VERSION_NUM < 502
-void AuthLua::registerLuaDNSPacket(void) {
-
-  luaL_newmetatable(d_lua, "LuaDNSPacket");
-
-  lua_pushstring(d_lua, "__index");
-  lua_pushvalue(d_lua, -2);  /* pushes the metatable */
-  lua_settable(d_lua, -3);  /* metatable.__index = metatable */
-
-  luaL_openlib(d_lua, NULL, ldp_methods, 0);
-
-  lua_pop(d_lua, 1);
-}
-#else
-
-void AuthLua::registerLuaDNSPacket(void) {
-
-  luaL_newmetatable(d_lua, "LuaDNSPacket");
-
-  lua_pushstring(d_lua, "__index");
-  lua_pushvalue(d_lua, -2);  /* pushes the metatable */
-  lua_settable(d_lua, -3);  /* metatable.__index = metatable */
-
-  luaL_setfuncs(d_lua, ldp_methods, 0);
-
-  lua_pop(d_lua, 1);
-}
-#endif
-
-#endif
diff --git a/pdns/lua-auth.hh b/pdns/lua-auth.hh
deleted file mode 100644 (file)
index 266bf9e..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This file is part of PowerDNS or dnsdist.
- * Copyright -- PowerDNS.COM B.V. and its contributors
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * In addition, for the avoidance of any doubt, permission is granted to
- * link this program with OpenSSL and to (re)distribute the binaries
- * produced as the result of such linking.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#ifndef PDNS_LUA_AUTH_HH
-#define PDNS_LUA_AUTH_HH
-#include "dns.hh"
-#include "iputils.hh"
-#include "dnspacket.hh"
-#include "lua-pdns.hh"
-#include "lock.hh"
-
-class AuthLua : public PowerDNSLua
-{
-public:
-  explicit AuthLua(const std::string& fname);
-  // ~AuthLua();
-
-private:
-  void registerLuaDNSPacket(void);
-
-  pthread_mutex_t d_lock;
-};
-
-#endif
diff --git a/pdns/lua-iputils.cc b/pdns/lua-iputils.cc
deleted file mode 100644 (file)
index ad52f6c..0000000
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * This file is part of PowerDNS or dnsdist.
- * Copyright -- PowerDNS.COM B.V. and its contributors
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * In addition, for the avoidance of any doubt, permission is granted to
- * link this program with OpenSSL and to (re)distribute the binaries
- * produced as the result of such linking.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#ifdef HAVE_LUA
-extern "C" {
-#include <lua.h>
-#include <lauxlib.h>
-}
-#include <iostream>
-#include "iputils.hh"
-#include <string>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <stdlib.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <netdb.h>
-#include "namespaces.hh"       
-#undef L
-
-#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
-/*
-** Adapted from Lua 5.2.0
-*/
-static void pdns_luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
-  luaL_checkstack(L, nup+1, "too many upvalues");
-  for (; l->name != NULL; l++) {  /* fill the table with given functions */
-    int i;
-    lua_pushstring(L, l->name);
-    for (i = 0; i < nup; i++)  /* copy upvalues to the top */
-      lua_pushvalue(L, -(nup+1));
-    lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */
-    lua_settable(L, -(nup + 3));
-  }
-  lua_pop(L, nup);  /* remove upvalues */
-}
-#else
-static void pdns_luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
-  luaL_setfuncs(L, l, nup);
-}
-#endif
-
-
-/////////////////////////////////
-
-static int l_new_ca(lua_State* L)
-{
-  ComboAddress* ca=(ComboAddress*)lua_newuserdata(L, sizeof(ComboAddress)); 
-  memset(ca, 0, sizeof(ComboAddress));
-  *ca=ComboAddress(luaL_checkstring(L, 1));
-  luaL_getmetatable(L, "iputils.ca");
-  lua_setmetatable(L, -2);
-  return 1;
-}
-
-static int l_ca_tostring(lua_State* L)
-{
-  ComboAddress* ca = (ComboAddress*)luaL_checkudata(L, 1, "iputils.ca");
-  
-  string ret=ca->toString();
-  lua_pushstring(L, ret.c_str());
-  return 1;
-}
-
-static int l_ca_tostringWithPort(lua_State* L)
-{
-  ComboAddress* ca = (ComboAddress*)luaL_checkudata(L, 1, "iputils.ca");
-  
-  string ret=ca->toStringWithPort();
-  lua_pushstring(L, ret.c_str());
-  return 1;
-}
-
-static int l_ca_equal(lua_State* L)
-{
-  ComboAddress* ca1 = (ComboAddress*)luaL_checkudata(L, 1, "iputils.ca");
-  ComboAddress* ca2 = (ComboAddress*)luaL_checkudata(L, 2, "iputils.ca");
-  lua_pushboolean(L, *ca1==*ca2);
-  return 1;
-}
-
-static const struct luaL_Reg iputils_ca_methods[]={
-    {"tostring", l_ca_tostring},
-    {"__tostring", l_ca_tostring},
-    {"__eq", l_ca_equal},
-    {"tostringwithport", l_ca_tostringWithPort},
-    {NULL, NULL}
-};
-
-
-/////////////////////////////
-
-typedef set<ComboAddress, ComboAddress::addressOnlyLessThan> ourset_t;
-
-static int l_ipset_index(lua_State* L)
-{
-  ourset_t *ourset = (ourset_t*)luaL_checkudata(L, 1, "iputils.ipset");
-  ComboAddress* ca1 = (ComboAddress*)luaL_checkudata(L, 2, "iputils.ca");
-  if(ourset->count(*ca1)) {
-    lua_pushboolean(L, 1);
-    return 1;
-  }
-  
-  return 0;
-}
-
-static int l_ipset_newindex(lua_State* L)
-{
-  ourset_t*ourset = (ourset_t*)luaL_checkudata(L, 1, "iputils.ipset");
-  ComboAddress* ca1 = (ComboAddress*)luaL_checkudata(L, 2, "iputils.ca");
-  ourset->insert(*ca1);
-  return 0;
-}
-
-static int l_newipset(lua_State* L)
-{
-  new(lua_newuserdata(L, sizeof(ourset_t))) ourset_t();
-  luaL_getmetatable(L, "iputils.ipset");
-  lua_setmetatable(L, -2);
-  return 1;
-}
-
-static int l_ipset_gc(lua_State* L)
-{
-  ourset_t*ourset = (ourset_t*)luaL_checkudata(L, 1, "iputils.ipset");
-  ourset->~ourset_t();
-  return 0;
-}
-
-static const struct luaL_Reg ipset_methods[]={
-    {"__index", l_ipset_index},
-    {"__newindex", l_ipset_newindex},
-    {"__gc", l_ipset_gc},
-    {NULL, NULL}
-};
-
-////////////////////////////////////////////////////
-
-
-static int l_netmask_tostring(lua_State* L)
-{
-  Netmask* nm = (Netmask*)luaL_checkudata(L, 1, "iputils.netmask");
-  string ret=nm->toString();
-  lua_pushstring(L, ret.c_str());
-  return 1;
-}
-
-static int l_new_netmask(lua_State* L)
-{
-  /*Netmask* nm=*/ new(lua_newuserdata(L, sizeof(Netmask))) Netmask(luaL_checkstring(L, 1));
-  luaL_getmetatable(L, "iputils.netmask");
-  lua_setmetatable(L, -2);
-  return 1;
-}
-
-static int l_netmask_match(lua_State* L)
-{
-  Netmask* nm=(Netmask*)luaL_checkudata(L, 1, "iputils.netmask");
-  ComboAddress* ca1 = (ComboAddress*)luaL_checkudata(L, 2, "iputils.ca");
-  lua_pushboolean(L, nm->match(*ca1));
-  return 1;
-}
-
-static int l_netmask_gc(lua_State* L)
-{
-  Netmask* nm = (Netmask*)luaL_checkudata(L, 1, "iputils.netmask");
-  nm->~Netmask();
-  return 0;
-}
-
-static const struct luaL_Reg iputils_netmask_methods[]={
-    {"__tostring", l_netmask_tostring},
-    {"tostring", l_netmask_tostring},
-    {"match", l_netmask_match},
-    {"__gc", l_netmask_gc},
-    {NULL, NULL}
-};
-
-
-//////////////////////
-
-static int l_nmgroup_tostring(lua_State* L)
-{
-  NetmaskGroup* nmg = (NetmaskGroup*)luaL_checkudata(L, 1, "iputils.nmgroup");
-  
-  string ret=nmg->toString();
-  lua_pushstring(L, ret.c_str());
-  return 1;
-}
-
-static int l_new_nmgroup(lua_State* L)
-{
-  /*NetmaskGroup*nmg= */ new(lua_newuserdata(L, sizeof(NetmaskGroup))) NetmaskGroup();
-  luaL_getmetatable(L, "iputils.nmgroup");
-  lua_setmetatable(L, -2);
-  return 1;
-}
-
-static int l_nmgroup_match(lua_State* L)
-{
-  NetmaskGroup* nm=(NetmaskGroup*)luaL_checkudata(L, 1, "iputils.nmgroup");
-  ComboAddress* ca1 = (ComboAddress*)luaL_checkudata(L, 2, "iputils.ca");
-  lua_pushboolean(L, nm->match(*ca1));
-  return 1;
-}
-
-static int l_nmgroup_add(lua_State* L)
-{
-  NetmaskGroup* nm=(NetmaskGroup*)luaL_checkudata(L, 1, "iputils.nmgroup");
-  nm->addMask(luaL_checkstring(L, 2));
-  return 0;
-}
-
-
-static int l_nmgroup_gc(lua_State* L)
-{
-  NetmaskGroup* nm = (NetmaskGroup*)luaL_checkudata(L, 1, "iputils.nmgroup");
-  nm->~NetmaskGroup();
-  return 0;
-}
-
-static const struct luaL_Reg iputils_nmgroup_methods[]={
-    {"__tostring", l_nmgroup_tostring},
-    {"tostring", l_nmgroup_tostring},
-    {"match", l_nmgroup_match},
-    {"add", l_nmgroup_add},
-    {"__gc", l_nmgroup_gc},
-    {NULL, NULL}
-};
-
-////////////
-
-static const struct luaL_Reg iputils[]={
-    {"newca", l_new_ca},
-    {"newipset", l_newipset},
-    {"newnm", l_new_netmask},
-    {"newnmgroup", l_new_nmgroup},
-    {NULL, NULL}
-};
-
-
-extern "C" int luaopen_iputils(lua_State* L)
-{
-  luaL_newmetatable(L, "iputils.ca");
-  lua_pushvalue(L, -1);
-  lua_setfield(L, -2, "__index");
-  pdns_luaL_setfuncs(L, iputils_ca_methods, 0);
-
-  luaL_newmetatable(L, "iputils.ipset");
-  lua_pushvalue(L, -1);
-  lua_setfield(L, -2, "__index");
-  pdns_luaL_setfuncs(L, ipset_methods, 0);
-
-  luaL_newmetatable(L, "iputils.netmask");
-  lua_pushvalue(L, -1);
-  lua_setfield(L, -2, "__index");
-  pdns_luaL_setfuncs(L, iputils_netmask_methods, 0);
-
-  luaL_newmetatable(L, "iputils.nmgroup");
-  lua_pushvalue(L, -1);
-  lua_setfield(L, -2, "__index");
-  pdns_luaL_setfuncs(L, iputils_nmgroup_methods, 0);
-
-#if LUA_VERSION_NUM < 502
-  luaL_register(L, "iputils", iputils);
-#else
-  luaL_newlib(L, iputils);
-#endif
-  return 1;
-}
-
-#endif
diff --git a/pdns/lua-pdns.cc b/pdns/lua-pdns.cc
deleted file mode 100644 (file)
index 2d10551..0000000
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * This file is part of PowerDNS or dnsdist.
- * Copyright -- PowerDNS.COM B.V. and its contributors
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * In addition, for the avoidance of any doubt, permission is granted to
- * link this program with OpenSSL and to (re)distribute the binaries
- * produced as the result of such linking.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "lua-pdns.hh"
-// #include "syncres.hh"
-
-
-#if !defined(HAVE_LUA)
-
-// stub implementation
-
-PowerDNSLua::PowerDNSLua(const std::string& fname)
-{
-  throw runtime_error("Lua support disabled");
-}
-
-
-PowerDNSLua::~PowerDNSLua()
-{
-
-}
-
-#else
-
-extern "C" {
-#undef L
-/* Include the Lua API header files. */
-#include <lua.h>
-#include <lauxlib.h>
-#include <lualib.h>
-}
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string>
-#include <vector>
-#include <stdexcept>
-#include "logger.hh"
-#include "namespaces.hh"
-#include "dnsparser.hh"
-#undef L
-
-bool netmaskMatchTable(lua_State* lua, const std::string& ip)
-{
-  lua_pushnil(lua);  /* first key */
-  while (lua_next(lua, 2) != 0) {
-    string netmask=lua_tostring(lua, -1);
-    Netmask nm(netmask);
-    ComboAddress ca(ip);
-    lua_pop(lua, 1);
-
-    if(nm.match(ip))
-      return true;
-  }
-  return false;
-}
-
-static bool getFromTable(lua_State *lua, const std::string &key, std::string& value)
-{
-  lua_pushstring(lua, key.c_str()); // 4 is now '1'
-  lua_gettable(lua, -2);  // replace by the first entry of our table we hope
-
-  bool ret=false;
-  if(!lua_isnil(lua, -1)) {
-    value = lua_tostring(lua, -1);
-    ret=true;
-  }
-  lua_pop(lua, 1);
-  return ret;
-}
-
-static bool getFromTable(lua_State *lua, const std::string &key, uint32_t& value)
-{
-  lua_pushstring(lua, key.c_str()); // 4 is now '1'
-  lua_gettable(lua, -2);  // replace by the first entry of our table we hope
-
-  bool ret=false;
-
-  if(!lua_isnil(lua, -1)) {
-    value = (uint32_t)lua_tonumber(lua, -1);
-    ret=true;
-  }
-  lua_pop(lua, 1);
-  return ret;
-}
-
-
-void pushLuaTable(lua_State* lua, const vector<pair<string,string>>& table)
-{
-  lua_newtable(lua);
-  for(const auto& e : table) {
-    lua_pushstring(lua, e.second.c_str());
-    lua_setfield(lua, -2, e.first.c_str());
-  }
-}
-
-vector<pair<string,string>> getLuaTable(lua_State* lua, int index)
-{
-  vector<pair<string,string>> ret;
-  // Push another reference to the table on top of the stack (so we know
-  // where it is, and this function can work for negative, positive and
-  // pseudo indices
-  lua_pushvalue(lua, index);
-  // stack now contains: -1 => table
-  lua_pushnil(lua);
-  // stack now contains: -1 => nil; -2 => table
-  while (lua_next(lua, -2)) {
-    // stack now contains: -1 => value; -2 => key; -3 => table
-    // copy the key so that lua_tostring does not modify the original
-    lua_pushvalue(lua, -2);
-    // stack now contains: -1 => key; -2 => value; -3 => key; -4 => table
-    const char *key = lua_tostring(lua, -1);
-    const char *value = lua_tostring(lua, -2);
-    ret.push_back({key,value});
-    // pop value + copy of key, leaving original key
-    lua_pop(lua, 2);
-    // stack now contains: -1 => key; -2 => table
-  }
-  // stack now contains: -1 => table (when lua_next returns 0 it pops the key
-  // but does not push anything.)
-  // Pop table
-  lua_pop(lua, 1);
-  // Stack is now the same as it was on entry to this function
-  return ret;
-}
-
-
-void pushResourceRecordsTable(lua_State* lua, const vector<DNSRecord>& records)
-{
-  // make a table of tables
-  lua_newtable(lua);
-
-  int pos=0;
-  for(const auto& rr: records)
-  {
-    // row number, used by 'lua_settable' below
-    lua_pushnumber(lua, ++pos);
-    // "row" table
-    lua_newtable(lua);
-
-    lua_pushstring(lua, rr.d_name.toString().c_str());
-    lua_setfield(lua, -2, "qname");  // pushes value at the top of the stack to the table immediately below that (-1 = top, -2 is below)
-
-    lua_pushstring(lua, rr.d_content->getZoneRepresentation().c_str());
-    lua_setfield(lua, -2, "content");
-
-    lua_pushnumber(lua, rr.d_type);
-    lua_setfield(lua, -2, "qtype");
-
-    lua_pushnumber(lua, rr.d_ttl);
-    lua_setfield(lua, -2, "ttl");
-
-    lua_pushnumber(lua, rr.d_place);
-    lua_setfield(lua, -2, "place");
-
-    lua_pushnumber(lua, rr.d_class);
-    lua_setfield(lua, -2, "qclass");
-
-    lua_settable(lua, -3); // pushes the table we just built into the master table at position pushed above
-  }
-}
-// override the __index metatable under loglevels to return Logger::Error to account for nil accesses to the loglevels table
-int loglevels_index(lua_State* lua)
-{
-  lua_pushnumber(lua, Logger::Error);
-  return 1;
-}
-// push the loglevel subtable onto the stack that will eventually be the pdns table
-void pushSyslogSecurityLevelTable(lua_State* lua)
-{
-  lua_newtable(lua);
-// this function takes the global lua_state from the PowerDNSLua constructor and populates it with the syslog enums values
-  lua_pushnumber(lua, Logger::All);
-  lua_setfield(lua, -2, "All");
-  lua_pushnumber(lua, Logger::Alert);
-  lua_setfield(lua, -2, "Alert");
-  lua_pushnumber(lua, Logger::Critical);
-  lua_setfield(lua, -2, "Critical");
-  lua_pushnumber(lua, Logger::Error);
-  lua_setfield(lua, -2, "Error");
-  lua_pushnumber(lua, Logger::Warning);
-  lua_setfield(lua, -2, "Warning");
-  lua_pushnumber(lua, Logger::Notice);
-  lua_setfield(lua, -2, "Notice");
-  lua_pushnumber(lua, Logger::Info);
-  lua_setfield(lua, -2, "Info");
-  lua_pushnumber(lua, Logger::Debug);
-  lua_setfield(lua, -2, "Debug");
-  lua_pushnumber(lua, Logger::None);
-  lua_setfield(lua, -2, "None");
-  lua_createtable(lua, 0, 1);
-  lua_pushcfunction(lua, loglevels_index);
-  lua_setfield(lua, -2, "__index");
-  lua_setmetatable(lua, -2);
-}
-int getLuaTableLength(lua_State* lua, int depth)
-{
-#ifndef LUA_VERSION_NUM
-  return luaL_getn(lua, 2);
-#elif LUA_VERSION_NUM < 502
-  return lua_objlen(lua, 2);
-#else
-  return lua_rawlen(lua, 2);
-#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 DNSName &query, vector<DNSRecord>& ret)
-{
-  /* get the result */
-  DNSRecord rr;
-  rr.d_name = query;
-  rr.d_place = DNSResourceRecord::ANSWER;
-  rr.d_ttl = 3600;
-
-  int tableLen = getLuaTableLength(lua, 2);
-
-  for(int n=1; n < tableLen + 1; ++n) {
-    lua_pushnumber(lua, n);
-    lua_gettable(lua, 2);
-
-    uint32_t tmpnum=0;
-    if(!getFromTable(lua, "qtype", tmpnum))
-      rr.d_type=QType::A;
-    else
-      rr.d_type=tmpnum;
-
-    if(!getFromTable(lua, "qclass", tmpnum))
-      rr.d_class = QClass::IN;
-    else {
-      rr.d_class = tmpnum;
-    }
-
-
-    string content;
-    getFromTable(lua, "content", content);
-    rr.d_content=DNSRecordContent::mastermake(rr.d_type, rr.d_class, content);
-
-    if(!getFromTable(lua, "ttl", rr.d_ttl))
-      rr.d_ttl=3600;
-
-    string qname;
-    if(getFromTable(lua, "qname", qname))
-      rr.d_name = DNSName(qname);
-    else
-      rr.d_name = query;
-
-    if(!getFromTable(lua, "place", tmpnum))
-      rr.d_place = DNSResourceRecord::ANSWER;
-    else {
-      rr.d_place = static_cast<DNSResourceRecord::Place>(tmpnum);
-      if(rr.d_place > DNSResourceRecord::ADDITIONAL)
-        rr.d_place = DNSResourceRecord::ADDITIONAL;
-    }
-
-
-    /* removes 'value'; keeps 'key' for next iteration */
-    lua_pop(lua, 1); // table
-
-    //    cerr<<"Adding content '"<<rr.content<<"' with place "<<(int)rr.d_place<<" \n";
-    ret.push_back(rr);
-  }
-}
-
-extern "C" {
-
-int netmaskMatchLua(lua_State *lua)
-{
-  bool result=false;
-  if(lua_gettop(lua) >= 2) {
-    string ip=lua_tostring(lua, 1);
-    if(lua_istable(lua, 2)) {
-      result = netmaskMatchTable(lua, ip);
-    }
-    else {
-      for(int n=2 ; n <= lua_gettop(lua); ++n) {
-        string netmask=lua_tostring(lua, n);
-        Netmask nm(netmask);
-        ComboAddress ca(ip);
-
-        result = nm.match(ip);
-        if(result)
-          break;
-      }
-    }
-  }
-
-  lua_pushboolean(lua, result);
-  return 1;
-}
-
-int getLocalAddressLua(lua_State* lua)
-{
-  lua_getfield(lua, LUA_REGISTRYINDEX, "__PowerDNSLua");
-  PowerDNSLua* pl = (PowerDNSLua*)lua_touserdata(lua, -1);
-
-  lua_pushstring(lua, pl->getLocal().toString().c_str());
-  return 1;
-}
-
-// called by lua to indicate that this answer is 'variable' and should not be cached
-int setVariableLua(lua_State* lua)
-{
-  lua_getfield(lua, LUA_REGISTRYINDEX, "__PowerDNSLua");
-  PowerDNSLua* pl = (PowerDNSLua*)lua_touserdata(lua, -1);
-  pl->setVariable();
-  return 0;
-}
-
-int logLua(lua_State *lua)
-{
-  // get # of arguments from the pdnslog() lua stack
-  // if it is 1, then the old pdnslog(msg) is used, which we keep for posterity and to prevent lua scripts from breaking
-  // if it is >= 2, then we process it as pdnslog(msg, urgencylevel) for more granular logging
-  int argc = lua_gettop(lua);
-  if(argc == 1) {
-    string message=lua_tostring(lua, 1);
-    theL()<<Logger::Error<<"From Lua script: "<<message<<endl;
-  } else if(argc >= 2) {
-    string message=lua_tostring(lua, 1);
-    int urgencylevel = lua_tonumber(lua, 2);
-    theL()<<urgencylevel<<" "<<message<<endl;
-  }
-  return 0;
-}
-}
-
-PowerDNSLua::PowerDNSLua(const std::string& fname)
-{
-  d_lua = luaL_newstate();
-
-  // create module iputils & load it
-#if LUA_VERSION_NUM < 502
-  luaopen_iputils(d_lua);
-#else
-  luaL_requiref(d_lua, "iputils", luaopen_iputils, 1);
-#endif
-
-  lua_pushcfunction(d_lua, netmaskMatchLua);
-  lua_setglobal(d_lua, "matchnetmask");
-
-  lua_pushcfunction(d_lua, logLua);
-  lua_setglobal(d_lua, "pdnslog");
-
-  lua_newtable(d_lua);
-
-  for(vector<QType::namenum>::const_iterator iter = QType::names.begin(); iter != QType::names.end(); ++iter) {
-    lua_pushnumber(d_lua, iter->second);
-    lua_setfield(d_lua, -2, iter->first.c_str());
-  }
-  lua_pushnumber(d_lua, 0);
-  lua_setfield(d_lua, -2, "NOERROR");
-  lua_pushnumber(d_lua, 1);
-  lua_setfield(d_lua, -2, "FORMERR");
-  lua_pushnumber(d_lua, 2);
-  lua_setfield(d_lua, -2, "SERVFAIL");
-  lua_pushnumber(d_lua, 3);
-  lua_setfield(d_lua, -2, "NXDOMAIN");
-  lua_pushnumber(d_lua, 4);
-  lua_setfield(d_lua, -2, "NOTIMP");
-  lua_pushnumber(d_lua, 5);
-  lua_setfield(d_lua, -2, "REFUSED");
-  // set syslog codes used by Logger/enum Urgency
-  pushSyslogSecurityLevelTable(d_lua);
-  lua_setfield(d_lua, -2, "loglevels");
-  lua_pushnumber(d_lua, PolicyDecision::PASS);
-  lua_setfield(d_lua, -2, "PASS");
-  lua_pushnumber(d_lua, PolicyDecision::DROP);
-  lua_setfield(d_lua, -2, "DROP");
-  lua_pushnumber(d_lua, PolicyDecision::TRUNCATE);
-  lua_setfield(d_lua, -2, "TRUNCATE");
-
-  lua_setglobal(d_lua, "pdns");
-
-#ifndef LUA_VERSION_NUM
-  luaopen_base(d_lua);
-  luaopen_string(d_lua);
-
-  if(lua_dofile(d_lua,  fname.c_str()))
-#else
-  luaL_openlibs(d_lua);
-  if(luaL_dofile(d_lua,  fname.c_str()))
-#endif
-    throw runtime_error(string("Error loading Lua file '")+fname+"': "+ string(lua_isstring(d_lua, -1) ? lua_tostring(d_lua, -1) : "unknown error"));
-
-  lua_settop(d_lua, 0);
-
-  lua_pushcfunction(d_lua, setVariableLua);
-  lua_setglobal(d_lua, "setvariable");
-
-  lua_pushcfunction(d_lua, getLocalAddressLua);
-  lua_setglobal(d_lua, "getlocaladdress");
-
-  lua_pushlightuserdata(d_lua, (void*)this);
-  lua_setfield(d_lua, LUA_REGISTRYINDEX, "__PowerDNSLua");
-}
-
-bool PowerDNSLua::getFromTable(const std::string& key, std::string& value)
-{
-  return ::getFromTable(d_lua, key, value);
-}
-
-bool PowerDNSLua::getFromTable(const std::string& key, uint32_t& value)
-{
-  return ::getFromTable(d_lua, key, value);
-}
-
-PowerDNSLua::~PowerDNSLua()
-{
-  lua_close(d_lua);
-}
-
-#if 0
-void luaStackDump (lua_State *Lua) {
-  int i;
-  int top = lua_gettop(Lua);
-  for (i = 1; i <= top; i++) {  /* repeat for each level */
-    int t = lua_type(Lua, i);
-    switch (t) {
-
-    case LUA_TSTRING:  /* strings */
-      printf("`%s'", lua_tostring(Lua, i));
-      break;
-
-    case LUA_TBOOLEAN:  /* booleans */
-      printf(lua_toboolean(Lua, i) ? "true" : "false");
-      break;
-
-    case LUA_TNUMBER:  /* numbers */
-      printf("%g", lua_tonumber(Lua, i));
-      break;
-
-    default:  /* other values */
-      printf("%s", lua_typename(Lua, t));
-      break;
-
-    }
-    printf("  ");  /* put a separator */
-  }
-  printf("\n");  /* end the listing */
-}
-#endif
-
-#endif
diff --git a/pdns/lua-pdns.hh b/pdns/lua-pdns.hh
deleted file mode 100644 (file)
index b2dfc37..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * This file is part of PowerDNS or dnsdist.
- * Copyright -- PowerDNS.COM B.V. and its contributors
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * In addition, for the avoidance of any doubt, permission is granted to
- * link this program with OpenSSL and to (re)distribute the binaries
- * produced as the result of such linking.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#ifndef PDNS_LUA_PDNS_HH
-#define PDNS_LUA_PDNS_HH
-
-#include "dns.hh"
-#include "iputils.hh"
-struct lua_State;
-
-class PowerDNSLua
-{
-public:
-  explicit PowerDNSLua(const std::string& fname);
-  ~PowerDNSLua();
-  void reload();
-  ComboAddress getLocal()
-  {
-    return d_local;
-  }
-
-  void setVariable()
-  {
-    d_variable=true;
-  }
-
-protected: // FIXME?
-  lua_State* d_lua;
-  bool passthrough(const string& func, const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res, bool* variable);
-  bool getFromTable(const std::string& key, std::string& value);
-  bool getFromTable(const std::string& key, uint32_t& value);
-  ComboAddress d_local;
-  bool d_failed;
-  bool d_variable;  
-};
-
-void pushResourceRecordsTable(lua_State* lua, const vector<DNSRecord>& records);
-void popResourceRecordsTable(lua_State *lua, const DNSName &query, vector<DNSRecord>& ret);
-void pushSyslogSecurityLevelTable(lua_State *lua);
-int getLuaTableLength(lua_State* lua, int depth);
-std::vector<std::pair<std::string, std::string>> getLuaTable(lua_State* lua, int index=0);
-void pushLuaTable(lua_State* lua, const vector<pair<string,string>>& table);
-void luaStackDump (lua_State *lua);
-extern "C" int luaopen_iputils(lua_State*);
-#endif
index 6c76445a5e7d97dd7e7f26208e73122cf833e8e4..e9be90e42a989d66bdc0a44be8a483421e669620 100644 (file)
@@ -29,7 +29,6 @@
 #include "dnspacket.hh"
 #include "packetcache.hh"
 #include "dnsseckeeper.hh"
-#include "lua-auth.hh"
 #include "lua-auth4.hh"
 #include "gss_context.hh"
 
index 5adb410988b408a619130a69c7bef1036316f0f3..8c11d6758b17a3029c621dc5f0c6bd5d88b69616 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "base64.hh"
 #include "inflighter.cc"
-#include "lua-auth.hh"
 #include "namespaces.hh"
 #include "common_startup.hh"