]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/dynloader.cc
remove no-op dnslog tool
[thirdparty/pdns.git] / pdns / dynloader.cc
CommitLineData
12c86877
BH
1/*
2 PowerDNS Versatile Database Driven Nameserver
040712e0 3 Copyright (C) 2002 - 2008 PowerDNS.COM BV
12c86877
BH
4
5 This program is free software; you can redistribute it and/or modify
894eff0f
BH
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation
12c86877
BH
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
06bd9ccf 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12c86877
BH
17*/
18#include <iostream>
19#include <cstdio>
20#include <cstring>
21#include <cstdlib>
22#include <unistd.h>
23#include <errno.h>
24#include <climits>
25#include <string>
26#include <map>
27#include <sys/mman.h>
28#include <fcntl.h>
29#include <sys/types.h>
040712e0 30#include <boost/shared_ptr.hpp>
12c86877
BH
31
32#include <sys/stat.h>
33#include "ahuexception.hh"
34#include "misc.hh"
35#include "dynmessenger.hh"
36#include "arguments.hh"
37#include "config.h"
38#include "statbag.hh"
39#include "misc.hh"
10f4eea8 40#include "namespaces.hh"
61b26744 41#include "namespaces.hh"
12c86877
BH
42
43ArgvMap &arg()
44{
45 static ArgvMap arg;
46 return arg;
47}
48
49StatBag S;
50
51int main(int argc, char **argv)
52{
53 string s_programname="pdns";
54 string localdir;
55
56 static char pietje[128]="!@@SYSCONFDIR@@:";
dfeb00b2 57 ::arg().set("config-dir","Location of configuration directory (pdns.conf)")=
12c86877
BH
58 strcmp(pietje+1,"@@SYSCONFDIR@@:") ? pietje+strlen("@@SYSCONFDIR@@:")+1 : SYSCONFDIR;
59
dfeb00b2
BH
60 ::arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR;
61 ::arg().set("remote-address","Remote address to query");
62 ::arg().set("remote-port","Remote port to query")="53000";
63 ::arg().set("secret","Secret needed to connect to remote PowerDNS");
040712e0 64
dfeb00b2
BH
65 ::arg().set("config-name","Name of this virtual configuration - will rename the binary image")="";
66 ::arg().set("chroot","")="";
67 ::arg().setCmd("help","Provide a helpful message");
68 ::arg().laxParse(argc,argv);
12c86877 69
dfeb00b2 70 if(::arg().mustDo("help")) {
894eff0f 71 cerr<<"syntax:"<<endl<<endl;
dfeb00b2 72 cerr<<::arg().helpstring(::arg()["help"])<<endl;
894eff0f
BH
73 exit(99);
74 }
75
dfeb00b2
BH
76 if(::arg()["config-name"]!="")
77 s_programname+="-"+::arg()["config-name"];
12c86877 78
dfeb00b2 79 string configname=::arg()["config-dir"]+"/"+s_programname+".conf";
12c86877
BH
80 cleanSlashes(configname);
81
dfeb00b2
BH
82 ::arg().laxFile(configname.c_str());
83 string socketname=::arg()["socket-dir"]+"/"+s_programname+".controlsocket";
84 if(::arg()["chroot"].empty())
12c86877
BH
85 localdir="/tmp";
86 else
87 localdir=dirname(strdup(socketname.c_str()));
88
dfeb00b2 89 const vector<string>&commands=::arg().getCommands();
12c86877
BH
90
91 if(commands.empty()) {
92 cerr<<"No command passed"<<endl;
93 return 0;
94 }
95
96 try {
97 string command=commands[0];
040712e0 98 shared_ptr<DynMessenger> D;
dfeb00b2 99 if(::arg()["remote-address"].empty())
040712e0
BH
100 D=shared_ptr<DynMessenger>(new DynMessenger(localdir,socketname));
101 else {
102 uint16_t port;
103 try {
4957a608 104 port = lexical_cast<uint16_t>(::arg()["remote-port"]);
040712e0
BH
105 }
106 catch(...) {
4957a608
BH
107 cerr<<"Unable to convert '"<<::arg()["remote-port"]<<"' to a port number for connecting to remote PowerDNS\n";
108 exit(99);
040712e0
BH
109 }
110
dfeb00b2 111 D=shared_ptr<DynMessenger>(new DynMessenger(ComboAddress(::arg()["remote-address"], port), ::arg()["secret"]));
040712e0 112 }
12c86877
BH
113
114 string message;
115 for(vector<string>::const_iterator i=commands.begin();i!=commands.end();++i) {
116 if(i!=commands.begin())
4957a608 117 message+=" ";
12c86877
BH
118 message+=*i;
119 }
120
121 if(command=="show") {
122 message="SHOW ";
123 for(unsigned int n=1;n<commands.size();n++) {
4957a608
BH
124 message+=commands[n];
125 message+=" ";
12c86877
BH
126 }
127 }
128 else if(command=="list") {
129 message="SHOW *";
130 command="show";
131 }
132 else if(command=="quit" || command=="QUIT") {
133 message="QUIT";
134 }
135 else if(command=="status" || command=="STATUS") {
136 message="STATUS";
137 }
138 else if(command=="version" || command=="VERSION") {
139 message="VERSION";
140 }
141
142
040712e0 143 if(D->send(message)<0) {
12c86877
BH
144 cerr<<"Error sending command"<<endl;
145 return 1;
146 }
147
040712e0 148 string resp=D->receive();
12c86877
BH
149
150 cout<<resp<<endl;
151 }
152 catch(AhuException &ae) {
153 cerr<<"Fatal error: "<<ae.reason<<endl;
20ca8e7d 154 return 1;
12c86877
BH
155 }
156 return 0;
157}
158
159