From: Bert Hubert Date: Wed, 18 Dec 2002 09:30:13 +0000 (+0000) Subject: bind bind bind! X-Git-Tag: pdns-2.9.3~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd11bd1dc767cb41e489d009af0750b91ed619b1;p=pdns bind bind bind! git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@85 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/ChangeLog b/ChangeLog index 6e62de8d7..b18b7189d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,9 @@ Changes since 2.9.2: - can now understand incoming RP records in AXFR - fixed potential crasher bug in shortened packet parsing - now groks LOC records incoming/outgoing + - configparser now strips leading spaces in arguments + - improved chroot error reporting + - lots of bind backend work Changes since 2.9.1: - removed debugging output from the webserver (found by Paul Wouters) diff --git a/TODO b/TODO index 2e6f81165..54096cf22 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +reset yacc/lex in bindparser + bugs: pdns.conf-dist contains old descriptions diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 196f50a05..31a34e5c5 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "utility.hh" +#include "utility.hh" #include #include #include "logger.hh" @@ -42,7 +42,7 @@ string & ArgvMap::set(const string &var) } bool ArgvMap::mustDo(const string &var) -{ +{ return ((*this)[var]!="no") && ((*this)[var]!="off"); } @@ -232,6 +232,11 @@ void ArgvMap::parseOne(const string &arg, const string &parseOnly, bool lax) } if(var!="" && (parseOnly.empty() || var==parseOnly)) { + + pos=val.find_first_not_of(" \t"); // strip leading whitespace + if(pos && pos!=string::npos) + val=val.substr(pos); + if(parmIsset(var)) params[var]=val; else diff --git a/pdns/backends/bind/bindbackend.cc b/pdns/backends/bind/bindbackend.cc index 4805ac633..e00318ee2 100644 --- a/pdns/backends/bind/bindbackend.cc +++ b/pdns/backends/bind/bindbackend.cc @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// $Id: bindbackend.cc,v 1.3 2002/12/17 16:50:31 ahu Exp $ +// $Id: bindbackend.cc,v 1.4 2002/12/18 09:30:13 ahu Exp $ #include #include #include @@ -39,7 +39,7 @@ using namespace std; #include "huffman.hh" #include "qtype.hh" #include "misc.hh" - +#include "dynlistener.hh" using namespace std; @@ -58,6 +58,7 @@ BBDomainInfo::BBDomainInfo() d_last_check=0; d_checknow=false; d_rwlock=new pthread_rwlock_t; + d_confcount=0; //cout<<"Generated a new bbdomaininfo: "<<(void*)d_rwlock<<"/"< *unfreshDomains) sd.last_check=i->second.d_last_check; sd.backend=this; sd.kind=DomainInfo::Slave; - SOAData soadata; soadata.serial=0; soadata.refresh=0; - getSOA(i->second.d_name,soadata); - sd.serial=soadata.serial; + soadata.serial=0; + try { + getSOA(i->second.d_name,soadata); // we might not *have* a SOA yet + sd.serial=soadata.serial; + } + catch(...){} if(sd.last_check+soadata.refresh<(unsigned int)time(0)) unfreshDomains->push_back(sd); @@ -191,10 +195,12 @@ bool BindBackend::getDomainInfo(const string &domain, DomainInfo &di) static string canonic(string ret) { string::iterator i; + for(i=ret.begin(); i!=ret.end(); ++i) - *i=tolower(*i); + *i=*i; //tolower(*i); + if(*(i-1)=='.') ret.resize(i-ret.begin()-1); @@ -271,6 +277,13 @@ BBResourceRecord BindBackend::resourceMaker(int id, const string &qtype, const s static BindBackend *us; static int domain_id; +BindBackend *self; +string BindBackend::DLReloadHandler(const vector&parts, Utility::pid_t ppid) +{ + for(map::iterator i=self->d_bbds.begin();i!=self->d_bbds.end();++i) + i->second.d_checknow=true; + return "queued"; +} static void callback(const string &domain, const string &qtype, const string &content, int ttl, int prio) { @@ -281,12 +294,11 @@ static void callback(const string &domain, const string &qtype, const string &co BindBackend::BindBackend(const string &suffix) { + d_logprefix="[bind"+suffix+"backend]"; + setArgPrefix("bind"+suffix); if(!s_first) return; - d_logprefix="[bind"+suffix+"backend]"; - setArgPrefix("bind"+suffix); - s_first=0; if(!mustDo("enable-huffman")) s_hc.passthrough(true); @@ -315,10 +327,33 @@ BindBackend::BindBackend(const string &suffix) d_bbds[0].d_loaded=true; } + loadConfig(); + + + extern DynListener *dl; + self=this; + dl->registerFunc("BIND-RELOAD", &DLReloadHandler); +} + + +void BindBackend::rediscover() +{ + loadConfig(); +} + +void BindBackend::loadConfig() +{ + static int s_confcount; if(!getArg("config").empty()) { BindParser BP; - BP.parse(getArg("config")); + try { + BP.parse(getArg("config")); + } + catch(AhuException &ae) { + L< nbbds; + for(vector::const_iterator i=domains.begin(); i!=domains.end(); ++i) @@ -339,35 +379,48 @@ BindBackend::BindBackend(const string &suffix) bbd.d_name=i->name; bbd.d_filename=i->filename; bbd.d_master=i->master; - bbd.d_id=domain_id; + bbd.setCtime(); bbd.setCheckInterval(getArgAsNum("check-interval")); + + map::const_iterator j=d_bbds.begin(); + for(;j!=d_bbds.end();++j) + if(j->second.d_name==bbd.d_name) { + bbd.d_id=j->second.d_id; + break; + } + if(j==d_bbds.end()) + bbd.d_id=domain_id++; - d_bbds[domain_id]=bbd; + nbbds[bbd.d_id]=bbd; L<name<<"' from file '"<filename<<"'"<filename,i->name); // calls callback for us - d_bbds[domain_id].d_loaded=true; + nbbds[bbd.d_id].d_loaded=true; } catch(AhuException &ae) { L<name<<"' from file '"<filename<<"': "< *>&tmp=d_zone_id_map[domain_id]; // shrink trick + vector *>&tmp=d_zone_id_map[bbd.d_id]; // shrink trick vector *>(tmp).swap(tmp); - - domain_id++; } - L< oldnames, newnames; + for(map::const_iterator j=d_bbds.begin();j!=d_bbds.end();++j) + oldnames.push_back(j->second.d_name); + for(map::const_iterator j=nbbds.begin();j!=nbbds.end();++j) + newnames.push_back(j->second.d_name); + + d_bbds.swap(nbbds); // commit + + L<&parts, Utility::pid_t ppid); + void loadConfig(); }; diff --git a/pdns/backends/bind/bindparser.cc b/pdns/backends/bind/bindparser.cc index c34973c86..b6aab10a3 100644 --- a/pdns/backends/bind/bindparser.cc +++ b/pdns/backends/bind/bindparser.cc @@ -1,22 +1,4 @@ -/* - PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 PowerDNS.COM BV - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -/* A Bison parser, made from /home/ahu/programming/ahudns/backends/bind/bindparser.yy +/* A Bison parser, made from /home/ahu/programming/pdns/pdns/backends/bind/bindparser.yy by GNU bison 1.35. */ #define YYBISON 1 /* Identify Bison output. */ @@ -68,6 +50,7 @@ extern "C" { return 1; } + void yyrestart(FILE *); } @@ -88,7 +71,7 @@ void BindParser::parse(const string &fname) { yydebug=0; yyin=fopen(fname.c_str(),"r"); - + yyrestart(yyin); if(!yyin) throw AhuException("Unable to open '"+fname+"': "+strerror(errno)); @@ -218,11 +201,11 @@ static const short yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const short yyrline[] = { - 0, 107, 108, 112, 112, 112, 112, 115, 116, 120, - 124, 131, 141, 143, 147, 148, 151, 154, 155, 159, - 163, 164, 168, 168, 171, 178, 179, 183, 183, 183, - 185, 189, 193, 194, 198, 198, 198, 198, 201, 204, - 205, 209, 215, 223, 232, 239 + 0, 108, 109, 113, 113, 113, 113, 116, 117, 121, + 125, 132, 142, 144, 148, 149, 152, 155, 156, 160, + 164, 165, 169, 169, 172, 179, 180, 184, 184, 184, + 186, 190, 194, 195, 199, 199, 199, 199, 202, 205, + 206, 210, 216, 224, 233, 240 }; #endif @@ -1038,7 +1021,7 @@ yyreduce: switch (yyn) { case 10: -#line 126 "bindparser.yy" +#line 127 "bindparser.yy" { s_di.name=yyvsp[-1]; parent->commit(s_di); @@ -1046,7 +1029,7 @@ case 10: } break; case 11: -#line 133 "bindparser.yy" +#line 134 "bindparser.yy" { s_di.name=yyvsp[-2]; parent->commit(s_di); @@ -1054,33 +1037,33 @@ case 11: } break; case 24: -#line 172 "bindparser.yy" +#line 173 "bindparser.yy" { parent->setDirectory(yyvsp[0]); } break; case 41: -#line 210 "bindparser.yy" +#line 211 "bindparser.yy" { s_di.master=yyvsp[0]; } break; case 42: -#line 217 "bindparser.yy" +#line 218 "bindparser.yy" { // printf("Found a filename: '%s'\n",$2); s_di.filename=yyvsp[0]; } break; case 43: -#line 225 "bindparser.yy" +#line 226 "bindparser.yy" { // printf("Found a filename: '%s'\n",$2); // ztype=$2; } break; case 44: -#line 234 "bindparser.yy" +#line 235 "bindparser.yy" { yyval=yyvsp[0]; } @@ -1318,4 +1301,4 @@ yyreturn: #endif return yyresult; } -#line 240 "bindparser.yy" +#line 241 "bindparser.yy" diff --git a/pdns/backends/bind/bindparser.yy b/pdns/backends/bind/bindparser.yy index 345f9bdc5..68b623a44 100644 --- a/pdns/backends/bind/bindparser.yy +++ b/pdns/backends/bind/bindparser.yy @@ -29,6 +29,7 @@ extern "C" { return 1; } + void yyrestart(FILE *); } @@ -49,7 +50,7 @@ void BindParser::parse(const string &fname) { yydebug=0; yyin=fopen(fname.c_str(),"r"); - + yyrestart(yyin); if(!yyin) throw AhuException("Unable to open '"+fname+"': "+strerror(errno)); diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 62ae03dd8..8a5fe2475 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -236,7 +236,7 @@ void mainthread() #ifndef WIN32 if(!arg()["chroot"].empty()) { if(chroot(arg()["chroot"].c_str())<0) { - L< cmdomains; B->getUpdatedMasters(&cmdomains); - if(cmdomains.empty()) - L<1 ? "s" : "")<<" for which we are master need"<< (cmdomains.size()>1 ? "" : "s")<< " notifications"<1 ? "s" : "")<<" need"<< (sdomains.size()>1 ? "" : "s")<< " checking"<::const_iterator i=sdomains.begin();i!=sdomains.end();++i) { + d_slaveschanged=true; u_int32_t theirserial=0; try { Resolver resolver; diff --git a/pdns/communicator.hh b/pdns/communicator.hh index d902832ca..81894c533 100644 --- a/pdns/communicator.hh +++ b/pdns/communicator.hh @@ -128,6 +128,7 @@ public: // sem_init(&d_suck_sem,0,0); // sem_init(&d_any_sem,0,0); d_tickinterval=60; + d_masterschanged=d_slaveschanged=true; } int doNotifications(); void go() @@ -162,6 +163,7 @@ private: Semaphore d_any_sem; int d_tickinterval; NotificationQueue d_nq; + bool d_masterschanged, d_slaveschanged; }; #endif diff --git a/pdns/dnspacket.hh b/pdns/dnspacket.hh index adc4aad4e..e30686cf2 100644 --- a/pdns/dnspacket.hh +++ b/pdns/dnspacket.hh @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// $Id: dnspacket.hh,v 1.6 2002/12/17 16:50:30 ahu Exp $ +// $Id: dnspacket.hh,v 1.7 2002/12/18 09:30:13 ahu Exp $ #ifndef DNSPACKET_HH #define DNSPACKET_HH @@ -299,7 +299,7 @@ int DNSPacket::parse(const char *mesg, int length) d_qlen=offset+4; // this points to the start of any answers } - if(15+offset>=stringbuffer.length()) { + if((unsigned int)(15+offset)>=stringbuffer.length()) { L << Logger::Warning << "Ignoring packet: question too short from " << getRemote() << endl; return -1; diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index 039c99d10..72978b14e 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -16,14 +16,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "utility.hh" +#include "utility.hh" #include "dynhandler.hh" #include "statbag.hh" #include "logger.hh" #include "dns.hh" #include "arguments.hh" #include -#include "misc.hh" +#include "misc.hh" #include "communicator.hh" static bool s_pleasequit; @@ -207,9 +207,15 @@ string DLNotifyHandler(const vector&parts, Utility::pid_t ppid) string DLRediscoverHandler(const vector&parts, Utility::pid_t ppid) { PacketHandler P; - P.getBackend()->rediscover(); - L<rediscover(); + return "Ok"; + } + catch(AhuException &ae) { + return ae.reason; + } + } string DLReloadHandler(const vector&parts, Utility::pid_t ppid)