]> granicus.if.org Git - pdns/commitdiff
rest of the big whitespace/tab cleanup
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 24 Dec 2009 16:56:43 +0000 (16:56 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 24 Dec 2009 16:56:43 +0000 (16:56 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1471 d19b8d6e-7fed-0310-83ef-9ca221ded41b

34 files changed:
modules/db2backend/DB2Backend.cc
modules/geobackend/geobackend.cc
modules/geobackend/geobackend.hh
modules/geobackend/ippreftree.cc
modules/geobackend/ippreftree.hh
modules/gmysqlbackend/gmysqlbackend.cc
modules/gmysqlbackend/smysql.cc
modules/gmysqlbackend/smysql.hh
modules/goraclebackend/goraclebackend.cc
modules/goraclebackend/soracle.cc
modules/goraclebackend/soracle.hh
modules/gpgsqlbackend/gpgsqlbackend.cc
modules/gpgsqlbackend/spgsql.cc
modules/gpgsqlbackend/spgsql.hh
modules/ldapbackend/ldapbackend.cc
modules/ldapbackend/ldapbackend.hh
modules/ldapbackend/powerldap.cc
modules/ldapbackend/powerldap.hh
modules/ldapbackend/utils.hh
modules/mydnsbackend/mydnsbackend.cc
modules/mydnsbackend/mydnsbackend.hh
modules/mysqlbackend/mysqlcbackend.cc
modules/opendbxbackend/odbxbackend.cc
modules/opendbxbackend/odbxbackend.hh
modules/opendbxbackend/odbxprivate.cc
modules/oraclebackend/oraclebackend.cc
modules/oraclebackend/oraclebackend.hh
modules/pdnsbackend/pdnsbackend.cc
modules/pipebackend/coprocess.cc
modules/pipebackend/pipebackend.cc
modules/xdbbackend/xdb-fill.cc
modules/xdbbackend/xdbbackend.cc
modules/xdbbackend/xgdbm.cc
modules/xdbbackend/xtdb.cc

index a60c9dac609d492ec1357632ab0dd73d368c9e4f..33016dc6ddd55e42eb3ca18f961ae506b2bbaf72 100644 (file)
@@ -316,23 +316,23 @@ void DB2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pkt_
    {
       case kForwardQuery:
       case kForwardWildcardQuery:
-        strncpy(mParamName, qname.c_str(), sizeof(mParamName));
+         strncpy(mParamName, qname.c_str(), sizeof(mParamName));
          strncpy(mParamType, qtype.getName().c_str(), sizeof(mParamType));
          //cerr << ">>>>>>>>  Name = " << mParamName << " Type = " << mParamType << endl;
-        break;
+         break;
 
       case kForwardByZoneQuery:
-        strncpy(mParamName, qname.c_str(), sizeof(mParamName));
-        strncpy(mParamType, qtype.getName().c_str(), sizeof(mParamType));       
-        mParamZoneId = zoneId;
+         strncpy(mParamName, qname.c_str(), sizeof(mParamName));
+         strncpy(mParamType, qtype.getName().c_str(), sizeof(mParamType));      
+         mParamZoneId = zoneId;
          //cerr << ">>>>>>>>  Name = " << mParamName << " Type = " << mParamType << " ZoneId = " << mParamZoneId << endl;
-        break;
+         break;
 
       case kForwardAnyQuery:
       case kForwardWildcardAnyQuery:
-        strncpy(mParamName, qname.c_str(), sizeof(mParamName));
+         strncpy(mParamName, qname.c_str(), sizeof(mParamName));
          //cerr << ">>>>>>>>  Name = " << mParamName << endl;
-        break;
+         break;
    }
 
    //
@@ -596,14 +596,14 @@ class DB2Factory : public BackendFactory
   
       void declareArguments(const string &suffix="")
       {
-        declare(suffix,"server","Server","powerdns");
-        declare(suffix,"user","User","powerdns");
-        declare(suffix,"password","Password","powerdns");
+         declare(suffix,"server","Server","powerdns");
+         declare(suffix,"user","User","powerdns");
+         declare(suffix,"password","Password","powerdns");
       }
       
       DNSBackend *make(const string &suffix="")
       {
-        return new DB2Backend(suffix);
+         return new DB2Backend(suffix);
       }
 };
 
@@ -615,8 +615,8 @@ class DB2Loader
 
       Loader()
       {
-        BackendMakers().report(new DB2Factory);
-        L << Logger::Notice << kBackendName << " This is the DB2 module version "VERSION" ("__DATE__", "__TIME__") reporting" << endl;
+         BackendMakers().report(new DB2Factory);
+         L << Logger::Notice << kBackendName << " This is the DB2 module version "VERSION" ("__DATE__", "__TIME__") reporting" << endl;
       }
 };
 
index 19296160e2d88edeba3ee799e11ddbcaee19b0d2..106a8edd4c9139d103edf9728ce7722a78d704e4 100644 (file)
@@ -1,8 +1,8 @@
-/*     geobackend.cc
- *     Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
- *             This software is licensed under the terms of the GPL, version 2.
+/*        geobackend.cc
+ *         Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
+ *             This software is licensed under the terms of the GPL, version 2.
  * 
- *     $Id$
+ *         $Id$
  */
 
 #include <fstream>
@@ -47,491 +47,491 @@ GeoRecord::GeoRecord() : origin(".") {}
 // Class GeoBackend, public methods
 
 GeoBackend::GeoBackend(const string &suffix) : forceReload(false) {
-       setArgPrefix("geo" + suffix);
-       
-       // Make sure only one (the first) backend instance is initializing static things
-       Lock lock(&startup_lock);
-
-       backendcount++;
-
-       if (!first)
-               return;
-       first = false;
-       
-       ipt = NULL;
-       
-       loadZoneName();
-       loadTTLValues();
-       loadSOAValues();
-       loadNSRecords();
-       reload();
+        setArgPrefix("geo" + suffix);
+        
+        // Make sure only one (the first) backend instance is initializing static things
+        Lock lock(&startup_lock);
+
+        backendcount++;
+
+        if (!first)
+               return;
+        first = false;
+        
+        ipt = NULL;
+        
+        loadZoneName();
+        loadTTLValues();
+        loadSOAValues();
+        loadNSRecords();
+        reload();
 }
 
 GeoBackend::~GeoBackend() {
-       Lock lock(&startup_lock);
-       backendcount--; 
-       if (backendcount == 0) {
-               for (map<string, GeoRecord*>::iterator i = georecords.begin(); i != georecords.end(); ++i)
-                       delete i->second;
-               
-               if (ipt != NULL) {
-                       delete ipt;
-                       ipt = NULL;
-               }
-       }
+        Lock lock(&startup_lock);
+        backendcount--;        
+        if (backendcount == 0) {
+               for (map<string, GeoRecord*>::iterator i = georecords.begin(); i != georecords.end(); ++i)
+                       delete i->second;
+               
+               if (ipt != NULL) {
+                       delete ipt;
+                       ipt = NULL;
+               }
+        }
 }
 
 bool GeoBackend::getSOA(const string &name, SOAData &soadata, DNSPacket *p) {
-       if (toLower(name) != toLower(zoneName) || soaMasterServer.empty() || soaHostmaster.empty())
-               return false;
-       
-       soadata.nameserver = soaMasterServer;
-       soadata.hostmaster = soaHostmaster;
-       soadata.domain_id = 1;  // We serve only one zone
-       soadata.db = this;
-       
-       // These values are bogus for backends like this one
-       soadata.serial = 1;
-       soadata.refresh = 86400;
-       soadata.retry = 2*soadata.refresh;
-       soadata.expire = 7*soadata.refresh;
-       soadata.default_ttl = 3600;     
-       
-       return true;
+        if (toLower(name) != toLower(zoneName) || soaMasterServer.empty() || soaHostmaster.empty())
+               return false;
+        
+        soadata.nameserver = soaMasterServer;
+        soadata.hostmaster = soaHostmaster;
+        soadata.domain_id = 1; // We serve only one zone
+        soadata.db = this;
+        
+        // These values are bogus for backends like this one
+        soadata.serial = 1;
+        soadata.refresh = 86400;
+        soadata.retry = 2*soadata.refresh;
+        soadata.expire = 7*soadata.refresh;
+        soadata.default_ttl = 3600;    
+        
+        return true;
 }
 
 void GeoBackend::lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p, int zoneId) {
-       answers.clear();
-       
-       if ((qtype.getCode() == QType::NS || qtype.getCode() == QType::ANY)
-               && toLower(qdomain) == toLower(zoneName))
-               queueNSRecords(qdomain);
-       
-       if (qtype.getCode() == QType::ANY || qtype.getCode() == QType::CNAME)
-               answerGeoRecord(qtype, qdomain, pkt_p);
-       
-       if ((qtype.getCode() == QType::ANY || qtype.getCode() == QType::A)
-               && toLower(qdomain) == "localhost." + toLower(zoneName))
-               answerLocalhostRecord(qdomain, pkt_p);
-       
-       if (!answers.empty())   
-               i_answers = answers.begin();            
+        answers.clear();
+        
+        if ((qtype.getCode() == QType::NS || qtype.getCode() == QType::ANY)
+               && toLower(qdomain) == toLower(zoneName))
+               queueNSRecords(qdomain);
+        
+        if (qtype.getCode() == QType::ANY || qtype.getCode() == QType::CNAME)
+               answerGeoRecord(qtype, qdomain, pkt_p);
+        
+        if ((qtype.getCode() == QType::ANY || qtype.getCode() == QType::A)
+               && toLower(qdomain) == "localhost." + toLower(zoneName))
+               answerLocalhostRecord(qdomain, pkt_p);
+        
+        if (!answers.empty())  
+               i_answers = answers.begin();            
 }
 
 bool GeoBackend::list(const string &target, int domain_id) {
-       answers.clear();
-       queueNSRecords(zoneName);
-       answerLocalhostRecord("localhost."+zoneName, NULL);
-       queueGeoRecords();
-       
-       if (!answers.empty())
-               i_answers = answers.begin();
-       return true;
+        answers.clear();
+        queueNSRecords(zoneName);
+        answerLocalhostRecord("localhost."+zoneName, NULL);
+        queueGeoRecords();
+        
+        if (!answers.empty())
+               i_answers = answers.begin();
+        return true;
 }
 
 bool GeoBackend::get(DNSResourceRecord &r) {
-       if (answers.empty()) return false;
-       
-       if (i_answers != answers.end()) {
-               // FIXME DNSResourceRecord could do with a copy constructor
-               DNSResourceRecord *ir = *i_answers;
-               r.qtype = ir->qtype;
-               r.qname = ir->qname;
-               r.content = ir->content;
-               r.priority = ir->priority;
-               r.ttl = ir->ttl;
-               r.domain_id = ir->domain_id;
-               r.last_modified = ir->last_modified;
-                               
-               delete ir;
-               i_answers++;
-               return true;
-       }
-       else {
-               answers.clear();
-               return false;
-       }
+        if (answers.empty()) return false;
+        
+        if (i_answers != answers.end()) {
+               // FIXME DNSResourceRecord could do with a copy constructor
+               DNSResourceRecord *ir = *i_answers;
+               r.qtype = ir->qtype;
+               r.qname = ir->qname;
+               r.content = ir->content;
+               r.priority = ir->priority;
+               r.ttl = ir->ttl;
+               r.domain_id = ir->domain_id;
+               r.last_modified = ir->last_modified;
+                               
+               delete ir;
+               i_answers++;
+               return true;
+        }
+        else {
+               answers.clear();
+               return false;
+        }
 }
 
 void GeoBackend::reload() {
-       forceReload = true;
-       rediscover();
-       forceReload = false;
+        forceReload = true;
+        rediscover();
+        forceReload = false;
 }
 
 void GeoBackend::rediscover(string *status) {
-       // Store current time for use after discovery
-       struct timeval nowtime;
-       gettimeofday(&nowtime, NULL);
-       
-       loadIPLocationMap();
-       loadGeoRecords();
-       
-       // Use time at start of discovery for checking whether files have changed
-       // next time
-       lastDiscoverTime = nowtime.tv_sec;
+        // Store current time for use after discovery
+        struct timeval nowtime;
+        gettimeofday(&nowtime, NULL);
+        
+        loadIPLocationMap();
+        loadGeoRecords();
+        
+        // Use time at start of discovery for checking whether files have changed
+        // next time
+        lastDiscoverTime = nowtime.tv_sec;
 }
 
 // Private methods
 
-void GeoBackend::answerGeoRecord(const QType &qtype, const string &qdomain, DNSPacket *p) {            
-       const string lqdomain = toLower(qdomain);
-
-       if (georecords.count(lqdomain) == 0) 
-               return;
-       
-       GeoRecord *gr = georecords[lqdomain];
-                                       
-       // Try to find the isocode of the country corresponding to the source ip
-       // If that fails, use the default
-       short isocode = 0;
-       if (p != NULL && ipt != NULL) {
-               try {
-                       isocode = ipt->lookup(p->getRemote());
-               }
-               catch(ParsePrefixException &e) {        // Ignore
-                       L << Logger::Notice << logprefix << "Unable to parse IP '"
-                               << p->getRemote()       << " as IPv4 prefix" << endl;
-               }
-       }
-       
-       DNSResourceRecord *rr = new DNSResourceRecord;
-       string target = resolveTarget(*gr, isocode);
-       fillGeoResourceRecord(qdomain, target, rr);
-       
-       L << Logger::Debug << logprefix << "Serving " << qdomain << " "
-               << rr->qtype.getName() << " " << target << " to " << p->getRemote()
-               << " (" << isocode << ")" << endl;
-               
-       answers.push_back(rr);          
+void GeoBackend::answerGeoRecord(const QType &qtype, const string &qdomain, DNSPacket *p) {            
+        const string lqdomain = toLower(qdomain);
+
+        if (georecords.count(lqdomain) == 0) 
+               return;
+        
+        GeoRecord *gr = georecords[lqdomain];
+                                       
+        // Try to find the isocode of the country corresponding to the source ip
+        // If that fails, use the default
+        short isocode = 0;
+        if (p != NULL && ipt != NULL) {
+               try {
+                       isocode = ipt->lookup(p->getRemote());
+               }
+               catch(ParsePrefixException &e) {        // Ignore
+                       L << Logger::Notice << logprefix << "Unable to parse IP '"
+                               << p->getRemote()       << " as IPv4 prefix" << endl;
+               }
+        }
+        
+        DNSResourceRecord *rr = new DNSResourceRecord;
+        string target = resolveTarget(*gr, isocode);
+        fillGeoResourceRecord(qdomain, target, rr);
+        
+        L << Logger::Debug << logprefix << "Serving " << qdomain << " "
+               << rr->qtype.getName() << " " << target << " to " << p->getRemote()
+               << " (" << isocode << ")" << endl;
+               
+        answers.push_back(rr);         
 }
 
 void GeoBackend::answerLocalhostRecord(const string &qdomain, DNSPacket *p) {
-       short isocode = 0;
-       if (p != NULL) {
-               try {
-                       isocode = ipt->lookup(p->getRemote());
-               }
-               catch(ParsePrefixException &e) {}       // Ignore
-       }
-       
-       ostringstream target;
-       target << "127.0." << ((isocode >> 8) & 0xff) << "." << (isocode & 0xff);
-       
-       DNSResourceRecord *rr = new DNSResourceRecord;
-       rr->qtype = QType::A;
-       rr->qname = qdomain;
-       rr->content = target.str();
-       rr->priority = 0;
-       rr->ttl = geoTTL;
-       rr->domain_id = 1;
-       rr->last_modified = 0;
-       
-       answers.push_back(rr);  
+        short isocode = 0;
+        if (p != NULL) {
+               try {
+                       isocode = ipt->lookup(p->getRemote());
+               }
+               catch(ParsePrefixException &e) {}       // Ignore
+        }
+        
+        ostringstream target;
+        target << "127.0." << ((isocode >> 8) & 0xff) << "." << (isocode & 0xff);
+        
+        DNSResourceRecord *rr = new DNSResourceRecord;
+        rr->qtype = QType::A;
+        rr->qname = qdomain;
+        rr->content = target.str();
+        rr->priority = 0;
+        rr->ttl = geoTTL;
+        rr->domain_id = 1;
+        rr->last_modified = 0;
+        
+        answers.push_back(rr); 
 }
 
 void GeoBackend::queueNSRecords(const string &qname) {
-       // nsRecords may be empty, e.g. when used in overlay mode
-       
-       for (vector<string>::const_iterator i = nsRecords.begin(); i != nsRecords.end(); ++i) {
-               DNSResourceRecord *rr = new DNSResourceRecord;
-               rr->qtype = QType::NS;
-               rr->qname = qname;
-               rr->content = *i;
-               rr->priority = 0;
-               rr->ttl = nsTTL;
-               rr->domain_id = 1;
-               rr->last_modified = 0;
-               
-               answers.push_back(rr);
-       }       
+        // nsRecords may be empty, e.g. when used in overlay mode
+        
+        for (vector<string>::const_iterator i = nsRecords.begin(); i != nsRecords.end(); ++i) {
+               DNSResourceRecord *rr = new DNSResourceRecord;
+               rr->qtype = QType::NS;
+               rr->qname = qname;
+               rr->content = *i;
+               rr->priority = 0;
+               rr->ttl = nsTTL;
+               rr->domain_id = 1;
+               rr->last_modified = 0;
+               
+               answers.push_back(rr);
+        }      
 }
 
 void GeoBackend::queueGeoRecords() {
-       for (map<string, GeoRecord*>::const_iterator i = georecords.begin(); i != georecords.end(); ++i) {
-               GeoRecord *gr = i->second;
-               DNSResourceRecord *rr = new DNSResourceRecord;
-               
-               fillGeoResourceRecord(gr->qname, resolveTarget(*gr, 0), rr);
-               answers.push_back(rr);
-       }
+        for (map<string, GeoRecord*>::const_iterator i = georecords.begin(); i != georecords.end(); ++i) {
+               GeoRecord *gr = i->second;
+               DNSResourceRecord *rr = new DNSResourceRecord;
+               
+               fillGeoResourceRecord(gr->qname, resolveTarget(*gr, 0), rr);
+               answers.push_back(rr);
+        }
 }
 
 void GeoBackend::fillGeoResourceRecord(const string &qdomain, const string &target, DNSResourceRecord *rr) {
-       rr->qtype = QType::CNAME;
-       rr->qname = qdomain;
-       rr->content = target;
-       rr->priority = 0;
-       rr->ttl = geoTTL;
-       rr->domain_id = 1;
-       rr->last_modified = 0;
+        rr->qtype = QType::CNAME;
+        rr->qname = qdomain;
+        rr->content = target;
+        rr->priority = 0;
+        rr->ttl = geoTTL;
+        rr->domain_id = 1;
+        rr->last_modified = 0;
 }
 
 const string GeoBackend::resolveTarget(const GeoRecord &gr, short isocode) const {
-       // If no mapping exists for this isocode, use the default
-       if (gr.dirmap.count(isocode) == 0)
-               isocode = 0;
-       
-       // Append $ORIGIN only if target does not end with a dot                
-       string target(gr.dirmap.find(isocode)->second);
-       if (target[target.size()-1] != '.')
-               target += gr.origin;
-       else
-               target.resize(target.size()-1);
-               
-       return target;
+        // If no mapping exists for this isocode, use the default
+        if (gr.dirmap.count(isocode) == 0)
+               isocode = 0;
+        
+        // Append $ORIGIN only if target does not end with a dot               
+        string target(gr.dirmap.find(isocode)->second);
+        if (target[target.size()-1] != '.')
+               target += gr.origin;
+        else
+               target.resize(target.size()-1);
+               
+        return target;
 }
 
 void GeoBackend::loadZoneName() {
-       zoneName = getArg("zone");
-       if (zoneName.empty())
-               throw AhuException("zone parameter must be set");       
+        zoneName = getArg("zone");
+        if (zoneName.empty())
+               throw AhuException("zone parameter must be set");       
 }
 
 void GeoBackend::loadTTLValues() {
-       geoTTL = getArgAsNum("ttl");
-       nsTTL = getArgAsNum("ns-ttl");
+        geoTTL = getArgAsNum("ttl");
+        nsTTL = getArgAsNum("ns-ttl");
 }
 
 void GeoBackend::loadSOAValues() {
-       vector<string> values;
-       stringtok(values, getArg("soa-values"), " ,");
-       
-       if (values.empty())
-               // No SOA values, probably no SOA record wanted because of overlay mode
-               return;
-       
-       if (values.size() != 2)
-               throw AhuException("Invalid number of soa-values specified in configuration");
-       
-       soaMasterServer = values[0];
-       soaHostmaster = values[1];      
+        vector<string> values;
+        stringtok(values, getArg("soa-values"), " ,");
+        
+        if (values.empty())
+               // No SOA values, probably no SOA record wanted because of overlay mode
+               return;
+        
+        if (values.size() != 2)
+               throw AhuException("Invalid number of soa-values specified in configuration");
+        
+        soaMasterServer = values[0];
+        soaHostmaster = values[1];     
 }
 
 void GeoBackend::loadNSRecords() {
-       stringtok(nsRecords, getArg("ns-records"), " ,");
+        stringtok(nsRecords, getArg("ns-records"), " ,");
 }
 
 void GeoBackend::loadIPLocationMap() {
-       string filename = getArg("ip-map-zonefile");
-       
-       if (filename.empty())
-               throw AhuException("No IP map zonefile specified in configuration");
-       
-       // Stat file to see if it has changed since last read
-       struct stat stbuf;
-       if (stat(filename.c_str(), &stbuf) != 0 || !S_ISREG(stbuf.st_mode)) {
-               const string errormsg = "stat() failed, or " + filename + " is no regular file.";
-               if (lastDiscoverTime == 0)      // We have no older map, bail out
-                       throw AhuException(errormsg);
-               else {
-                       // Log, but continue
-                       L << Logger::Error << logprefix << errormsg;
-                       return;
-               }
-       }
-       
-       if (stbuf.st_mtime < lastDiscoverTime && !forceReload)  // File hasn't changed
-               return;
-       
-       ifstream ifs(filename.c_str(), ios::in);
-       if (!ifs)
-               throw AhuException("Unable to open IP map zonefile for read: " + stringerror());
-               
-       L << Logger::Info << logprefix << "Parsing IP map zonefile" << endl;
-       
-       IPPrefTree *new_ipt = new IPPrefTree;
-       string line;
-       int linenr = 0, entries = 0;
-       
-       while (getline(ifs, line)) {
-               linenr++;               
-               trim_right(line);       // Erase whitespace
-               
-               if (line[0] == '#')
-                       continue;       // Skip comments
-
-               vector<string> words;
-               stringtok(words, line, " :");
-               
-               if (words.empty() || words[0] == "$SOA")
-                       continue;
-                       
-               // Assume words[0] is a prefix. Feed it to the ip prefix tree
-               try {
-                       // Parse country code nr
-                       if (words.size() < 2 || words[1].empty()) {
-                               L << Logger::Warning << logprefix
-                                       << "Country code number is missing at line " << linenr << endl;
-                               continue;
-                       }
-                       
-                       struct in_addr addr;
-                       if (inet_aton(words[1].c_str(), &addr) < 0) {
-                               L << Logger::Warning << logprefix << "Invalid IP address '"
-                                       << words[1] << " at line " << linenr << endl;
-                               continue;
-                       }
-                       short value = ntohl(addr.s_addr) & 0x7fff;
-                       
-                       new_ipt->add(words[0], value);
-                       entries++;
-               }
-               catch(ParsePrefixException &e) {
-                       L << Logger::Warning << logprefix << "Error while parsing prefix at line "
-                               << linenr << ": " << e.reason << endl;
-               }
-       }
-       ifs.close();
-       
-       L << Logger::Info << logprefix << "Finished parsing IP map zonefile: added " 
-               << entries << " prefixes, stored in " << new_ipt->getNodeCount()
-               << " nodes using " << new_ipt->getMemoryUsage() << " bytes of memory"
-               << endl;
-       
-       // Swap the new tree with the old tree
-       IPPrefTree *oldipt = NULL;
-       {
-               Lock iptl(&ipt_lock);
-               
-               oldipt = ipt;
-               ipt = new_ipt;
-       }
-       
-       // Delete the old ip prefix tree
-       if (oldipt != NULL)
-               delete oldipt;
+        string filename = getArg("ip-map-zonefile");
+        
+        if (filename.empty())
+               throw AhuException("No IP map zonefile specified in configuration");
+        
+        // Stat file to see if it has changed since last read
+        struct stat stbuf;
+        if (stat(filename.c_str(), &stbuf) != 0 || !S_ISREG(stbuf.st_mode)) {
+               const string errormsg = "stat() failed, or " + filename + " is no regular file.";
+               if (lastDiscoverTime == 0)      // We have no older map, bail out
+                       throw AhuException(errormsg);
+               else {
+                       // Log, but continue
+                       L << Logger::Error << logprefix << errormsg;
+                       return;
+               }
+        }
+        
+        if (stbuf.st_mtime < lastDiscoverTime && !forceReload) // File hasn't changed
+               return;
+        
+        ifstream ifs(filename.c_str(), ios::in);
+        if (!ifs)
+               throw AhuException("Unable to open IP map zonefile for read: " + stringerror());
+               
+        L << Logger::Info << logprefix << "Parsing IP map zonefile" << endl;
+        
+        IPPrefTree *new_ipt = new IPPrefTree;
+        string line;
+        int linenr = 0, entries = 0;
+        
+        while (getline(ifs, line)) {
+               linenr++;               
+               trim_right(line);       // Erase whitespace
+               
+               if (line[0] == '#')
+                       continue;       // Skip comments
+
+               vector<string> words;
+               stringtok(words, line, " :");
+               
+               if (words.empty() || words[0] == "$SOA")
+                       continue;
+                       
+               // Assume words[0] is a prefix. Feed it to the ip prefix tree
+               try {
+                       // Parse country code nr
+                       if (words.size() < 2 || words[1].empty()) {
+                               L << Logger::Warning << logprefix
+                                       << "Country code number is missing at line " << linenr << endl;
+                               continue;
+                       }
+                       
+                       struct in_addr addr;
+                       if (inet_aton(words[1].c_str(), &addr) < 0) {
+                               L << Logger::Warning << logprefix << "Invalid IP address '"
+                                       << words[1] << " at line " << linenr << endl;
+                               continue;
+                       }
+                       short value = ntohl(addr.s_addr) & 0x7fff;
+                       
+                       new_ipt->add(words[0], value);
+                       entries++;
+               }
+               catch(ParsePrefixException &e) {
+                       L << Logger::Warning << logprefix << "Error while parsing prefix at line "
+                               << linenr << ": " << e.reason << endl;
+               }
+        }
+        ifs.close();
+        
+        L << Logger::Info << logprefix << "Finished parsing IP map zonefile: added " 
+               << entries << " prefixes, stored in " << new_ipt->getNodeCount()
+               << " nodes using " << new_ipt->getMemoryUsage() << " bytes of memory"
+               << endl;
+        
+        // Swap the new tree with the old tree
+        IPPrefTree *oldipt = NULL;
+        {
+               Lock iptl(&ipt_lock);
+               
+               oldipt = ipt;
+               ipt = new_ipt;
+        }
+        
+        // Delete the old ip prefix tree
+        if (oldipt != NULL)
+               delete oldipt;
 }
 
 void GeoBackend::loadGeoRecords() {
-       vector<GeoRecord*> newgrs;
-               
-       vector<string> maps;
-       stringtok(maps, getArg("maps"), " ,");
-       for (vector<string>::const_iterator i = maps.begin(); i != maps.end(); ++i) {
-               struct stat stbuf;
-               
-               if (stat(i->c_str(), &stbuf) != 0)
-                       continue;
-               
-               if (S_ISREG(stbuf.st_mode)) {
-                       // Regular file
-                       GeoRecord *gr = new GeoRecord;
-                       gr->directorfile = *i;
-                       newgrs.push_back(gr);
-               }
-               else if (S_ISDIR(stbuf.st_mode)) {      // Directory
-                       DIR *dir = opendir(i->c_str());
-                       if (dir != NULL) {
-                               struct dirent *dent;
-                               while ((dent = readdir(dir)) != NULL) {
-                                       string filename(*i);
-                                       if (filename[filename.size()-1] != '/')
-                                               filename += '/';
-                                       
-                                       if (dent->d_name[0] == '.')
-                                               continue;       // skip filenames starting with a dot
-                                               
-                                       filename += dent->d_name;
-                                       
-                                       if (stat(filename.c_str(), &stbuf) != 0 || !S_ISREG(stbuf.st_mode))
-                                               continue;       // skip everything but regular files
-                                               
-                                       GeoRecord *gr = new GeoRecord;
-                                       gr->directorfile = filename;
-                                       newgrs.push_back(gr);
-                               }
-                               closedir(dir);
-                       }       
-               }
-       }
-       
-       loadDirectorMaps(newgrs);
+        vector<GeoRecord*> newgrs;
+               
+        vector<string> maps;
+        stringtok(maps, getArg("maps"), " ,");
+        for (vector<string>::const_iterator i = maps.begin(); i != maps.end(); ++i) {
+               struct stat stbuf;
+               
+               if (stat(i->c_str(), &stbuf) != 0)
+                       continue;
+               
+               if (S_ISREG(stbuf.st_mode)) {
+                       // Regular file
+                       GeoRecord *gr = new GeoRecord;
+                       gr->directorfile = *i;
+                       newgrs.push_back(gr);
+               }
+               else if (S_ISDIR(stbuf.st_mode)) {      // Directory
+                       DIR *dir = opendir(i->c_str());
+                       if (dir != NULL) {
+                               struct dirent *dent;
+                               while ((dent = readdir(dir)) != NULL) {
+                                       string filename(*i);
+                                       if (filename[filename.size()-1] != '/')
+                                               filename += '/';
+                                       
+                                       if (dent->d_name[0] == '.')
+                                               continue;       // skip filenames starting with a dot
+                                               
+                                       filename += dent->d_name;
+                                       
+                                       if (stat(filename.c_str(), &stbuf) != 0 || !S_ISREG(stbuf.st_mode))
+                                               continue;       // skip everything but regular files
+                                               
+                                       GeoRecord *gr = new GeoRecord;
+                                       gr->directorfile = filename;
+                                       newgrs.push_back(gr);
+                               }
+                               closedir(dir);
+                       }       
+               }
+        }
+        
+        loadDirectorMaps(newgrs);
 }
 
 void GeoBackend::loadDirectorMaps(const vector<GeoRecord*> &newgrs) {
-       map<string, GeoRecord*> new_georecords;
-       
-       int mapcount = 0;
-       for (vector<GeoRecord*>::const_iterator i = newgrs.begin(); i != newgrs.end(); ++i) {
-               GeoRecord *gr = *i;
-               try {
-                       loadDirectorMap(*gr);
-                       if (new_georecords.count(gr->qname) == 0) {
-                               new_georecords[gr->qname] = gr;
-                               mapcount++;
-                       }
-                       else
-                               throw AhuException("duplicate georecord " + gr->qname + ", skipping");
-               }
-               catch(AhuException &e) {
-                       L << Logger::Error << logprefix << "Error occured while reading director file "
-                               << gr->directorfile << ": " << e.reason << endl;
-                       delete gr;
-               }
-       }
-       
-       // Swap the new georecord map with the old one.
-       georecords.swap(new_georecords);
-               
-       L << Logger::Notice << logprefix << "Finished parsing " << mapcount 
-               << " director map files, "      << newgrs.size() - mapcount << " failures" << endl;
-
-       // Cleanup old georecords
-       for (map<string, GeoRecord*>::iterator i = new_georecords.begin(); i != new_georecords.end(); ++i)
-               delete i->second;
+        map<string, GeoRecord*> new_georecords;
+        
+        int mapcount = 0;
+        for (vector<GeoRecord*>::const_iterator i = newgrs.begin(); i != newgrs.end(); ++i) {
+               GeoRecord *gr = *i;
+               try {
+                       loadDirectorMap(*gr);
+                       if (new_georecords.count(gr->qname) == 0) {
+                               new_georecords[gr->qname] = gr;
+                               mapcount++;
+                       }
+                       else
+                               throw AhuException("duplicate georecord " + gr->qname + ", skipping");
+               }
+               catch(AhuException &e) {
+                       L << Logger::Error << logprefix << "Error occured while reading director file "
+                               << gr->directorfile << ": " << e.reason << endl;
+                       delete gr;
+               }
+        }
+        
+        // Swap the new georecord map with the old one.
+        georecords.swap(new_georecords);
+               
+        L << Logger::Notice << logprefix << "Finished parsing " << mapcount 
+               << " director map files, "      << newgrs.size() - mapcount << " failures" << endl;
+
+        // Cleanup old georecords
+        for (map<string, GeoRecord*>::iterator i = new_georecords.begin(); i != new_georecords.end(); ++i)
+               delete i->second;
 }
 
 void GeoBackend::loadDirectorMap(GeoRecord &gr) {
-       L << Logger::Info << logprefix << "Parsing director map " << gr.directorfile << endl;
-       
-       ifstream ifs(gr.directorfile.c_str(), ios::in);
-       if (!ifs)
-               throw AhuException("Error opening file.");
-       
-       string line;
-       while(getline(ifs, line)) {
-               trim_right(line);       // Erase whitespace
-
-               if (line.empty() || line[0] == '#')
-                       continue;       // Skip empty lines and comments
-       
-               // Parse $RECORD
-               if (line.substr(0, 7) == "$RECORD") {
-                       gr.qname = line.substr(8);
-                       trim_right(gr.qname);
-                       if (gr.qname[gr.qname.size()-1] != '.')
-                               gr.qname += '.' + zoneName;
-                       else {
-                               gr.qname.resize(gr.qname.size()-1);
-                               // Check whether zoneName is a prefix of this FQDN
-                               if (gr.qname.rfind(zoneName) == string::npos)
-                                       throw AhuException("georecord " + gr.qname + " is out of zone " + zoneName);
-                       }
-                       continue;
-               }
-       
-               // Parse $ORIGIN
-               if (line.substr(0, 7) == "$ORIGIN") {
-                       gr.origin = line.substr(8);
-                       trim_right_if(gr.origin, boost::is_any_of(" \t."));
-                       gr.origin.insert(0, ".");
-                       continue;
-               }       
-               
-               istringstream ii(line);
-               short isocode;
-               string target;
-               ii >> isocode >> target;
-               
-               gr.dirmap[isocode] = target;
-       }
-       
-       // Do some checks on the validness of this director map / georecord
-       
-       if (gr.qname.empty())
-               throw AhuException("$RECORD line empty or missing, georecord qname unknown");
-       
-       if (gr.dirmap.count(0) == 0)
-               throw AhuException("No default (0) director map entry");
+        L << Logger::Info << logprefix << "Parsing director map " << gr.directorfile << endl;
+        
+        ifstream ifs(gr.directorfile.c_str(), ios::in);
+        if (!ifs)
+               throw AhuException("Error opening file.");
+        
+        string line;
+        while(getline(ifs, line)) {
+               trim_right(line);       // Erase whitespace
+
+               if (line.empty() || line[0] == '#')
+                       continue;       // Skip empty lines and comments
+        
+               // Parse $RECORD
+               if (line.substr(0, 7) == "$RECORD") {
+                       gr.qname = line.substr(8);
+                       trim_right(gr.qname);
+                       if (gr.qname[gr.qname.size()-1] != '.')
+                               gr.qname += '.' + zoneName;
+                       else {
+                               gr.qname.resize(gr.qname.size()-1);
+                               // Check whether zoneName is a prefix of this FQDN
+                               if (gr.qname.rfind(zoneName) == string::npos)
+                                       throw AhuException("georecord " + gr.qname + " is out of zone " + zoneName);
+                       }
+                       continue;
+               }
+        
+               // Parse $ORIGIN
+               if (line.substr(0, 7) == "$ORIGIN") {
+                       gr.origin = line.substr(8);
+                       trim_right_if(gr.origin, boost::is_any_of(" \t."));
+                       gr.origin.insert(0, ".");
+                       continue;
+               }       
+               
+               istringstream ii(line);
+               short isocode;
+               string target;
+               ii >> isocode >> target;
+               
+               gr.dirmap[isocode] = target;
+        }
+        
+        // Do some checks on the validness of this director map / georecord
+        
+        if (gr.qname.empty())
+               throw AhuException("$RECORD line empty or missing, georecord qname unknown");
+        
+        if (gr.dirmap.count(0) == 0)
+               throw AhuException("No default (0) director map entry");
 }
index b46b89406fa7fb85548ee27e341569e228f5b725..9edf2af20c06130b7f3cc5fd829a784a3d0c237a 100644 (file)
@@ -1,8 +1,8 @@
-/*     geobackend.hh
- *             Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
- *             This software is licensed under the terms of the GPL, version 2.
+/*        geobackend.hh
+ *             Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
+ *             This software is licensed under the terms of the GPL, version 2.
  * 
- *             $Id$
+ *             $Id$
  */
 
 
@@ -19,96 +19,96 @@ using namespace std;
 
 class GeoRecord {
 public:
-       GeoRecord();
+        GeoRecord();
 
-       string qname;
-       string origin;
-       string directorfile;
-       map<short, string> dirmap;
+        string qname;
+        string origin;
+        string directorfile;
+        map<short, string> dirmap;
 };
 
 class GeoBackend : public DNSBackend{
 public:
 
-       GeoBackend(const string &suffix);
-       ~GeoBackend();
-       
-       virtual void lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1);
-       virtual bool list(const string &target, int domain_id);
-       virtual bool get(DNSResourceRecord &r);
-       virtual bool getSOA(const string &name, SOAData &soadata, DNSPacket *p=0);
-       
-       virtual void reload();
-       virtual void rediscover(string *status = 0);
-       
+        GeoBackend(const string &suffix);
+        ~GeoBackend();
+        
+        virtual void lookup(const QType &qtype, const string &qdomain, DNSPacket *pkt_p=0, int zoneId=-1);
+        virtual bool list(const string &target, int domain_id);
+        virtual bool get(DNSResourceRecord &r);
+        virtual bool getSOA(const string &name, SOAData &soadata, DNSPacket *p=0);
+        
+        virtual void reload();
+        virtual void rediscover(string *status = 0);
+        
 private:
-       // Static resources, shared by all instances
-       static IPPrefTree *ipt;
-       static vector<string> nsRecords;
-       static map<string, GeoRecord*> georecords;
-       static string soaMasterServer;
-       static string soaHostmaster;
-       static string zoneName;
-       static uint32_t geoTTL;
-       static uint32_t nsTTL;
-       static time_t lastDiscoverTime;
-       const static string logprefix;
-       
-       bool forceReload;
-       
-       // Locking
-       static bool first;
-       static int backendcount;
-       static pthread_mutex_t startup_lock;
-       static pthread_mutex_t ipt_lock;
+        // Static resources, shared by all instances
+        static IPPrefTree *ipt;
+        static vector<string> nsRecords;
+        static map<string, GeoRecord*> georecords;
+        static string soaMasterServer;
+        static string soaHostmaster;
+        static string zoneName;
+        static uint32_t geoTTL;
+        static uint32_t nsTTL;
+        static time_t lastDiscoverTime;
+        const static string logprefix;
+        
+        bool forceReload;
+        
+        // Locking
+        static bool first;
+        static int backendcount;
+        static pthread_mutex_t startup_lock;
+        static pthread_mutex_t ipt_lock;
 
-       vector<DNSResourceRecord*> answers;
-       vector<DNSResourceRecord*>::const_iterator i_answers;
-       
-       void answerGeoRecord(const QType &qtype, const string &qdomain, DNSPacket *p);
-       void answerLocalhostRecord(const string &qdomain, DNSPacket *p);
-       void queueNSRecords(const string &qname);
-       void queueGeoRecords();
-       void fillGeoResourceRecord(const string &qname, const string &target, DNSResourceRecord *rr);
-       const inline string resolveTarget(const GeoRecord &gr, short isocode) const;
+        vector<DNSResourceRecord*> answers;
+        vector<DNSResourceRecord*>::const_iterator i_answers;
+        
+        void answerGeoRecord(const QType &qtype, const string &qdomain, DNSPacket *p);
+        void answerLocalhostRecord(const string &qdomain, DNSPacket *p);
+        void queueNSRecords(const string &qname);
+        void queueGeoRecords();
+        void fillGeoResourceRecord(const string &qname, const string &target, DNSResourceRecord *rr);
+        const inline string resolveTarget(const GeoRecord &gr, short isocode) const;
 
-       void loadZoneName();
-       void loadTTLValues();
-       void loadSOAValues();
-       void loadNSRecords();
-       void loadIPLocationMap();
-       void loadGeoRecords();
-       void loadDirectorMaps(const vector<GeoRecord*> &newgrs);
-       void loadDirectorMap(GeoRecord &gr);
+        void loadZoneName();
+        void loadTTLValues();
+        void loadSOAValues();
+        void loadNSRecords();
+        void loadIPLocationMap();
+        void loadGeoRecords();
+        void loadDirectorMaps(const vector<GeoRecord*> &newgrs);
+        void loadDirectorMap(GeoRecord &gr);
 };
 
 class GeoFactory : public BackendFactory{
 public:
-       GeoFactory() : BackendFactory("geo") {}
-       
-       void declareArguments(const string &suffix = "") {
-               declare(suffix, "zone", "zonename to be served", "");
-               declare(suffix, "soa-values", "values of the SOA master nameserver and hostmaster fields, comma seperated", "");
-               declare(suffix, "ns-records", "targets of the NS records, comma seperated.", "");
-               declare(suffix, "ttl", "TTL value for geo records", "3600");
-               declare(suffix, "ns-ttl", "TTL value for NS records", "86400");
-               declare(suffix, "ip-map-zonefile", "path to the rbldnsd format zonefile", "zz.countries.nerd.dk.rbldnsd");
-               declare(suffix, "maps", "list of paths to director maps or directories containing director map files", "");
-       }
-       
-       DNSBackend *make(const string &suffix) {
-               return new GeoBackend(suffix);
-       }
+        GeoFactory() : BackendFactory("geo") {}
+        
+        void declareArguments(const string &suffix = "") {
+               declare(suffix, "zone", "zonename to be served", "");
+               declare(suffix, "soa-values", "values of the SOA master nameserver and hostmaster fields, comma seperated", "");
+               declare(suffix, "ns-records", "targets of the NS records, comma seperated.", "");
+               declare(suffix, "ttl", "TTL value for geo records", "3600");
+               declare(suffix, "ns-ttl", "TTL value for NS records", "86400");
+               declare(suffix, "ip-map-zonefile", "path to the rbldnsd format zonefile", "zz.countries.nerd.dk.rbldnsd");
+               declare(suffix, "maps", "list of paths to director maps or directories containing director map files", "");
+        }
+        
+        DNSBackend *make(const string &suffix) {
+               return new GeoBackend(suffix);
+        }
 };
 
 class GeoLoader {
 public:
-       GeoLoader() {
-               BackendMakers().report(new GeoFactory);
-               
-               L << Logger::Info << "[GeoBackend] This is the geobackend ("
-                       __DATE__", "__TIME__" - $Revision: 1.1 $) reporting" << endl;
-       }
+        GeoLoader() {
+               BackendMakers().report(new GeoFactory);
+               
+               L << Logger::Info << "[GeoBackend] This is the geobackend ("
+                       __DATE__", "__TIME__" - $Revision: 1.1 $) reporting" << endl;
+        }
 };
 
 static GeoLoader geoloader;
