along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "packetcache.hh"
#include "utility.hh"
#include <string>
#include <sys/types.h>
PacketHandler::PacketHandler():B(s_programname)
{
s_count++;
- d_doFancyRecords = (arg()["fancy-records"]!="no");
- d_doWildcards = (arg()["wildcards"]!="no");
- d_doCNAME = (arg()["skip-cname"]=="no");
- d_doRecursion= arg().mustDo("recursor");
- d_logDNSDetails= arg().mustDo("log-dns-details");
- d_doIPv6AdditionalProcessing = arg().mustDo("do-ipv6-additional-processing");
+ d_doFancyRecords = (::arg()["fancy-records"]!="no");
+ d_doWildcards = (::arg()["wildcards"]!="no");
+ d_doCNAME = (::arg()["skip-cname"]=="no");
+ d_doRecursion= ::arg().mustDo("recursor");
+ d_logDNSDetails= ::arg().mustDo("log-dns-details");
+ d_doIPv6AdditionalProcessing = ::arg().mustDo("do-ipv6-additional-processing");
}
DNSBackend *PacketHandler::getBackend()
r->addRecord(rr);
}
- if(boost::iequals(arg()["send-root-referral"], "lean"))
+ if(boost::iequals(::arg()["send-root-referral"], "lean"))
return;
// add the additional stuff
if(wedoforward) {
r->clearRecords();
- rr.content=arg()["smtpredirector"];
+ rr.content=::arg()["smtpredirector"];
rr.priority=25;
rr.ttl=7200;
rr.qtype=QType::MX;
r->clearRecords();
found=true;
DLOG(L << "Found a URL!" << endl);
- rr.content=arg()["urlredirector"];
+ rr.content=::arg()["urlredirector"];
rr.qtype=QType::A;
rr.qname=target;
r->clearRecords();
found=true;
DLOG(L << "Found a CURL!" << endl);
- rr.content=arg()["urlredirector"];
+ rr.content=::arg()["urlredirector"];
rr.qtype=1; // A
rr.qname=target;
rr.ttl=300;
DNSResourceRecord rr;
// modes: anonymous, powerdns only, full, spoofed
- const string mode=arg()["version-string"];
+ const string mode=::arg()["version-string"];
if(p->qtype.getCode()==QType::TXT && target=="version.bind") {// TXT
if(mode.empty() || mode=="full")
rr.content="Served by POWERDNS "VERSION" $Id$";
rr.qname=target;
if(d_doFancyRecords && p->qtype.getCode()==QType::ANY && (rr.qtype.getCode()==QType::URL || rr.qtype.getCode()==QType::CURL)) {
- rr.content=arg()["urlredirector"];
+ rr.content=::arg()["urlredirector"];
rr.qtype=QType::A;
}
retargeted=true;
}
}
- else if(d_doFancyRecords && arg().mustDo("wildcard-url") && p->qtype.getCode()==QType::A && rr.qtype.getName()=="URL") {
- rr.content=arg()["urlredirector"];
+ else if(d_doFancyRecords && ::arg().mustDo("wildcard-url") && p->qtype.getCode()==QType::A && rr.qtype.getName()=="URL") {
+ rr.content=::arg()["urlredirector"];
rr.qtype=QType::A;
rr.qname=target;
bool foundOne=false;
while(B.get(rr)) {
foundOne=true;
- if(rr.domain_id!=i->domain_id && arg()["out-of-zone-additional-processing"]=="no") {
+ if(rr.domain_id!=i->domain_id && ::arg()["out-of-zone-additional-processing"]=="no") {
DLOG(L<<Logger::Warning<<"Not including out-of-zone additional processing of "<<i->qname<<" ("<<rr.qname<<")"<<endl);
continue; // not adding out-of-zone additional data
}
We determine the SOA at our (known) master
if master is higher -> do stuff
*/
- if(!arg().mustDo("slave")) {
+ if(!::arg().mustDo("slave")) {
L<<Logger::Error<<"Received NOTIFY for "<<p->qdomain<<" from "<<p->getRemote()<<" but slave support is disabled in the configuration"<<endl;
return RCode::NotImp;
}
}
string authServer(p->getRemote());
- if(arg().contains("trusted-notification-proxy", p->getRemote())) {
+ if(::arg().contains("trusted-notification-proxy", p->getRemote())) {
L<<Logger::Error<<"Received NOTIFY for "<<p->qdomain<<" from trusted-notification-proxy "<< p->getRemote()<<endl;
if(di.masters.empty()) {
L<<Logger::Error<<"However, "<<p->qdomain<<" does not have any masters defined"<<endl;
// XXX FIXME do this in DNSPacket::parse ?
if(!validDNSName(p->qdomain)) {
- if(arg().mustDo("log-dns-details"))
+ if(::arg().mustDo("log-dns-details"))
L<<Logger::Error<<"Received a malformed qdomain from "<<p->getRemote()<<", '"<<p->qdomain<<"': dropping"<<endl;
S.inc("corrupt-packets");
return 0;
}
if(p->d.opcode) { // non-zero opcode (again thanks RA!)
if(p->d.opcode==Opcode::Update) {
- if(arg().mustDo("log-failed-updates"))
+ if(::arg().mustDo("log-failed-updates"))
L<<Logger::Notice<<"Received an UPDATE opcode from "<<p->getRemote()<<" for "<<p->qdomain<<", sending NOTIMP"<<endl;
r=p->replyPacket();
r->setRcode(RCode::NotImp); // notimp;
DLOG(L<<"Found a direct answer: "<<rr.content<<endl);
found=true;
if(d_doFancyRecords && p->qtype.getCode()==QType::ANY && (rr.qtype.getCode()==QType::URL || rr.qtype.getCode()==QType::CURL)) {
- rr.content=arg()["urlredirector"];
+ rr.content=::arg()["urlredirector"];
rr.qtype=QType::A;
rr.qname=target;
}
int zoneId;
zoneId=-1;
- if(p->d.rd && d_doRecursion && arg().mustDo("allow-recursion-override"))
+ if(p->d.rd && d_doRecursion && ::arg().mustDo("allow-recursion-override"))
weAuth=getAuth(p, &sd, target, &zoneId);
else
weAuth=false;
p->getRemote()<< (p->d.rd ? " (recursion was desired)" : "") <<endl;
r->setA(false);
- if(arg().mustDo("send-root-referral")) {
+ if(::arg().mustDo("send-root-referral")) {
DLOG(L<<Logger::Warning<<"Adding root-referral"<<endl);
addRootReferral(r);
}
/*
PowerDNS Versatile Database Driven Nameserver
- Copyright (C) 2002 - 2007 PowerDNS.COM BV
+ Copyright (C) 2002 - 2008 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 version 2
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "packetcache.hh"
#include <cstdio>
#include <signal.h>
#include "packethandler.hh"
#include "statbag.hh"
#include "tcpreceiver.hh"
-#include "packetcache.hh"
#include "ws.hh"
#include "misc.hh"
#include "dynlistener.hh"
static void writePid(void)
{
- string fname=arg()["socket-dir"]+"/"+s_programname+".pid";
+ string fname=::arg()["socket-dir"]+"/"+s_programname+".pid";
ofstream of(fname.c_str());
if(of)
of<<getpid()<<endl;
char **const newargv=new char*[argc+2];
int n;
- if(arg()["config-name"]!="") {
- progname+="-"+arg()["config-name"];
- L<<Logger::Error<<"Virtual configuration name: "<<arg()["config-name"]<<endl;
+ if(::arg()["config-name"]!="") {
+ progname+="-"+::arg()["config-name"];
+ L<<Logger::Error<<"Virtual configuration name: "<<::arg()["config-name"]<<endl;
}
newargv[0]=strdup(const_cast<char *>((progname+"-instance").c_str()));
static void UNIX_declareArguments()
{
static char pietje[128]="!@@SYSCONFDIR@@:";
- arg().set("config-dir","Location of configuration directory (pdns.conf)")=
+ ::arg().set("config-dir","Location of configuration directory (pdns.conf)")=
strcmp(pietje+1,"@@SYSCONFDIR@@:") ? pietje+strlen("@@SYSCONFDIR@@:")+1 : SYSCONFDIR;
- arg().set("config-name","Name of this virtual configuration - will rename the binary image")="";
- arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR;
- arg().set("module-dir","Default directory for modules")=LIBDIR;
- arg().set("chroot","If set, chroot to this directory for more security")="";
- arg().set("logging-facility","Log under a specific facility")="";
- arg().set("daemon","Operate as a daemon")="no";
+ ::arg().set("config-name","Name of this virtual configuration - will rename the binary image")="";
+ ::arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR;
+ ::arg().set("module-dir","Default directory for modules")=LIBDIR;
+ ::arg().set("chroot","If set, chroot to this directory for more security")="";
+ ::arg().set("logging-facility","Log under a specific facility")="";
+ ::arg().set("daemon","Operate as a daemon")="no";
}
static void loadModules()
{
- if(!arg()["load-modules"].empty()) {
+ if(!::arg()["load-modules"].empty()) {
vector<string>modules;
- stringtok(modules,arg()["load-modules"],",");
+ stringtok(modules,::arg()["load-modules"],",");
for(vector<string>::const_iterator i=modules.begin();i!=modules.end();++i) {
bool res;
const string &module=*i;
if(module.find(".")==string::npos)
- res=UeberBackend::loadmodule(arg()["module-dir"]+"/lib"+module+"backend.so");
+ res=UeberBackend::loadmodule(::arg()["module-dir"]+"/lib"+module+"backend.so");
else if(module[0]=='/' || (module[0]=='.' && module[1]=='/') || (module[0]=='.' && module[1]=='.')) // absolute or current path
res=UeberBackend::loadmodule(module);
else
- res=UeberBackend::loadmodule(arg()["module-dir"]+"/"+module);
+ res=UeberBackend::loadmodule(::arg()["module-dir"]+"/"+module);
if(res==false) {
L<<Logger::Error<<"receiver unable to load module "<<module<<endl;
declareArguments();
UNIX_declareArguments();
- arg().laxParse(argc,argv); // do a lax parse
+ ::arg().laxParse(argc,argv); // do a lax parse
- if(arg()["config-name"]!="")
- s_programname+="-"+arg()["config-name"];
+ if(::arg()["config-name"]!="")
+ s_programname+="-"+::arg()["config-name"];
(void)theL(s_programname);
- string configname=arg()["config-dir"]+"/"+s_programname+".conf";
+ string configname=::arg()["config-dir"]+"/"+s_programname+".conf";
cleanSlashes(configname);
- if(!arg().mustDo("config") && !arg().mustDo("no-config")) // "config" == print a configuration file
- arg().laxFile(configname.c_str());
+ if(!::arg().mustDo("config") && !::arg().mustDo("no-config")) // "config" == print a configuration file
+ ::arg().laxFile(configname.c_str());
- arg().laxParse(argc,argv); // reparse so the commandline still wins
- if(!arg()["logging-facility"].empty()) {
- boost::optional<int> val=logFacilityToLOG(arg().asNum("logging-facility") );
+ ::arg().laxParse(argc,argv); // reparse so the commandline still wins
+ if(!::arg()["logging-facility"].empty()) {
+ boost::optional<int> val=logFacilityToLOG(::arg().asNum("logging-facility") );
if(val)
theL().setFacility(*val);
else
- L<<Logger::Error<<"Unknown logging facility "<<arg().asNum("logging-facility") <<endl;
+ L<<Logger::Error<<"Unknown logging facility "<<::arg().asNum("logging-facility") <<endl;
}
- L.setLoglevel((Logger::Urgency)(arg().asNum("loglevel")));
- L.toConsole((Logger::Urgency)(arg().asNum("loglevel")));
+ L.setLoglevel((Logger::Urgency)(::arg().asNum("loglevel")));
+ L.toConsole((Logger::Urgency)(::arg().asNum("loglevel")));
- if(arg().mustDo("help") || arg().mustDo("config")) {
- arg().set("daemon")="no";
- arg().set("guardian")="no";
+ if(::arg().mustDo("help") || ::arg().mustDo("config")) {
+ ::arg().set("daemon")="no";
+ ::arg().set("guardian")="no";
}
- if(arg().mustDo("guardian") && !isGuarded(argv)) {
- if(arg().mustDo("daemon")) {
+ if(::arg().mustDo("guardian") && !isGuarded(argv)) {
+ if(::arg().mustDo("daemon")) {
L.toConsole(Logger::Critical);
daemonize();
}
cerr<<"Um, we did get here!"<<endl;
}
- if(arg().mustDo("version")) {
+ if(::arg().mustDo("version")) {
cerr<<"Version: "VERSION", compiled on "<<__DATE__", "__TIME__;
#ifdef __GNUC__
cerr<<" with gcc version "<<__VERSION__;
// we really need to do work - either standalone or as an instance
loadModules();
- BackendMakers().launch(arg()["launch"]); // vrooooom!
+ BackendMakers().launch(::arg()["launch"]); // vrooooom!
- if(!arg().getCommands().empty()) {
+ if(!::arg().getCommands().empty()) {
cerr<<"Fatal: non-option on the command line, perhaps a '--setting=123' statement missed the '='?"<<endl;
exit(99);
}
- if(arg().mustDo("help")) {
+ if(::arg().mustDo("help")) {
cerr<<"syntax:"<<endl<<endl;
- cerr<<arg().helpstring(arg()["help"])<<endl;
+ cerr<<::arg().helpstring(::arg()["help"])<<endl;
exit(99);
}
- if(arg().mustDo("config")) {
- cout<<arg().configstring()<<endl;
+ if(::arg().mustDo("config")) {
+ cout<<::arg().configstring()<<endl;
exit(99);
}
- if(arg().mustDo("list-modules")) {
+ if(::arg().mustDo("list-modules")) {
vector<string>modules=BackendMakers().getModules();
cerr<<"Modules available:"<<endl;
for(vector<string>::const_iterator i=modules.begin();i!=modules.end();++i)
exit(99);
}
- if(!arg().asNum("local-port")) {
+ if(!::arg().asNum("local-port")) {
L<<Logger::Error<<"Unable to launch, binding to no port or port 0 makes no sense"<<endl;
exit(99); // this isn't going to fix itself either
}
L<<Logger::Error<<"Unable to launch, no backends configured for querying"<<endl;
exit(99); // this isn't going to fix itself either
}
- if(arg().mustDo("daemon")) {
+ if(::arg().mustDo("daemon")) {
L.toConsole(Logger::None);
if(!isGuarded(argv))
daemonize();
else {
L<<Logger::Warning<<"This is a standalone pdns"<<endl;
- if(arg().mustDo("control-console"))
+ if(::arg().mustDo("control-console"))
dl=new DynListener();
else
dl=new DynListener(s_programname);
// reparse, with error checking
- if(!arg().mustDo("no-config"))
- arg().file(configname.c_str());
- arg().parse(argc,argv);
+ if(!::arg().mustDo("no-config"))
+ ::arg().file(configname.c_str());
+ ::arg().parse(argc,argv);
UeberBackend::go();
N=new UDPNameserver; // this fails when we are not root, throws exception
- if(!arg().mustDo("disable-tcp"))
+ if(!::arg().mustDo("disable-tcp"))
TN=new TCPNameserver;
}
catch(const ArgException &A) {
mainthread();
}
catch(AhuException &AE) {
- if(!arg().mustDo("daemon"))
+ if(!::arg().mustDo("daemon"))
cerr<<"Exiting because: "<<AE.reason<<endl;
L<<Logger::Error<<"Exiting because: "<<AE.reason<<endl;
}
catch(exception &e) {
- if(!arg().mustDo("daemon"))
+ if(!::arg().mustDo("daemon"))
cerr<<"Exiting because of STL error: "<<e.what()<<endl;
L<<Logger::Error<<"Exiting because of STL error: "<<e.what()<<endl;
}