]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dynloader.cc
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002 - 2008 PowerDNS.COM BV
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation
9 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <sys/types.h>
34 #include <boost/shared_ptr.hpp>
37 #include "pdnsexception.hh"
39 #include "dynmessenger.hh"
40 #include "arguments.hh"
44 #include "namespaces.hh"
45 #include "namespaces.hh"
55 int main(int argc
, char **argv
)
57 string s_programname
="pdns";
60 ::arg().set("config-dir","Location of configuration directory (pdns.conf)")=SYSCONFDIR
;
61 ::arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR
;
62 ::arg().set("remote-address","Remote address to query");
63 ::arg().set("remote-port","Remote port to query")="53000";
64 ::arg().set("secret","Secret needed to connect to remote PowerDNS");
66 ::arg().set("config-name","Name of this virtual configuration - will rename the binary image")="";
67 ::arg().setCmd("no-config","Don't parse configuration file");
68 ::arg().set("chroot","")="";
69 ::arg().setCmd("help","Provide a helpful message");
70 ::arg().laxParse(argc
,argv
);
72 if(::arg().mustDo("help")) {
73 cout
<<"syntax:"<<endl
<<endl
;
74 cout
<<::arg().helpstring(::arg()["help"])<<endl
;
78 const vector
<string
>commands
=::arg().getCommands();
80 if(commands
.empty()) {
81 cerr
<<"No command passed"<<endl
;
85 if(::arg()["config-name"]!="")
86 s_programname
+="-"+::arg()["config-name"];
88 string configname
=::arg()["config-dir"]+"/"+s_programname
+".conf";
89 cleanSlashes(configname
);
91 if(!::arg().mustDo("no-config")) {
92 ::arg().laxFile(configname
.c_str());
93 ::arg().laxParse(argc
,argv
); // reparse so the commandline still wins
96 string socketname
=::arg()["socket-dir"]+"/"+s_programname
+".controlsocket";
97 cleanSlashes(socketname
);
99 if(::arg()["chroot"].empty())
102 localdir
=dirname(strdup(socketname
.c_str()));
105 string command
=commands
[0];
106 shared_ptr
<DynMessenger
> D
;
107 if(::arg()["remote-address"].empty())
108 D
=shared_ptr
<DynMessenger
>(new DynMessenger(localdir
,socketname
));
112 port
= lexical_cast
<uint16_t>(::arg()["remote-port"]);
115 cerr
<<"Unable to convert '"<<::arg()["remote-port"]<<"' to a port number for connecting to remote PowerDNS\n";
119 D
=shared_ptr
<DynMessenger
>(new DynMessenger(ComboAddress(::arg()["remote-address"], port
), ::arg()["secret"]));
123 for(vector
<string
>::const_iterator i
=commands
.begin();i
!=commands
.end();++i
) {
124 if(i
!=commands
.begin())
129 if(command
=="show") {
131 for(unsigned int n
=1;n
<commands
.size();n
++) {
132 message
+=commands
[n
];
136 else if(command
=="list") {
140 else if(command
=="quit" || command
=="QUIT") {
143 else if(command
=="status" || command
=="STATUS") {
146 else if(command
=="version" || command
=="VERSION") {
151 if(D
->send(message
)<0) {
152 cerr
<<"Error sending command"<<endl
;
156 string resp
=D
->receive();
160 catch(TimeoutException
&ae
) {
161 cerr
<<"Timeout error: "<<ae
.reason
<<endl
;
164 catch(PDNSException
&ae
) {
165 cerr
<<"Fatal error: "<<ae
.reason
<<endl
;