index 45bf70c3dd739077f806ba84b366fbbcae02f048..0f48a1f9dd6b61c0e72fc1705ea3a4618e85118d 100644 (file)
@@ -1,8 +1,8 @@
-/*     ippreftree.cc
- *     Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
- *             This software is licensed under the terms of the GPL, version 2.
+/*        ippreftree.cc
+ *         Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
+ *             This software is licensed under the terms of the GPL, version 2.
  * 
- *     $Id$
+ *         $Id$
  */
 
 #include <sstream>
 #include "ippreftree.hh"
 
 IPPrefTree::IPPrefTree(): nodecount(0) {
-       root = allocateNode();
-       nodecount++;
+        root = allocateNode();
+        nodecount++;
 }
 
 IPPrefTree::~IPPrefTree() {
-       removeNode(root);
+        removeNode(root);
 }
 
 void IPPrefTree::add(const string &prefix, const short value) {
-       uint32_t ip;
-       int preflen;
-       parsePrefix(prefix, ip, preflen);
-       
-       add(ip, preflen, value);
+        uint32_t ip;
+        int preflen;
+        parsePrefix(prefix, ip, preflen);
+        
+        add(ip, preflen, value);
 }
 
 void IPPrefTree::add(const uint32_t ip, const int preflen, const short value) {
-       addNode(root, ip, preflenToNetmask(preflen), value);
+        addNode(root, ip, preflenToNetmask(preflen), value);
 }
 
 short IPPrefTree::lookup(const string &prefix) const {
-       uint32_t ip;
-       int preflen;
-       parsePrefix(prefix, ip, preflen);
-       
-       return lookup(ip, preflen);
+        uint32_t ip;
+        int preflen;
+        parsePrefix(prefix, ip, preflen);
+        
+        return lookup(ip, preflen);
 }
 
 short IPPrefTree::lookup(const uint32_t ip, const int preflen) const {
-       const node_t *node = findDeepestFilledNode(root, ip, preflenToNetmask(preflen));
-       return (node == NULL ? 0 : node->value);
+        const node_t *node = findDeepestFilledNode(root, ip, preflenToNetmask(preflen));
+        return (node == NULL ? 0 : node->value);
 }
 
 void IPPrefTree::clear() {
-       // Remove all children of the root node, but not the root node itself (reallocate it)
-       removeNode(root);
-       root = allocateNode();
-       nodecount++;
+        // Remove all children of the root node, but not the root node itself (reallocate it)
+        removeNode(root);
+        root = allocateNode();
+        nodecount++;
 }
 
 int IPPrefTree::getNodeCount() const {
-       return nodecount;
+        return nodecount;
 }
 
 int IPPrefTree::getMemoryUsage() const {
-       return nodecount * sizeof(node_t);
+        return nodecount * sizeof(node_t);
 }
 
 // Private methods
 
 inline uint32_t IPPrefTree::preflenToNetmask (const int preflen) const {
-       return ~( (1 << (32 - preflen)) - 1);
+        return ~( (1 << (32 - preflen)) - 1);
 }
 
 inline void IPPrefTree::parsePrefix(const string &prefix, uint32_t &ip, int &preflen) const {
-       // Parse the prefix string (with format 131.155.230.139/25)
-       istringstream is(prefix);
-       ip = 0; preflen = 32;
-       char c;
-       
-       for (int i = 0; i < 4; i++) {
-               int octet = 0;
-               is >> octet;
-               ip = (ip << 8) | octet;
-               is.get(c);
-               if (c != '.' && c != '/')
-                       throw ParsePrefixException("Invalid format: expected '.' or '/'");
-       }
-       
-       if (is.good() && c == '/') {
-               // Read the prefix length
-               is >> preflen;
-       }       
+        // Parse the prefix string (with format 131.155.230.139/25)
+        istringstream is(prefix);
+        ip = 0; preflen = 32;
+        char c;
+        
+        for (int i = 0; i < 4; i++) {
+               int octet = 0;
+               is >> octet;
+               ip = (ip << 8) | octet;
+               is.get(c);
+               if (c != '.' && c != '/')
+                       throw ParsePrefixException("Invalid format: expected '.' or '/'");
+        }
+        
+        if (is.good() && c == '/') {
+               // Read the prefix length
+               is >> preflen;
+        }      
 }
 
 void IPPrefTree::addNode(node_t *node, const uint32_t ip, const uint32_t mask, const short value) {
-       if (mask == 0) {
-               // We are at the correct depth in the tree
-               node->value = value;
-       }
-       else {  /* mask > 0 */
-               // We need to walk deeper into the tree, and extend it if needed
-               int b = (ip >> 31);
-               
-               if (node->child[b] == NULL) {
-                       node->child[b] = allocateNode();
-                       nodecount++;
-               }
-               
-               // Recursively add
-               addNode(node->child[b], ip << 1, mask << 1, value);
-       }
+        if (mask == 0) {
+               // We are at the correct depth in the tree
+               node->value = value;
+        }
+        else { /* mask > 0 */
+               // We need to walk deeper into the tree, and extend it if needed
+               int b = (ip >> 31);
+               
+               if (node->child[b] == NULL) {
+                       node->child[b] = allocateNode();
+                       nodecount++;
+               }
+               
+               // Recursively add
+               addNode(node->child[b], ip << 1, mask << 1, value);
+        }
 }
 
 node_t * IPPrefTree::allocateNode() {
-       node_t *node = new node_t;
-       
-       // Initialize
-       node->child[0] = node->child[1] = NULL;
-       node->value = 0;
-       
-       return node;    
+        node_t *node = new node_t;
+        
+        // Initialize
+        node->child[0] = node->child[1] = NULL;
+        node->value = 0;
+        
+        return node;   
 }
 
 const node_t * IPPrefTree::findDeepestFilledNode(const node_t *node, const uint32_t ip, const uint32_t mask) const {
-       if (node == NULL) return NULL;
-       
-       if (mask == 0) {
-               return (node->value == 0 ? NULL : node);
-       }
-       else {  /* mask > 0 */
-               int b = (ip >> 31);
-               const node_t *descendant = findDeepestFilledNode(node->child[b], ip << 1, mask << 1);
-               if (descendant == NULL) {
-                       if (node->value != 0)   // Children have no (more) explicit information, do we?
-                               return node;
-                       else
-                               return NULL;
-               }
-               else
-                       return descendant;
-       }
+        if (node == NULL) return NULL;
+        
+        if (mask == 0) {
+               return (node->value == 0 ? NULL : node);
+        }
+        else { /* mask > 0 */
+               int b = (ip >> 31);
+               const node_t *descendant = findDeepestFilledNode(node->child[b], ip << 1, mask << 1);
+               if (descendant == NULL) {
+                       if (node->value != 0)   // Children have no (more) explicit information, do we?
+                               return node;
+                       else
+                               return NULL;
+               }
+               else
+                       return descendant;
+        }
 }
 
 void IPPrefTree::removeNode(node_t *node) {
-       if (node == NULL) return;
-       
-       // Recursively remove and deallocate all descendants
-       removeNode(node->child[0]);
-       removeNode(node->child[1]);
-       nodecount--;
-       
-       delete node;
-}      
+        if (node == NULL) return;
+        
+        // Recursively remove and deallocate all descendants
+        removeNode(node->child[0]);
+        removeNode(node->child[1]);
+        nodecount--;
+        
+        delete node;
+}        
index 7af7503a411a11548bc8bf95cf8d4f807a9dbad6..ce2e5c3705618d0326635dc833e9c291c47d453b 100644 (file)
@@ -1,8 +1,8 @@
-/*     ippreftree.hh
- *     Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
- *             This software is licensed under the terms of the GPL, version 2.
+/*        ippreftree.hh
+ *         Copyright (C) 2004 Mark Bergsma <mark@nedworks.org>
+ *             This software is licensed under the terms of the GPL, version 2.
  * 
- *     $Id$
+ *         $Id$
  */
 
 #include <string>
@@ -14,45 +14,45 @@ using namespace std;
 
 // Use old style C structs for efficiency
 typedef struct node_t {
-       node_t *child[2];
-       short value;
-} node_t;      
+        node_t *child[2];
+        short value;
+} node_t;        
 
 class IPPrefTree{
 
 public:
-       IPPrefTree();
-       ~IPPrefTree();
-
-       void add(const string &prefix, const short value);      
-       void add(const uint32_t ip, const int preflen, const short value);
-       
-       short lookup(const string &prefix) const;
-       short lookup(const uint32_t ip, const int preflen) const;
-       
-       void clear();
-       
-       int getNodeCount() const;
-       int getMemoryUsage() const;
+        IPPrefTree();
+        ~IPPrefTree();
+
+        void add(const string &prefix, const short value);     
+        void add(const uint32_t ip, const int preflen, const short value);
+        
+        short lookup(const string &prefix) const;
+        short lookup(const uint32_t ip, const int preflen) const;
+        
+        void clear();
+        
+        int getNodeCount() const;
+        int getMemoryUsage() const;
 
 private:
-       node_t *root;   // root of the tree
-       int nodecount;  // total number of nodes in the tree
-       
-       void addNode(node_t * node, const uint32_t ip, const uint32_t mask, const short value);
-       node_t * allocateNode();
-       const node_t * findDeepestFilledNode(const node_t *root, const uint32_t ip, const uint32_t mask) const;
-       void removeNode(node_t * node);
-       
-       inline uint32_t preflenToNetmask(const int preflen) const;
-       inline void parsePrefix(const string &prefix, uint32_t &ip, int &preflen) const;
+        node_t *root;  // root of the tree
+        int nodecount; // total number of nodes in the tree
+        
+        void addNode(node_t * node, const uint32_t ip, const uint32_t mask, const short value);
+        node_t * allocateNode();
+        const node_t * findDeepestFilledNode(const node_t *root, const uint32_t ip, const uint32_t mask) const;
+        void removeNode(node_t * node);
+        
+        inline uint32_t preflenToNetmask(const int preflen) const;
+        inline void parsePrefix(const string &prefix, uint32_t &ip, int &preflen) const;
 };
 
 class ParsePrefixException
 {
 public:
-       ParsePrefixException() { reason = ""; };
-       ParsePrefixException(string r) { reason = r; };
-       
-       string reason;
+        ParsePrefixException() { reason = ""; };
+        ParsePrefixException(string r) { reason = r; };
+        
+        string reason;
 };
index 8b30f43235a7b4df0f22225c6440c3366cbb4ba0..e020677ba16921705c689bd27d2ed7c40583dbfb 100644 (file)
@@ -22,11 +22,11 @@ gMySQLBackend::gMySQLBackend(const string &mode, const string &suffix)  : GSQLBa
 {
   try {
     setDB(new SMySQL(getArg("dbname"),
-                    getArg("host"),
-                    getArgAsNum("port"),
-                    getArg("socket"),
-                    getArg("user"),
-                    getArg("password")));
+                    getArg("host"),
+                    getArgAsNum("port"),
+                    getArg("socket"),
+                    getArg("user"),
+                    getArg("password")));
     
   }
   
index 703aa4cb9d9041389ef122dfe8f3f8df8dc3bf8a..ec666c5a1063450a5dab72e6d96b4fcefba8aafa 100644 (file)
@@ -12,7 +12,7 @@ using namespace std;
 bool SMySQL::s_dolog;
 
 SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const string &msocket, const string &user, 
-              const string &password)
+               const string &password)
 {
   mysql_init(&d_db);
   mysql_options(&d_db, MYSQL_READ_DEFAULT_GROUP, "client");
@@ -20,11 +20,11 @@ SMySQL::SMySQL(const string &database, const string &host, uint16_t port, const
   mysql_options(&d_db, MYSQL_OPT_RECONNECT, &reconnect);
   
   if (!mysql_real_connect(&d_db, host.empty() ? 0 : host.c_str(), 
-                         user.empty() ? 0 : user.c_str(), 
-                         password.empty() ? 0 : password.c_str(),
-                         database.c_str(), port,
-                         msocket.empty() ? 0 : msocket.c_str(),
-                         0)) {
+                         user.empty() ? 0 : user.c_str(), 
+                         password.empty() ? 0 : password.c_str(),
+                         database.c_str(), port,
+                         msocket.empty() ? 0 : msocket.c_str(),
+                         0)) {
 
     throw sPerrorException("Unable to connect to database");
   }
@@ -126,7 +126,7 @@ int main()
       const SSql::row_t &row=juh[i];
 
       for(SSql::row_t::const_iterator j=row.begin();j!=row.end();++j)
-       cout <<"'"<< *j<<"', ";
+        cout <<"'"<< *j<<"', ";
       cout<<endl;
     }
   }
index 97023e4d62a475dc8f877c732365f13832c1c5e4..55974a3659064986ae8eadee195e00f1012a9581 100644 (file)
@@ -12,8 +12,8 @@ class SMySQL : public SSql
 {
 public:
   SMySQL(const string &database, const string &host="", uint16_t port=0,
-        const string &msocket="",const string &user="", 
-        const string &password="");
+         const string &msocket="",const string &user="", 
+         const string &password="");
 
   ~SMySQL();
   
index 305e3e85716491c5f3d9d5796341aa07784a4696..adc4d78c141cfb4ada59fa142273321fc0125e5d 100644 (file)
@@ -22,8 +22,8 @@ gOracleBackend::gOracleBackend(const string &mode, const string &suffix)  : GSQL
 {
   try {
     setDB(new SOracle(getArg("tnsname"),
-                    getArg("user"),
-                    getArg("password")));
+                    getArg("user"),
+                    getArg("password")));
     
   }
   
index e36c59e53192a7c9b4095b66f6637bafed57c84a..a10646935cebb0aee23292eb36f5e8280fb806a4 100644 (file)
@@ -27,9 +27,9 @@ string SOracle::getOracleError()
     if (errcode) {
       char *p = (char*) msg;
       while (*p++ != 0x00) {
-       if (*p == '\n' || *p == '\r') {
-         *p = ';';
-       }
+        if (*p == '\n' || *p == '\r') {
+          *p = ';';
+        }
       }
       
       mReason = (char*) msg;
@@ -39,8 +39,8 @@ string SOracle::getOracleError()
 }
 
 SOracle::SOracle(const string &database, 
-                const string &user, 
-                const string &password)
+                const string &user, 
+                const string &password)
 {
    d_environmentHandle = NULL;
    d_errorHandle = NULL;
@@ -68,7 +68,7 @@ SOracle::SOracle(const string &database,
    const char *username = user.c_str();
 
    err = OCILogon(d_environmentHandle, d_errorHandle, &d_serviceContextHandle, (OraText*) username, strlen(username),
-                 (OraText*) password.c_str(),  strlen(password.c_str()), (OraText*) database.c_str(), strlen(database.c_str()));
+                 (OraText*) password.c_str(),  strlen(password.c_str()), (OraText*) database.c_str(), strlen(database.c_str()));
    
    if (err) 
      throw sPerrorException("Loging in to Oracle gave error: " + getOracleError());
@@ -142,13 +142,13 @@ int SOracle::doQuery(const string &query)
     return 0;
 
   int err = OCIHandleAlloc(d_environmentHandle, (dvoid **) &d_handle, OCI_HTYPE_STMT, 0, NULL);
-        
+         
   if (err) {
     throw sPerrorException("Allocating a query handle: "+getOracleError());
   }
 
   err = OCIStmtPrepare(d_handle, d_errorHandle, (text*) query.c_str(), strlen(query.c_str()),
-                      OCI_NTV_SYNTAX, OCI_DEFAULT);
+                      OCI_NTV_SYNTAX, OCI_DEFAULT);
   
   if (err) {
     throw sPerrorException("Preparing statement: "+getOracleError());
@@ -156,8 +156,8 @@ int SOracle::doQuery(const string &query)
 
   ub4 prefetch=1000;
   err=OCIAttrSet(d_handle, (ub4) OCI_HTYPE_STMT,
-            (dvoid *) &prefetch, (ub4) sizeof(ub4), 
-            (ub4) OCI_ATTR_PREFETCH_ROWS, d_errorHandle);
+             (dvoid *) &prefetch, (ub4) sizeof(ub4), 
+             (ub4) OCI_ATTR_PREFETCH_ROWS, d_errorHandle);
 
   if (err) {
     throw sPerrorException("setting prefetch: "+getOracleError());
@@ -172,7 +172,7 @@ int SOracle::doQuery(const string &query)
     //    cerr<<"bind: "<<n<<endl;
     OCIDefine *theDefineHandle = NULL; 
     err = OCIDefineByPos(d_handle, &theDefineHandle, d_errorHandle, n+1, d_fields[n].content,
-                        sizeof(d_fields[n].content) - 1, SQLT_STR, (dvoid*) &d_fields[n].indicator, NULL, NULL, OCI_DEFAULT);
+                        sizeof(d_fields[n].content) - 1, SQLT_STR, (dvoid*) &d_fields[n].indicator, NULL, NULL, OCI_DEFAULT);
     
     if (err) {
       throw sPerrorException("Error binding returns: "+getOracleError());
@@ -182,7 +182,7 @@ int SOracle::doQuery(const string &query)
   //  cerr<<"Done binding fields"<<endl;
 
   d_queryResult = OCIStmtExecute(d_serviceContextHandle, d_handle, d_errorHandle, 1, 0,
-                                (OCISnapshot *)NULL, (OCISnapshot*) NULL, OCI_DEFAULT);
+                                (OCISnapshot *)NULL, (OCISnapshot*) NULL, OCI_DEFAULT);
   
   if (d_queryResult != OCI_SUCCESS && d_queryResult != OCI_SUCCESS_WITH_INFO && d_queryResult != OCI_NO_DATA) {
     throw sPerrorException("executing oracle query: "+getOracleError());
@@ -219,9 +219,9 @@ bool SOracle::getRow(row_t &row)
   else {
     for(int n=0;n < d_numfields ;++n)
       if(!d_fields[n].indicator)
-       row.push_back(d_fields[n].content);
+        row.push_back(d_fields[n].content);
       else
-       row.push_back("");
+        row.push_back("");
   }
 
   d_queryResult = OCIStmtFetch(d_handle, d_errorHandle, 1, 0, 0);
@@ -263,9 +263,9 @@ int main(int argc, char **argv)
       SSql::row_t row;
       
       while(s.getRow(row)) {
-       for(SSql::row_t::const_iterator j=row.begin();j!=row.end();++j)
-         cout <<"'"<< *j<<"', ";
-       cout<<"\n";
+        for(SSql::row_t::const_iterator j=row.begin();j!=row.end();++j)
+          cout <<"'"<< *j<<"', ";
+        cout<<"\n";
       }
     }
     time_t spent=time(0)-then;
