]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/luabackend/luabackend.hh
Merge pull request #8434 from mind04/pdns-remove-mydns
[thirdparty/pdns.git] / modules / luabackend / luabackend.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #ifndef LUABACKEND_HH
24 #define LUABACKEND_HH
25
26 #include "lua.hpp"
27
28 #include "pdns/dnsbackend.hh"
29
30 #include <string>
31 using std::string;
32
33 #define LUABACKEND_PREFIX "lua"
34
35 class LUAException {
36 public:
37 LUAException(const string &ex) : what(ex){}
38 string what;
39 };
40
41 class LUABackend : public DNSBackend {
42
43 public:
44
45 // MINIMAL BACKEND
46
47 LUABackend(const string &suffix="");
48 ~LUABackend();
49 bool list(const DNSName &target, int domain_id, bool include_disabled=false) override;
50 void lookup(const QType &qtype, const DNSName &qname, int domain_id, DNSPacket *p=nullptr) override;
51 bool get(DNSResourceRecord &rr) override;
52 //! fills the soadata struct with the SOA details. Returns false if there is no SOA.
53 bool getSOA(const DNSName &name, SOAData &soadata) override;
54
55
56 // MASTER BACKEND
57
58 void getUpdatedMasters(vector<DomainInfo>* domains) override;
59 void setNotified(uint32_t id, uint32_t serial) override;
60
61
62 // SLAVE BACKEND
63
64 bool getDomainInfo(const DNSName& domain, DomainInfo &di, bool getSerial=true) override;
65 void getUnfreshSlaveInfos(vector<DomainInfo>* domains) override;
66 void setFresh(uint32_t id) override;
67
68 bool startTransaction(const DNSName &qname, int id) override;
69 bool commitTransaction() override;
70 bool abortTransaction() override;
71 bool feedRecord(const DNSResourceRecord &rr, const DNSName &ordername, bool ordernameIsNSEC3=false) override;
72
73
74 // SUPERMASTER BACKEND
75
76 bool superMasterBackend(const string &ip, const DNSName &domain, const vector<DNSResourceRecord>&nsset, string *nameserver, string *account, DNSBackend **db) override;
77 bool createSlaveDomain(const string &ip, const DNSName &domain, const string &nameserver, const string &account) override;
78
79
80 // DNSSEC BACKEND
81
82 //! get a list of IP addresses that should also be notified for a domain
83 void alsoNotifies(const DNSName &domain, set<string> *ips) override;
84 bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta) override;
85 bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::vector<std::string>& meta) override;
86
87 bool getDomainKeys(const DNSName& name, std::vector<KeyData>& keys) override ;
88 bool removeDomainKey(const DNSName& name, unsigned int id) override ;
89 bool activateDomainKey(const DNSName& name, unsigned int id) override ;
90 bool deactivateDomainKey(const DNSName& name, unsigned int id) override ;
91 bool getTSIGKey(const DNSName& name, DNSName* algorithm, string* content) override ;
92 bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id) override ;
93 bool updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const DNSName& qname, const std::string& ordername, bool auth);
94 bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
95 bool updateDNSSECOrderNameAndAuth(uint32_t domain_id, const DNSName& qname, const DNSName& ordername, bool auth, const uint16_t qtype=QType::ANY) override;
96 bool updateDNSSECOrderAndAuth(uint32_t domain_id, const DNSName& zonename, const DNSName& qname, bool auth);
97
98
99 // OTHER
100 void reload() override ;
101 void rediscover(string* status=0) override ;
102
103
104 string backend_name;
105 lua_State *lua;
106 DNSPacket *dnspacket;
107
108 //private.cc
109 string my_getArg(string a);
110 bool my_mustDo(string a);
111 bool my_isEmpty(string a);
112
113 private:
114
115 pthread_t backend_pid;
116 unsigned int backend_count{0};
117
118 int f_lua_exec_error;
119
120 //minimal functions....
121 int f_lua_list;
122 int f_lua_lookup;
123 int f_lua_get;
124 int f_lua_getsoa;
125
126 //master functions....
127 int f_lua_getupdatedmasters;
128 int f_lua_setnotified;
129
130 //slave functions....
131 int f_lua_getdomaininfo;
132 int f_lua_ismaster;
133 int f_lua_getunfreshslaveinfos;
134 int f_lua_setfresh;
135
136 int f_lua_starttransaction;
137 int f_lua_committransaction;
138 int f_lua_aborttransaction;
139 int f_lua_feedrecord;
140
141 //supermaster functions....
142 int f_lua_supermasterbackend;
143 int f_lua_createslavedomain;
144
145 //rediscover
146 int f_lua_rediscover;
147
148 //dnssec
149 int f_lua_alsonotifies;
150 int f_lua_getdomainmetadata;
151 int f_lua_setdomainmetadata;
152
153 int f_lua_getdomainkeys;
154 int f_lua_removedomainkey;
155 int f_lua_activatedomainkey;
156 int f_lua_deactivatedomainkey;
157 int f_lua_updatedomainkey;
158 int f_lua_gettsigkey;
159 int f_lua_adddomainkey;
160
161 int f_lua_getbeforeandafternamesabsolute;
162 int f_lua_updatednssecorderandauthabsolute;
163 int f_lua_updatednssecorderandauth;
164
165
166 // FUNCTIONS TO THIS BACKEND
167 bool getValueFromTable(lua_State *lua, const std::string& key, string& value);
168 bool getValueFromTable(lua_State *lua, const std::string& key, DNSName& value);
169 bool getValueFromTable(lua_State *lua, uint32_t key, string& value);
170 #if !(defined(__i386__) && defined(__FreeBSD__))
171 bool getValueFromTable(lua_State *lua, const std::string& key, time_t& value);
172 #endif
173 bool getValueFromTable(lua_State *lua, const std::string& key, uint32_t& value);
174 bool getValueFromTable(lua_State *lua, const std::string& key, uint16_t& value);
175 bool getValueFromTable(lua_State *lua, const std::string& key, uint8_t& value);
176 bool getValueFromTable(lua_State *lua, const std::string& key, int& value);
177 bool getValueFromTable(lua_State *lua, const std::string& key, bool& value);
178
179 //private.cc
180 bool domaininfo_from_table(DomainInfo *di);
181 void domains_from_table(vector<DomainInfo>* domains, const char *f_name);
182 void dnsrr_to_table(lua_State *lua, const DNSResourceRecord *rr);
183 bool dnsrr_from_table(lua_State *lua, DNSResourceRecord &rr);
184
185 //reload.cc
186 void get_lua_function(lua_State *lua, const char *name, int *function);
187
188 bool dnssec;
189
190 bool logging;
191
192 //dnssec.cc
193 bool updateDomainKey(const DNSName& name, unsigned int &id, bool toowhat);
194 };
195
196 #endif