From: Peter van Dijk Date: Wed, 2 Jan 2013 11:48:22 +0000 (+0000) Subject: drop the mongodbbackend, as it does not compile with any recent Mongo libs anyway X-Git-Tag: auth-3.2-rc4~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ecbcd268e0b9d8ab37d8d06c03f457af8a4475c;p=thirdparty%2Fpdns.git drop the mongodbbackend, as it does not compile with any recent Mongo libs anyway git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3017 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/configure.ac b/configure.ac index 47196fc557..6cff60a2f1 100644 --- a/configure.ac +++ b/configure.ac @@ -661,7 +661,6 @@ modules/gmysqlbackend/Makefile modules/db2backend/Makefile \ modules/geobackend/Makefile modules/opendbxbackend/Makefile \ modules/pipebackend/Makefile modules/oraclebackend/Makefile \ modules/xdbbackend/Makefile modules/godbcbackend/Makefile \ -modules/mongodbbackend/Makefile \ modules/gpgsqlbackend/Makefile modules/ldapbackend/Makefile \ modules/gsqlite3backend/Makefile \ modules/goraclebackend/Makefile modules/mydnsbackend/Makefile \ diff --git a/modules/Makefile.am b/modules/Makefile.am index 3c26ef6de6..e6e84adfa5 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -1,2 +1,2 @@ SUBDIRS=@moduledirs@ -DIST_SUBDIRS=db2backend geobackend gmysqlbackend godbcbackend goraclebackend gpgsqlbackend gsqlite3backend ldapbackend luabackend mongodbbackend mydnsbackend opendbxbackend oraclebackend pipebackend xdbbackend tinydnsbackend remotebackend +DIST_SUBDIRS=db2backend geobackend gmysqlbackend godbcbackend goraclebackend gpgsqlbackend gsqlite3backend ldapbackend luabackend mydnsbackend opendbxbackend oraclebackend pipebackend xdbbackend tinydnsbackend remotebackend diff --git a/modules/mongodbbackend/Makefile.am b/modules/mongodbbackend/Makefile.am deleted file mode 100644 index 999ea00f10..0000000000 --- a/modules/mongodbbackend/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -AM_CPPFLAGS=@THREADFLAGS@ $(BOOST_CPPFLAGS) -EXTRA_DIST=OBJECTFILES OBJECTLIBS - -INCLUDES=-I/opt/mongo/include/mongo/ - -lib_LTLIBRARIES = libmongodbbackend.la - -libmongodbbackend_la_SOURCES=mongodbbackend.cc mongodbbackend.hh minimal.cc slave.cc master.cc reload.cc private.cc dnssec.cc supermaster.cc crc32.cc -libmongodbbackend_la_LDFLAGS=-module -avoid-version -L/opt/mongo/lib64 $(BOOST_THREAD_LDFLAGS) $(BOOST_FILESYSTEM_LDFLAGS) $(BOOST_SYSTEM_LDFLAGS) -lmongoclient $(BOOST_THREAD_LIBS) $(BOOST_FILESYSTEM_LIBS) $(BOOST_SYSTEM_LIBS) - diff --git a/modules/mongodbbackend/OBJECTFILES b/modules/mongodbbackend/OBJECTFILES deleted file mode 100644 index 81e9e69e4b..0000000000 --- a/modules/mongodbbackend/OBJECTFILES +++ /dev/null @@ -1 +0,0 @@ -mongodbbackend.o minimal.o slave.o master.o reload.o private.o dnssec.o supermaster.o crc32.o \ No newline at end of file diff --git a/modules/mongodbbackend/OBJECTLIBS b/modules/mongodbbackend/OBJECTLIBS deleted file mode 100644 index 53981a3528..0000000000 --- a/modules/mongodbbackend/OBJECTLIBS +++ /dev/null @@ -1 +0,0 @@ --L/opt/mongo/lib64/ -lmongoclient -lboost_thread -lboost_filesystem -lboost_system diff --git a/modules/mongodbbackend/README b/modules/mongodbbackend/README deleted file mode 100644 index 2394d2e05c..0000000000 --- a/modules/mongodbbackend/README +++ /dev/null @@ -1,213 +0,0 @@ -==================================================== -README FILE FOR MONGODBBACKEND FOR USE WITH POWERDNS -==================================================== - -You do understand the concept of Mongo DB? -If not please go to www.mongodb.org first! - - -Supported functions for this backend is for the moment: - - o) NATIVE - o) MASTER - o) DNSSEC - -============================ -WHY NO SLAVE SUPPORT FOR NOW -============================ - -The first reason that slave isn't suported at this time is that there is no -transaction support in Mongo DB per se. -I do know that "db.eval" will lock the database and this is probably the -route to take to implement the slave functionallity with Mongo DB. - -The second reason is that is very difficult to generate an unique id within -a database cluster when some database server could be disconnected from eachother -and at the same time everybody wants an unique id. - -My proposal to this problem is to use uuid (universally unique identifier) and take -that string and calculate an crc32 of that for the use of unique id and yes, also -check that the crc32 doesn't exists before it's use! - -In a shell you can use something like this to generate the crc32 of an uuid: - --------------------------------------------- -#!/bin/sh - -u=`uuidgen -r` - -c=`echo "${u}" | cksum | awk '{print $1}'` - -echo "uuid: ${u}" -echo "crc32: ${c}" ---------------------------------------------- - - -=========================================== -WHAT YOU WILL FIND UNDER THE TEST DIRECTORY -=========================================== - -I have converted all the domains (example.com, test.com, wtest.com) that does -exists under the pdns/regression-tests into json format for this backend. - -To import this you first need to change the path to the "mongoimport" program -in the file "json.import". When you run this program, remember that - -IT WILL DELETE YOUR FULL DATABASE WITH ALL INFORMATION IN IT! - -so don't run/use it on a production server, okay? - -There is one line within the file "mongodb.example.com" that does not import -correctly at this time and the reason for that is that I haven't figured out -to escape the string for it to import. - -When you have run "json.import" you have an clean database with no dnssec -information in it. To get that run the "./pdnssec secure-zone " from the -test directory and you should be ready to test it! - - -============================= -OPTIONS IN THE CONFIGURE FILE -============================= - -The default values is: - -mongodb-host = localhost:27017 -mongodb-database = dns - -Tables in Mongo DB is called collection: - -collection-domains = domains -collection-records = records -collection-domainmetadata = domainmetadata -collection-cryptokeys = cryptokeys -collection-tsigkeys = tsigkeys - -DNSSEC is set to yes as default since you don't have to convert anything to get -this functionallity. Only if don't want dnssec you should set "mongodb-dnssec" -to "no". - -For the first time you connect to an empty or populated database, you should run -PowerDNS with the option "mongodb-checkindex" set to "yes". This will create all -the index that the backend use and then some more. In your log you will see this -a couple of times: - -"Apr 05 19:40:29 [MONGODBBackend: 2466240256 (1)] (Re)creating index... " - -Now you can stop PowerDNS and set this option to no. You don't need it anymore -since it is created. A tip is to check with Mongo DB that this as been done for -example via the web interface which normaly is at -http://localhost:28017/ - - -If you have the global option "query-logging" set to yes, you will get something -like this in your log: - -".....(getSOA) Query: { name: "example.com" }" - -If you also have the "mongodb-logging-content" set to "yes" you will also -get the result from that question. This can be very much of information but -also very helpfull if something is wrong with the answer. - -If you are running the pdnssec utility it can be a little difficult to get -log information so there also exists an option to log to stderr with the -"mongodb-logging-cerr" set to "yes". - - -========================================================================= -OBS! OBS! THE RECORD OF "SOA" IS MOVED FROM RECORDS TO DOMAINS! OBS! OBS! -========================================================================= - -I did this for the benefit of losing at least one database query every time -you allready have got the information for the domain you are looking for in -the collection "domains". - -It has only came back and bite me (and you) in the back once. In the -regression-tests there is the 'any-query' test that fails. It does this -because it does not get the SOA record in a question of 'any example.com' since -that record does not exists in the collection "records" anymore. - -The funny part of this is that PowerDNS allready has got the SOA record to know -if we have the domain we are asking for. Because of that I don't know if this -really should be fixed in the backend or in the logic of PowerDNS. - - -=========================== -THE FAILED REGRESSION-TESTS -=========================== - -If you have imported the test domains with the help of the "json.import" you can -run the test with the following command: - -src_svn/pdns/regression-tests$ nameserver=127.0.0.1 port=5300 ./runtests - -The failed test are: - - o) url-record - o) mboxfw-record - o) any-query - o) external-cname-pointer - o) multi-txt-escape-resolution - - -============================ -THE JSON FORMAT OF THE DATA -=========================== - -The structure of the data is that there should only be one record and not as in the sql variants -of PowerDNS multiply of the same record. To duplicate some data that is unqiue in json format we -use arrays. - -For all of the collections in this backend the field 'content' does hold the data for that record. -The 'content' can be an array of either strings or an array of records (documents in Mongo DB language). - -For example, take this record: - -{ "domain_id" : 10, "name" : "smtp-servers.example.com", "type" : "A", "ttl" : 120, - "content" : [ {"data" : "192.168.0.2"}, {"data" : "192.168.0.3"}, {"data" : "192.168.0.4"} ] -} - -As you can see this is an dns type 'A' record for the name 'smtp-servers.example.com' -with a ttl of '120' seconds with three ip addresses of that server with the numbers: -192.168.0.2, 192.168.0.3, 192.168.0.4. - -Now let's say that we need to change the ttl field for the ip address 192.168.0.3. -What needed to be changed is the document (record) that holds data for the ip address -'192.168.0.3' and not the other ones. - -{ "domain_id" : 10, "name" : "smtp-servers.example.com", "type" : "A", "ttl" : 120, - "content" : [ {"data" : "192.168.0.2"}, {"data" : "192.168.0.3", "ttl" : 60}, {"data" : "192.168.0.4"} ] -} - -See?!? It's that easy to change the ttl for the ip address 192.168.0.3 to '60' -seconds and the others will still have the '120' seconds ttl and we don't have -duplicate the same data anymore. - -For the dns type 'MX' and 'SRV' there must also be an field with name "prio" (for the priority). - -{ "domain_id" : 12, "name" : "wtest.com", "type" : "MX", "ttl" : 3600, - "content" : [ {"prio" : 10, "data" : "smtp-servers.example.com"}, - {"prio" : 15, "data" : "smtp-servers.wtest.com"} - ] -} - - -Let's also take a look at the SOA record since that now are in the collection of 'domains': - -{"domain_id" : 10, "name" : "example.com", "type" : "NATIVE", "ttl" : 120, - "SOA" : { "hostmaster" : "ahu.example.com", - "nameserver" : "ns1.example.com", - "serial" : 2000081501, - "refresh" : 28800, - "retry" : 7200, - "expire" : 604800, - "default_ttl" : 86400 - } -} - -The field "SOA" in 'domains' holds a document of the values required for this dns type. - - -You can send question about this backend to >dev/null first and if you don't get any -answer from that you can try to send them to me at fredan-pdns@fredan.org - diff --git a/modules/mongodbbackend/crc32.cc b/modules/mongodbbackend/crc32.cc deleted file mode 100644 index c611dfd5dd..0000000000 --- a/modules/mongodbbackend/crc32.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Danerklint - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published - by the Free Software Foundation - - 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 St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include - -#include "mongodbbackend.hh" - -int MONGODBBackend::generateCRC32(const string& data) { - boost::crc_32_type crc32; - crc32.process_bytes(data.data(), data.length()); - return crc32.checksum(); -} diff --git a/modules/mongodbbackend/dnssec.cc b/modules/mongodbbackend/dnssec.cc deleted file mode 100644 index eca546ffe8..0000000000 --- a/modules/mongodbbackend/dnssec.cc +++ /dev/null @@ -1,442 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Danerklint - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published - by the Free Software Foundation - - 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 St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - -#include "mongodbbackend.hh" - -#include "pdns/logger.hh" -#include "pdns/arguments.hh" - -/* - virtual bool updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth) - virtual bool updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const std::string& qname, const std::string& ordername, bool auth) - virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const std::string& qname, std::string& unhashed, std::string& before, std::string& after) - - virtual bool getDomainKeys(const string& name, unsigned int kind, std::vector& keys) - virtual bool removeDomainKey(const string& name, unsigned int id) - virtual int addDomainKey(const string& name, const KeyData& key) - virtual bool activateDomainKey(const string& name, unsigned int id) - virtual bool deactivateDomainKey(const string& name, unsigned int id) - - virtual bool getTSIGKey(const string& name, string* algorithm, string* content) { return false; } - - virtual bool setDomainMetadata(const string& name, const std::string& kind, std::vector& meta) - virtual bool getDomainMetadata(const string& name, const std::string& kind, std::vector& meta) - virtual void alsoNotifies(const string &domain, set *ips) - -*/ - -bool MONGODBBackend::updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth) { - - if(!dnssec) - return false; - - string ins=toLower(labelReverse(makeRelative(qname, zonename))); - return this->updateDNSSECOrderAndAuthAbsolute(domain_id, qname, ins, auth); -} - -bool MONGODBBackend::updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const std::string& qname, const std::string& ordername, bool auth) { - if(!dnssec) - return false; - - mongo::Query mongo_q = QUERY( "name" << qname << "domain_id" << domain_id ); - bson::bo update = BSON( "$set" << BSON("ordername" << ordername << "auth" << auth) ); - - if(logging) { - L< mongo_c; - - bool afterafter = false; - bson::bo fields = BSON("ordername" << 1); - -retryAfter: - if(logging) - L<more() && !beforebefore) { - lqname = "{"; - beforebefore = true; - goto retryBefore; - } - - if (mongo_c->more()) { - mongo_r = mongo_c->next(); - - if(logging_content) - L<more()) - mongo_r = mongo_c->next(); - - if(logging_content) - L<empty(); -} - -bool MONGODBBackend::changeDomainKey(const string& name, unsigned int &id, bool toowhat ) { - if (!dnssec) - return false; - - mongo::Query mongo_q = QUERY( "name" << name << "content.id" << id); - bson::bo update = BSON( "$set" << BSON("content.$.active" << toowhat) ); - - string f_name = toowhat ? "(activateDomainKey)" : "(deactivateDomainKey)"; - - if(logging) { - L<& keys) { - //what is kind used for? - - if (!dnssec) - return false; - - mongo::Query mongo_q = QUERY( "name" << name); - - if(logging) - L< 0; -} - -bool MONGODBBackend::setDomainMetadata(const string& name, const std::string& kind, std::vector& meta) { - if (!dnssec) - return false; - - mongo::Query mongo_q1 = QUERY( "name" << name << "content.kind" << kind); - - if(logging) - L<::iterator i; - - mongo::BSONArrayBuilder contents; - - for(i = meta.begin(); i& meta, set *ips) { - if (!dnssec) - return false; - - mongo::Query mongo_q = QUERY( "name" << name << "content.kind" << kind); - - if(logging) - L<insert(e.valuestr()); - c++; - } - - return c > 0; -} - -void MONGODBBackend::alsoNotifies(const string &domain, set *ips) { - if (!dnssec) - return; - - string kind = "ALSO-NOTIFY"; - std::vector meta; - - getDomainMetadata(domain, kind, meta , ips); -} diff --git a/modules/mongodbbackend/master.cc b/modules/mongodbbackend/master.cc deleted file mode 100644 index 03c64e6b06..0000000000 --- a/modules/mongodbbackend/master.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Danerklint - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published - by the Free Software Foundation - - 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 St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - -#include "mongodbbackend.hh" - -#include "pdns/logger.hh" -#include "pdns/arguments.hh" - -/* - virtual void getUpdatedMasters(vector* domains); - virtual void setNotifed(int id, u_int32_t serial); -*/ - -void MONGODBBackend::getUpdatedMasters(vector* domains) { - //please see the function getTheFreshOnes in private.cc - - string type = "MASTER"; - string f_name = "(getUpdatedMasters)"; - - getTheFreshOnes(domains, &type, &f_name); -} - -void MONGODBBackend::setNotifed(int id, u_int32_t serial) { - mongo::Query mongo_q = QUERY( "domain_id" << id ); - bson::bo update = BSON( "$set" << BSON("notified_serial" << serial )); - - if(logging) { - L<more(); -} - -void MONGODBBackend::lookup(const QType &qtype, const string &qname, DNSPacket *p, int domain_id) { - string q_type; - - q_type = qtype.getName(); - q_name = qname; - - mongo_query = q_type == "ANY" ? QUERY( "name" << toLower(qname) ) : QUERY( "name" << toLower(qname) << "type" << q_type); - mongo_query.hint(q_type == "ANY" ? BSON("name" << 1) : BSON("name" << 1 << "type" << 1)); - - elements = false; - default_ttl = 0; - - if(logging) - L<more()) - return false; - - bson::bo o1, o2; - - o1 = contents->next().wrap(); - - if(logging_content) - L<qname.clear(); - rr->qtype = 255; - rr->ttl = 0; - rr->domain_id = 0; - rr->last_modified = 0; - rr->priority = 0; - rr->content.clear(); - rr->auth = false; - - o2 = o1.firstElement().embeddedObject(); - - if (!o2.hasElement("data")) { - L<qtype = rr_record.qtype; - rr->qname = rr_record.qname; - rr->domain_id = rr_record.domain_id; - rr->last_modified = rr_record.last_modified; - rr->auth = rr_record.auth; - - rr->priority = o2.getIntField("prio"); - - if (o2.hasElement("ttl")) - rr->ttl = o2.getIntField("ttl"); - else - rr->ttl = rr_record.ttl; - - rr->content = o2.getStringField("data"); - if (rr->content.empty()) { - L<more(); -} - -bool MONGODBBackend::get(DNSResourceRecord &rr) { - - rr.content.clear(); - - if (elements) { - elements = content(&rr); - if (!rr.content.empty() ) - return true; - } - -again: - if (cursor->more()) { - - mongo_record = cursor->next(); - - if(logging_content) - L< 0) { - rr_record.ttl = default_ttl; - } else { - L< -using std::string; - -#include "client/dbclient.h" - -class MONGODBException { -public: - MONGODBException(const string &ex) : what(ex){} - string what; -}; - -class MONGODBBackend : public DNSBackend { - -public: - - -// MINIMAL BACKEND - - MONGODBBackend(const string &suffix=""); - ~MONGODBBackend(); - bool list(const string &target, int domain_id); - void lookup(const QType &qtype, const string &qname, DNSPacket *p, int domain_id); - bool get(DNSResourceRecord &rr); - //! fills the soadata struct with the SOA details. Returns false if there is no SOA. - bool getSOA(const string &name, SOAData &soadata, DNSPacket *p=0); - - -// SLAVE BACKEND - - bool getDomainInfo(const string &domain, DomainInfo &di, SOAData *soadata = NULL, unsigned int domain_id = 0); - bool isMaster(const string &name, const string &ip); - void getUnfreshSlaveInfos(vector* domains); - void setFresh(int id); -/* - bool startTransaction(const string &qname, int id); - bool commitTransaction(); - bool abortTransaction(); - bool feedRecord(const DNSResourceRecord &rr); -*/ - - -// SUPERMASTER BACKEND -/* - bool superMasterBackend(const string &ip, const string &domain, const vector&nsset, string *account, DNSBackend **db) - bool createSlaveDomain(const string &ip, const string &domain, const string &account) -*/ - - -// MASTER BACKEND - - void getUpdatedMasters(vector* domains); - void setNotifed(int id, u_int32_t serial); - - -// DNSSEC BACKEND - //! get a list of IP addresses that should also be notified for a domain - void alsoNotifies(const string &domain, set *ips); - bool getDomainMetadata(const string& name, const std::string& kind, std::vector& meta, set *ips = NULL); - bool setDomainMetadata(const string& name, const std::string& kind, std::vector& meta); - - bool getDomainKeys(const string& name, unsigned int kind, std::vector& keys); - bool removeDomainKey(const string& name, unsigned int id); - bool activateDomainKey(const string& name, unsigned int id); - bool deactivateDomainKey(const string& name, unsigned int id); - bool getTSIGKey(const string& name, string* algorithm, string* content); - int addDomainKey(const string& name, const KeyData& key); - - bool getBeforeAndAfterNamesAbsolute(uint32_t id, const std::string& qname, std::string& unhashed, std::string& before, std::string& after); - bool updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const std::string& qname, const std::string& ordername, bool auth); - bool updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth); - - -// OTHER - void reload(); - - -private: -// FUNCTIONS TO THIS BACKEND - - //minimal.cc - bool content(DNSResourceRecord* rr); - - //private.cc - void getTheFreshOnes(vector* domains, string *type, string *f_name); - bool checkDomainInfo(const string *domain, mongo::BSONObj *mongo_r, string *f_name, string *mongo_q, DomainInfo *di, SOAData *soadata = NULL); - - //dnssec.cc - bool changeDomainKey(const string& name, unsigned int &id, bool toowhat); - - //crc32.cc - int generateCRC32(const string& my_string); - - string mongo_db; - string collection_domains; - string collection_records; - - string collection_domainmetadata; - string collection_cryptokeys; - string collection_tsigkeys; - - mongo::DBClientConnection m_db; - - auto_ptr cursor; - - string q_name; - -// long long unsigned int count; - mongo::Query mongo_query; - mongo::BSONObj mongo_record; - bool elements; - DNSResourceRecord rr_record; - string type; - mongo::BSONObjIterator* contents; - - - string backend_name; - pthread_t backend_pid; - unsigned int backend_count; - - unsigned int default_ttl; - - bool logging; - bool logging_cerr; - bool logging_content; - - bool dnssec; - bool checkindex; - - bool use_default_ttl; - -}; -#endif diff --git a/modules/mongodbbackend/private.cc b/modules/mongodbbackend/private.cc deleted file mode 100644 index f50e3fc0e8..0000000000 --- a/modules/mongodbbackend/private.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Danerklint - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published - by the Free Software Foundation - - 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 St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "mongodbbackend.hh" - -#include "pdns/logger.hh" -#include "pdns/arguments.hh" - -bool MONGODBBackend::checkDomainInfo(const string *domain, mongo::BSONObj *mongo_r, string *f_name, string *mongo_q, DomainInfo *di, SOAData *soadata) { - if (mongo_r->hasElement("type") && mongo_r->hasElement("domain_id") && mongo_r->hasElement("SOA")) { - di->backend = this; - di->serial = 0; - di->zone = *domain; - - di->id = mongo_r->getIntField("domain_id"); - di->last_check = mongo_r->getIntField("last_check"); - di->notified_serial = mongo_r->getIntField("notified_serial"); - - if (soadata == NULL) - for( bson::bo::iterator i(mongo_r->getObjectField("masters")); i.more(); ) { - bson::bo o; - bson::be e; - o = i.next().wrap(); - e = o.firstElement(); - di->masters.push_back(e.valuestr()); - } - - string type = toUpper(mongo_r->getStringField("type")); - - if (soadata != NULL || type == "SLAVE") { - //filling out soadata. - mongo::BSONObj soa = mongo_r->getObjectField("SOA"); - if (soa.hasElement("serial") && soa.hasElement("refresh") && soa.hasElement("retry") && soa.hasElement("expire") && soa.hasElement("default_ttl") && mongo_r->hasElement("ttl")) { - if (soadata != NULL) { - soadata->db = this; - soadata->serial = soa.getIntField("serial"); - di->serial = soadata->serial; - - soadata->refresh = soa.getIntField("refresh"); - soadata->retry = soa.getIntField("retry"); - soadata->expire = soa.getIntField("expire"); - soadata->default_ttl = soa.getIntField("default_ttl"); - soadata->domain_id = di->id; - - soadata->ttl = mongo_r->getIntField("ttl"); - - soadata->nameserver = soa.getStringField("nameserver"); - if (soadata->nameserver.empty()) { - soadata->nameserver = arg()["default-soa-name"]; - if (soadata->nameserver.empty()) { - L<hostmaster = soa.getStringField("hostmaster"); - if (soadata->hostmaster.empty()) - soadata->hostmaster = "hostmaster." + *domain; - - } else { - //hopefully called as getDomainInfo with no soadata! - di->serial = soa.getIntField("serial"); - } - - } else { - L<kind = DomainInfo::Slave; - - } else if (type == "MASTER") { - di->kind = DomainInfo::Master; - - } else { - di->kind = DomainInfo::Native; - } - - return true; - - } else { - L<toString() << "' is missing required element(s) for the query '" << *mongo_q << "'" << endl; - } - - return false; -} - -void MONGODBBackend::getTheFreshOnes(vector* domains, string *type, string *f_name) { - mongo::Query mongo_q = QUERY( "type" << *type ); - - auto_ptr mongo_c; - mongo_c = m_db.query(collection_domains, mongo_q); - - string m_q = mongo_q.toString(); - - if(logging) - L<more()) - return; - - while(mongo_c->more()) { - DomainInfo di; - SOAData sd; - - mongo::BSONObj mongo_r = mongo_c->next(); - - string domain = mongo_r.getStringField("domain"); - - if (checkDomainInfo(&domain, &mongo_r, f_name, &m_q, &di, &sd)) { - if ( (*type == "SLAVE" && ((time_t)(di.last_check + sd.refresh) < time(0)) ) || (*type == "MASTER" && (di.notified_serial != sd.serial) ) ) { - di.serial = sd.serial; - domains->push_back(di); - } - } - } -} diff --git a/modules/mongodbbackend/reload.cc b/modules/mongodbbackend/reload.cc deleted file mode 100644 index 58d5ac5be8..0000000000 --- a/modules/mongodbbackend/reload.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Danerklint - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published - by the Free Software Foundation - - 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 St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "mongodbbackend.hh" - -#include "pdns/logger.hh" -#include "pdns/arguments.hh" - -/* - virtual void reload(); -*/ - -void MONGODBBackend::reload() { - logging = ::arg().mustDo("query-logging") || mustDo("logging-query"); - - logging_cerr = mustDo("logging-cerr"); - logging_content = mustDo("logging-content"); - - dnssec = mustDo("dnssec"); - checkindex = mustDo("checkindex"); - - use_default_ttl = mustDo("use-default-ttl"); - - backend_name.clear(); - -// backend_name = "[MONGODBBackend: " + uitoa(backend_pid) + " (" + uitoa(backend_count) +")] "; - backend_name = "[MONGODBBackend: (" + uitoa(backend_count) +")] "; -} diff --git a/modules/mongodbbackend/schema.mongodb.sql b/modules/mongodbbackend/schema.mongodb.sql deleted file mode 100644 index e54b3e496b..0000000000 --- a/modules/mongodbbackend/schema.mongodb.sql +++ /dev/null @@ -1,71 +0,0 @@ -/* the name ends with .sql because of (some) nice colours in mcedit ;-) */ - - -mongo table domains - { "domain_id" : int, - "name" : string, - "last_check" : int, - "notified_serial" : int, - "type" : string, - "ttl" : int, - "account" : string, - "SOA" : { - "serial" : int, - "refresh" : int, - "retry" : int, - "expire" : int, - "default_ttl" : int, - "hostmaster" : string - }, - "masters" : [ string, ... ], - } - -mongo table record - { "domain_id" : int , - "name" : string, - "type" : string, - "ttl" : int, - "ordername" : string, - "auth" : bool, - "content" : [ - { "prio" : int, - "ttl" : int, - "data" : string - } - , ... - ] - -mongo table domainmetadata - { "name" : string , - "content" : [ - { "kind" : string, - "data" : [ string, ...] - } - , ... - ] - } - -mongo table cryptokeys - { "domain_id" : int, - "name" : string , - "content" : [ - { "id" : int, - "flags" : int, - "active" : bool, - "data" : string - } - , ... - ] - } - -mongo table tsigkeys - { "name" : string, - "content" : [ - { "algorithm" : string, - "secret" : string - } - , ... - ] - } - - diff --git a/modules/mongodbbackend/slave.cc b/modules/mongodbbackend/slave.cc deleted file mode 100644 index 9a78f6a0c7..0000000000 --- a/modules/mongodbbackend/slave.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* - Copyright (C) 2011 Fredrik Danerklint - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as published - by the Free Software Foundation - - 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 St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - -#include "mongodbbackend.hh" - -#include "pdns/logger.hh" -#include "pdns/arguments.hh" - -/* - //transaction is not yet implemented in this backend - - virtual bool startTransaction(const string &qname, int id); - virtual bool commitTransaction(); - virtual bool abortTransaction(); - virtual bool feedRecord(const DNSResourceRecord &rr); - - virtual bool getDomainInfo(const string &domain, DomainInfo &di); - virtual bool isMaster(const string &name, const string &ip); - virtual void getUnfreshSlaveInfos(vector* domains); - virtual void setFresh(int id); -*/ - -void MONGODBBackend::setFresh(int id) { - mongo::Query mongo_q = QUERY( "domain_id" << id ); - bson::bo update = BSON( "$set" << BSON("last_check" << (unsigned int) time(0) ) ); - - if(logging) { - L<* domains) { - //please see the function getTheFreshOnes in private.cc - - string type = "SLAVE"; - string f_name = "(getUnfreshSlaveInfos)"; - - getTheFreshOnes(domains, &type, &f_name); -} - -bool MONGODBBackend::isMaster(const string &domain, const string &ip) { - - mongo::Query mongo_q = QUERY( "name" << toLower(domain) ); - - mongo::BSONObj mongo_r = m_db.findOne(collection_domains, mongo_q ); - - string f_name = "(isMaster)"; - - string m_q = mongo_q.toString(); - - if(logging) - L<::const_iterator iter=di.masters.begin(); iter != di.masters.end(); ++iter) { - // we can also have masters with a port specified (which we ignore here) - ServiceTuple st; - parseService(*iter, st); - if (!strcmp(ip.c_str(), st.host.c_str())) { - return true; - } - } - - return false; -} - -bool MONGODBBackend::getDomainInfo(const string &domain, DomainInfo &di, SOAData *soadata, unsigned int domain_id) { - - mongo::Query mongo_q; - - if (domain_id > 0) - mongo_q = QUERY( "domain_id" << domain_id ); - else - mongo_q = QUERY( "name" << toLower(domain) ); - - mongo::BSONObj mongo_r = m_db.findOne(collection_domains, mongo_q ); - - string f_name = soadata == NULL ? "(getDomainInfo)" : "(getSOA)"; - - string m_q = mongo_q.toString(); - - if(logging) - L<&nsset, string *account, DNSBackend **db) - - //! called by PowerDNS to create a slave record for a superMaster - virtual bool createSlaveDomain(const string &ip, const string &domain, const string &account) - -*/ - -//void MONGODBBackend:: diff --git a/modules/mongodbbackend/test/json.export b/modules/mongodbbackend/test/json.export deleted file mode 100755 index 74b5fe6ccb..0000000000 --- a/modules/mongodbbackend/test/json.export +++ /dev/null @@ -1,6 +0,0 @@ -time mongoexport -d dns -c records >json.exported.records -time mongoexport -d dns -c domains >json.exported.domains - -time mongoexport -d dns -c cryptokeys >json.exported.cryptokeys -time mongoexport -d dns -c domainmetadata >json.exported.domainmetadata -time mongoexport -d dns -c tsigkeys >json.exported.tsigkeys diff --git a/modules/mongodbbackend/test/json.export.records.sorted b/modules/mongodbbackend/test/json.export.records.sorted deleted file mode 100755 index 9ef1872f51..0000000000 --- a/modules/mongodbbackend/test/json.export.records.sorted +++ /dev/null @@ -1 +0,0 @@ -time mongoexport -d dns -c records -f "name,ordername" -q "{"domain_id" : 10, "auth" : true }" | awk '{ print $11,$14 }' | sort >json.exported.records.sorted diff --git a/modules/mongodbbackend/test/json.import b/modules/mongodbbackend/test/json.import deleted file mode 100755 index 1f4ed66787..0000000000 --- a/modules/mongodbbackend/test/json.import +++ /dev/null @@ -1,17 +0,0 @@ -head -n1 mongodb.example.com >json.imported.domains -head -n1 mongodb.test.com >>json.imported.domains -head -n1 mongodb.wtest.com >>json.imported.domains - -tail -n+2 mongodb.example.com >json.imported.records -tail -n+2 mongodb.test.com >>json.imported.records -tail -n+2 mongodb.wtest.com >>json.imported.records - -mongoimport -d dns -c records --drop modules/geobackend/README, part of the PowerDNS Authoritative Server distribution. - MongoDB Backend - - - - This section is a subset of the full documentation which can be found in modules/mongodbbackend/README of - the PowerDNS distribution. - - - - - The main author for this module is Fredrik Danerklint. - - - - MongoDB backend capabilities - - - NativeYes - MasterYes - SlaveNo - SuperslaveNo - AutoserialNo - DNSSECYes - - -
-
- - The MongoDB Backend is available since PowerDNS Authoritative Server 3.0. In 3.0 and 3.1, this backend is marked as - Experimental! - - - The MongoDB backend is a full service backend that stores data in a MongoDB instance. - - - More details can be found here, or in - modules/mongodbbackend/README, part of the PowerDNS Authoritative Server distribution. - -
Lua Backend