index b20028521dd397e98dc09c70c38a56d1b8b43cd3..b85655f4d709a4b64e2e2c698b1f32c3f0438914 100644 (file)
@@ -12,8 +12,8 @@ class SOracle : public SSql
 {
 public:
   SOracle(const string &database, 
-         const string &user="", 
-         const string &password="");
+          const string &user="", 
+          const string &password="");
   
   ~SOracle();
   
index 1d1445a569231471f8f3e94f0045fbb6919ec32d..e460dcc82dcd2b79884b74832415ded01937d209 100644 (file)
@@ -21,11 +21,11 @@ gPgSQLBackend::gPgSQLBackend(const string &mode, const string &suffix)  : GSQLBa
 {
   try {
     setDB(new SPgSQL(getArg("dbname"),
-                 getArg("host"),
-                 getArg("port"),
-                 getArg("socket"),
-                 getArg("user"),
-                 getArg("password")));
+                 getArg("host"),
+                 getArg("port"),
+                 getArg("socket"),
+                 getArg("user"),
+                 getArg("password")));
     
   }
   
index 7cd86404392400439fb7225aec0674f7f6d827a3..4ff597fb773e2bdea4b9c3ac3091de4919ea4c5b 100644 (file)
@@ -12,7 +12,7 @@ using namespace std;
 bool SPgSQL::s_dolog;
 
 SPgSQL::SPgSQL(const string &database, const string &host, const string& port, const string &msocket, const string &user, 
-              const string &password)
+               const string &password)
 {
   d_db=0;
   string connectstr;
@@ -39,7 +39,7 @@ SPgSQL::SPgSQL(const string &database, const string &host, const string& port, c
     }
     catch(...) {
       if(d_db)
-       PQfinish(d_db);
+        PQfinish(d_db);
       throw;
     }
   }
index bea5db8c062ad72e8623f54dcf9529aac09cc948..592b403078efcab29ca39603b9c85f639d30e141 100644 (file)
@@ -10,8 +10,8 @@ class SPgSQL : public SSql
 {
 public:
   SPgSQL(const string &database, const string &host="", const string& port="",
-        const string &msocket="",const string &user="", 
-        const string &password="");
+         const string &msocket="",const string &user="", 
+         const string &password="");
 
   ~SPgSQL();
   
index 14e12ad31afc13230042aa100b6f628f6790f5f0..26748a30fcd3169752f37c5b219b58c75e10bbd9 100644 (file)
@@ -8,513 +8,513 @@ unsigned int ldap_host_index = 0;
 
 LdapBackend::LdapBackend( const string &suffix )
 {
-       string hoststr;
-       unsigned int i, idx;
-       vector<string> hosts;
-
-
-       try
-       {
-               m_msgid = 0;
-               m_qname = "";
-               m_pldap = NULL;
-               m_qlog = arg().mustDo( "query-logging" );
-               m_default_ttl = arg().asNum( "default-ttl" );
-               m_myname = "[LdapBackend]";
-
-               // we need UTC time for timestamps
-               setenv( "TZ", "", 1 ); tzset();
-
-               setArgPrefix( "ldap" + suffix );
-
-               m_getdn = false;
-               m_list_fcnt = &LdapBackend::list_simple;
-               m_lookup_fcnt = &LdapBackend::lookup_simple;
-               m_prepare_fcnt = &LdapBackend::prepare_simple;
-
-               if( getArg( "method" ) == "tree" )
-               {
-                       m_lookup_fcnt = &LdapBackend::lookup_tree;
-               }
-
-               if( getArg( "method" ) == "strict" || mustDo( "disable-ptrrecord" ) )
-               {
-                       m_list_fcnt = &LdapBackend::list_strict;
-                       m_lookup_fcnt = &LdapBackend::lookup_strict;
-                       m_prepare_fcnt = &LdapBackend::prepare_strict;
-               }
-
-               stringtok( hosts, getArg( "host" ), ", " );
-               idx = ldap_host_index++ % hosts.size();
-               hoststr = hosts[idx];
-
-               for( i = 1; i < hosts.size(); i++ )
-               {
-                       hoststr += " " + hosts[ ( idx + i ) % hosts.size() ];
-               }
-
-               L << Logger::Info << m_myname << " LDAP servers = " << hoststr << endl;
-
-               m_pldap = new PowerLDAP( hoststr.c_str(), LDAP_PORT, mustDo( "starttls" ) );
-               m_pldap->setOption( LDAP_OPT_DEREF, LDAP_DEREF_ALWAYS );
-               m_pldap->bind( getArg( "binddn" ), getArg( "secret" ), LDAP_AUTH_SIMPLE, getArgAsNum( "timeout" ) );
-
-               L << Logger::Notice << m_myname << " Ldap connection succeeded" << endl;
-               return;
-       }
-       catch( LDAPTimeout &lt )
-       {
-               L << Logger::Error << m_myname << " Ldap connection to server failed because of timeout" << endl;
-       }
-       catch( LDAPException &le )
-       {
-               L << Logger::Error << m_myname << " Ldap connection to server failed: " << le.what() << endl;
-       }
-       catch( exception &e )
-       {
-               L << Logger::Error << m_myname << " Caught STL exception: " << e.what() << endl;
-       }
-
-       if( m_pldap != NULL ) { delete( m_pldap ); }
-       throw( AhuException( "Unable to connect to ldap server" ) );
+        string hoststr;
+        unsigned int i, idx;
+        vector<string> hosts;
+
+
+        try
+        {
+               m_msgid = 0;
+               m_qname = "";
+               m_pldap = NULL;
+               m_qlog = arg().mustDo( "query-logging" );
+               m_default_ttl = arg().asNum( "default-ttl" );
+               m_myname = "[LdapBackend]";
+
+               // we need UTC time for timestamps
+               setenv( "TZ", "", 1 ); tzset();
+
+               setArgPrefix( "ldap" + suffix );
+
+               m_getdn = false;
+               m_list_fcnt = &LdapBackend::list_simple;
+               m_lookup_fcnt = &LdapBackend::lookup_simple;
+               m_prepare_fcnt = &LdapBackend::prepare_simple;
+
+               if( getArg( "method" ) == "tree" )
+               {
+                       m_lookup_fcnt = &LdapBackend::lookup_tree;
+               }
+
+               if( getArg( "method" ) == "strict" || mustDo( "disable-ptrrecord" ) )
+               {
+                       m_list_fcnt = &LdapBackend::list_strict;
+                       m_lookup_fcnt = &LdapBackend::lookup_strict;
+                       m_prepare_fcnt = &LdapBackend::prepare_strict;
+               }
+
+               stringtok( hosts, getArg( "host" ), ", " );
+               idx = ldap_host_index++ % hosts.size();
+               hoststr = hosts[idx];
+
+               for( i = 1; i < hosts.size(); i++ )
+               {
+                       hoststr += " " + hosts[ ( idx + i ) % hosts.size() ];
+               }
+
+               L << Logger::Info << m_myname << " LDAP servers = " << hoststr << endl;
+
+               m_pldap = new PowerLDAP( hoststr.c_str(), LDAP_PORT, mustDo( "starttls" ) );
+               m_pldap->setOption( LDAP_OPT_DEREF, LDAP_DEREF_ALWAYS );
+               m_pldap->bind( getArg( "binddn" ), getArg( "secret" ), LDAP_AUTH_SIMPLE, getArgAsNum( "timeout" ) );
+
+               L << Logger::Notice << m_myname << " Ldap connection succeeded" << endl;
+               return;
+        }
+        catch( LDAPTimeout &lt )
+        {
+               L << Logger::Error << m_myname << " Ldap connection to server failed because of timeout" << endl;
+        }
+        catch( LDAPException &le )
+        {
+               L << Logger::Error << m_myname << " Ldap connection to server failed: " << le.what() << endl;
+        }
+        catch( exception &e )
+        {
+               L << Logger::Error << m_myname << " Caught STL exception: " << e.what() << endl;
+        }
+
+        if( m_pldap != NULL ) { delete( m_pldap ); }
+        throw( AhuException( "Unable to connect to ldap server" ) );
 }
 
 
 
 LdapBackend::~LdapBackend()
 {
-       if( m_pldap != NULL ) { delete( m_pldap ); }
-       L << Logger::Notice << m_myname << " Ldap connection closed" << endl;
+        if( m_pldap != NULL ) { delete( m_pldap ); }
+        L << Logger::Notice << m_myname << " Ldap connection closed" << endl;
 }
 
 
 
 bool LdapBackend::list( const string& target, int domain_id )
 {
-       try
-       {
-               m_qname = target;
-               m_axfrqlen = target.length();
-               m_adomain = m_adomains.end();   // skip loops in get() first time
-
-               return (this->*m_list_fcnt)( target, domain_id );
-       }
-       catch( LDAPTimeout &lt )
-       {
-               L << Logger::Warning << m_myname << " Unable to get zone " + target + " from LDAP directory: " << lt.what() << endl;
-               throw( DBException( "LDAP server timeout" ) );
-       }
-       catch( LDAPException &le )
-       {
-               L << Logger::Error << m_myname << " Unable to get zone " + target + " from LDAP directory: " << le.what() << endl;
-               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
-       }
-       catch( exception &e )
-       {
-               L << Logger::Error << m_myname << " Caught STL exception for target " << target << ": " << e.what() << endl;
-               throw( DBException( "STL exception" ) );
-       }
-
-       return false;
+        try
+        {
+               m_qname = target;
+               m_axfrqlen = target.length();
+               m_adomain = m_adomains.end();   // skip loops in get() first time
+
+               return (this->*m_list_fcnt)( target, domain_id );
+        }
+        catch( LDAPTimeout &lt )
+        {
+               L << Logger::Warning << m_myname << " Unable to get zone " + target + " from LDAP directory: " << lt.what() << endl;
+               throw( DBException( "LDAP server timeout" ) );
+        }
+        catch( LDAPException &le )
+        {
+               L << Logger::Error << m_myname << " Unable to get zone " + target + " from LDAP directory: " << le.what() << endl;
+               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
+        }
+        catch( exception &e )
+        {
+               L << Logger::Error << m_myname << " Caught STL exception for target " << target << ": " << e.what() << endl;
+               throw( DBException( "STL exception" ) );
+        }
+
+        return false;
 }
 
 
 
 inline bool LdapBackend::list_simple( const string& target, int domain_id )
 {
-       string dn;
-       string filter;
+        string dn;
+        string filter;
     string qesc;
 
 
-       dn = getArg( "basedn" );
-       qesc = toLower( m_pldap->escape( target ) );
+        dn = getArg( "basedn" );
+        qesc = toLower( m_pldap->escape( target ) );
 
-       // search for SOARecord of target
-       filter = strbind( ":target:", "&(associatedDomain=" + qesc + ")(sOARecord=*)", getArg( "filter-axfr" ) );
-       m_msgid = m_pldap->search( dn, LDAP_SCOPE_SUBTREE, filter, (const char**) ldap_attrany );
-       m_pldap->getSearchEntry( m_msgid, m_result, true );
+        // search for SOARecord of target
+        filter = strbind( ":target:", "&(associatedDomain=" + qesc + ")(sOARecord=*)", getArg( "filter-axfr" ) );
+        m_msgid = m_pldap->search( dn, LDAP_SCOPE_SUBTREE, filter, (const char**) ldap_attrany );
+        m_pldap->getSearchEntry( m_msgid, m_result, true );
 
-       if( m_result.count( "dn" ) && !m_result["dn"].empty() )
-       {
-               dn = m_result["dn"][0];
-               m_result.erase( "dn" );
-       }
+        if( m_result.count( "dn" ) && !m_result["dn"].empty() )
+        {
+               dn = m_result["dn"][0];
+               m_result.erase( "dn" );
+        }
 
-       prepare();
-       filter = strbind( ":target:", "associatedDomain=*." + qesc, getArg( "filter-axfr" ) );
-       DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << dn << ", filter: " << filter << endl );
-       m_msgid = m_pldap->search( dn, LDAP_SCOPE_SUBTREE, filter, (const char**) ldap_attrany );
+        prepare();
+        filter = strbind( ":target:", "associatedDomain=*." + qesc, getArg( "filter-axfr" ) );
+        DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << dn << ", filter: " << filter << endl );
+        m_msgid = m_pldap->search( dn, LDAP_SCOPE_SUBTREE, filter, (const char**) ldap_attrany );
 
-       return true;
+        return true;
 }
 
 
 
 inline bool LdapBackend::list_strict( const string& target, int domain_id )
 {
-       if( target.size() > 13 && target.substr( target.size() - 13, 13 ) == ".in-addr.arpa" ||
-               target.size() > 9 && target.substr( target.size() - 9, 9 ) == ".ip6.arpa" )
-       {
-               L << Logger::Warning << m_myname << " Request for reverse zone AXFR, but this is not supported in strict mode" << endl;
-               return false;   // AXFR isn't supported in strict mode. Use simple mode and additional PTR records
-       }
-
-       return list_simple( target, domain_id );
+        if( target.size() > 13 && target.substr( target.size() - 13, 13 ) == ".in-addr.arpa" ||
+               target.size() > 9 && target.substr( target.size() - 9, 9 ) == ".ip6.arpa" )
+        {
+               L << Logger::Warning << m_myname << " Request for reverse zone AXFR, but this is not supported in strict mode" << endl;
+               return false;   // AXFR isn't supported in strict mode. Use simple mode and additional PTR records
+        }
+
+        return list_simple( target, domain_id );
 }
 
 
 
 void LdapBackend::lookup( const QType &qtype, const string &qname, DNSPacket *dnspkt, int zoneid )
 {
-       try
-       {
-               m_axfrqlen = 0;
-               m_qname = qname;
-               m_adomain = m_adomains.end();   // skip loops in get() first time
-
-               if( m_qlog ) { L.log( "Query: '" + qname + "|" + qtype.getName() + "'", Logger::Error ); }
-               (this->*m_lookup_fcnt)( qtype, qname, dnspkt, zoneid );
-       }
-       catch( LDAPTimeout &lt )
-       {
-               L << Logger::Warning << m_myname << " Unable to search LDAP directory: " << lt.what() << endl;
-               throw( DBException( "LDAP server timeout" ) );
-       }
-       catch( LDAPException &le )
-       {
-               L << Logger::Error << m_myname << " Unable to search LDAP directory: " << le.what() << endl;
-               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
-       }
-       catch( exception &e )
-       {
-               L << Logger::Error << m_myname << " Caught STL exception for qname " << qname << ": " << e.what() << endl;
-               throw( DBException( "STL exception" ) );
-       }
+        try
+        {
+               m_axfrqlen = 0;
+               m_qname = qname;
+               m_adomain = m_adomains.end();   // skip loops in get() first time
+
+               if( m_qlog ) { L.log( "Query: '" + qname + "|" + qtype.getName() + "'", Logger::Error ); }
+               (this->*m_lookup_fcnt)( qtype, qname, dnspkt, zoneid );
+        }
+        catch( LDAPTimeout &lt )
+        {
+               L << Logger::Warning << m_myname << " Unable to search LDAP directory: " << lt.what() << endl;
+               throw( DBException( "LDAP server timeout" ) );
+        }
+        catch( LDAPException &le )
+        {
+               L << Logger::Error << m_myname << " Unable to search LDAP directory: " << le.what() << endl;
+               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
+        }
+        catch( exception &e )
+        {
+               L << Logger::Error << m_myname << " Caught STL exception for qname " << qname << ": " << e.what() << endl;
+               throw( DBException( "STL exception" ) );
+        }
 }
 
 
 
 void LdapBackend::lookup_simple( const QType &qtype, const string &qname, DNSPacket *dnspkt, int zoneid )
 {
-       string filter, attr, qesc;
-       const char** attributes = ldap_attrany + 1;   // skip associatedDomain
-       const char* attronly[] = { NULL, "dNSTTL", "modifyTimestamp", NULL };
+        string filter, attr, qesc;
+        const char** attributes = ldap_attrany + 1;   // skip associatedDomain
+        const char* attronly[] = { NULL, "dNSTTL", "modifyTimestamp", NULL };
 
 
-       qesc = toLower( m_pldap->escape( qname ) );
-       filter = "associatedDomain=" + qesc;
+        qesc = toLower( m_pldap->escape( qname ) );
+        filter = "associatedDomain=" + qesc;
 
-       if( qtype.getCode() != QType::ANY )
-       {
-               attr = qtype.getName() + "Record";
-               filter = "&(" + filter + ")(" + attr + "=*)";
-               attronly[0] = attr.c_str();
-               attributes = attronly;
-       }
+        if( qtype.getCode() != QType::ANY )
+        {
+               attr = qtype.getName() + "Record";
+               filter = "&(" + filter + ")(" + attr + "=*)";
+               attronly[0] = attr.c_str();
+               attributes = attronly;
+        }
 
-       filter = strbind( ":target:", filter, getArg( "filter-lookup" ) );
+        filter = strbind( ":target:", filter, getArg( "filter-lookup" ) );
 
-       DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl );
-       m_msgid = m_pldap->search( getArg( "basedn" ), LDAP_SCOPE_SUBTREE, filter, attributes );
+        DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl );
+        m_msgid = m_pldap->search( getArg( "basedn" ), LDAP_SCOPE_SUBTREE, filter, attributes );
 }
 
 
 
 void LdapBackend::lookup_strict( const QType &qtype, const string &qname, DNSPacket *dnspkt, int zoneid )
 {
-       int len;
-       vector<string> parts;
-       string filter, attr, qesc;
-       const char** attributes = ldap_attrany + 1;   // skip associatedDomain
-       const char* attronly[] = { NULL, "dNSTTL", "modifyTimestamp", NULL };
-
-
-       qesc = toLower( m_pldap->escape( qname ) );
-       stringtok( parts, qesc, "." );
-       len = qesc.length();
-
-        if( parts.size() == 6 && len > 13 && qesc.substr( len - 13, 13 ) == ".in-addr.arpa" )   // IPv4 reverse lookups
-       {
-               filter = "aRecord=" + ptr2ip4( parts );
-               attronly[0] = "associatedDomain";
-               attributes = attronly;
-       }
-       else if( parts.size() == 34 && len > 9 && ( qesc.substr( len - 9, 9 ) == ".ip6.arpa" ) )   // IPv6 reverse lookups
-       {
-               filter = "aAAARecord=" + ptr2ip6( parts );
-               attronly[0] = "associatedDomain";
-               attributes = attronly;
-       }
-       else   // IPv4 and IPv6 lookups
-       {
-               filter = "associatedDomain=" + qesc;
-               if( qtype.getCode() != QType::ANY )
-               {
-                       attr = qtype.getName() + "Record";
-                       filter = "&(" + filter + ")(" + attr + "=*)";
-                       attronly[0] = attr.c_str();
-                       attributes = attronly;
-               }
-       }
-
-       filter = strbind( ":target:", filter, getArg( "filter-lookup" ) );
-
-       DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl );
-       m_msgid = m_pldap->search( getArg( "basedn" ), LDAP_SCOPE_SUBTREE, filter, attributes );
+        int len;
+        vector<string> parts;
+        string filter, attr, qesc;
+        const char** attributes = ldap_attrany + 1;   // skip associatedDomain
+        const char* attronly[] = { NULL, "dNSTTL", "modifyTimestamp", NULL };
+
+
+        qesc = toLower( m_pldap->escape( qname ) );
+        stringtok( parts, qesc, "." );
+        len = qesc.length();
+
+         if( parts.size() == 6 && len > 13 && qesc.substr( len - 13, 13 ) == ".in-addr.arpa" )   // IPv4 reverse lookups
+        {
+               filter = "aRecord=" + ptr2ip4( parts );
+               attronly[0] = "associatedDomain";
+               attributes = attronly;
+        }
+        else if( parts.size() == 34 && len > 9 && ( qesc.substr( len - 9, 9 ) == ".ip6.arpa" ) )   // IPv6 reverse lookups
+        {
+               filter = "aAAARecord=" + ptr2ip6( parts );
+               attronly[0] = "associatedDomain";
+               attributes = attronly;
+        }
+        else   // IPv4 and IPv6 lookups
+        {
+               filter = "associatedDomain=" + qesc;
+               if( qtype.getCode() != QType::ANY )
+               {
+                       attr = qtype.getName() + "Record";
+                       filter = "&(" + filter + ")(" + attr + "=*)";
+                       attronly[0] = attr.c_str();
+                       attributes = attronly;
+               }
+        }
+
+        filter = strbind( ":target:", filter, getArg( "filter-lookup" ) );
+
+        DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl );
+        m_msgid = m_pldap->search( getArg( "basedn" ), LDAP_SCOPE_SUBTREE, filter, attributes );
 }
 
 
 
 void LdapBackend::lookup_tree( const QType &qtype, const string &qname, DNSPacket *dnspkt, int zoneid )
 {
-       string filter, attr, qesc, dn;
-       const char** attributes = ldap_attrany + 1;   // skip associatedDomain
-       const char* attronly[] = { NULL, "dNSTTL", "modifyTimestamp", NULL };
-       vector<string>::reverse_iterator i;
-       vector<string> parts;
-
-
-       qesc = toLower( m_pldap->escape( qname ) );
-       filter = "associatedDomain=" + qesc;
-
-       if( qtype.getCode() != QType::ANY )
-       {
-               attr = qtype.getName() + "Record";
-               filter = "&(" + filter + ")(" + attr + "=*)";
-               attronly[0] = attr.c_str();
-               attributes = attronly;
-       }
-
-       filter = strbind( ":target:", filter, getArg( "filter-lookup" ) );
-
-       stringtok( parts, toLower( qname ), "." );
-       for( i = parts.rbegin(); i != parts.rend(); i++ )
-       {
-               dn = "dc=" + *i + "," + dn;
-       }
-
-       DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << dn + getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl );
-       m_msgid = m_pldap->search( dn + getArg( "basedn" ), LDAP_SCOPE_BASE, filter, attributes );
+        string filter, attr, qesc, dn;
+        const char** attributes = ldap_attrany + 1;   // skip associatedDomain
+        const char* attronly[] = { NULL, "dNSTTL", "modifyTimestamp", NULL };
+        vector<string>::reverse_iterator i;
+        vector<string> parts;
+
+
+        qesc = toLower( m_pldap->escape( qname ) );
+        filter = "associatedDomain=" + qesc;
+
+        if( qtype.getCode() != QType::ANY )
+        {
+               attr = qtype.getName() + "Record";
+               filter = "&(" + filter + ")(" + attr + "=*)";
+               attronly[0] = attr.c_str();
+               attributes = attronly;
+        }
+
+        filter = strbind( ":target:", filter, getArg( "filter-lookup" ) );
+
+        stringtok( parts, toLower( qname ), "." );
+        for( i = parts.rbegin(); i != parts.rend(); i++ )
+        {
+               dn = "dc=" + *i + "," + dn;
+        }
+
+        DLOG( L << Logger::Debug << m_myname << " Search = basedn: " << dn + getArg( "basedn" ) << ", filter: " << filter << ", qtype: " << qtype.getName() << endl );
+        m_msgid = m_pldap->search( dn + getArg( "basedn" ), LDAP_SCOPE_BASE, filter, attributes );
 }
 
 
 inline bool LdapBackend::prepare()
 {
-       m_adomains.clear();
-       m_ttl = m_default_ttl;
-       m_last_modified = 0;
-
-       if( m_result.count( "dNSTTL" ) && !m_result["dNSTTL"].empty() )
-       {
-               char* endptr;
-
-               m_ttl = (uint32_t) strtol( m_result["dNSTTL"][0].c_str(), &endptr, 10 );
-               if( *endptr != '\0' )
-               {
-                       L << Logger::Warning << m_myname << " Invalid time to life for " << m_qname << ": " << m_result["dNSTTL"][0] << endl;
-                       m_ttl = m_default_ttl;
-               }
-               m_result.erase( "dNSTTL" );
-       }
-
-       if( m_result.count( "modifyTimestamp" ) && !m_result["modifyTimestamp"].empty() )
-       {
-               if( ( m_last_modified = str2tstamp( m_result["modifyTimestamp"][0] ) ) == 0 )
-               {
-                       L << Logger::Warning << m_myname << " Invalid modifyTimestamp for " << m_qname << ": " << m_result["modifyTimestamp"][0] << endl;
-               }
-               m_result.erase( "modifyTimestamp" );
-       }
-
-       if( !(this->*m_prepare_fcnt)() )
-       {
-               return false;
-       }
-
-       m_adomain = m_adomains.begin();
-       m_attribute = m_result.begin();
-       m_value = m_attribute->second.begin();
-
-       return true;
+        m_adomains.clear();
+        m_ttl = m_default_ttl;
+        m_last_modified = 0;
+
+        if( m_result.count( "dNSTTL" ) && !m_result["dNSTTL"].empty() )
+        {
+               char* endptr;
+
+               m_ttl = (uint32_t) strtol( m_result["dNSTTL"][0].c_str(), &endptr, 10 );
+               if( *endptr != '\0' )
+               {
+                       L << Logger::Warning << m_myname << " Invalid time to life for " << m_qname << ": " << m_result["dNSTTL"][0] << endl;
+                       m_ttl = m_default_ttl;
+               }
+               m_result.erase( "dNSTTL" );
+        }
+
+        if( m_result.count( "modifyTimestamp" ) && !m_result["modifyTimestamp"].empty() )
+        {
+               if( ( m_last_modified = str2tstamp( m_result["modifyTimestamp"][0] ) ) == 0 )
+               {
+                       L << Logger::Warning << m_myname << " Invalid modifyTimestamp for " << m_qname << ": " << m_result["modifyTimestamp"][0] << endl;
+               }
+               m_result.erase( "modifyTimestamp" );
+        }
+
+        if( !(this->*m_prepare_fcnt)() )
+        {
+               return false;
+        }
+
+        m_adomain = m_adomains.begin();
+        m_attribute = m_result.begin();
+        m_value = m_attribute->second.begin();
+
+        return true;
 }
 
 
 
 inline bool LdapBackend::prepare_simple()
 {
-       if( !m_axfrqlen )   // request was a normal lookup()
-       {
-               m_adomains.push_back( m_qname );
-       }
-       else   // request was a list() for AXFR
-       {
-               if( m_result.count( "associatedDomain" ) )
-               {
-                       vector<string>::iterator i;
-                       for( i = m_result["associatedDomain"].begin(); i != m_result["associatedDomain"].end(); i++ ) {
-                               if( i->size() >= m_axfrqlen && i->substr( i->size() - m_axfrqlen, m_axfrqlen ) == m_qname ) {
-                                       m_adomains.push_back( *i );
-                               }
-                       }
-                       m_result.erase( "associatedDomain" );
-               }
-       }
-
-       return true;
+        if( !m_axfrqlen )   // request was a normal lookup()
+        {
+               m_adomains.push_back( m_qname );
+        }
+        else   // request was a list() for AXFR
+        {
+               if( m_result.count( "associatedDomain" ) )
+               {
+                       vector<string>::iterator i;
+                       for( i = m_result["associatedDomain"].begin(); i != m_result["associatedDomain"].end(); i++ ) {
+                               if( i->size() >= m_axfrqlen && i->substr( i->size() - m_axfrqlen, m_axfrqlen ) == m_qname ) {
+                                       m_adomains.push_back( *i );
+                               }
+                       }
+                       m_result.erase( "associatedDomain" );
+               }
+        }
+
+        return true;
 }
 
 
 
 inline bool LdapBackend::prepare_strict()
 {
-       if( !m_axfrqlen )   // request was a normal lookup()
-       {
-               m_adomains.push_back( m_qname );
-               if( m_result.count( "associatedDomain" ) )
-               {
-                       m_result["PTRRecord"] = m_result["associatedDomain"];
-                       m_result.erase( "associatedDomain" );
-               }
-       }
-       else   // request was a list() for AXFR
-       {
-               if( m_result.count( "associatedDomain" ) )
-               {
-                       vector<string>::iterator i;
-                       for( i = m_result["associatedDomain"].begin(); i != m_result["associatedDomain"].end(); i++ ) {
-                               if( i->size() >= m_axfrqlen && i->substr( i->size() - m_axfrqlen, m_axfrqlen ) == m_qname ) {
-                                       m_adomains.push_back( *i );
-                               }
-                       }
-                       m_result.erase( "associatedDomain" );
-               }
-       }
-
-       return true;
+        if( !m_axfrqlen )   // request was a normal lookup()
+        {
+               m_adomains.push_back( m_qname );
+               if( m_result.count( "associatedDomain" ) )
+               {
+                       m_result["PTRRecord"] = m_result["associatedDomain"];
+                       m_result.erase( "associatedDomain" );
+               }
+        }
+        else   // request was a list() for AXFR
+        {
+               if( m_result.count( "associatedDomain" ) )
+               {
+                       vector<string>::iterator i;
+                       for( i = m_result["associatedDomain"].begin(); i != m_result["associatedDomain"].end(); i++ ) {
+                               if( i->size() >= m_axfrqlen && i->substr( i->size() - m_axfrqlen, m_axfrqlen ) == m_qname ) {
+                                       m_adomains.push_back( *i );
+                               }
+                       }
+                       m_result.erase( "associatedDomain" );
+               }
+        }
+
+        return true;
 }
 
 
 
 bool LdapBackend::get( DNSResourceRecord &rr )
 {
-       QType qt;
-       vector<string> parts;
-       string attrname, content, qstr;
-
-
-       try
-       {
-               do
-               {
-                       while( m_adomain != m_adomains.end() )
-                       {
-                               while( m_attribute != m_result.end() )
-                               {
-                                       attrname = m_attribute->first;
-                                       qstr = attrname.substr( 0, attrname.length() - 6 );   // extract qtype string from ldap attribute name
-                                       qt = QType( const_cast<char*>(toUpper( qstr ).c_str()) );
-
-                                       while( m_value != m_attribute->second.end() )
-                                       {
-                                               content = *m_value;
-
-                                               rr.qtype = qt;
-                                               rr.qname = *m_adomain;
-                                               rr.priority = 0;
-                                               rr.ttl = m_ttl;
-                                               rr.last_modified = m_last_modified;
-
-                                               if( qt.getCode() == QType::MX || qt.getCode() == QType::SRV )   // Priority, e.g. 10 smtp.example.com
-                                               {
-                                                       char* endptr;
-                                                       string::size_type first = content.find_first_of( " " );
-
-                                                       if( first == string::npos )
-                                                       {
-                                                               L << Logger::Warning << m_myname << " Invalid " << attrname << " without priority for " << m_qname << ": " << content << endl;
-                                                               m_value++;
-                                                               continue;
-                                                       }
-
-                                                       rr.priority = (uint16_t) strtoul( (content.substr( 0, first )).c_str(), &endptr, 10 );
-                                                       if( *endptr != '\0' )
-                                                       {
-                                                               L << Logger::Warning << m_myname << " Invalid " << attrname << " without priority for " << m_qname << ": " << content << endl;
-                                                               m_value++;
-                                                               continue;
-                                                       }
-
-                                                       content = content.substr( first + 1, content.length() - first - 1 );
-                                               }
-
-                                               rr.content = content;
-                                               m_value++;
-
-                                               DLOG( L << Logger::Debug << m_myname << " Record = qname: " << rr.qname << ", qtype: " << (rr.qtype).getName() << ", priority: " << rr.priority << ", ttl: " << rr.ttl << ", content: " << rr.content << endl );
-                                               return true;
-                                       }
-
-                                       m_attribute++;
-                                       m_value = m_attribute->second.begin();
-                               }
-                               m_adomain++;
-                               m_attribute = m_result.begin();
-                               m_value = m_attribute->second.begin();
-                       }
-               }
-               while( m_pldap->getSearchEntry( m_msgid, m_result, m_getdn ) && prepare() );
-
-       }
-       catch( LDAPTimeout &lt )
-       {
-               L << Logger::Warning << m_myname << " Search failed: " << lt.what() << endl;
-               throw( DBException( "LDAP server timeout" ) );
-       }
-       catch( LDAPException &le )
-       {
-               L << Logger::Error << m_myname << " Search failed: " << le.what() << endl;
-               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
-       }
-       catch( exception &e )
-       {
-               L << Logger::Error << m_myname << " Caught STL exception for " << m_qname << ": " << e.what() << endl;
-               throw( DBException( "STL exception" ) );
-       }
-
-       return false;
+        QType qt;
+        vector<string> parts;
+        string attrname, content, qstr;
+
+
+        try
+        {
+               do
+               {
+                       while( m_adomain != m_adomains.end() )
+                       {
+                               while( m_attribute != m_result.end() )
+                               {
+                                       attrname = m_attribute->first;
+                                       qstr = attrname.substr( 0, attrname.length() - 6 );   // extract qtype string from ldap attribute name
+                                       qt = QType( const_cast<char*>(toUpper( qstr ).c_str()) );
+
+                                       while( m_value != m_attribute->second.end() )
+                                       {
+                                               content = *m_value;
+
+                                               rr.qtype = qt;
+                                               rr.qname = *m_adomain;
+                                               rr.priority = 0;
+                                               rr.ttl = m_ttl;
+                                               rr.last_modified = m_last_modified;
+
+                                               if( qt.getCode() == QType::MX || qt.getCode() == QType::SRV )   // Priority, e.g. 10 smtp.example.com
+                                               {
+                                                       char* endptr;
+                                                       string::size_type first = content.find_first_of( " " );
+
+                                                       if( first == string::npos )
+                                                       {
+                                                               L << Logger::Warning << m_myname << " Invalid " << attrname << " without priority for " << m_qname << ": " << content << endl;
+                                                               m_value++;
+                                                               continue;
+                                                       }
+
+                                                       rr.priority = (uint16_t) strtoul( (content.substr( 0, first )).c_str(), &endptr, 10 );
+                                                       if( *endptr != '\0' )
+                                                       {
+                                                               L << Logger::Warning << m_myname << " Invalid " << attrname << " without priority for " << m_qname << ": " << content << endl;
+                                                               m_value++;
+                                                               continue;
+                                                       }
+
+                                                       content = content.substr( first + 1, content.length() - first - 1 );
+                                               }
+
+                                               rr.content = content;
+                                               m_value++;
+
+                                               DLOG( L << Logger::Debug << m_myname << " Record = qname: " << rr.qname << ", qtype: " << (rr.qtype).getName() << ", priority: " << rr.priority << ", ttl: " << rr.ttl << ", content: " << rr.content << endl );
+                                               return true;
+                                       }
+
+                                       m_attribute++;
+                                       m_value = m_attribute->second.begin();
+                               }
+                               m_adomain++;
+                               m_attribute = m_result.begin();
+                               m_value = m_attribute->second.begin();
+                       }
+               }
+               while( m_pldap->getSearchEntry( m_msgid, m_result, m_getdn ) && prepare() );
+
+        }
+        catch( LDAPTimeout &lt )
+        {
+               L << Logger::Warning << m_myname << " Search failed: " << lt.what() << endl;
+               throw( DBException( "LDAP server timeout" ) );
+        }
+        catch( LDAPException &le )
+        {
+               L << Logger::Error << m_myname << " Search failed: " << le.what() << endl;
+               throw( AhuException( "LDAP server unreachable" ) );   // try to reconnect to another server
+        }
+        catch( exception &e )
+        {
+               L << Logger::Error << m_myname << " Caught STL exception for " << m_qname << ": " << e.what() << endl;
+               throw( DBException( "STL exception" ) );
+        }
+
+        return false;
 }
 
 
 
  bool LdapBackend::getDomainInfo( const string& domain, DomainInfo& di )
 {
-       string filter;
-       SOAData sd;
-       const char* attronly[] = { "sOARecord", NULL };
+        string filter;
+        SOAData sd;
+        const char* attronly[] = { "sOARecord", NULL };
 
 
-       // search for SOARecord of domain
-       filter = "(&(associatedDomain=" + toLower( m_pldap->escape( domain ) ) + ")(SOARecord=*))";
-       m_msgid = m_pldap->search( getArg( "basedn" ), LDAP_SCOPE_SUBTREE, filter, attronly );
-       m_pldap->getSearchEntry( m_msgid, m_result );
+        // search for SOARecord of domain
+        filter = "(&(associatedDomain=" + toLower( m_pldap->escape( domain ) ) + ")(SOARecord=*))";
+        m_msgid = m_pldap->search( getArg( "basedn" ), LDAP_SCOPE_SUBTREE, filter, attronly );
+        m_pldap->getSearchEntry( m_msgid, m_result );
 
-       if( m_result.count( "sOARecord" ) && !m_result["sOARecord"].empty() )
-       {
-               sd.serial = 0;
-               fillSOAData( m_result["sOARecord"][0], sd );
+        if( m_result.count( "sOARecord" ) && !m_result["sOARecord"].empty() )
+        {
+               sd.serial = 0;
+               fillSOAData( m_result["sOARecord"][0], sd );
 
-               di.id = 0;
-               di.serial = sd.serial;
-               di.zone = domain;
-               di.last_check = 0;
-               di.backend = this;
-               di.kind = DomainInfo::Master;
+               di.id = 0;
+               di.serial = sd.serial;
+               di.zone = domain;
+               di.last_check = 0;
+               di.backend = this;
+               di.kind = DomainInfo::Master;
 
-               return true;
-       }
+               return true;
+        }
 
-       return false;
+        return false;
 }
 
 
@@ -526,28 +526,28 @@ class LdapFactory : public BackendFactory
 
 public:
 
-       LdapFactory() : BackendFactory( "ldap" ) {}
+        LdapFactory() : BackendFactory( "ldap" ) {}
 
 
-       void declareArguments( const string &suffix="" )
-       {
-               declare( suffix, "host", "One or more LDAP server with ports or LDAP URIs (separated by spaces)","ldap://127.0.0.1:389/" );
-               declare( suffix, "starttls", "Use TLS to encrypt connection (unused for LDAP URIs)", "no" );
-               declare( suffix, "basedn", "Search root in ldap tree (must be set)","" );
-               declare( suffix, "binddn", "User dn for non anonymous binds","" );
-               declare( suffix, "secret", "User password for non anonymous binds", "" );
-               declare( suffix, "timeout", "Seconds before connecting to server fails", "5" );
-               declare( suffix, "method", "How to search entries (simple, strict or tree)", "simple" );
-               declare( suffix, "filter-axfr", "LDAP filter for limiting AXFR results", "(:target:)" );
-               declare( suffix, "filter-lookup", "LDAP filter for limiting IP or name lookups", "(:target:)" );
-               declare( suffix, "disable-ptrrecord", "Deprecated, use ldap-method=strict instead", "no" );
-       }
+        void declareArguments( const string &suffix="" )
+        {
+               declare( suffix, "host", "One or more LDAP server with ports or LDAP URIs (separated by spaces)","ldap://127.0.0.1:389/" );
+               declare( suffix, "starttls", "Use TLS to encrypt connection (unused for LDAP URIs)", "no" );
+               declare( suffix, "basedn", "Search root in ldap tree (must be set)","" );
+               declare( suffix, "binddn", "User dn for non anonymous binds","" );
+               declare( suffix, "secret", "User password for non anonymous binds", "" );
+               declare( suffix, "timeout", "Seconds before connecting to server fails", "5" );
+               declare( suffix, "method", "How to search entries (simple, strict or tree)", "simple" );
+               declare( suffix, "filter-axfr", "LDAP filter for limiting AXFR results", "(:target:)" );
+               declare( suffix, "filter-lookup", "LDAP filter for limiting IP or name lookups", "(:target:)" );
+               declare( suffix, "disable-ptrrecord", "Deprecated, use ldap-method=strict instead", "no" );
+        }
 
 
-       DNSBackend* make( const string &suffix="" )
-       {
-               return new LdapBackend( suffix );
-       }
+        DNSBackend* make( const string &suffix="" )
+        {
+               return new LdapBackend( suffix );
+        }
 };
 
 
@@ -556,15 +556,15 @@ public:
 
 class LdapLoader
 {
-       LdapFactory factory;
+        LdapFactory factory;
 
 public:
 
-       LdapLoader()
-       {
-               BackendMakers().report( &factory );
-               L << Logger::Info << " [LdapBackend] This is the ldap module version "VERSION" ("__DATE__", "__TIME__") reporting" << endl;
-       }
+        LdapLoader()
+        {
+               BackendMakers().report( &factory );
+               L << Logger::Info << " [LdapBackend] This is the ldap module version "VERSION" ("__DATE__", "__TIME__") reporting" << endl;
+        }
 };
 
 
index aefb2216be73f0105ce56066b635b22d6854d59d..a907422213a4ee22581bfe64c1615480b7a2db85 100644 (file)
@@ -55,86 +55,86 @@ using std::vector;
  */
 
 static const char* ldap_attrany[] = {
-       "associatedDomain",
-       "dNSTTL",
-       "aRecord",
-       "nSRecord",
-       "cNAMERecord",
-       "sOARecord",
-       "pTRRecord",
-       "hInfoRecord",
-       "mXRecord",
-       "tXTRecord",
-       "rPRecord",
-       "aFSDBRecord",
-//     "SigRecord",
-       "KeyRecord",
-//     "gPosRecord",
-       "aAAARecord",
-       "lOCRecord",
-       "sRVRecord",
-       "nAPTRRecord",
-       "kXRecord",
-       "certRecord",
-//     "a6Record",
-//     "dNameRecord",
-//     "aPLRecord",
-       "dSRecord",
-       "sSHFPRecord",
-       "iPSecKeyRecord",
-       "rRSIGRecord",
-       "nSECRecord",
-       "dNSKeyRecord",
-       "dHCIDRecord",
-       "sPFRecord",
-       "modifyTimestamp",
-       NULL
+        "associatedDomain",
+        "dNSTTL",
+        "aRecord",
+        "nSRecord",
+        "cNAMERecord",
+        "sOARecord",
+        "pTRRecord",
+        "hInfoRecord",
+        "mXRecord",
+        "tXTRecord",
+        "rPRecord",
+        "aFSDBRecord",
+//        "SigRecord",
+        "KeyRecord",
+//        "gPosRecord",
+        "aAAARecord",
+        "lOCRecord",
+        "sRVRecord",
+        "nAPTRRecord",
+        "kXRecord",
+        "certRecord",
+//        "a6Record",
+//        "dNameRecord",
+//        "aPLRecord",
+        "dSRecord",
+        "sSHFPRecord",
+        "iPSecKeyRecord",
+        "rRSIGRecord",
+        "nSECRecord",
+        "dNSKeyRecord",
+        "dHCIDRecord",
+        "sPFRecord",
+        "modifyTimestamp",
+        NULL
 };
 
 
 
 class LdapBackend : public DNSBackend
 {
-       bool m_getdn;
-       bool m_qlog;
-       int m_msgid;
-       uint32_t m_ttl;
-       uint32_t m_default_ttl;
-       unsigned int m_axfrqlen;
-       time_t m_last_modified;
-       string m_myname;
-       string m_qname;
-       PowerLDAP* m_pldap;
-       PowerLDAP::sentry_t m_result;
-       PowerLDAP::sentry_t::iterator m_attribute;
-       vector<string>::iterator m_value, m_adomain;
-       vector<string> m_adomains;
-
-       bool (LdapBackend::*m_list_fcnt)( const string&, int );
-       void (LdapBackend::*m_lookup_fcnt)( const QType&, const string&, DNSPacket*, int );
-       bool (LdapBackend::*m_prepare_fcnt)();
-
-       bool list_simple( const string& target, int domain_id );
-       bool list_strict( const string& target, int domain_id );
-
-       void lookup_simple( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
-       void lookup_strict( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
-       void lookup_tree( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
-
-       bool prepare();
-       bool prepare_simple();
-       bool prepare_strict();
-
-       bool getDomainInfo( const string& domain, DomainInfo& di );
+        bool m_getdn;
+        bool m_qlog;
+        int m_msgid;
+        uint32_t m_ttl;
+        uint32_t m_default_ttl;
+        unsigned int m_axfrqlen;
+        time_t m_last_modified;
+        string m_myname;
+        string m_qname;
+        PowerLDAP* m_pldap;
+        PowerLDAP::sentry_t m_result;
+        PowerLDAP::sentry_t::iterator m_attribute;
+        vector<string>::iterator m_value, m_adomain;
+        vector<string> m_adomains;
+
+        bool (LdapBackend::*m_list_fcnt)( const string&, int );
+        void (LdapBackend::*m_lookup_fcnt)( const QType&, const string&, DNSPacket*, int );
+        bool (LdapBackend::*m_prepare_fcnt)();
+
+        bool list_simple( const string& target, int domain_id );
+        bool list_strict( const string& target, int domain_id );
+
+        void lookup_simple( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
+        void lookup_strict( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
+        void lookup_tree( const QType& qtype, const string& qdomain, DNSPacket* p, int zoneid );
+
+        bool prepare();
+        bool prepare_simple();
+        bool prepare_strict();
+
+        bool getDomainInfo( const string& domain, DomainInfo& di );
 
 public:
 
-       LdapBackend( const string &suffix="" );
-       ~LdapBackend();
+        LdapBackend( const string &suffix="" );
+        ~LdapBackend();
 
-       bool list( const string& target, int domain_id );
-       void lookup( const QType& qtype, const string& qdomain, DNSPacket* p = 0, int zoneid = -1 );
-       bool get( DNSResourceRecord& rr );
+        bool list( const string& target, int domain_id );
+        void lookup( const QType& qtype, const string& qdomain, DNSPacket* p = 0, int zoneid = -1 );
+        bool get( DNSResourceRecord& rr );
 };
 
 #endif /* LDAPBACKEND_HH */
index 938c0283570dbc1488d406bbb808654b1b5cf059..8ac36b83f9493a85638147941e4e654766ea06f5 100644 (file)
@@ -6,98 +6,98 @@
 
 PowerLDAP::PowerLDAP( const string& hosts, uint16_t port, bool tls )
 {
-       int err;
+        int err;
 
 #ifdef HAVE_LDAP_INITIALIZE
-       if( ( err = ldap_initialize( &d_ld, hosts.c_str() ) ) != LDAP_SUCCESS )
-       {
-               string ldapuris;
-               vector<string> uris;
-               stringtok( uris, hosts );
-
-               for( size_t i = 0; i < uris.size(); i++ )
-               {
-                       ldapuris += " ldap://" + uris[i];
-               }
-
-               if( ( err = ldap_initialize( &d_ld, ldapuris.c_str() ) ) != LDAP_SUCCESS )
-               {
-                               throw LDAPException( "Error initializing LDAP connection to '" + ldapuris + ": " + getError( err ) );
-               }
-       }
+        if( ( err = ldap_initialize( &d_ld, hosts.c_str() ) ) != LDAP_SUCCESS )
+        {
+               string ldapuris;
+               vector<string> uris;
+               stringtok( uris, hosts );
+
+               for( size_t i = 0; i < uris.size(); i++ )
+               {
+                       ldapuris += " ldap://" + uris[i];
+               }
+
+               if( ( err = ldap_initialize( &d_ld, ldapuris.c_str() ) ) != LDAP_SUCCESS )
+               {
+                               throw LDAPException( "Error initializing LDAP connection to '" + ldapuris + ": " + getError( err ) );
+               }
+        }
 #else
-       if( ( d_ld = ldap_init( hosts.c_str(), port ) ) == NULL )
-       {
-               throw LDAPException( "Error initializing LDAP connection to '" + hosts + "': " + string( strerror( errno ) ) );
-       }
+        if( ( d_ld = ldap_init( hosts.c_str(), port ) ) == NULL )
+        {
+               throw LDAPException( "Error initializing LDAP connection to '" + hosts + "': " + string( strerror( errno ) ) );
+        }
 #endif
 
-       int protocol = LDAP_VERSION3;
-       if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS )
-       {
-               protocol = LDAP_VERSION2;
-               if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS )
-               {
-                       ldap_unbind_ext( d_ld, NULL, NULL );
-                       throw LDAPException( "Couldn't set protocol version to LDAPv3 or LDAPv2" );
-               }
-       }
-
-       if( tls && ( err = ldap_start_tls_s( d_ld, NULL, NULL ) ) != LDAP_SUCCESS )
-       {
-               ldap_unbind_ext( d_ld, NULL, NULL );
-               throw LDAPException( "Couldn't perform STARTTLS: " + getError( err ) );
-       }
+        int protocol = LDAP_VERSION3;
+        if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS )
+        {
+               protocol = LDAP_VERSION2;
+               if( ldap_set_option( d_ld, LDAP_OPT_PROTOCOL_VERSION, &protocol ) != LDAP_OPT_SUCCESS )
+               {
+                       ldap_unbind_ext( d_ld, NULL, NULL );
+                       throw LDAPException( "Couldn't set protocol version to LDAPv3 or LDAPv2" );
+               }
+        }
+
+        if( tls && ( err = ldap_start_tls_s( d_ld, NULL, NULL ) ) != LDAP_SUCCESS )
+        {
+               ldap_unbind_ext( d_ld, NULL, NULL );
+               throw LDAPException( "Couldn't perform STARTTLS: " + getError( err ) );
+        }
 }
 
 
 PowerLDAP::~PowerLDAP()
 {
-       ldap_unbind_ext( d_ld, NULL, NULL );
+        ldap_unbind_ext( d_ld, NULL, NULL );
 }
 
 
 void PowerLDAP::setOption( int option, int value )
 {
-       if( ldap_set_option( d_ld, option, (void*) &value ) != LDAP_OPT_SUCCESS )
-       {
-               throw( LDAPException( "Unable to set option" ) );
-       }
+        if( ldap_set_option( d_ld, option, (void*) &value ) != LDAP_OPT_SUCCESS )
+        {
+               throw( LDAPException( "Unable to set option" ) );
+        }
 }
 
 
 void PowerLDAP::getOption( int option, int *value )
 {
-       if( ldap_get_option( d_ld, option, (void*) value ) != LDAP_OPT_SUCCESS )
-       {
-               throw( LDAPException( "Unable to get option" ) );
-       }
+        if( ldap_get_option( d_ld, option, (void*) value ) != LDAP_OPT_SUCCESS )
+        {
+               throw( LDAPException( "Unable to get option" ) );
+        }
 }
 
 
 void PowerLDAP::bind( const string& ldapbinddn, const string& ldapsecret, int method, int timeout )
 {
-       int msgid;
+        int msgid;
 
 #ifdef HAVE_LDAP_SASL_BIND
-       int rc;
-       struct berval passwd;
+        int rc;
+        struct berval passwd;
 
-       passwd.bv_val = (char *)ldapsecret.c_str();
-       passwd.bv_len = strlen( passwd.bv_val );
+        passwd.bv_val = (char *)ldapsecret.c_str();
+        passwd.bv_len = strlen( passwd.bv_val );
 
-       if( ( rc = ldap_sasl_bind( d_ld, ldapbinddn.c_str(), LDAP_SASL_SIMPLE, &passwd, NULL, NULL, &msgid ) ) != LDAP_SUCCESS )
-       {
-               throw LDAPException( "Failed to bind to LDAP server: " + getError( rc ) );
-       }
+        if( ( rc = ldap_sasl_bind( d_ld, ldapbinddn.c_str(), LDAP_SASL_SIMPLE, &passwd, NULL, NULL, &msgid ) ) != LDAP_SUCCESS )
+        {
+               throw LDAPException( "Failed to bind to LDAP server: " + getError( rc ) );
+        }
 #else
-       if( ( msgid = ldap_bind( d_ld, ldapbinddn.c_str(), ldapsecret.c_str(), method ) ) == -1 )
-       {
-               throw LDAPException( "Failed to bind to LDAP server: " + getError( msgid ) );
-       }
+        if( ( msgid = ldap_bind( d_ld, ldapbinddn.c_str(), ldapsecret.c_str(), method ) ) == -1 )
+        {
+               throw LDAPException( "Failed to bind to LDAP server: " + getError( msgid ) );
+        }
 #endif
 
-       waitResult( msgid, timeout, NULL );
+        waitResult( msgid, timeout, NULL );
 }
 
 
@@ -107,20 +107,20 @@ void PowerLDAP::bind( const string& ldapbinddn, const string& ldapsecret, int me
 
 void PowerLDAP::simpleBind( const string& ldapbinddn, const string& ldapsecret )
 {
-       this->bind( ldapbinddn, ldapsecret, LDAP_AUTH_SIMPLE, 30 );
+        this->bind( ldapbinddn, ldapsecret, LDAP_AUTH_SIMPLE, 30 );
 }
 
 
 int PowerLDAP::search( const string& base, int scope, const string& filter, const char** attr )
 {
-       int msgid, rc;
+        int msgid, rc;
 
-       if( ( rc = ldap_search_ext( d_ld, base.c_str(), scope, filter.c_str(), const_cast<char**> (attr), 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &msgid ) ) != LDAP_SUCCESS )
-       {
-               throw LDAPException( "Starting LDAP search: " + getError( rc ) );
-       }
+        if( ( rc = ldap_search_ext( d_ld, base.c_str(), scope, filter.c_str(), const_cast<char**> (attr), 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &msgid ) ) != LDAP_SUCCESS )
+        {
+               throw LDAPException( "Starting LDAP search: " + getError( rc ) );
+        }
 
-       return msgid;
+        return msgid;
 }
 
 
@@ -132,132 +132,132 @@ int PowerLDAP::search( const string& base, int scope, const string& filter, cons
 
 int PowerLDAP::waitResult( int msgid, int timeout, LDAPMessage** result )
 {
-       struct timeval tv;
-       LDAPMessage* res;
+        struct timeval tv;
+        LDAPMessage* res;
 
 
-       tv.tv_sec = timeout;
-       tv.tv_usec = 0;
+        tv.tv_sec = timeout;
+        tv.tv_usec = 0;
 
-       int rc = ldap_result( d_ld, msgid, LDAP_MSG_ONE, &tv, &res );
+        int rc = ldap_result( d_ld, msgid, LDAP_MSG_ONE, &tv, &res );
 
-       switch( rc )
-       {
-               case -1:
-                       throw LDAPException( "Error waiting for LDAP result: " + getError() );
-               case 0:
-                       throw LDAPTimeout();
-       }
+        switch( rc )
+        {
+               case -1:
+                       throw LDAPException( "Error waiting for LDAP result: " + getError() );
+               case 0:
+                       throw LDAPTimeout();
+        }
 
-       if( result == NULL )
-       {
-               ldap_msgfree( res );
-               return rc;
-       }
+        if( result == NULL )
+        {
+               ldap_msgfree( res );
+               return rc;
+        }
 
-       *result = res;
-       return rc;
+        *result = res;
+        return rc;
 }
 
 
 bool PowerLDAP::getSearchEntry( int msgid, sentry_t& entry, bool dn, int timeout )
 {
-       int i;
-       char* attr;
-       BerElement* ber;
-       struct berval** berval;
-       vector<string> values;
-       LDAPMessage* result;
-       LDAPMessage* object;
-
-
-       if( ( i = waitResult( msgid, timeout, &result ) ) == LDAP_RES_SEARCH_RESULT )
-       {
-               ldap_msgfree( result );
-               return false;
-       }
-
-       if( i != LDAP_RES_SEARCH_ENTRY )
-       {
-               ldap_msgfree( result );
-               throw LDAPException( "Search returned an unexpected result" );
-       }
-
-       if( ( object = ldap_first_entry( d_ld, result ) ) == NULL )
-       {
-               ldap_msgfree( result );
-               throw LDAPException( "Couldn't get first result entry: " + getError() );
-       }
-
-       entry.clear();
-
-       if( dn )
-       {
-               attr = ldap_get_dn( d_ld, object );
-               values.push_back( string( attr ) );
-               ldap_memfree( attr );
-               entry["dn"] = values;
-       }
-
-       if( ( attr = ldap_first_attribute( d_ld, object, &ber ) ) != NULL )
-       {
-               do
-               {
-                       if( ( berval = ldap_get_values_len( d_ld, object, attr ) ) != NULL )
-                       {
-                               values.clear();
-                               for( i = 0; i < ldap_count_values_len( berval ); i++ )
-                               {
-                                       values.push_back( berval[i]->bv_val );   // use berval[i]->bv_len for non string values?
-                               }
-
-                               entry[attr] = values;
-                               ldap_value_free_len( berval );
-                       }
-                       ldap_memfree( attr );
-               }
-               while( ( attr = ldap_next_attribute( d_ld, object, ber ) ) != NULL );
-
-               ber_free( ber, 0 );
-       }
-
-       ldap_msgfree( result );
-       return true;
+        int i;
+        char* attr;
+        BerElement* ber;
+        struct berval** berval;
+        vector<string> values;
+        LDAPMessage* result;
+        LDAPMessage* object;
+
+
+        if( ( i = waitResult( msgid, timeout, &result ) ) == LDAP_RES_SEARCH_RESULT )
+        {
+               ldap_msgfree( result );
+               return false;
+        }
+
+        if( i != LDAP_RES_SEARCH_ENTRY )
+        {
+               ldap_msgfree( result );
+               throw LDAPException( "Search returned an unexpected result" );
+        }
+
+        if( ( object = ldap_first_entry( d_ld, result ) ) == NULL )
+        {
+               ldap_msgfree( result );
+               throw LDAPException( "Couldn't get first result entry: " + getError() );
+        }
+
+        entry.clear();
+
+        if( dn )
+        {
+               attr = ldap_get_dn( d_ld, object );
+               values.push_back( string( attr ) );
+               ldap_memfree( attr );
+               entry["dn"] = values;
+        }
+
+        if( ( attr = ldap_first_attribute( d_ld, object, &ber ) ) != NULL )
+        {
+               do
+               {
+                       if( ( berval = ldap_get_values_len( d_ld, object, attr ) ) != NULL )
+                       {
+                               values.clear();
+                               for( i = 0; i < ldap_count_values_len( berval ); i++ )
+                               {
+                                       values.push_back( berval[i]->bv_val );   // use berval[i]->bv_len for non string values?
+                               }
+
+                               entry[attr] = values;
+                               ldap_value_free_len( berval );
+                       }
+                       ldap_memfree( attr );
+               }
+               while( ( attr = ldap_next_attribute( d_ld, object, ber ) ) != NULL );
+
+               ber_free( ber, 0 );
+        }
+
+        ldap_msgfree( result );
+        return true;
 }
 
 
 void PowerLDAP::getSearchResults( int msgid, sresult_t& result, bool dn, int timeout )
 {
-       sentry_t entry;
+        sentry_t entry;
 
-       result.clear();
-       while( getSearchEntry( msgid, entry, dn, timeout ) )
-       {
-               result.push_back( entry );
-       }
+        result.clear();
+        while( getSearchEntry( msgid, entry, dn, timeout ) )
+        {
+               result.push_back( entry );
+        }
 }
 
 
 const string PowerLDAP::getError( int rc )
 {
-       if( rc == -1 ) { getOption( LDAP_OPT_ERROR_NUMBER, &rc ); }
+        if( rc == -1 ) { getOption( LDAP_OPT_ERROR_NUMBER, &rc ); }
 
-       return string( ldap_err2string( rc ) );;
+        return string( ldap_err2string( rc ) );;
 }
 
 
 const string PowerLDAP::escape( const string& str )
 {
-       string a;
-       string::const_iterator i;
-
-       for( i = str.begin(); i != str.end(); i++ )
-       {
-               if( *i == '*' || *i == '\\' ) {
-                       a += '\\';
-               }
-               a += *i;
-       }
-
-       return a;
+        string a;
+        string::const_iterator i;
+
+        for( i = str.begin(); i != str.end(); i++ )
+        {
+               if( *i == '*' || *i == '\\' ) {
+                       a += '\\';
+               }
+               a += *i;
+        }
+
+        return a;
 }
index 39b238f973e7af21b3cb43590feb2e83e3b0e367..f793df2a8fee69c5c3f777be94c5e22ff9220492 100644 (file)
@@ -49,7 +49,7 @@ using std::vector;
 class LDAPException : public std::runtime_error
 {
 public:
-       explicit LDAPException( const string &str ) : std::runtime_error( str ) {}
+        explicit LDAPException( const string &str ) : std::runtime_error( str ) {}
 };
 
 
@@ -57,36 +57,36 @@ public:
 class LDAPTimeout : public LDAPException
 {
 public:
-       explicit LDAPTimeout() : LDAPException( "Timeout" ) {}
+        explicit LDAPTimeout() : LDAPException( "Timeout" ) {}
 };
 
 
 
 class PowerLDAP
 {
-       LDAP* d_ld;
+        LDAP* d_ld;
 
-       const string getError( int rc = -1 );
-       int waitResult( int msgid = LDAP_RES_ANY, int timeout = 0, LDAPMessage** result = NULL );
+        const string getError( int rc = -1 );
+        int waitResult( int msgid = LDAP_RES_ANY, int timeout = 0, LDAPMessage** result = NULL );
 
 public:
-       typedef map<string, vector<string> > sentry_t;
-       typedef vector<sentry_t> sresult_t;
+        typedef map<string, vector<string> > sentry_t;
+        typedef vector<sentry_t> sresult_t;
 
-       PowerLDAP( const string& hosts = "ldap://127.0.0.1/", uint16_t port = LDAP_PORT, bool tls = false );
-       ~PowerLDAP();
+        PowerLDAP( const string& hosts = "ldap://127.0.0.1/", uint16_t port = LDAP_PORT, bool tls = false );
+        ~PowerLDAP();
 
-       void getOption( int option, int* value );
-       void setOption( int option, int value );
+        void getOption( int option, int* value );
+        void setOption( int option, int value );
 
-       void bind( const string& ldapbinddn = "", const string& ldapsecret = "", int method = LDAP_AUTH_SIMPLE, int timeout = 5 );
-       void simpleBind( const string& ldapbinddn = "", const string& ldapsecret = "" );
-       int search( const string& base, int scope, const string& filter, const char** attr = 0 );
+        void bind( const string& ldapbinddn = "", const string& ldapsecret = "", int method = LDAP_AUTH_SIMPLE, int timeout = 5 );
+        void simpleBind( const string& ldapbinddn = "", const string& ldapsecret = "" );
+        int search( const string& base, int scope, const string& filter, const char** attr = 0 );
 
-       bool getSearchEntry( int msgid, sentry_t& entry, bool dn = false, int timeout = 5 );
-       void getSearchResults( int msgid, sresult_t& result, bool dn = false, int timeout = 5 );
+        bool getSearchEntry( int msgid, sentry_t& entry, bool dn = false, int timeout = 5 );
+        void getSearchResults( int msgid, sresult_t& result, bool dn = false, int timeout = 5 );
 
-       static const string escape( const string& tobe );
+        static const string escape( const string& tobe );
 };
 
 
index 84b7bf8798a540e94ea90f7d47aded25bd88ad9d..17e3b60993950b6bfa0acd8aeab0a217b6e557ea 100644 (file)
@@ -14,123 +14,123 @@ using std::vector;
 
 inline string ptr2ip4( vector<string>& parts )
 {
-       string ip;
-       parts.pop_back();
-       parts.pop_back();
+        string ip;
+        parts.pop_back();
+        parts.pop_back();
 
 
-       ip = parts.back();
-       parts.pop_back();
+        ip = parts.back();
+        parts.pop_back();
 
-       while( !parts.empty() )
-       {
-               ip += "." + parts.back();
-               parts.pop_back();
-       }
+        while( !parts.empty() )
+        {
+               ip += "." + parts.back();
+               parts.pop_back();
+        }
 
-       return ip;
+        return ip;
 }
 
 
 inline string ptr2ip6( vector<string>& parts )
 {
-       int i = 0;
-       string ip;
-
-
-       parts.pop_back();
-       parts.pop_back();
-
-       while( i < 3 && parts.size() > 1 && parts.back() == "0" )
-       {
-               parts.pop_back();
-               i++;
-       }
-
-       while( i++ < 4 && !parts.empty() )
-       {
-               ip += parts.back();
-               parts.pop_back();
-       }
-
-       while( !parts.empty() )
-       {
-               i = 0;
-               ip += ":";
-
-               while( i < 3 && parts.size() > 1 && parts.back() == "0" )
-               {
-                       parts.pop_back();
-                       i++;
-               }
-
-               while( i++ < 4 && !parts.empty() )
-               {
-                       ip += parts.back();
-                       parts.pop_back();
-               }
-       }
-
-       return ip;
+        int i = 0;
+        string ip;
+
+
+        parts.pop_back();
+        parts.pop_back();
+
+        while( i < 3 && parts.size() > 1 && parts.back() == "0" )
+        {
+               parts.pop_back();
+               i++;
+        }
+
+        while( i++ < 4 && !parts.empty() )
+        {
+               ip += parts.back();
+               parts.pop_back();
+        }
+
+        while( !parts.empty() )
+        {
+               i = 0;
+               ip += ":";
+
+               while( i < 3 && parts.size() > 1 && parts.back() == "0" )
+               {
+                       parts.pop_back();
+                       i++;
+               }
+
+               while( i++ < 4 && !parts.empty() )
+               {
+                       ip += parts.back();
+                       parts.pop_back();
+               }
+        }
+
+        return ip;
 }
 
 
 inline string ip2ptr4( const string& ip )
 {
-       string ptr;
-       vector<string> parts;
+        string ptr;
+        vector<string> parts;
 
-       stringtok( parts, ip, "." );
-       while( !parts.empty() )
-       {
-               ptr += parts.back() +  ".";
-               parts.pop_back();
-       }
+        stringtok( parts, ip, "." );
+        while( !parts.empty() )
+        {
+               ptr += parts.back() +  ".";
+               parts.pop_back();
+        }
 
-       return ptr + "in-addr.arpa";
+        return ptr + "in-addr.arpa";
 }
 
 
 inline string ip2ptr6( const string& ip )
 {
-       string ptr, part, defstr;
-       vector<string> parts;
-
-       stringtok( parts, ip, ":" );
-       while( !parts.empty() )
-       {
-               defstr = "0.0.0.0.";
-               part = parts.back();
-
-               while( part.length() < 4 )
-               {
-                       part = "0" + part;
-               }
-
-               defstr[0] = part[3];
-               defstr[2] = part[2];
-               defstr[4] = part[1];
-               defstr[6] = part[0];
-               ptr += defstr;
-               parts.pop_back();
-       }
-
-       return ptr + "ip6.arpa";
+        string ptr, part, defstr;
+        vector<string> parts;
+
+        stringtok( parts, ip, ":" );
+        while( !parts.empty() )
+        {
+               defstr = "0.0.0.0.";
+               part = parts.back();
+
+               while( part.length() < 4 )
+               {
+                       part = "0" + part;
+               }
+
+               defstr[0] = part[3];
+               defstr[2] = part[2];
+               defstr[4] = part[1];
+               defstr[6] = part[0];
+               ptr += defstr;
+               parts.pop_back();
+        }
+
+        return ptr + "ip6.arpa";
 }
 
 
 inline string strbind( const string& search, const string& replace, string subject )
 {
-       size_t pos = 0;
+        size_t pos = 0;
 
 
-       while( ( pos = subject.find( search, pos ) ) != string::npos )
-       {
-               subject.replace( pos, search.size(), replace );
-               pos += replace.size();
-       }
+        while( ( pos = subject.find( search, pos ) ) != string::npos )
+        {
+               subject.replace( pos, search.size(), replace );
+               pos += replace.size();
+        }
 
-       return subject;
+        return subject;
 }
 
 /*
@@ -139,17 +139,17 @@ inline string strbind( const string& search, const string& replace, string subje
 
 inline time_t str2tstamp( const string& str )
 {
-       char* tmp;
-       struct tm tm;
+        char* tmp;
+        struct tm tm;
 
-       tmp =  strptime( str.c_str(), "%Y%m%d%H%M%SZ", &tm );
+        tmp =  strptime( str.c_str(), "%Y%m%d%H%M%SZ", &tm );
 
-       if( tmp != NULL && *tmp == 0 )
-       {
-               return mktime( &tm );
-       }
+        if( tmp != NULL && *tmp == 0 )
+        {
+               return mktime( &tm );
+        }
 
-       return 0;
+        return 0;
 }
 
 #endif
index 7c89b556cb2c61f991bbb31097f7259f4b182727..79e6af66f326ef2d732d8d0c93f52aa82b12db7a 100644 (file)
@@ -40,318 +40,318 @@ using namespace std;
 static string backendName="[MyDNSbackend]";
 
 MyDNSBackend::MyDNSBackend(const string &suffix) {
-       setArgPrefix("mydns"+suffix);
-
-       try {
-               d_db = new SMySQL(getArg("dbname"),
-                               getArg("host"),
-                               getArgAsNum("port"),
-                               getArg("socket"),
-                               getArg("user"),
-                               getArg("password"));
-
-       }
-       catch(SSqlException &e) {
-               L<<Logger::Error<<backendName<<" Connection failed: "<<e.txtReason()<<endl;
-               throw AhuException(backendName+"Unable to launch connection: "+e.txtReason());
-       }
-
-       d_rrtable=getArg("rr-table");
-       d_soatable=getArg("soa-table");
-       d_rrwhere=(mustDo("rr-active")?"active = 1 and ":"")+getArg("rr-where");
-       d_soawhere=(mustDo("soa-active")?"active = 1 and ":"")+getArg("soa-where");
-
-       L<<Logger::Warning<<backendName<<" Connection succesful"<<endl;
+        setArgPrefix("mydns"+suffix);
+
+        try {
+               d_db = new SMySQL(getArg("dbname"),
+                               getArg("host"),
+                               getArgAsNum("port"),
+                               getArg("socket"),
+                               getArg("user"),
+                               getArg("password"));
+
+        }
+        catch(SSqlException &e) {
+               L<<Logger::Error<<backendName<<" Connection failed: "<<e.txtReason()<<endl;
+               throw AhuException(backendName+"Unable to launch connection: "+e.txtReason());
+        }
+
+        d_rrtable=getArg("rr-table");
+        d_soatable=getArg("soa-table");
+        d_rrwhere=(mustDo("rr-active")?"active = 1 and ":"")+getArg("rr-where");
+        d_soawhere=(mustDo("soa-active")?"active = 1 and ":"")+getArg("soa-where");
+
+        L<<Logger::Warning<<backendName<<" Connection succesful"<<endl;
 }
 
 MyDNSBackend::~MyDNSBackend() {
-       if (d_db)
-               delete(d_db);
+        if (d_db)
+               delete(d_db);
 }
 
 
 void MyDNSBackend::Query(const string &query) {
-       try {
-               d_db->doQuery(query);
-       } catch (SSqlException &e) {
-               throw AhuException("Query failed: "+e.txtReason());
-       }
+        try {
+               d_db->doQuery(query);
+        } catch (SSqlException &e) {
+               throw AhuException("Query failed: "+e.txtReason());
+        }
 }
 
 bool MyDNSBackend::list(const string &target, int zoneId) {
-       string query;
-       string sname;
-       SSql::row_t rrow;
+        string query;
+        string sname;
+        SSql::row_t rrow;
 
-       d_db->setLog(::arg().mustDo("query-logging"));
+        d_db->setLog(::arg().mustDo("query-logging"));
 
-       query = "select origin, minimum from "+d_soatable+" where id = ";
-       ostringstream o;
-       o<<zoneId;
-       query+=o.str();
-       query+= " and "+d_soawhere;
+        query = "select origin, minimum from "+d_soatable+" where id = ";
+        ostringstream o;
+        o<<zoneId;
+        query+=o.str();
+        query+= " and "+d_soawhere;
 
-       this->Query(query);
+        this->Query(query);
 
-       if(!d_db->getRow(rrow)) {
-               // No such zone
-               return false;
-       }
-       
-       d_origin = rrow[0];
-       if (d_origin[d_origin.length()-1] == '.')
-               d_origin.erase(d_origin.length()-1);
-       d_minimum = atol(rrow[1].c_str());
+        if(!d_db->getRow(rrow)) {
+               // No such zone
+               return false;
+        }
+        
+        d_origin = rrow[0];
+        if (d_origin[d_origin.length()-1] == '.')
+               d_origin.erase(d_origin.length()-1);
+        d_minimum = atol(rrow[1].c_str());
 
-       while (d_db->getRow(rrow)) {
-               L<<Logger::Warning<<backendName<<" Found more than one matching origin for zone ID: "+zoneId<<endl;
-       };
+        while (d_db->getRow(rrow)) {
+               L<<Logger::Warning<<backendName<<" Found more than one matching origin for zone ID: "+zoneId<<endl;
+        };
 
-       query = "select type, data, aux, ttl, zone, name from "+d_rrtable+" where zone = ";
-       query+=o.str();
-       query += " and "+d_rrwhere;
+        query = "select type, data, aux, ttl, zone, name from "+d_rrtable+" where zone = ";
+        query+=o.str();
+        query += " and "+d_rrwhere;
 
-       this->Query(query);
+        this->Query(query);
 
-       d_qname = "";
-       return true;
+        d_qname = "";
+        return true;
 
 }
 
 bool MyDNSBackend::getSOA(const string& name, SOAData& soadata, DNSPacket*) {
-       string query;
-       SSql::row_t rrow;
+        string query;
+        SSql::row_t rrow;
 
-       d_db->setLog(::arg().mustDo("query-logging"));
+        d_db->setLog(::arg().mustDo("query-logging"));
 
-       if (name.empty())
-               return false;
+        if (name.empty())
+               return false;
 
-       query = "select id, mbox, serial, ns, refresh, retry, expire, minimum, ttl from "+d_soatable+" where origin = '";
+        query = "select id, mbox, serial, ns, refresh, retry, expire, minimum, ttl from "+d_soatable+" where origin = '";
 
-       if (name.find_first_of("'\\")!=string::npos)
-               query+=d_db->escape(name);
-       else
-               query+=name;
+        if (name.find_first_of("'\\")!=string::npos)
+               query+=d_db->escape(name);
+        else
+               query+=name;
 
-       query+=".' and "+d_soawhere;
+        query+=".' and "+d_soawhere;
 
-       this->Query(query);
+        this->Query(query);
 
-       if(!(d_db->getRow(rrow))) {
-               return false;
-       }
+        if(!(d_db->getRow(rrow))) {
+               return false;
+        }
 
-       soadata.domain_id = atol(rrow[0].c_str());
-       soadata.hostmaster = rrow[1];
-       soadata.serial = atol(rrow[2].c_str());
-       soadata.nameserver = rrow[3];
-       soadata.refresh = atol(rrow[4].c_str());
-       soadata.retry = atol(rrow[5].c_str());
-       soadata.expire = atol(rrow[6].c_str());
-       soadata.default_ttl = atol(rrow[7].c_str());
-       soadata.ttl = atol(rrow[8].c_str());
-       if (soadata.ttl < soadata.default_ttl) {
-               soadata.ttl = soadata.default_ttl;
-       }
-       soadata.db = this;
+        soadata.domain_id = atol(rrow[0].c_str());
+        soadata.hostmaster = rrow[1];
+        soadata.serial = atol(rrow[2].c_str());
+        soadata.nameserver = rrow[3];
+        soadata.refresh = atol(rrow[4].c_str());
+        soadata.retry = atol(rrow[5].c_str());
+        soadata.expire = atol(rrow[6].c_str());
+        soadata.default_ttl = atol(rrow[7].c_str());
+        soadata.ttl = atol(rrow[8].c_str());
+        if (soadata.ttl < soadata.default_ttl) {
+               soadata.ttl = soadata.default_ttl;
+        }
+        soadata.db = this;
 
-       while (d_db->getRow(rrow)) {
-               L<<Logger::Warning<<backendName<<" Found more than one matching zone for: "+name<<endl;
-       };
+        while (d_db->getRow(rrow)) {
+               L<<Logger::Warning<<backendName<<" Found more than one matching zone for: "+name<<endl;
+        };
 
-       return true;
+        return true;
 }
 
 void MyDNSBackend::lookup(const QType &qtype, const string &qname, DNSPacket *p, int zoneId) {
-       string query;
-       string sname;
-       SSql::row_t rrow;
-       bool found = false;
-
-       d_origin = "";
-
-       d_db->setLog(::arg().mustDo("query-logging"));
-
-       if (qname.empty())
-               return;
-
-       // Escape the name, after this point we only want to use it in queries
-       if (qname.find_first_of("'\\")!=string::npos)
-               sname=d_db->escape(qname);
-       else
-               sname = qname;
-       sname += ".";
-
-       if (zoneId < 0) {
-               // First off we need to work out what zone we're working with
-               // MyDNS records aren't always fully qualified, so we need to work out the zone ID.
-               
-               size_t pos;
-               string sdom;
-
-               pos = 0;
-               sdom = sname;
-               while (!sdom.empty() && pos != string::npos) {
-                       query = "select id, origin, minimum from "+d_soatable+" where origin = '"+sdom+"' and "+d_soawhere;
-
-                       this->Query(query);
-                       if(d_db->getRow(rrow)) {
-                               zoneId = atol(rrow[0].c_str());
-                               d_origin = rrow[1];
-                               if (d_origin[d_origin.length()-1] == '.')
-                                       d_origin.erase(d_origin.length()-1);
-                               d_minimum = atol(rrow[2].c_str());
-                               found = true;
-                               break;
-                       }
-
-                       pos = sname.find_first_of(".",pos+1);
-                       sdom = sname.substr(pos+1);
-               }
-
-       } else {
-               query = "select origin, minimum from "+d_soatable+" where id = ";
-               ostringstream o;
-               o<<zoneId;
-               query+=o.str();
-               query+= " and "+d_soawhere;
-
-               this->Query(query);
-
-               if(!d_db->getRow(rrow)) {
-                       throw AhuException("lookup() passed zoneId = "+o.str()+" but no such zone!");
-               }
-               
-               found = true;
-               d_origin = rrow[0];
-               if (d_origin[d_origin.length()-1] == '.')
-                       d_origin.erase(d_origin.length()-1);
-               d_minimum = atol(rrow[1].c_str());
-       }
-
-
-       if (found) {
-               while (d_db->getRow(rrow)) {
-                       L<<Logger::Warning<<backendName<<" Found more than one matching zone for: "+d_origin<<endl;
-               };
-               // We found the zoneId, so we can work out how to find our rr
-               string host;
-
-               // The host part of the query is the name less the origin
-               if (qname.length() == d_origin.length())
-                       host = "";
-               else
-                       host = qname.substr(0, (qname.length() - d_origin.length())-1);
-
-               if (host.find_first_of("'\\")!=string::npos)
-                       host=d_db->escape(host);
-
-               query = "select type, data, aux, ttl, zone from "+d_rrtable+" where zone = ";
-               ostringstream o;
-               o<<zoneId;
-               query+=o.str();
-               query += " and (name = '"+host+"' or name = '"+sname+"')";
-
-               if(qtype.getCode()!=255) {  // ANY
-                       query+=" and type='";
-                       query+=qtype.getName();
-                       query+="'";
-               }
-               query += " and "+d_rrwhere+" order by type,aux,data";
-
-               this->Query(query);
-
-               d_qname = qname;
-       }
+        string query;
+        string sname;
+        SSql::row_t rrow;
+        bool found = false;
+
+        d_origin = "";
+
+        d_db->setLog(::arg().mustDo("query-logging"));
+
+        if (qname.empty())
+               return;
+
+        // Escape the name, after this point we only want to use it in queries
+        if (qname.find_first_of("'\\")!=string::npos)
+               sname=d_db->escape(qname);
+        else
+               sname = qname;
+        sname += ".";
+
+        if (zoneId < 0) {
+               // First off we need to work out what zone we're working with
+               // MyDNS records aren't always fully qualified, so we need to work out the zone ID.
+               
+               size_t pos;
+               string sdom;
+
+               pos = 0;
+               sdom = sname;
+               while (!sdom.empty() && pos != string::npos) {
+                       query = "select id, origin, minimum from "+d_soatable+" where origin = '"+sdom+"' and "+d_soawhere;
+
+                       this->Query(query);
+                       if(d_db->getRow(rrow)) {
+                               zoneId = atol(rrow[0].c_str());
+                               d_origin = rrow[1];
+                               if (d_origin[d_origin.length()-1] == '.')
+                                       d_origin.erase(d_origin.length()-1);
+                               d_minimum = atol(rrow[2].c_str());
+                               found = true;
+                               break;
+                       }
+
+                       pos = sname.find_first_of(".",pos+1);
+                       sdom = sname.substr(pos+1);
+               }
+
+        } else {
+               query = "select origin, minimum from "+d_soatable+" where id = ";
+               ostringstream o;
+               o<<zoneId;
+               query+=o.str();
+               query+= " and "+d_soawhere;
+
+               this->Query(query);
+
+               if(!d_db->getRow(rrow)) {
+                       throw AhuException("lookup() passed zoneId = "+o.str()+" but no such zone!");
+               }
+               
+               found = true;
+               d_origin = rrow[0];
+               if (d_origin[d_origin.length()-1] == '.')
+                       d_origin.erase(d_origin.length()-1);
+               d_minimum = atol(rrow[1].c_str());
+        }
+
+
+        if (found) {
+               while (d_db->getRow(rrow)) {
+                       L<<Logger::Warning<<backendName<<" Found more than one matching zone for: "+d_origin<<endl;
+               };
+               // We found the zoneId, so we can work out how to find our rr
+               string host;
+
+               // The host part of the query is the name less the origin
+               if (qname.length() == d_origin.length())
+                       host = "";
+               else
+                       host = qname.substr(0, (qname.length() - d_origin.length())-1);
+
+               if (host.find_first_of("'\\")!=string::npos)
+                       host=d_db->escape(host);
+
+               query = "select type, data, aux, ttl, zone from "+d_rrtable+" where zone = ";
+               ostringstream o;
+               o<<zoneId;
+               query+=o.str();
+               query += " and (name = '"+host+"' or name = '"+sname+"')";
+
+               if(qtype.getCode()!=255) {  // ANY
+                       query+=" and type='";
+                       query+=qtype.getName();
+                       query+="'";
+               }
+               query += " and "+d_rrwhere+" order by type,aux,data";
+
+               this->Query(query);
+
+               d_qname = qname;
+        }
 
 }
 
 bool MyDNSBackend::get(DNSResourceRecord &rr) {
-       if (d_origin.empty()) {
-               // This happens if lookup() couldn't find the zone
-               return false;
-       }
-
-       SSql::row_t rrow;
-
-       if(!d_db->getRow(rrow)) {
-               return false;
-       }
-
-       rr.qtype=rrow[0];
-       rr.content = rrow[1];
-
-       if(!d_qname.empty()) {
-               // use this to distinguish between select with 'name' field (list()) and one without
-               rr.qname=d_qname;
-       } else {
-               rr.qname=rrow[5];
-               if (rr.qname[rr.qname.length()-1] == '.') {
-                       rr.qname.erase(rr.qname.length()-1); // Fully qualified, nuke the last .
-               } else {
-                       if (!rr.qname.empty())
-                               rr.qname += ".";
-                       rr.qname += d_origin; // Not fully qualified
-               }
-       }
-
-       if (rr.qtype == "NS" || rr.qtype == "MX" || rr.qtype == "CNAME" || rr.qtype == "PTR") {
-               if (rr.content[rr.content.length()-1] == '.') {
-                       rr.content.erase(rr.content.length()-1); // Fully qualified, nuke the last .
-               } else {
-                       if (!rr.content.empty())
-                               rr.content += ".";
-                       rr.content += d_origin;
-               }
-       }
-
-       rr.priority = atol(rrow[2].c_str());
-       rr.ttl = atol(rrow[3].c_str());
-       if (rr.ttl < d_minimum)
-               rr.ttl = d_minimum;
-       rr.domain_id=atol(rrow[4].c_str());
+        if (d_origin.empty()) {
+               // This happens if lookup() couldn't find the zone
+               return false;
+        }
+
+        SSql::row_t rrow;
+
+        if(!d_db->getRow(rrow)) {
+               return false;
+        }
+
+        rr.qtype=rrow[0];
+        rr.content = rrow[1];
+
+        if(!d_qname.empty()) {
+               // use this to distinguish between select with 'name' field (list()) and one without
+               rr.qname=d_qname;
+        } else {
+               rr.qname=rrow[5];
+               if (rr.qname[rr.qname.length()-1] == '.') {
+                       rr.qname.erase(rr.qname.length()-1); // Fully qualified, nuke the last .
+               } else {
+                       if (!rr.qname.empty())
+                               rr.qname += ".";
+                       rr.qname += d_origin; // Not fully qualified
+               }
+        }
+
+        if (rr.qtype == "NS" || rr.qtype == "MX" || rr.qtype == "CNAME" || rr.qtype == "PTR") {
+               if (rr.content[rr.content.length()-1] == '.') {
+                       rr.content.erase(rr.content.length()-1); // Fully qualified, nuke the last .
+               } else {
+                       if (!rr.content.empty())
+                               rr.content += ".";
+                       rr.content += d_origin;
+               }
+        }
+
+        rr.priority = atol(rrow[2].c_str());
+        rr.ttl = atol(rrow[3].c_str());
+        if (rr.ttl < d_minimum)
+               rr.ttl = d_minimum;
+        rr.domain_id=atol(rrow[4].c_str());
 
   
-       rr.last_modified=0;
+        rr.last_modified=0;
   
-       return true;
+        return true;
 
 }
 
 class MyDNSFactory : public BackendFactory {
 
 public:
-       MyDNSFactory() : BackendFactory("mydns") {}
-
-       void declareArguments(const string &suffix = "") {
-               declare(suffix,"dbname","Pdns backend database name to connect to","mydns");
-               declare(suffix,"user","Pdns backend user to connect as","powerdns");
-               declare(suffix,"host","Pdns backend host to connect to","");
-               declare(suffix,"port","Pdns backend host to connect to","");
-               declare(suffix,"password","Pdns backend password to connect with","");
-               declare(suffix,"socket","Pdns backend socket to connect to","");
-               declare(suffix,"rr-table","Name of RR table to use","rr");
-               declare(suffix,"soa-table","Name of SOA table to use","soa");
-               declare(suffix,"soa-where","Additional WHERE clause for SOA","1 = 1");
-               declare(suffix,"rr-where","Additional WHERE clause for RR","1 = 1");
-               declare(suffix,"soa-active","Use the active column in the SOA table","yes");
-               declare(suffix,"rr-active","Use the active column in the RR table","yes");
-       }
-
-       MyDNSBackend *make(const string &suffix = "") {
-               return new MyDNSBackend(suffix);
-       }
+        MyDNSFactory() : BackendFactory("mydns") {}
+
+        void declareArguments(const string &suffix = "") {
+               declare(suffix,"dbname","Pdns backend database name to connect to","mydns");
+               declare(suffix,"user","Pdns backend user to connect as","powerdns");
+               declare(suffix,"host","Pdns backend host to connect to","");
+               declare(suffix,"port","Pdns backend host to connect to","");
+               declare(suffix,"password","Pdns backend password to connect with","");
+               declare(suffix,"socket","Pdns backend socket to connect to","");
+               declare(suffix,"rr-table","Name of RR table to use","rr");
+               declare(suffix,"soa-table","Name of SOA table to use","soa");
+               declare(suffix,"soa-where","Additional WHERE clause for SOA","1 = 1");
+               declare(suffix,"rr-where","Additional WHERE clause for RR","1 = 1");
+               declare(suffix,"soa-active","Use the active column in the SOA table","yes");
+               declare(suffix,"rr-active","Use the active column in the RR table","yes");
+        }
+
+        MyDNSBackend *make(const string &suffix = "") {
+               return new MyDNSBackend(suffix);
+        }
 
 };
 
 class MyDNSLoader {
 
 public:
-       MyDNSLoader() {
-               BackendMakers().report(new MyDNSFactory());
-               L<<Logger::Info<<backendName<<" This is the MyDNSBackend ("__DATE__", "__TIME__") reporting"<<endl;
-       }
+        MyDNSLoader() {
+               BackendMakers().report(new MyDNSFactory());
+               L<<Logger::Info<<backendName<<" This is the MyDNSBackend ("__DATE__", "__TIME__") reporting"<<endl;
+        }
 };
 
 static MyDNSLoader mydnsloader;
index a4ae01c450daafcd44ae568f4dd3a210cf942986..5ce616cf1bb52e5ecd5d6f183518a27818921157 100644 (file)
@@ -11,26 +11,26 @@ using namespace std;
 class MyDNSBackend : public DNSBackend
 {
 public:
-       MyDNSBackend(const string &suffix="");
-       ~MyDNSBackend();
-       MyDNSBackend *parent;
-       
-       void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1);
-       bool list(const string &target, int domain_id);
-       bool get(DNSResourceRecord &r);
-       bool getSOA(const string& name, SOAData& soadata, DNSPacket*);
-         
+        MyDNSBackend(const string &suffix="");
+        ~MyDNSBackend();
+        MyDNSBackend *parent;
+        
+        void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1);
+        bool list(const string &target, int domain_id);
+        bool get(DNSResourceRecord &r);
+        bool getSOA(const string& name, SOAData& soadata, DNSPacket*);
+          
 private:
-       void Query(const string& query);
-       SMySQL *d_db; 
+        void Query(const string& query);
+        SMySQL *d_db; 
 
-       string d_qname;
-       string d_rrtable;
-       string d_soatable;
-       string d_soawhere;
-       string d_rrwhere;
-       string d_origin;
-       unsigned int d_minimum;
+        string d_qname;
+        string d_rrtable;
+        string d_soatable;
+        string d_soawhere;
+        string d_rrwhere;
+        string d_origin;
+        unsigned int d_minimum;
 
 };
 #endif /* MYDNSBACKEND_HH */
index bf27d7f37522e65988b9c29f8f00019ecae70711..027d03186de3ba1e16aae9ba960fa4b8b6eef54f 100644 (file)
@@ -40,12 +40,12 @@ MySQLBackend::MySQLBackend(const string &suffix)
   L<<Logger::Error<<backendName<<" *** THIS BACKEND IS DEPRECATED - USE GMYSQL! ***"<<endl;
   setArgPrefix("mysql"+suffix);
   if (!mysql_real_connect(&db,getArg("host").c_str(),
-                         getArg("user").c_str(),
-                         getArg("password").c_str(),
-                         getArg("dbname").c_str(),
-                         0,
-                         getArg("socket").empty() ? 
-                         NULL : getArg("socket").c_str(),0)) {
+                         getArg("user").c_str(),
+                         getArg("password").c_str(),
+                         getArg("dbname").c_str(),
+                         0,
+                         getArg("socket").empty() ? 
+                         NULL : getArg("socket").c_str(),0)) {
     L<<Logger::Error<<backendName<<" Failed to connect to database: Error: "<<mysql_error(&db)<<endl;
     throw(AhuException(backendName+string(" Failed to connect to database: Error: ")+mysql_error(&db)));
   }
index 15909288e92f030acf4977505d9d7636c6e434f7..136c91bbfd53eaf05b39b0238e8f9d490b1d22fc 100644 (file)
 
 inline string& strbind( const string& search, const string& replace, string& subject )
 {
-       size_t pos = 0;
+        size_t pos = 0;
 
-       while( ( pos = subject.find( search, pos ) ) != string::npos )
-       {
-               subject.replace( pos, search.size(), replace );
-               pos += replace.size();
-       }
+        while( ( pos = subject.find( search, pos ) ) != string::npos )
+        {
+               subject.replace( pos, search.size(), replace );
+               pos += replace.size();
+        }
 
-       return subject;
+        return subject;
 }
 
 
 
 inline string& toLowerByRef( string& str )
 {
-       for( unsigned int i = 0; i < str.length(); i++ )
-       {
-               str[i] = dns_tolower( str[i] );
-       }
+        for( unsigned int i = 0; i < str.length(); i++ )
+        {
+               str[i] = dns_tolower( str[i] );
+        }
 
-       return str;
+        return str;
 }
 
 
 
 OdbxBackend::OdbxBackend( const string& suffix )
 {
-       vector<string> hosts;
-
-
-       try
-       {
-               m_result = NULL;
-               m_handle[READ] = NULL;
-               m_handle[WRITE] = NULL;
-               m_myname = "[OpendbxBackend]";
-               m_default_ttl = arg().asNum( "default-ttl" );
-               m_qlog = arg().mustDo( "query-logging" );
-
-               setArgPrefix( "opendbx" + suffix );
-
-               if( getArg( "host" ).size() > 0 )
-               {
-                       L.log( m_myname + " WARNING: Using depricated opendbx-host parameter", Logger::Warning );
-                       stringtok( m_hosts[READ], getArg( "host" ), ", " );
-                       m_hosts[WRITE] = m_hosts[READ];
-               }
-               else
-               {
-                       stringtok( m_hosts[READ], getArg( "host-read" ), ", " );
-                       stringtok( m_hosts[WRITE], getArg( "host-write" ), ", " );
-               }
-
-               if( !connectTo( m_hosts[READ], READ ) ) { throw( AhuException( "Fatal: Connecting to server for reading failed" ) ); }
-               if( !connectTo( m_hosts[WRITE], WRITE ) ) { throw( AhuException( "Fatal: Connecting to server for writing failed" ) ); }
-       }
-       catch( exception& e )
-       {
-               L.log( m_myname + " OdbxBackend(): Caught STL exception - " + e.what(),  Logger::Error );
-               throw( AhuException( "Fatal: STL exception" ) );
-       }
+        vector<string> hosts;
+
+
+        try
+        {
+               m_result = NULL;
+               m_handle[READ] = NULL;
+               m_handle[WRITE] = NULL;
+               m_myname = "[OpendbxBackend]";
+               m_default_ttl = arg().asNum( "default-ttl" );
+               m_qlog = arg().mustDo( "query-logging" );
+
+               setArgPrefix( "opendbx" + suffix );
+
+               if( getArg( "host" ).size() > 0 )
+               {
+                       L.log( m_myname + " WARNING: Using depricated opendbx-host parameter", Logger::Warning );
+                       stringtok( m_hosts[READ], getArg( "host" ), ", " );
+                       m_hosts[WRITE] = m_hosts[READ];
+               }
+               else
+               {
+                       stringtok( m_hosts[READ], getArg( "host-read" ), ", " );
+                       stringtok( m_hosts[WRITE], getArg( "host-write" ), ", " );
+               }
+
+               if( !connectTo( m_hosts[READ], READ ) ) { throw( AhuException( "Fatal: Connecting to server for reading failed" ) ); }
+               if( !connectTo( m_hosts[WRITE], WRITE ) ) { throw( AhuException( "Fatal: Connecting to server for writing failed" ) ); }
+        }
+        catch( exception& e )
+        {
+               L.log( m_myname + " OdbxBackend(): Caught STL exception - " + e.what(),  Logger::Error );
+               throw( AhuException( "Fatal: STL exception" ) );
+        }
 }
 
 
 
 OdbxBackend::~OdbxBackend()
 {
-       odbx_unbind( m_handle[WRITE] );
-       odbx_unbind( m_handle[READ] );
+        odbx_unbind( m_handle[WRITE] );
+        odbx_unbind( m_handle[READ] );
 
-       odbx_finish( m_handle[WRITE] );
-       odbx_finish( m_handle[READ] );
+        odbx_finish( m_handle[WRITE] );
+        odbx_finish( m_handle[READ] );
 }
 
 
 
 bool OdbxBackend::getDomainInfo( const string& domain, DomainInfo& di )
 {
-       const char* tmp;
-
-
-       try
-       {
-               DLOG( L.log( m_myname + " getDomainInfo()", Logger::Debug ) );
-
-               string stmt = getArg( "sql-zoneinfo" );
-               string& stmtref = strbind( ":name", escape( toLower( domain ), READ ), stmt );
-
-               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
-               if( !getRecord( READ ) ) { return false; }
-
-               do
-               {
-                       di.id = 0;
-                       di.zone = "";
-                       di.masters.clear();
-                       di.last_check = 0;
-                       di.notified_serial = 0;
-                       di.kind = DomainInfo::Native;
-                       di.backend = this;
-                       di.serial = 0;
-
-                       if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
-                       {
-                               SOAData sd;
-
-                               sd.serial = 0;
-                               fillSOAData( string( tmp, odbx_field_length( m_result, 6 ) ), sd );
-
-                               if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
-                               {
-                                       sd.serial = strtol( tmp, NULL, 10 );
-                               }
-
-                               di.serial = sd.serial;
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
-                       {
-                               di.last_check = strtol( tmp, NULL, 10 );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
-                       {
-                               stringtok(di.masters, string( tmp, odbx_field_length( m_result, 3 ) ), ", \t");
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
-                       {
-                               if( !strncmp( tmp, "SLAVE", 5 ) )
-                               {
-                                       di.kind = DomainInfo::Slave;
-                               }
-                               else if( !strncmp( tmp, "MASTER", 6 ) )
-                               {
-                                       di.kind = DomainInfo::Master;
-                               }
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
-                       {
-                               di.zone = string( tmp, odbx_field_length( m_result, 1 ) );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
-                       {
-                               di.id = strtol( tmp, NULL, 10 );
-                       }
-               }
-               while( getRecord( READ ) );
-       }
-       catch( exception& e )
-       {
-               L.log( m_myname + " getDomainInfo: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+        const char* tmp;
+
+
+        try
+        {
+               DLOG( L.log( m_myname + " getDomainInfo()", Logger::Debug ) );
+
+               string stmt = getArg( "sql-zoneinfo" );
+               string& stmtref = strbind( ":name", escape( toLower( domain ), READ ), stmt );
+
+               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
+               if( !getRecord( READ ) ) { return false; }
+
+               do
+               {
+                       di.id = 0;
+                       di.zone = "";
+                       di.masters.clear();
+                       di.last_check = 0;
+                       di.notified_serial = 0;
+                       di.kind = DomainInfo::Native;
+                       di.backend = this;
+                       di.serial = 0;
+
+                       if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
+                       {
+                               SOAData sd;
+
+                               sd.serial = 0;
+                               fillSOAData( string( tmp, odbx_field_length( m_result, 6 ) ), sd );
+
+                               if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
+                               {
+                                       sd.serial = strtol( tmp, NULL, 10 );
+                               }
+
+                               di.serial = sd.serial;
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
+                       {
+                               di.last_check = strtol( tmp, NULL, 10 );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
+                       {
+                               stringtok(di.masters, string( tmp, odbx_field_length( m_result, 3 ) ), ", \t");
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
+                       {
+                               if( !strncmp( tmp, "SLAVE", 5 ) )
+                               {
+                                       di.kind = DomainInfo::Slave;
+                               }
+                               else if( !strncmp( tmp, "MASTER", 6 ) )
+                               {
+                                       di.kind = DomainInfo::Master;
+                               }
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
+                       {
+                               di.zone = string( tmp, odbx_field_length( m_result, 1 ) );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
+                       {
+                               di.id = strtol( tmp, NULL, 10 );
+                       }
+               }
+               while( getRecord( READ ) );
+        }
+        catch( exception& e )
+        {
+               L.log( m_myname + " getDomainInfo: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
 
 
 
 bool OdbxBackend::getSOA( const string& domain, SOAData& sd, DNSPacket* p )
 {
-       const char* tmp;
-
-
-       try
-       {
-               DLOG( L.log( m_myname + " getSOA()", Logger::Debug ) );
-
-               string stmt = getArg( "sql-lookupsoa" );
-               string& stmtref = strbind( ":name", escape( toLower( domain ), READ ), stmt );
-
-               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
-               if( !getRecord( READ ) ) { return false; }
-
-               do
-               {
-                       sd.serial = 0;
-                       sd.ttl = m_default_ttl;
-
-                       if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
-                       {
-                               fillSOAData( string( tmp, odbx_field_length( m_result, 3 ) ), sd );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
-                       {
-                               sd.ttl = strtoul( tmp, NULL, 10 );
-                       } 
-
-                       if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
-                       {
-                               sd.serial = strtol( tmp, NULL, 10 );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
-                       {
-                               sd.domain_id = strtol( tmp, NULL, 10 );
-                       }
-
-                       if( sd.nameserver.empty() )
-                       {
-                               sd.nameserver = arg()["default-soa-name"];
-                       }
-
-                       if( sd.hostmaster.empty() )
-                       {
-                               sd.hostmaster = "hostmaster." + domain;
-                       }
-
-                       sd.db = this;
-               }
-               while( getRecord( READ ) );
-       }
-       catch( exception& e )
-       {
-               L.log( m_myname + " getSOA: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+        const char* tmp;
+
+
+        try
+        {
+               DLOG( L.log( m_myname + " getSOA()", Logger::Debug ) );
+
+               string stmt = getArg( "sql-lookupsoa" );
+               string& stmtref = strbind( ":name", escape( toLower( domain ), READ ), stmt );
+
+               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
+               if( !getRecord( READ ) ) { return false; }
+
+               do
+               {
+                       sd.serial = 0;
+                       sd.ttl = m_default_ttl;
+
+                       if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
+                       {
+                               fillSOAData( string( tmp, odbx_field_length( m_result, 3 ) ), sd );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
+                       {
+                               sd.ttl = strtoul( tmp, NULL, 10 );
+                       } 
+
+                       if( sd.serial == 0 && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
+                       {
+                               sd.serial = strtol( tmp, NULL, 10 );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
+                       {
+                               sd.domain_id = strtol( tmp, NULL, 10 );
+                       }
+
+                       if( sd.nameserver.empty() )
+                       {
+                               sd.nameserver = arg()["default-soa-name"];
+                       }
+
+                       if( sd.hostmaster.empty() )
+                       {
+                               sd.hostmaster = "hostmaster." + domain;
+                       }
+
+                       sd.db = this;
+               }
+               while( getRecord( READ ) );
+        }
+        catch( exception& e )
+        {
+               L.log( m_myname + " getSOA: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
 
 
 
 bool OdbxBackend::list( const string& target, int zoneid )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " list()", Logger::Debug ) );
-
-               m_qname = "";
-               m_result = NULL;
-
-               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid );
-
-               if( len < 0 )
-               {
-                       L.log( m_myname + " list: Unable to convert zone id to string - format error",  Logger::Error );
-                       return false;
-               }
-
-               if( len > sizeof( m_buffer ) - 1 )
-               {
-                       L.log( m_myname + " list: Unable to convert zone id to string - insufficient buffer space",  Logger::Error );
-                       return false;
-               }
-
-               string stmt = getArg( "sql-list" );
-               string& stmtref = strbind( ":id", string( m_buffer, len ), stmt );
-
-               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
-       }
-       catch( exception& e )
-       {
-               L.log( m_myname + " list: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+        try
+        {
+               DLOG( L.log( m_myname + " list()", Logger::Debug ) );
+
+               m_qname = "";
+               m_result = NULL;
+
+               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid );
+
+               if( len < 0 )
+               {
+                       L.log( m_myname + " list: Unable to convert zone id to string - format error",  Logger::Error );
+                       return false;
+               }
+
+               if( len > sizeof( m_buffer ) - 1 )
+               {
+                       L.log( m_myname + " list: Unable to convert zone id to string - insufficient buffer space",  Logger::Error );
+                       return false;
+               }
+
+               string stmt = getArg( "sql-list" );
+               string& stmtref = strbind( ":id", string( m_buffer, len ), stmt );
+
+               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
+        }
+        catch( exception& e )
+        {
+               L.log( m_myname + " list: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
 
 
 
 void OdbxBackend::lookup( const QType& qtype, const string& qname, DNSPacket* dnspkt, int zoneid )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " lookup()", Logger::Debug ) );
-
-               string stmt;
-               string& stmtref = stmt;
-
-               m_result = NULL;
-               m_qname = qname;
-
-               if( zoneid < 0 )
-               {
-                       if( qtype.getCode() == QType::ANY )
-                       {
-                               stmt = getArg( "sql-lookup" );
-                       } else {
-                               stmt = getArg( "sql-lookuptype" );
-                               stmtref = strbind( ":type", qtype.getName(), stmt );
-                       }
-               }
-               else
-               {
-                       if( qtype.getCode() == QType::ANY )
-                       {
-                               stmt = getArg( "sql-lookupid" );
-                       } else {
-                               stmt = getArg( "sql-lookuptypeid" );
-                               stmtref = strbind( ":type", qtype.getName(), stmt );
-                       }
-
-                       size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid );
-
-                       if( len < 0 )
-                       {
-                               L.log( m_myname + " lookup: Unable to convert zone id to string - format error",  Logger::Error );
-                               throw( DBException( "Error: Libc error" ) );
-                       }
-
-                       if( len > sizeof( m_buffer ) - 1 )
-                       {
-                               L.log( m_myname + " lookup: Unable to convert zone id to string - insufficient buffer space",  Logger::Error );
-                               throw( DBException( "Error: Libc error" ) );
-               }
-
-                       stmtref = strbind( ":id", string( m_buffer, len ), stmtref );
-               }
-
-               string tmp = qname;
-               stmtref = strbind( ":name", escape( toLowerByRef( tmp ), READ ), stmtref );
-
-               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) )
-               {
-                       throw( DBException( "Error: DB statement failed" ) );
-               }
-       }
-       catch( exception& e )
-       {
-               L.log( m_myname + " lookup: Caught STL exception - " + e.what(),  Logger::Error );
-               throw( DBException( "Error: STL exception" ) );
-       }
+        try
+        {
+               DLOG( L.log( m_myname + " lookup()", Logger::Debug ) );
+
+               string stmt;
+               string& stmtref = stmt;
+
+               m_result = NULL;
+               m_qname = qname;
+
+               if( zoneid < 0 )
+               {
+                       if( qtype.getCode() == QType::ANY )
+                       {
+                               stmt = getArg( "sql-lookup" );
+                       } else {
+                               stmt = getArg( "sql-lookuptype" );
+                               stmtref = strbind( ":type", qtype.getName(), stmt );
+                       }
+               }
+               else
+               {
+                       if( qtype.getCode() == QType::ANY )
+                       {
+                               stmt = getArg( "sql-lookupid" );
+                       } else {
+                               stmt = getArg( "sql-lookuptypeid" );
+                               stmtref = strbind( ":type", qtype.getName(), stmt );
+                       }
+
+                       size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid );
+
+                       if( len < 0 )
+                       {
+                               L.log( m_myname + " lookup: Unable to convert zone id to string - format error",  Logger::Error );
+                               throw( DBException( "Error: Libc error" ) );
+                       }
+
+                       if( len > sizeof( m_buffer ) - 1 )
+                       {
+                               L.log( m_myname + " lookup: Unable to convert zone id to string - insufficient buffer space",  Logger::Error );
+                               throw( DBException( "Error: Libc error" ) );
+               }
+
+                       stmtref = strbind( ":id", string( m_buffer, len ), stmtref );
+               }
+
+               string tmp = qname;
+               stmtref = strbind( ":name", escape( toLowerByRef( tmp ), READ ), stmtref );
+
+               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) )
+               {
+                       throw( DBException( "Error: DB statement failed" ) );
+               }
+        }
+        catch( exception& e )
+        {
+               L.log( m_myname + " lookup: Caught STL exception - " + e.what(),  Logger::Error );
+               throw( DBException( "Error: STL exception" ) );
+        }
 }
 
 
 
 bool OdbxBackend::get( DNSResourceRecord& rr )
 {
-       const char* tmp;
-
-
-       try
-       {
-               DLOG( L.log( m_myname + " get()", Logger::Debug ) );
-
-               if( getRecord( READ ) )
-               {
-                       rr.content = "";
-                       rr.priority = 0;
-                       rr.domain_id = 0;
-                       rr.last_modified = 0;
-                       rr.ttl = m_default_ttl;
-                       rr.qname = m_qname;
-
-                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
-                       {
-                               rr.domain_id = strtol( tmp, NULL, 10 );
-                       }
-
-                       if( m_qname.empty() && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
-                       {
-                               rr.qname = string( tmp, odbx_field_length( m_result, 1 ) );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
-                       {
-                               rr.qtype = QType( tmp );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
-                       {
-                               rr.ttl = strtoul( tmp, NULL, 10 );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
-                       {
-                               rr.priority = (uint16_t) strtoul( tmp, NULL, 10 );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
-                       {
-                               rr.content = string( tmp, odbx_field_length( m_result, 5 ) );
-                       }
-
-                       return true;
-               }
-       }
-       catch( exception& e )
-       {
-               L.log( m_myname + " get: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return false;
+        const char* tmp;
+
+
+        try
+        {
+               DLOG( L.log( m_myname + " get()", Logger::Debug ) );
+
+               if( getRecord( READ ) )
+               {
+                       rr.content = "";
+                       rr.priority = 0;
+                       rr.domain_id = 0;
+                       rr.last_modified = 0;
+                       rr.ttl = m_default_ttl;
+                       rr.qname = m_qname;
+
+                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
+                       {
+                               rr.domain_id = strtol( tmp, NULL, 10 );
+                       }
+
+                       if( m_qname.empty() && ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
+                       {
+                               rr.qname = string( tmp, odbx_field_length( m_result, 1 ) );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
+                       {
+                               rr.qtype = QType( tmp );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
+                       {
+                               rr.ttl = strtoul( tmp, NULL, 10 );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
+                       {
+                               rr.priority = (uint16_t) strtoul( tmp, NULL, 10 );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
+                       {
+                               rr.content = string( tmp, odbx_field_length( m_result, 5 ) );
+                       }
+
+                       return true;
+               }
+        }
+        catch( exception& e )
+        {
+               L.log( m_myname + " get: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return false;
 }
 
 
 void OdbxBackend::setFresh( uint32_t domain_id )
 {
-       size_t len;
-
-
-       try
-       {
-               DLOG( L.log( m_myname + " setFresh()", Logger::Debug ) );
-
-               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
-               {
-                       L.log( m_myname + " setFresh: Master server is unreachable",  Logger::Error );
-                       throw( DBException( "Error: Server unreachable" ) );
-               }
-
-               len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-update-lastcheck" ).c_str(), time( 0 ), domain_id );
-
-               if( len < 0 )
-               {
-                       L.log( m_myname + " setFresh: Unable to insert values into statement '" + getArg( "sql-update-lastcheck" ) + "' - format error",  Logger::Error );
-                       throw( DBException( "Error: Libc error" ) );
-               }
-
-               if( len > sizeof( m_buffer ) - 1 )
-               {
-                       L.log( m_myname + " setFresh: Unable to insert values into statement '" + getArg( "sql-update-lastcheck" ) + "' - insufficient buffer space",  Logger::Error );
-                       throw( DBException( "Error: Libc error" ) );
-               }
-
-               if( !execStmt( m_buffer, len, WRITE ) )
-               {
-                       throw( DBException( "Error: DB statement failed" ) );
-               }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " setFresh: Caught STL exception - " + e.what(),  Logger::Error );
-               throw( DBException( "Error: STL exception" ) );
-       }
+        size_t len;
+
+
+        try
+        {
+               DLOG( L.log( m_myname + " setFresh()", Logger::Debug ) );
+
+               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
+               {
+                       L.log( m_myname + " setFresh: Master server is unreachable",  Logger::Error );
+                       throw( DBException( "Error: Server unreachable" ) );
+               }
+
+               len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-update-lastcheck" ).c_str(), time( 0 ), domain_id );
+
+               if( len < 0 )
+               {
+                       L.log( m_myname + " setFresh: Unable to insert values into statement '" + getArg( "sql-update-lastcheck" ) + "' - format error",  Logger::Error );
+                       throw( DBException( "Error: Libc error" ) );
+               }
+
+               if( len > sizeof( m_buffer ) - 1 )
+               {
+                       L.log( m_myname + " setFresh: Unable to insert values into statement '" + getArg( "sql-update-lastcheck" ) + "' - insufficient buffer space",  Logger::Error );
+                       throw( DBException( "Error: Libc error" ) );
+               }
+
+               if( !execStmt( m_buffer, len, WRITE ) )
+               {
+                       throw( DBException( "Error: DB statement failed" ) );
+               }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " setFresh: Caught STL exception - " + e.what(),  Logger::Error );
+               throw( DBException( "Error: STL exception" ) );
+        }
 }
 
 
 
 void OdbxBackend::setNotified( uint32_t domain_id, uint32_t serial )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " setNotified()", Logger::Debug ) );
-
-               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
-               {
-                       L.log( m_myname + " setFresh: Master server is unreachable",  Logger::Error );
-                       throw( DBException( "Error: Server unreachable" ) );
-               }
-
-               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-update-serial" ).c_str(), serial, domain_id );
-
-               if( len < 0 )
-               {
-                       L.log( m_myname + " setNotified: Unable to insert values into statement '" + getArg( "sql-update-serial" ) + "' - format error",  Logger::Error );
-                       throw( DBException( "Error: Libc error" ) );
-               }
-
-               if( len > sizeof( m_buffer ) - 1 )
-               {
-                       L.log( m_myname + " setNotified: Unable to insert values into statement '" + getArg( "sql-update-serial" ) + "' - insufficient buffer space",  Logger::Error );
-                       throw( DBException( "Error: Libc error" ) );
-               }
-
-               if( !execStmt( m_buffer, len, WRITE ) )
-               {
-                       throw( DBException( "Error: DB statement failed" ) );
-               }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " setNotified: Caught STL exception - " + e.what(),  Logger::Error );
-               throw( DBException( "Error: STL exception" ) );
-       }
+        try
+        {
+               DLOG( L.log( m_myname + " setNotified()", Logger::Debug ) );
+
+               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
+               {
+                       L.log( m_myname + " setFresh: Master server is unreachable",  Logger::Error );
+                       throw( DBException( "Error: Server unreachable" ) );
+               }
+
+               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-update-serial" ).c_str(), serial, domain_id );
+
+               if( len < 0 )
+               {
+                       L.log( m_myname + " setNotified: Unable to insert values into statement '" + getArg( "sql-update-serial" ) + "' - format error",  Logger::Error );
+                       throw( DBException( "Error: Libc error" ) );
+               }
+
+               if( len > sizeof( m_buffer ) - 1 )
+               {
+                       L.log( m_myname + " setNotified: Unable to insert values into statement '" + getArg( "sql-update-serial" ) + "' - insufficient buffer space",  Logger::Error );
+                       throw( DBException( "Error: Libc error" ) );
+               }
+
+               if( !execStmt( m_buffer, len, WRITE ) )
+               {
+                       throw( DBException( "Error: DB statement failed" ) );
+               }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " setNotified: Caught STL exception - " + e.what(),  Logger::Error );
+               throw( DBException( "Error: STL exception" ) );
+        }
 }
 
 
 
 bool OdbxBackend::isMaster( const string& domain, const string& ip )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " isMaster()", Logger::Debug ) );
-
-               string stmt = getArg( "sql-master" );
-               string& stmtref = strbind( ":name", escape( toLower( domain ), READ ), stmt );
-
-               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
-               if( !getRecord( READ ) ) { return false; }
-
-               do
-               {
-                       if( odbx_field_value( m_result, 0 ) != NULL )
-                       {
-                               if( !strcmp( odbx_field_value( m_result, 0 ), ip.c_str() ) )
-                               {
-                                       while( getRecord( READ ) );
-                                       return true;
-                               }
-                       }
-               }
-               while( getRecord( READ ) );
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " isMaster: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return false;
+        try
+        {
+               DLOG( L.log( m_myname + " isMaster()", Logger::Debug ) );
+
+               string stmt = getArg( "sql-master" );
+               string& stmtref = strbind( ":name", escape( toLower( domain ), READ ), stmt );
+
+               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
+               if( !getRecord( READ ) ) { return false; }
+
+               do
+               {
+                       if( odbx_field_value( m_result, 0 ) != NULL )
+                       {
+                               if( !strcmp( odbx_field_value( m_result, 0 ), ip.c_str() ) )
+                               {
+                                       while( getRecord( READ ) );
+                                       return true;
+                               }
+                       }
+               }
+               while( getRecord( READ ) );
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " isMaster: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return false;
 }
 
 
 
 void OdbxBackend::getUnfreshSlaveInfos( vector<DomainInfo>* unfresh )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " getUnfreshSlaveInfos()", Logger::Debug ) );
-
-               if( unfresh == NULL )
-               {
-                       L.log( m_myname + " getUnfreshSlaveInfos: invalid parameter - NULL pointer",  Logger::Error );
-                       return;
-               }
-
-               getDomainList( getArg( "sql-infoslaves" ), unfresh, &checkSlave );
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " getUnfreshSlaveInfo: Caught STL exception - " + e.what(),  Logger::Error );
-       }
+        try
+        {
+               DLOG( L.log( m_myname + " getUnfreshSlaveInfos()", Logger::Debug ) );
+
+               if( unfresh == NULL )
+               {
+                       L.log( m_myname + " getUnfreshSlaveInfos: invalid parameter - NULL pointer",  Logger::Error );
+                       return;
+               }
+
+               getDomainList( getArg( "sql-infoslaves" ), unfresh, &checkSlave );
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " getUnfreshSlaveInfo: Caught STL exception - " + e.what(),  Logger::Error );
+        }
 }
 
 
 
 void OdbxBackend::getUpdatedMasters( vector<DomainInfo>* updated )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " getUpdatedMasters()", Logger::Debug ) );
-
-               if( updated == NULL )
-               {
-                       L.log( m_myname + " getUpdatedMasters: invalid parameter - NULL pointer",  Logger::Error );
-                       return;
-               }
-
-               getDomainList( getArg( "sql-infomasters" ), updated, &checkMaster );
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " getUpdatedMasters: Caught STL exception - " + e.what(),  Logger::Error );
-       }
+        try
+        {
+               DLOG( L.log( m_myname + " getUpdatedMasters()", Logger::Debug ) );
+
+               if( updated == NULL )
+               {
+                       L.log( m_myname + " getUpdatedMasters: invalid parameter - NULL pointer",  Logger::Error );
+                       return;
+               }
+
+               getDomainList( getArg( "sql-infomasters" ), updated, &checkMaster );
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " getUpdatedMasters: Caught STL exception - " + e.what(),  Logger::Error );
+        }
 }
 
 
 
 bool OdbxBackend::superMasterBackend( const string& ip, const string& domain, const vector<DNSResourceRecord>& set, string* account, DNSBackend** ddb )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " superMasterBackend()", Logger::Debug ) );
-
-               if( account != NULL && ddb != NULL )
-               {
-                       vector<DNSResourceRecord>::const_iterator i;
-
-                       for( i = set.begin(); i != set.end(); i++ )
-                       {
-                               string stmt = getArg( "sql-supermaster" );
-                               string& stmtref = strbind( ":ip", escape( ip, READ ), stmt );
-                               stmtref = strbind( ":ns", escape( i->content, READ ), stmtref );
-
-                               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
-
-                               if( getRecord( READ ) )
-                               {
-                                       if( odbx_field_value( m_result, 0 ) != NULL )
-                                       {
-                                               *account = string( odbx_field_value( m_result, 0 ), odbx_field_length( m_result, 0 ) );
-                                       }
-
-                                       while( getRecord( READ ) );
-
-                               *ddb=this;
-                               return true;
-                       }
-               }
-       }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " superMasterBackend: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return false;
+        try
+        {
+               DLOG( L.log( m_myname + " superMasterBackend()", Logger::Debug ) );
+
+               if( account != NULL && ddb != NULL )
+               {
+                       vector<DNSResourceRecord>::const_iterator i;
+
+                       for( i = set.begin(); i != set.end(); i++ )
+                       {
+                               string stmt = getArg( "sql-supermaster" );
+                               string& stmtref = strbind( ":ip", escape( ip, READ ), stmt );
+                               stmtref = strbind( ":ns", escape( i->content, READ ), stmtref );
+
+                               if( !execStmt( stmtref.c_str(), stmtref.size(), READ ) ) { return false; }
+
+                               if( getRecord( READ ) )
+                               {
+                                       if( odbx_field_value( m_result, 0 ) != NULL )
+                                       {
+                                               *account = string( odbx_field_value( m_result, 0 ), odbx_field_length( m_result, 0 ) );
+                                       }
+
+                                       while( getRecord( READ ) );
+
+                               *ddb=this;
+                               return true;
+                       }
+               }
+        }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " superMasterBackend: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return false;
 }
 
 
 
 bool OdbxBackend::createSlaveDomain( const string& ip, const string& domain, const string& account )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " createSlaveDomain()", Logger::Debug ) );
-
-               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
-               {
-                       L.log( m_myname + " createSlaveDomain: Master server is unreachable",  Logger::Error );
-                       return false;
-               }
-
-               string tmp = domain;
-               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-insert-slave" ).c_str(), escape( toLowerByRef( tmp ), WRITE ).c_str(),
-                       escape( ip, WRITE ).c_str(), escape( account, WRITE ).c_str() );
-
-               if( len < 0 )
-               {
-                       L.log( m_myname + " createSlaveDomain: Unable to insert values in statement '" + getArg( "sql-insert-slave" ) + "' - format error",  Logger::Error );
-                       return false;
-               }
-
-               if( len > sizeof( m_buffer ) - 1 )
-               {
-                       L.log( m_myname + " createSlaveDomain: Unable to insert values in statement '" + getArg( "sql-insert-slave" ) + "' - insufficient buffer space",  Logger::Error );
-                       return false;
-               }
-
-               if( !execStmt( m_buffer, len, WRITE ) ) { return false; }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " createSlaveDomain: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+        try
+        {
+               DLOG( L.log( m_myname + " createSlaveDomain()", Logger::Debug ) );
+
+               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
+               {
+                       L.log( m_myname + " createSlaveDomain: Master server is unreachable",  Logger::Error );
+                       return false;
+               }
+
+               string tmp = domain;
+               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-insert-slave" ).c_str(), escape( toLowerByRef( tmp ), WRITE ).c_str(),
+                       escape( ip, WRITE ).c_str(), escape( account, WRITE ).c_str() );
+
+               if( len < 0 )
+               {
+                       L.log( m_myname + " createSlaveDomain: Unable to insert values in statement '" + getArg( "sql-insert-slave" ) + "' - format error",  Logger::Error );
+                       return false;
+               }
+
+               if( len > sizeof( m_buffer ) - 1 )
+               {
+                       L.log( m_myname + " createSlaveDomain: Unable to insert values in statement '" + getArg( "sql-insert-slave" ) + "' - insufficient buffer space",  Logger::Error );
+                       return false;
+               }
+
+               if( !execStmt( m_buffer, len, WRITE ) ) { return false; }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " createSlaveDomain: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
 
 
 
 bool OdbxBackend::feedRecord( const DNSResourceRecord& rr )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " feedRecord()", Logger::Debug ) );
-
-               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
-               {
-                       L.log( m_myname + " feedRecord: Master server is unreachable",  Logger::Error );
-                       return false;
-               }
-
-               string tmp = rr.qname;
-               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-insert-record" ).c_str(), rr.domain_id,
-                       escape( toLowerByRef( tmp ), WRITE ).c_str(), rr.qtype.getName().c_str(), rr.ttl, rr.priority,
-                       escape( rr.content, WRITE ).c_str() );
-
-               if( len < 0 )
-               {
-                       L.log( m_myname + " feedRecord: Unable to insert values in statement '" + getArg( "sql-insert-record" ) + "' - format error",  Logger::Error );
-                       return false;
-               }
-
-               if( len > sizeof( m_buffer ) - 1 )
-               {
-                       L.log( m_myname + " feedRecord: Unable to insert values in statement '" + getArg( "sql-insert-record" ) + "' - insufficient buffer space",  Logger::Error );
-                       return false;
-               }
-
-               if( !execStmt( m_buffer, len, WRITE ) ) { return false; }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " feedRecord: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+        try
+        {
+               DLOG( L.log( m_myname + " feedRecord()", Logger::Debug ) );
+
+               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
+               {
+                       L.log( m_myname + " feedRecord: Master server is unreachable",  Logger::Error );
+                       return false;
+               }
+
+               string tmp = rr.qname;
+               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, getArg( "sql-insert-record" ).c_str(), rr.domain_id,
+                       escape( toLowerByRef( tmp ), WRITE ).c_str(), rr.qtype.getName().c_str(), rr.ttl, rr.priority,
+                       escape( rr.content, WRITE ).c_str() );
+
+               if( len < 0 )
+               {
+                       L.log( m_myname + " feedRecord: Unable to insert values in statement '" + getArg( "sql-insert-record" ) + "' - format error",  Logger::Error );
+                       return false;
+               }
+
+               if( len > sizeof( m_buffer ) - 1 )
+               {
+                       L.log( m_myname + " feedRecord: Unable to insert values in statement '" + getArg( "sql-insert-record" ) + "' - insufficient buffer space",  Logger::Error );
+                       return false;
+               }
+
+               if( !execStmt( m_buffer, len, WRITE ) ) { return false; }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " feedRecord: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
 
 
 
 bool OdbxBackend::startTransaction( const string& domain, int zoneid )
 {
-       try
-       {
-               DLOG( L.log( m_myname + " startTransaction()", Logger::Debug ) );
+        try
+        {
+               DLOG( L.log( m_myname + " startTransaction()", Logger::Debug ) );
 
-               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
-               {
-                       L.log( m_myname + " startTransaction: Master server is unreachable",  Logger::Error );
-                       return false;
-               }
+               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
+               {
+                       L.log( m_myname + " startTransaction: Master server is unreachable",  Logger::Error );
+                       return false;
+               }
 
                string stmtref =  getArg( "sql-transactbegin" );
                if( !execStmt( stmtref.c_str(), stmtref.size(), WRITE ) ) { return false; }
-
-               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid );
-
-               if( len < 0 )
-               {
-                       L.log( m_myname + " startTransaction: Unable to convert zone id to string - format error",  Logger::Error );
-                       return false;
-               }
-
-               if( len > sizeof( m_buffer ) - 1 )
-               {
-                       L.log( m_myname + " startTransaction: Unable to convert zone id to string - insufficient buffer space",  Logger::Error );
-                       return false;
-               }
-
-               string stmt = getArg( "sql-zonedelete" );
-               stmtref = strbind( ":id", string( m_buffer, len ), stmt );
-               if( !execStmt( stmtref.c_str(), stmtref.size(), WRITE ) ) { return false; }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " startTransaction: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+               size_t len = snprintf( m_buffer, sizeof( m_buffer ) - 1, "%d", zoneid );
+
+               if( len < 0 )
+               {
+                       L.log( m_myname + " startTransaction: Unable to convert zone id to string - format error",  Logger::Error );
+                       return false;
+               }
+
+               if( len > sizeof( m_buffer ) - 1 )
+               {
+                       L.log( m_myname + " startTransaction: Unable to convert zone id to string - insufficient buffer space",  Logger::Error );
+                       return false;
+               }
+
+               string stmt = getArg( "sql-zonedelete" );
+               stmtref = strbind( ":id", string( m_buffer, len ), stmt );
+               if( !execStmt( stmtref.c_str(), stmtref.size(), WRITE ) ) { return false; }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " startTransaction: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
 
 
 
 bool OdbxBackend::commitTransaction()
 {
-       try
-       {
-               DLOG( L.log( m_myname + " commitTransaction()", Logger::Debug ) );
-
-               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
-               {
-                       L.log( m_myname + " commitTransaction: Master server is unreachable",  Logger::Error );
-                       return false;
-               }
-
-               const string& stmt = getArg( "sql-transactend" );
-               if( !execStmt( stmt.c_str(), stmt.size(), WRITE ) ) { return false; }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " commitTransaction: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+        try
+        {
+               DLOG( L.log( m_myname + " commitTransaction()", Logger::Debug ) );
+
+               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
+               {
+                       L.log( m_myname + " commitTransaction: Master server is unreachable",  Logger::Error );
+                       return false;
+               }
+
+               const string& stmt = getArg( "sql-transactend" );
+               if( !execStmt( stmt.c_str(), stmt.size(), WRITE ) ) { return false; }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " commitTransaction: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
 
 
 
 bool OdbxBackend::abortTransaction()
 {
-       try
-       {
-               DLOG( L.log( m_myname + " abortTransaction()", Logger::Debug ) );
-
-               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
-               {
-                       L.log( m_myname + " abortTransaction: Master server is unreachable",  Logger::Error );
-                       return false;
-               }
-
-               const string& stmt = getArg( "sql-transactabort" );
-               if( !execStmt( stmt.c_str(), stmt.size(), WRITE ) ) { return false; }
-       }
-       catch ( exception& e )
-       {
-               L.log( m_myname + " abortTransaction: Caught STL exception - " + e.what(),  Logger::Error );
-               return false;
-       }
-
-       return true;
+        try
+        {
+               DLOG( L.log( m_myname + " abortTransaction()", Logger::Debug ) );
+
+               if( !m_handle[WRITE] && !connectTo( m_hosts[WRITE], WRITE ) )
+               {
+                       L.log( m_myname + " abortTransaction: Master server is unreachable",  Logger::Error );
+                       return false;
+               }
+
+               const string& stmt = getArg( "sql-transactabort" );
+               if( !execStmt( stmt.c_str(), stmt.size(), WRITE ) ) { return false; }
+        }
+        catch ( exception& e )
+        {
+               L.log( m_myname + " abortTransaction: Caught STL exception - " + e.what(),  Logger::Error );
+               return false;
+        }
+
+        return true;
 }
index 032a994baf967031b734ab772e1c8bce4a520b58..8d63af840059da6a571b41cfec4359c31bd9ac98 100644 (file)
@@ -51,50 +51,50 @@ bool checkMaster( uint32_t last, uint32_t notified, SOAData* sd, DomainInfo* di
 
 class OdbxBackend : public DNSBackend
 {
-       enum QueryType { READ, WRITE };
+        enum QueryType { READ, WRITE };
 
-       string m_myname;
-       string m_qname;
-       int m_default_ttl;
-       bool m_qlog;
-       odbx_t* m_handle[2];
-       odbx_result_t* m_result;
-       char m_escbuf[BUFLEN];
-       char m_buffer[2*BUFLEN];
-       vector<string> m_hosts[2];
+        string m_myname;
+        string m_qname;
+        int m_default_ttl;
+        bool m_qlog;
+        odbx_t* m_handle[2];
+        odbx_result_t* m_result;
+        char m_escbuf[BUFLEN];
+        char m_buffer[2*BUFLEN];
+        vector<string> m_hosts[2];
 
-       string escape( const string& str, QueryType type );
-       bool connectTo( const vector<string>& host, QueryType type );
-       bool getDomainList( const string& query, vector<DomainInfo>* list, bool (*check_fcn)(uint32_t,uint32_t,SOAData*,DomainInfo*) );
-       bool execStmt( const char* stmt, unsigned long length, QueryType type );
-       bool getRecord( QueryType type );
+        string escape( const string& str, QueryType type );
+        bool connectTo( const vector<string>& host, QueryType type );
+        bool getDomainList( const string& query, vector<DomainInfo>* list, bool (*check_fcn)(uint32_t,uint32_t,SOAData*,DomainInfo*) );
+        bool execStmt( const char* stmt, unsigned long length, QueryType type );
+        bool getRecord( QueryType type );
 
 
 public:
 
-       OdbxBackend( const string& suffix="" );
-       ~OdbxBackend();
+        OdbxBackend( const string& suffix="" );
+        ~OdbxBackend();
 
-       void lookup( const QType& qtype, const string& qdomain, DNSPacket* p = 0, int zoneid = -1 );
-       bool getSOA( const string& domain, SOAData& sd, DNSPacket* p );
-       bool list( const string& target, int domain_id );
-       bool get( DNSResourceRecord& rr );
+        void lookup( const QType& qtype, const string& qdomain, DNSPacket* p = 0, int zoneid = -1 );
+        bool getSOA( const string& domain, SOAData& sd, DNSPacket* p );
+        bool list( const string& target, int domain_id );
+        bool get( DNSResourceRecord& rr );
 
-       bool startTransaction( const string& domain, int domain_id );
-       bool commitTransaction();
-       bool abortTransaction();
+        bool startTransaction( const string& domain, int domain_id );
+        bool commitTransaction();
+        bool abortTransaction();
 
-       bool isMaster( const string& domain, const string& ip );
-       bool getDomainInfo( const string& domain, DomainInfo& di );
-       bool feedRecord( const DNSResourceRecord& rr );
-       bool createSlaveDomain( const string& ip, const string& domain, const string& account );
-       bool superMasterBackend( const string& ip, const string& domain, const vector<DNSResourceRecord>& nsset, string* account, DNSBackend** ddb );
+        bool isMaster( const string& domain, const string& ip );
+        bool getDomainInfo( const string& domain, DomainInfo& di );
+        bool feedRecord( const DNSResourceRecord& rr );
+        bool createSlaveDomain( const string& ip, const string& domain, const string& account );
+        bool superMasterBackend( const string& ip, const string& domain, const vector<DNSResourceRecord>& nsset, string* account, DNSBackend** ddb );
 
-       void getUpdatedMasters( vector<DomainInfo>* updated );
-       void getUnfreshSlaveInfos( vector<DomainInfo>* unfresh );
+        void getUpdatedMasters( vector<DomainInfo>* updated );
+        void getUnfreshSlaveInfos( vector<DomainInfo>* unfresh );
 
-       void setFresh( uint32_t domain_id );
-       void setNotified( uint32_t domain_id, uint32_t serial );
+        void setFresh( uint32_t domain_id );
+        void setNotified( uint32_t domain_id, uint32_t serial );
 };
 
 
@@ -104,68 +104,68 @@ class OdbxFactory : public BackendFactory
 
 public:
 
-       OdbxFactory() : BackendFactory( "opendbx" ) {}
+        OdbxFactory() : BackendFactory( "opendbx" ) {}
 
 
-       void declareArguments( const string &suffix="" )
-       {
-               declare( suffix, "backend", "OpenDBX backend","mysql" );
-               declare( suffix, "host-read", "Name or address of one or more DBMS server to read from","127.0.0.1" );
-               declare( suffix, "host-write", "Name or address of one or more DBMS server used for updates","127.0.0.1" );
-               declare( suffix, "port", "Port the DBMS server are listening to","" );
-               declare( suffix, "database", "Database name containing the DNS records","powerdns" );
-               declare( suffix, "username","User for connecting to the DBMS","powerdns");
-               declare( suffix, "password","Password for connecting to the DBMS","");
+        void declareArguments( const string &suffix="" )
+        {
+               declare( suffix, "backend", "OpenDBX backend","mysql" );
+               declare( suffix, "host-read", "Name or address of one or more DBMS server to read from","127.0.0.1" );
+               declare( suffix, "host-write", "Name or address of one or more DBMS server used for updates","127.0.0.1" );
+               declare( suffix, "port", "Port the DBMS server are listening to","" );
+               declare( suffix, "database", "Database name containing the DNS records","powerdns" );
+               declare( suffix, "username","User for connecting to the DBMS","powerdns");
+               declare( suffix, "password","Password for connecting to the DBMS","");
 
-               declare( suffix, "sql-list", "AXFR query", "SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id" );
+               declare( suffix, "sql-list", "AXFR query", "SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id" );
 
-               declare( suffix, "sql-lookup", "Lookup query","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"name\"=':name'" );
-               declare( suffix, "sql-lookupid", "Lookup query with id","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id AND r.\"name\"=':name'" );
-               declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"name\"=':name' AND r.\"type\"=':type'" );
-               declare( suffix, "sql-lookuptypeid", "Lookup query with type and id","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id AND r.\"name\"=':name' AND r.\"type\"=':type'" );
-               declare( suffix, "sql-lookupsoa","Lookup query for SOA record","SELECT d.\"id\", d.\"auto_serial\", r.\"ttl\", r.\"content\" FROM \"records\" r JOIN \"domains\" d ON r.\"domain_id\"=d.\"id\" WHERE r.\"name\"=':name' AND r.\"type\"='SOA' AND d.\"status\"='A'" );
+               declare( suffix, "sql-lookup", "Lookup query","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"name\"=':name'" );
+               declare( suffix, "sql-lookupid", "Lookup query with id","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id AND r.\"name\"=':name'" );
+               declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"name\"=':name' AND r.\"type\"=':type'" );
+               declare( suffix, "sql-lookuptypeid", "Lookup query with type and id","SELECT r.\"domain_id\", r.\"name\", r.\"type\", r.\"ttl\", r.\"prio\", r.\"content\" FROM \"records\" r WHERE r.\"domain_id\"=:id AND r.\"name\"=':name' AND r.\"type\"=':type'" );
+               declare( suffix, "sql-lookupsoa","Lookup query for SOA record","SELECT d.\"id\", d.\"auto_serial\", r.\"ttl\", r.\"content\" FROM \"records\" r JOIN \"domains\" d ON r.\"domain_id\"=d.\"id\" WHERE r.\"name\"=':name' AND r.\"type\"='SOA' AND d.\"status\"='A'" );
 
-               declare( suffix, "sql-zonedelete","Delete all records for this zone","DELETE FROM \"records\" WHERE \"domain_id\"=:id" );
-               declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.\"id\", d.\"name\", d.\"type\", d.\"master\", d.\"last_check\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"name\"=':name' AND d.\"status\"='A'" );
+               declare( suffix, "sql-zonedelete","Delete all records for this zone","DELETE FROM \"records\" WHERE \"domain_id\"=:id" );
+               declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.\"id\", d.\"name\", d.\"type\", d.\"master\", d.\"last_check\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"name\"=':name' AND d.\"status\"='A'" );
 
-               declare( suffix, "sql-transactbegin", "Start transaction", "BEGIN" );
-               declare( suffix, "sql-transactend", "Finish transaction", "COMMIT" );
-               declare( suffix, "sql-transactabort", "Abort transaction", "ROLLBACK" );
+               declare( suffix, "sql-transactbegin", "Start transaction", "BEGIN" );
+               declare( suffix, "sql-transactend", "Finish transaction", "COMMIT" );
+               declare( suffix, "sql-transactabort", "Abort transaction", "ROLLBACK" );
 
-               declare( suffix, "sql-insert-slave","Add slave domain", "INSERT INTO \"domains\" ( \"name\", \"type\", \"master\", \"account\" ) VALUES ( '%s', 'SLAVE', '%s', '%s' )" );
-               declare( suffix, "sql-insert-record","Feed record into table", "INSERT INTO \"records\" ( \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" ) VALUES ( %d, '%s', '%s', %d, %d, '%s' )" );
+               declare( suffix, "sql-insert-slave","Add slave domain", "INSERT INTO \"domains\" ( \"name\", \"type\", \"master\", \"account\" ) VALUES ( '%s', 'SLAVE', '%s', '%s' )" );
+               declare( suffix, "sql-insert-record","Feed record into table", "INSERT INTO \"records\" ( \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" ) VALUES ( %d, '%s', '%s', %d, %d, '%s' )" );
 
-               declare( suffix, "sql-update-serial", "Set zone to notified", "UPDATE \"domains\" SET \"notified_serial\"=%d WHERE \"id\"=%d" );
-               declare( suffix, "sql-update-lastcheck", "Set time of last check", "UPDATE \"domains\" SET \"last_check\"=%d WHERE \"id\"=%d" );
+               declare( suffix, "sql-update-serial", "Set zone to notified", "UPDATE \"domains\" SET \"notified_serial\"=%d WHERE \"id\"=%d" );
+               declare( suffix, "sql-update-lastcheck", "Set time of last check", "UPDATE \"domains\" SET \"last_check\"=%d WHERE \"id\"=%d" );
 
-               declare( suffix, "sql-master", "Get master record for zone", "SELECT d.\"master\" FROM \"domains\" d WHERE d.\"name\"=':name' AND d.\"status\"='A' AND d.\"type\"='SLAVE'" );
-               declare( suffix, "sql-supermaster","Get supermaster info", "SELECT s.\"account\" FROM \"supermasters\" s WHERE s.\"ip\"=':ip' AND s.\"nameserver\"=':ns'" );
+               declare( suffix, "sql-master", "Get master record for zone", "SELECT d.\"master\" FROM \"domains\" d WHERE d.\"name\"=':name' AND d.\"status\"='A' AND d.\"type\"='SLAVE'" );
+               declare( suffix, "sql-supermaster","Get supermaster info", "SELECT s.\"account\" FROM \"supermasters\" s WHERE s.\"ip\"=':ip' AND s.\"nameserver\"=':ns'" );
 
-               declare( suffix, "sql-infoslaves", "Get all unfresh slaves", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"last_check\", d.\"notified_serial\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='SLAVE'" );
-               declare( suffix, "sql-infomasters", "Get all updated masters", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"last_check\", d.\"notified_serial\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='MASTER'" );
+               declare( suffix, "sql-infoslaves", "Get all unfresh slaves", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"last_check\", d.\"notified_serial\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='SLAVE'" );
+               declare( suffix, "sql-infomasters", "Get all updated masters", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"last_check\", d.\"notified_serial\", d.\"auto_serial\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='MASTER'" );
 
-               declare( suffix, "host", "depricated, use host-read and host-write instead","" );
-       }
+               declare( suffix, "host", "depricated, use host-read and host-write instead","" );
+        }
 
 
-       DNSBackend* make( const string &suffix="" )
-       {
-               return new OdbxBackend( suffix );
-       }
+        DNSBackend* make( const string &suffix="" )
+        {
+               return new OdbxBackend( suffix );
+        }
 };
 
 
 class OdbxLoader
 {
-       OdbxFactory factory;
+        OdbxFactory factory;
 
 public:
 
-       OdbxLoader()
-       {
-               BackendMakers().report( &factory );
-               L.log( " [OpendbxBackend] This is the opendbx module version "VERSION" ("__DATE__", "__TIME__") reporting", Logger::Info );
-       }
+        OdbxLoader()
+        {
+               BackendMakers().report( &factory );
+               L.log( " [OpendbxBackend] This is the opendbx module version "VERSION" ("__DATE__", "__TIME__") reporting", Logger::Info );
+        }
 };
 
 
index c08305897de7821c2a21ee04ee104bad5422997b..998580c12d10d2c38f76be5d4b56f6bfc35ee592 100644 (file)
@@ -8,253 +8,253 @@ unsigned int odbx_host_index[2] = { 0, 0 };
 
 bool OdbxBackend::connectTo( const vector<string>& hosts, QueryType type )
 {
-       int err;
-       unsigned int h, i;
-       int idx = odbx_host_index[type]++ % hosts.size();
-
-
-       if( m_handle[type] != NULL )
-       {
-               odbx_unbind( m_handle[type] );
-               odbx_finish( m_handle[type] );
-               m_handle[type] = NULL;
-       }
-
-       if( type == WRITE && getArg( "backend" ) == "sqlite" )
-       {
-               L.log( m_myname + " Using same SQLite connection for reading and writeing to '" + hosts[odbx_host_index[READ]] + "'", Logger::Notice );
-               m_handle[WRITE] = m_handle[READ];
-               return true;
-       }
-
-       for( i = 0; i < hosts.size(); i++ )
-       {
-               h = ( idx + i ) % hosts.size();
-
-               if( ( err = odbx_init( &(m_handle[type]), getArg( "backend" ).c_str(), hosts[h].c_str(), getArg( "port" ).c_str() ) ) == ODBX_ERR_SUCCESS )
-               {
-                       if( ( err = odbx_bind( m_handle[type], getArg( "database" ).c_str(), getArg( "username" ).c_str(), getArg( "password" ).c_str(), ODBX_BIND_SIMPLE ) ) == ODBX_ERR_SUCCESS )
-                       {
-                               L.log( m_myname + " Database connection (" + (type ? "write" : "read") + ") to '" + hosts[h] + "' succeeded", Logger::Notice );
-                               return true;
-                       }
-
-                       L.log( m_myname + " Unable to bind to database on host " + hosts[h] + " - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
-                       continue;
-               }
-
-               L.log( m_myname + " Unable to connect to server on host " + hosts[h] + " - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
-       }
-
-       m_handle[type] = NULL;
-       return false;
+        int err;
+        unsigned int h, i;
+        int idx = odbx_host_index[type]++ % hosts.size();
+
+
+        if( m_handle[type] != NULL )
+        {
+               odbx_unbind( m_handle[type] );
+               odbx_finish( m_handle[type] );
+               m_handle[type] = NULL;
+        }
+
+        if( type == WRITE && getArg( "backend" ) == "sqlite" )
+        {
+               L.log( m_myname + " Using same SQLite connection for reading and writeing to '" + hosts[odbx_host_index[READ]] + "'", Logger::Notice );
+               m_handle[WRITE] = m_handle[READ];
+               return true;
+        }
+
+        for( i = 0; i < hosts.size(); i++ )
+        {
+               h = ( idx + i ) % hosts.size();
+
+               if( ( err = odbx_init( &(m_handle[type]), getArg( "backend" ).c_str(), hosts[h].c_str(), getArg( "port" ).c_str() ) ) == ODBX_ERR_SUCCESS )
+               {
+                       if( ( err = odbx_bind( m_handle[type], getArg( "database" ).c_str(), getArg( "username" ).c_str(), getArg( "password" ).c_str(), ODBX_BIND_SIMPLE ) ) == ODBX_ERR_SUCCESS )
+                       {
+                               L.log( m_myname + " Database connection (" + (type ? "write" : "read") + ") to '" + hosts[h] + "' succeeded", Logger::Notice );
+                               return true;
+                       }
+
+                       L.log( m_myname + " Unable to bind to database on host " + hosts[h] + " - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
+                       continue;
+               }
+
+               L.log( m_myname + " Unable to connect to server on host " + hosts[h] + " - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
+        }
+
+        m_handle[type] = NULL;
+        return false;
 }
 
 
 
 bool OdbxBackend::execStmt( const char* stmt, unsigned long length, QueryType type )
 {
-       int err;
+        int err;
 
 
-       DLOG( L.log( m_myname + " execStmt()", Logger::Debug ) );
+        DLOG( L.log( m_myname + " execStmt()", Logger::Debug ) );
 
-       if( m_qlog ) { L.log( m_myname + " Query: " + stmt, Logger::Info ); }
+        if( m_qlog ) { L.log( m_myname + " Query: " + stmt, Logger::Info ); }
 
-       if( ( err = odbx_query( m_handle[type], stmt, length ) ) < 0 )
-       {
-               L.log( m_myname + " execStmt: Unable to execute query - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
+        if( ( err = odbx_query( m_handle[type], stmt, length ) ) < 0 )
+        {
+               L.log( m_myname + " execStmt: Unable to execute query - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
 
-               if( err != -ODBX_ERR_PARAM && odbx_error_type( m_handle[type], err ) > 0 ) { return false; }   // ODBX_ERR_PARAM workaround
-               if( !connectTo( m_hosts[type], type ) ) { return false; }
-               if( odbx_query( m_handle[type], stmt, length ) < 0 ) { return false; }
-       }
+               if( err != -ODBX_ERR_PARAM && odbx_error_type( m_handle[type], err ) > 0 ) { return false; }   // ODBX_ERR_PARAM workaround
+               if( !connectTo( m_hosts[type], type ) ) { return false; }
+               if( odbx_query( m_handle[type], stmt, length ) < 0 ) { return false; }
+        }
 
-       if( type == WRITE ) { while( getRecord( type ) ); }
+        if( type == WRITE ) { while( getRecord( type ) ); }
 
-       return true;
+        return true;
 }
 
 
 
 bool OdbxBackend::getRecord( QueryType type )
 {
-       int err = 3;
-
-
-       DLOG( L.log( m_myname + " getRecord()", Logger::Debug ) );
-
-       do
-       {
-               if( err < 0 )
-               {
-                       L.log( m_myname + " getRecord: Unable to get next result - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
-                       throw( AhuException( "Error: odbx_result() failed" ) );
-               }
-
-               if( m_result != NULL )
-               {
-                       if( err == 3 )
-                       {
-                               if( ( err = odbx_row_fetch( m_result ) ) < 0 )
-                               {
-                                       L.log( m_myname + " getRecord: Unable to get next row - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
-                                       throw( AhuException( "Error: odbx_row_fetch() failed" ) );
-                               }
-
-                               if( err > 0 )
-                               {
+        int err = 3;
+
+
+        DLOG( L.log( m_myname + " getRecord()", Logger::Debug ) );
+
+        do
+        {
+               if( err < 0 )
+               {
+                       L.log( m_myname + " getRecord: Unable to get next result - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
+                       throw( AhuException( "Error: odbx_result() failed" ) );
+               }
+
+               if( m_result != NULL )
+               {
+                       if( err == 3 )
+                       {
+                               if( ( err = odbx_row_fetch( m_result ) ) < 0 )
+                               {
+                                       L.log( m_myname + " getRecord: Unable to get next row - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
+                                       throw( AhuException( "Error: odbx_row_fetch() failed" ) );
+                               }
+
+                               if( err > 0 )
+                               {
 #ifdef VERBOSELOG
-                                       unsigned int i;
-                                       string fields;
-
-                                       for( i = 0; i < odbx_column_count( m_result ); i++ )
-                                       {
-                                               fields += string( odbx_column_name( m_result, i ) );
-
-                                               if( odbx_field_value( m_result, i ) != NULL )
-                                               {
-                                                       fields += "=" + string( odbx_field_value( m_result, i ) ) + ", ";
-                                               }
-                                               else
-                                               {
-                                                       fields += "=NULL, ";
-                                               }
-                                       }
-
-                                       L.log( m_myname + " Values: " + fields,  Logger::Error );
+                                       unsigned int i;
+                                       string fields;
+
+                                       for( i = 0; i < odbx_column_count( m_result ); i++ )
+                                       {
+                                               fields += string( odbx_column_name( m_result, i ) );
+
+                                               if( odbx_field_value( m_result, i ) != NULL )
+                                               {
+                                                       fields += "=" + string( odbx_field_value( m_result, i ) ) + ", ";
+                                               }
+                                               else
+                                               {
+                                                       fields += "=NULL, ";
+                                               }
+                                       }
+
+                                       L.log( m_myname + " Values: " + fields,  Logger::Error );
 #endif
-                                       return true;
-                               }
+                                       return true;
+                               }
 
-                       }
+                       }
 
-                       odbx_result_free( m_result );
-                       m_result = NULL;
-               }
-       }
-       while( ( err =  odbx_result( m_handle[type], &m_result, NULL, 0 ) ) != 0 );
+                       odbx_result_free( m_result );
+                       m_result = NULL;
+               }
+        }
+        while( ( err =  odbx_result( m_handle[type], &m_result, NULL, 0 ) ) != 0 );
 
-       m_result = NULL;
-       return false;
+        m_result = NULL;
+        return false;
 }
 
 
 
 string OdbxBackend::escape( const string& str, QueryType type )
 {
-       int err;
-       unsigned long len = sizeof( m_escbuf );
+        int err;
+        unsigned long len = sizeof( m_escbuf );
 
 
-       DLOG( L.log( m_myname + " escape(string)", Logger::Debug ) );
+        DLOG( L.log( m_myname + " escape(string)", Logger::Debug ) );
 
-       if( ( err = odbx_escape( m_handle[type], str.c_str(), str.size(), m_escbuf, &len ) ) < 0 )
-       {
-               L.log( m_myname + " escape(string): Unable to escape string - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
+        if( ( err = odbx_escape( m_handle[type], str.c_str(), str.size(), m_escbuf, &len ) ) < 0 )
+        {
+               L.log( m_myname + " escape(string): Unable to escape string - " + string( odbx_error( m_handle[type], err ) ),  Logger::Error );
 
-               if( err != -ODBX_ERR_PARAM && odbx_error_type( m_handle[type], err ) > 0 ) { throw( runtime_error( "odbx_escape() failed" ) ); }   // ODBX_ERR_PARAM workaround
-               if( !connectTo( m_hosts[type], type ) ) { throw( runtime_error( "odbx_escape() failed" ) ); }
-               if( odbx_escape( m_handle[type], str.c_str(), str.size(), m_escbuf, &len ) < 0 ) { throw( runtime_error( "odbx_escape() failed" ) ); }
-       }
+               if( err != -ODBX_ERR_PARAM && odbx_error_type( m_handle[type], err ) > 0 ) { throw( runtime_error( "odbx_escape() failed" ) ); }   // ODBX_ERR_PARAM workaround
+               if( !connectTo( m_hosts[type], type ) ) { throw( runtime_error( "odbx_escape() failed" ) ); }
+               if( odbx_escape( m_handle[type], str.c_str(), str.size(), m_escbuf, &len ) < 0 ) { throw( runtime_error( "odbx_escape() failed" ) ); }
+        }
 
-       return string( m_escbuf, len );
+        return string( m_escbuf, len );
 }
 
 
 
 bool OdbxBackend::getDomainList( const string& stmt, vector<DomainInfo>* list, bool (*check_fcn)(uint32_t,uint32_t,SOAData*,DomainInfo*) )
 {
-       const char* tmp;
-       uint32_t nlast, nserial;
-
-       SOAData sd;
-
-       DLOG( L.log( m_myname + " getDomainList()", Logger::Debug ) );
-
-       if( !execStmt( stmt.c_str(), stmt.size(), READ ) ) { return false; }
-       if( !getRecord( READ ) ) { return false; }
-
-       do
-       {
-               DomainInfo di;
-               nlast = 0;
-               nserial = 0;
-               sd.serial = 0;
-               sd.refresh = 0;
-
-               if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
-               {
-                       fillSOAData( string( tmp, odbx_field_length( m_result, 6 ) ), sd );
-               }
-
-               if( !sd.serial && ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
-               {
-                       sd.serial = strtol( tmp, NULL, 10 );
-               }
-
-               if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
-               {
-                       nserial = strtol( tmp, NULL, 10 );
-               }
-
-               if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
-               {
-                       nlast = strtol( tmp, NULL, 10 );
-               }
-
-               if( (*check_fcn)( nlast, nserial, &sd, &di ) )
-               {
-                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
-                       {
-                               stringtok(di.masters, string( tmp, odbx_field_length( m_result, 2 )), ", \t" );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
-                       {
-                               di.zone = string( tmp, odbx_field_length( m_result, 1 ) );
-                       }
-
-                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
-                       {
-                               di.id = strtol( tmp, NULL, 10 );
-                       }
-
-                       di.last_check = nlast;
-                       di.notified_serial = nserial;
-                       di.serial = sd.serial;
-                       di.backend = this;
-
-                       list->push_back( di );
-               }
-       }
-       while( getRecord( READ ) );
-
-       return true;
+        const char* tmp;
+        uint32_t nlast, nserial;
+
+        SOAData sd;
+
+        DLOG( L.log( m_myname + " getDomainList()", Logger::Debug ) );
+
+        if( !execStmt( stmt.c_str(), stmt.size(), READ ) ) { return false; }
+        if( !getRecord( READ ) ) { return false; }
+
+        do
+        {
+               DomainInfo di;
+               nlast = 0;
+               nserial = 0;
+               sd.serial = 0;
+               sd.refresh = 0;
+
+               if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
+               {
+                       fillSOAData( string( tmp, odbx_field_length( m_result, 6 ) ), sd );
+               }
+
+               if( !sd.serial && ( tmp = odbx_field_value( m_result, 5 ) ) != NULL )
+               {
+                       sd.serial = strtol( tmp, NULL, 10 );
+               }
+
+               if( ( tmp = odbx_field_value( m_result, 4 ) ) != NULL )
+               {
+                       nserial = strtol( tmp, NULL, 10 );
+               }
+
+               if( ( tmp = odbx_field_value( m_result, 3 ) ) != NULL )
+               {
+                       nlast = strtol( tmp, NULL, 10 );
+               }
+
+               if( (*check_fcn)( nlast, nserial, &sd, &di ) )
+               {
+                       if( ( tmp = odbx_field_value( m_result, 2 ) ) != NULL )
+                       {
+                               stringtok(di.masters, string( tmp, odbx_field_length( m_result, 2 )), ", \t" );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 1 ) ) != NULL )
+                       {
+                               di.zone = string( tmp, odbx_field_length( m_result, 1 ) );
+                       }
+
+                       if( ( tmp = odbx_field_value( m_result, 0 ) ) != NULL )
+                       {
+                               di.id = strtol( tmp, NULL, 10 );
+                       }
+
+                       di.last_check = nlast;
+                       di.notified_serial = nserial;
+                       di.serial = sd.serial;
+                       di.backend = this;
+
+                       list->push_back( di );
+               }
+        }
+        while( getRecord( READ ) );
+
+        return true;
 }
 
 
 
 bool checkSlave( uint32_t nlast, uint32_t nserial, SOAData* sd, DomainInfo* di )
 {
-       if( nlast + sd->refresh < (uint32_t) time( 0 ) )
-       {
-               di->kind = DomainInfo::Slave;
-               return true;
-       }
+        if( nlast + sd->refresh < (uint32_t) time( 0 ) )
+        {
+               di->kind = DomainInfo::Slave;
+               return true;
+        }
 
-       return false;
+        return false;
 }
 
 
 
 bool checkMaster( uint32_t nlast, uint32_t nserial, SOAData* sd, DomainInfo* di )
 {
-       if( nserial != sd->serial )
-       {
-               di->kind = DomainInfo::Master;
-               return true;
-       }
+        if( nserial != sd->serial )
+        {
+               di->kind = DomainInfo::Master;
+               return true;
+        }
 
-       return false;
+        return false;
 }
index ca54a56c017de2f9e2960ad9198f2cf99937927f..661cc28e35828a903e702e2fcb8e586e6d9d4520 100644 (file)
@@ -93,19 +93,19 @@ OracleBackend::OracleBackend(const string &suffix)
   
       err = OCIInitialize(OCI_THREADED, 0,  NULL, NULL, NULL);
       if (err) {
-        throw OracleException("OCIInitialize");
+         throw OracleException("OCIInitialize");
       }
 
       err = OCIEnvInit(&mEnvironmentHandle, OCI_DEFAULT, 0, 0);
       if (err) {
-        throw OracleException("OCIEnvInit");
+         throw OracleException("OCIEnvInit");
       }
   
       // Allocate an error handle
       
       err = OCIHandleAlloc(mEnvironmentHandle, (dvoid**) &mErrorHandle, OCI_HTYPE_ERROR, 0, NULL);
       if (err) {
-        throw OracleException("OCIHandleAlloc");
+         throw OracleException("OCIHandleAlloc");
       }
   
       // Logon to the database
@@ -115,136 +115,136 @@ OracleBackend::OracleBackend(const string &suffix)
       const char *database = getArg("database").c_str();
 
       err = OCILogon(mEnvironmentHandle, mErrorHandle, &mServiceContextHandle, (OraText*) username, strlen(username),
-                    (OraText*) password,  strlen(password), (OraText*) database, strlen(database));
+                    (OraText*) password,  strlen(password), (OraText*) database, strlen(database));
       
       if (err) {
-        throw OracleException(mErrorHandle);
+         throw OracleException(mErrorHandle);
       }
 
       // Allocate the statement handles, and prepare the statements
 
       for (int i = 0; i < kNumQueries; i++)
       {
-        err = OCIHandleAlloc(mEnvironmentHandle, (dvoid **) &mStatementHandles[i], OCI_HTYPE_STMT, 0, NULL);
-        
-        if (err) {
-           throw OracleException(mErrorHandle);
-        }
+         err = OCIHandleAlloc(mEnvironmentHandle, (dvoid **) &mStatementHandles[i], OCI_HTYPE_STMT, 0, NULL);
+         
+         if (err) {
+            throw OracleException(mErrorHandle);
+         }
 
-        err = OCIStmtPrepare(mStatementHandles[i], mErrorHandle, (text*) mQueries[i], strlen(mQueries[i]),
+         err = OCIStmtPrepare(mStatementHandles[i], mErrorHandle, (text*) mQueries[i], strlen(mQueries[i]),
            OCI_NTV_SYNTAX, OCI_DEFAULT);
 
-        if (err) {
-           throw OracleException(mErrorHandle);
-        }
+         if (err) {
+            throw OracleException(mErrorHandle);
+         }
 
-        // Bind query arguments
-        OCIBind *theBindHandle = NULL;
+         // Bind query arguments
+         OCIBind *theBindHandle = NULL;
 
          // Only the kListQuery and kForwardQueryByZone have an :id field
 
-        if (i == kListQuery || i == kForwardQueryByZone)
-        {
-           err = OCIBindByName(mStatementHandles[i], &theBindHandle, mErrorHandle, (OraText*) ":id", strlen(":id"),
-                               (ub1 *) &mQueryId, sizeof(mQueryId), SQLT_INT, NULL, NULL, 0, 0, NULL, OCI_DEFAULT);
-           
-           if (err) {
-              throw OracleException(mErrorHandle);
-           }       
-        }
+         if (i == kListQuery || i == kForwardQueryByZone)
+         {
+            err = OCIBindByName(mStatementHandles[i], &theBindHandle, mErrorHandle, (OraText*) ":id", strlen(":id"),
+                               (ub1 *) &mQueryId, sizeof(mQueryId), SQLT_INT, NULL, NULL, 0, 0, NULL, OCI_DEFAULT);
+            
+            if (err) {
+               throw OracleException(mErrorHandle);
+            }      
+         }
 
          // For all the other queries, except for kList Query we have more complex bindings
 
-        if (i != kListQuery)
-        {
+         if (i != kListQuery)
+         {
             // All queries have a name: field.
 
-           if (i < kListQuery)
-           {
-              err = OCIBindByName(mStatementHandles[i], &theBindHandle, mErrorHandle, (OraText*) ":name", strlen(":name"),
-                                  (ub1 *) mQueryName, sizeof(mQueryName), SQLT_STR, NULL, NULL, 0, 0, NULL, OCI_DEFAULT);
-              
-              if (err) {
-                 throw OracleException(mErrorHandle);
-              }
-           }
-           
+            if (i < kListQuery)
+            {
+               err = OCIBindByName(mStatementHandles[i], &theBindHandle, mErrorHandle, (OraText*) ":name", strlen(":name"),
+                                  (ub1 *) mQueryName, sizeof(mQueryName), SQLT_STR, NULL, NULL, 0, 0, NULL, OCI_DEFAULT);
+               
+               if (err) {
+                 throw OracleException(mErrorHandle);
+               }
+            }
+            
             // Only these queries have a type: field
 
-           if (i == kForwardQuery || i == kForwardQueryByZone || i == kForwardWildcardQuery )
-           {
-              err = OCIBindByName(mStatementHandles[i], &theBindHandle, mErrorHandle, (OraText*) ":type", strlen(":type"),
-                                  (ub1 *) mQueryType, sizeof(mQueryType), SQLT_STR, NULL, NULL, 0, 0, NULL, OCI_DEFAULT);
-              
-              if (err) {
-                 throw OracleException(mErrorHandle);
-              }            
-           }
-        }
-        
-        // Define the output
-        OCIDefine *theDefineHandle;
-
-        mResultContentIndicator = mResultTTLIndicator = mResultPriorityIndicator = mResultTypeIndicator
+            if (i == kForwardQuery || i == kForwardQueryByZone || i == kForwardWildcardQuery )
+            {
+               err = OCIBindByName(mStatementHandles[i], &theBindHandle, mErrorHandle, (OraText*) ":type", strlen(":type"),
+                                  (ub1 *) mQueryType, sizeof(mQueryType), SQLT_STR, NULL, NULL, 0, 0, NULL, OCI_DEFAULT);
+               
+               if (err) {
+                 throw OracleException(mErrorHandle);
+               }           
+            }
+         }
+         
+         // Define the output
+         OCIDefine *theDefineHandle;
+
+         mResultContentIndicator = mResultTTLIndicator = mResultPriorityIndicator = mResultTypeIndicator
            = mResultDomainIdIndicator = mResultChangeDateIndicator = 0;
 
-        theDefineHandle = NULL; 
-        err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 1, mResultContent,
+         theDefineHandle = NULL; 
+         err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 1, mResultContent,
            sizeof(mResultContent) - 1, SQLT_STR, (dvoid*) &mResultContentIndicator, NULL, NULL, OCI_DEFAULT);
-        
-        if (err) {
-           throw OracleException(mErrorHandle);
-        }
+         
+         if (err) {
+            throw OracleException(mErrorHandle);
+         }
 
-        theDefineHandle = NULL;
-        err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 2, &mResultTTL,
+         theDefineHandle = NULL;
+         err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 2, &mResultTTL,
            sizeof(mResultTTL), SQLT_INT, (dvoid*) &mResultTTLIndicator, NULL, NULL, OCI_DEFAULT);
-        
-        if (err) {
-          throw OracleException(mErrorHandle);
-        }
-        theDefineHandle = NULL;
-        err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 3, &mResultPriority,
+         
+         if (err) {
+           throw OracleException(mErrorHandle);
+         }
+         theDefineHandle = NULL;
+         err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 3, &mResultPriority,
            sizeof(mResultPriority), SQLT_INT, (dvoid*) &mResultPriorityIndicator, NULL, NULL, OCI_DEFAULT);
-        
-        if (err) {
-           throw OracleException(mErrorHandle);
-        }
-        
-        theDefineHandle = NULL;
-        err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 4, mResultType,
+         
+         if (err) {
+            throw OracleException(mErrorHandle);
+         }
+         
+         theDefineHandle = NULL;
+         err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 4, mResultType,
            sizeof(mResultType) - 1, SQLT_STR, (dvoid*) &mResultTypeIndicator, NULL, NULL, OCI_DEFAULT);
-        
-        if (err) {
-           throw OracleException(mErrorHandle);
-        }
+         
+         if (err) {
+            throw OracleException(mErrorHandle);
+         }
 
-        theDefineHandle = NULL;
-        err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 5, &mResultDomainId,
+         theDefineHandle = NULL;
+         err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 5, &mResultDomainId,
            sizeof(mResultDomainId), SQLT_INT, (dvoid*) &mResultDomainIdIndicator, NULL, NULL, OCI_DEFAULT);
-        
-        if (err) {
-           throw OracleException(mErrorHandle);
-        }
-        
-        theDefineHandle = NULL;
-        err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 6, &mResultChangeDate,
+         
+         if (err) {
+            throw OracleException(mErrorHandle);
+         }
+         
+         theDefineHandle = NULL;
+         err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 6, &mResultChangeDate,
            sizeof(mResultChangeDate), SQLT_INT, (dvoid*) &mResultChangeDateIndicator, NULL, NULL, OCI_DEFAULT);
-        
-        if (err) {
-           throw OracleException(mErrorHandle);
-        }
-
-        if (i == kListQuery)
-        {
-           theDefineHandle = NULL; 
-           err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 7, mResultName,
+         
+         if (err) {
+            throw OracleException(mErrorHandle);
+         }
+
+         if (i == kListQuery)
+         {
+            theDefineHandle = NULL; 
+            err = OCIDefineByPos(mStatementHandles[i], &theDefineHandle, mErrorHandle, 7, mResultName,
               sizeof(mResultName) - 1, SQLT_STR, (dvoid*) &mResultNameIndicator, NULL, NULL, OCI_DEFAULT);
-           
-           if (err) {
-              throw OracleException(mErrorHandle);
-           }
-        }
+            
+            if (err) {
+               throw OracleException(mErrorHandle);
+            }
+         }
       }      
 
    }
@@ -284,9 +284,9 @@ void OracleBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pk
        theQueryType = kForwardAnyQuery;
      } else {
        if (zoneId != -1) {
-        theQueryType = kForwardQueryByZone;
+         theQueryType = kForwardQueryByZone;
        } else {
-        theQueryType = kForwardQuery;
+         theQueryType = kForwardQuery;
        }
      }
    }
@@ -302,36 +302,36 @@ void OracleBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pk
    {
       case kForwardQuery:
       case kForwardWildcardQuery:
-        strncpy(mQueryName, qname.c_str(), sizeof(mQueryName));
-        strncpy(mQueryType, qtype.getName().c_str(), sizeof(mQueryType));
+         strncpy(mQueryName, qname.c_str(), sizeof(mQueryName));
+         strncpy(mQueryType, qtype.getName().c_str(), sizeof(mQueryType));
          if (mDebugQueries) {
             printf(">>> :name = '%s' :type = '%s'\n", mQueryName, mQueryType);
          }
-        break;
+         break;
 
       case kForwardQueryByZone:
-        strncpy(mQueryName, qname.c_str(), sizeof(mQueryName));
-        strncpy(mQueryType, qtype.getName().c_str(), sizeof(mQueryType));       
-        mQueryId = zoneId;
+         strncpy(mQueryName, qname.c_str(), sizeof(mQueryName));
+         strncpy(mQueryType, qtype.getName().c_str(), sizeof(mQueryType));      
+         mQueryId = zoneId;
          if (mDebugQueries) {
             printf(">>> :name = '%s' :type = '%s' :id = '%d'\n", mQueryName, mQueryType, mQueryId);
          }
-        break;
+         break;
 
       case kForwardAnyQuery:
       case kForwardWildcardAnyQuery:
-        strncpy(mQueryName, qname.c_str(), sizeof(mQueryName));
+         strncpy(mQueryName, qname.c_str(), sizeof(mQueryName));
          if (mDebugQueries) {
             printf(">>> :name = '%s'\n", mQueryName);
          }
-        break;
+         break;
 
    }
 
    if(mUpperCase == true) {
       char *p = mQueryName;
       while (*p != 0x00) {
-        *p++ = std::toupper(*p);
+         *p++ = std::toupper(*p);
       }
    }
    
@@ -351,7 +351,7 @@ void OracleBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pk
         (OCISnapshot *)NULL, (OCISnapshot*) NULL, OCI_DEFAULT);
    
       if (mQueryResult != OCI_SUCCESS && mQueryResult != OCI_SUCCESS_WITH_INFO && mQueryResult != OCI_NO_DATA) {
-        throw OracleException(mErrorHandle);
+         throw OracleException(mErrorHandle);
       }
    }
    
@@ -392,7 +392,7 @@ bool OracleBackend::list(const string &target, int domain_id)
         (OCISnapshot *)NULL, (OCISnapshot*) NULL, OCI_DEFAULT);
    
       if (mQueryResult != OCI_SUCCESS && mQueryResult != OCI_SUCCESS_WITH_INFO && mQueryResult != OCI_NO_DATA) {
-        throw OracleException(mErrorHandle);
+         throw OracleException(mErrorHandle);
       }
    }
 
@@ -432,7 +432,7 @@ bool OracleBackend::get(DNSResourceRecord &theRecord)
    {
       mQueryResult = OCIStmtFetch(mStatementHandles[mActiveQuery], mErrorHandle, 1, 0, 0);
       if (mQueryResult != OCI_SUCCESS && mQueryResult != OCI_SUCCESS_WITH_INFO && mQueryResult != OCI_NO_DATA) {
-        new OracleException(mErrorHandle);  // ? - ahu
+         new OracleException(mErrorHandle);  // ? - ahu
       }
     }
    catch (OracleException &theException)
@@ -515,11 +515,11 @@ class OracleFactory : public BackendFactory
 
       DNSBackend *make(const string &suffix="")
       {
-       try {
-         return new OracleBackend(suffix);
-       }
-       catch(...) {}
-       return 0;
+        try {
+          return new OracleBackend(suffix);
+        }
+        catch(...) {}
+        return 0;
       }
 };
 
@@ -533,8 +533,8 @@ class OracleLoader
       
       OracleLoader()
       {
-       BackendMakers().report(new OracleFactory);
-       L << Logger::Warning << kModuleId << "Oracle Backend loaded." << endl;
+        BackendMakers().report(new OracleFactory);
+        L << Logger::Warning << kModuleId << "Oracle Backend loaded." << endl;
       }
       
 };
index 94fbe496c90a74e9cebcc0a71f306db1ef33f633..16ceca5184d97c2a1fce77c8ca1c2bb9ba5c519d 100644 (file)
@@ -22,43 +22,43 @@ class OracleException
       
       OracleException()
       {
-        mReason = "Unspecified";
+         mReason = "Unspecified";
       }
       
       OracleException(string theReason)
       {
-        mReason = theReason;
+         mReason = theReason;
       }
 
       OracleException(OCIError *theErrorHandle)
       {
-        mReason = "ORA-UNKNOWN";
+         mReason = "ORA-UNKNOWN";
 
-        if (theErrorHandle != NULL)
-        {
-           text  msg[512];
-           sb4   errcode = 0;
+         if (theErrorHandle != NULL)
+         {
+            text  msg[512];
+            sb4   errcode = 0;
    
-           memset((void *) msg, (int)'\0', (size_t)512);
+            memset((void *) msg, (int)'\0', (size_t)512);
    
-           OCIErrorGet((dvoid *) theErrorHandle,1, NULL, &errcode, msg, sizeof(msg), OCI_HTYPE_ERROR);
-           if (errcode)
+            OCIErrorGet((dvoid *) theErrorHandle,1, NULL, &errcode, msg, sizeof(msg), OCI_HTYPE_ERROR);
+            if (errcode)
             {
-             char *p = (char*) msg;
-              while (*p++ != 0x00) {
-                 if (*p == '\n' || *p == '\r') {
-                   *p = ';';
-                 }
-               }
-               
-               mReason = (char*) msg;
-           }
-        }
+              char *p = (char*) msg;
+               while (*p++ != 0x00) {
+                 if (*p == '\n' || *p == '\r') {
+                   *p = ';';
+                 }
+               }
+               
+               mReason = (char*) msg;
+            }
+         }
       }
 
       string Reason()
       {
-        return mReason;
+         return mReason;
       }
       
       string mReason;
index 98ee140c1a6f883d1ebc03bcc17da5da491629ea..4b9859feb505bf1a5bd18929ff97da90bacf8845 100644 (file)
@@ -43,14 +43,14 @@ PdnsBackend::PdnsBackend(const string &suffix)
    d_suffix=suffix;
    MYSQL* theDatabase = mysql_real_connect
       (
-        &d_database,
-        arg()["pdns-"+suffix+"host"].c_str(),
-        arg()["pdns-"+suffix+"user"].c_str(),
-        arg()["pdns-"+suffix+"password"].c_str(),
-        arg()["pdns-"+suffix+"dbname"].c_str(),
-        0,
-        arg()["pdns-"+suffix+"socket"].empty() ? NULL : arg()["pdns-"+suffix+"socket"].c_str(),
-        0
+         &d_database,
+         arg()["pdns-"+suffix+"host"].c_str(),
+         arg()["pdns-"+suffix+"user"].c_str(),
+         arg()["pdns-"+suffix+"password"].c_str(),
+         arg()["pdns-"+suffix+"dbname"].c_str(),
+         0,
+         arg()["pdns-"+suffix+"socket"].empty() ? NULL : arg()["pdns-"+suffix+"socket"].c_str(),
+         0
       );
 
    if (theDatabase == NULL) {
@@ -270,7 +270,7 @@ bool PdnsBackend::getDomainInfo(const string &domain, DomainInfo &di)
       
       /* We have to store record in local variabel... theRow[2] == NULL makes it empty in di.master = theRow[2]???? */
       if(theRow[2] != NULL)
-        stringtok(masters, theRow[2], " ,\t");
+         stringtok(masters, theRow[2], " ,\t");
       
       if (masters.empty())
       {
@@ -366,20 +366,20 @@ bool PdnsBackend::feedRecord(const DNSResourceRecord &rr)
 
 bool PdnsBackend::commitTransaction()
 {
-        this->Execute("commit");
-        
-        d_axfrcount = 0;
-        
-        return true;
+         this->Execute("commit");
+         
+         d_axfrcount = 0;
+         
+         return true;
 }
 
 bool PdnsBackend::abortTransaction()
 {
-        this->Execute("rollback");
-        
-        d_axfrcount = 0;
-        
-        return true;
+         this->Execute("rollback");
+         
+         d_axfrcount = 0;
+         
+         return true;
 }
 
 void PdnsBackend::setFresh(u_int32_t domain_id)
@@ -419,12 +419,12 @@ bool PdnsBackend::get(DNSResourceRecord& r)
       r.content=row[0];  // content
   
       if(!row[1])  // ttl
-        r.ttl=0;
+         r.ttl=0;
       else
-        r.ttl=atoi(row[1]);
+         r.ttl=atoi(row[1]);
         
       if(row[2])
-        r.priority=atoi(row[2]);;
+         r.priority=atoi(row[2]);;
 
       r.qname=row[5];
    
@@ -432,9 +432,9 @@ bool PdnsBackend::get(DNSResourceRecord& r)
       
       r.domain_id=atoi(row[4]);
       if(!row[6])
-        r.last_modified=0;
+         r.last_modified=0;
       else
-        r.last_modified=atoi(row[6]);
+         r.last_modified=atoi(row[6]);
    
       theResult = true;
    }
@@ -450,18 +450,18 @@ class PDNSFactory : public BackendFactory
   
       void declareArguments(const string &suffix="")
       {
-        declare(suffix,"dbname","Pdns backend database name to connect to","powerdns");
-        declare(suffix,"user","Pdns backend user to connect as","powerdns");
-        declare(suffix,"host","Pdns backend host to connect to","");
-        declare(suffix,"password","Pdns backend password to connect with","");
-        declare(suffix,"socket","Pdns backend socket to connect to","");
-        declare(suffix,"soa-refresh","Pdns SOA refresh in seconds","");
-        declare(suffix,"max-slave-records","Pdns backend maximal records to transfer", "100");
+         declare(suffix,"dbname","Pdns backend database name to connect to","powerdns");
+         declare(suffix,"user","Pdns backend user to connect as","powerdns");
+         declare(suffix,"host","Pdns backend host to connect to","");
+         declare(suffix,"password","Pdns backend password to connect with","");
+         declare(suffix,"socket","Pdns backend socket to connect to","");
+         declare(suffix,"soa-refresh","Pdns SOA refresh in seconds","");
+         declare(suffix,"max-slave-records","Pdns backend maximal records to transfer", "100");
       }
       
       DNSBackend *make(const string &suffix="")
       {
-        return new PdnsBackend(suffix);
+         return new PdnsBackend(suffix);
       }
 };
 
@@ -473,8 +473,8 @@ class PdnsBeLoader
 
       PdnsBeLoader()
       {
-        BackendMakers().report(new PDNSFactory);
-        L<<Logger::Notice<<backendName<<" This is the pdns module version "VERSION" ("__DATE__", "__TIME__") reporting"<<endl;
+         BackendMakers().report(new PDNSFactory);
+         L<<Logger::Notice<<backendName<<" This is the pdns module version "VERSION" ("__DATE__", "__TIME__") reporting"<<endl;
       }
 };
 
index fff84f35a37d780ffcdfd89be967723ffafcb12d..3f8a460e5a75c6f7d45f73466807ad43a8be1e43 100644 (file)
@@ -99,7 +99,7 @@ void CoProcess::checkStatus()
       string reason="CoProcess died on receiving signal "+itoa(sig);
 #ifdef WCOREDUMP
       if(WCOREDUMP(status)) 
-       reason+=". Dumped core";
+        reason+=". Dumped core";
 #endif
       
       throw AhuException(reason);
index eb53413c00307442d609ec660085dd2f04d1543c..80571d8f59922f91c744c5c37785db469e870c4a 100644 (file)
@@ -119,7 +119,7 @@ void PipeBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pkt_
          
          if (pkt_p) {
             localIP=pkt_p->getLocal();
-           remoteIP=pkt_p->getRemote();
+            remoteIP=pkt_p->getRemote();
          }
 
          // pipebackend-abi-version = 1
@@ -220,24 +220,24 @@ bool PipeBackend::get(DNSResourceRecord &r)
          r.ttl=atoi(parts[4].c_str());
          r.domain_id=atoi(parts[5].c_str());
  
-        if(parts[3]!="MX") {
-          r.content.clear();
-          for(int n=6; n < parts.size(); ++n) {
-            if(n!=6)
-              r.content.append(1,' ');
-            r.content.append(parts[n]);
-          }
-        }
-        else {
-          if(parts.size()<8) {
+         if(parts[3]!="MX") {
+           r.content.clear();
+           for(int n=6; n < parts.size(); ++n) {
+             if(n!=6)
+               r.content.append(1,' ');
+             r.content.append(parts[n]);
+           }
+         }
+         else {
+           if(parts.size()<8) {
             L<<Logger::Error<<kBackendId<<" coprocess returned incomplete MX line in data section for query for "<<d_qname<<endl;
             throw AhuException("Format error communicating with coprocess in data section of MX record");
-          }
-          
-          r.priority=atoi(parts[6].c_str());
-          r.content=parts[7];
+           }
+           
+           r.priority=atoi(parts[6].c_str());
+           r.content=parts[7];
 
-        }
+         }
          break;
       }
       else
index 5709c423c81d7af2988744d98136bf3b89005086..2df29072a37dfca9eefb0c144c5d592d970a08e2 100644 (file)
@@ -69,7 +69,7 @@ typedef void insertFunc(int domain_id, const string &qname, const string &qtype,
 void walk(FILE *fp, insertFunc *ifp)
 {
   char line[1024];
-  // 0 'ORG'   'SOA'   'A.GTLD-SERVERS.NET. NSTLD.VERISIGN-GRS.COM. 2002100700 1800 900 604800 86400'  0       3600
+  // 0        'ORG'    'SOA'   'A.GTLD-SERVERS.NET. NSTLD.VERISIGN-GRS.COM. 2002100700 1800 900 604800 86400'  0       3600
   int count=0;
   while(fgets(line,1023,fp)) {
     if(!((count++)%10000))
index 33c49903e6f1579219f1ca883be84c5fa14d7973..3f55db2bbe3e20be0ef0a2e8ded9284c7d0e38be 100644 (file)
@@ -47,9 +47,9 @@ public:
     /*
     if(arg().mustDo("query-logging")) {
       if(ret)
-       L<<Logger::Error<<"Raw Answer: '"<<d_answer<<"'"<<endl;
+        L<<Logger::Error<<"Raw Answer: '"<<d_answer<<"'"<<endl;
       else
-       L<<Logger::Error<<"No answer"<<endl;
+        L<<Logger::Error<<"No answer"<<endl;
     }
     */
 
@@ -62,11 +62,11 @@ public:
       int len=rr.unSerialize(d_answer);
       d_answer=d_answer.substr(len);
       if(d_qtype.getCode()==QType::ANY || rr.qtype==d_qtype) {
-       /*
-       if(arg().mustDo("query-logging")) {
-         L<<Logger::Error<<"Real answer: "<<rr.qtype.getName()<<"/"<<rr.content<<endl;
-       */
-       return true;
+        /*
+        if(arg().mustDo("query-logging")) {
+          L<<Logger::Error<<"Real answer: "<<rr.qtype.getName()<<"/"<<rr.content<<endl;
+        */
+        return true;
       }
     }
     return false;                                                   // no more data
index e55a82ab9cebb185e1138d83befe820fd3584b97..025d83098c57611fdc6f222b78e07f8ca4be31e3 100644 (file)
@@ -15,8 +15,8 @@ XGDBMWrapper::XGDBMWrapper(const string &fname, Mode mode)
 {
   if(!s_db) {
     s_db = gdbm_open(const_cast<char *>(fname.c_str()), 2048,
-                 mode==ReadWrite ? GDBM_WRITER|GDBM_WRCREAT|GDBM_FAST : GDBM_READER,
-                 0666 , 0); 
+                 mode==ReadWrite ? GDBM_WRITER|GDBM_WRCREAT|GDBM_FAST : GDBM_READER,
+                 0666 , 0); 
     if(!s_db) 
       throw XDBException("Unable to open database: "+string(strerror(errno)));
   }
index 678d9c1e10006d516d9e6c293f0187c7a7f42288..01b1a9eba9d94ef041290a3cbd73090356f5aa59 100644 (file)
@@ -20,8 +20,8 @@ XTDBWrapper::XTDBWrapper(const string &fname)
   Lock l(&s_lock);
   if(!s_db) {
     s_db = tdb_open(const_cast<char *>(fname.c_str()), 5213331,
-                 TDB_NOLOCK,
-                 O_RDWR | O_CREAT , 0600); 
+                 TDB_NOLOCK,
+                 O_RDWR | O_CREAT , 0600); 
     if(!s_db) 
       throw XDBException("Unable to open database: "+string(strerror(errno)));
   }