]>
Commit | Line | Data |
---|---|---|
12c86877 BH |
1 | /* |
2 | PowerDNS Versatile Database Driven Nameserver | |
3 | Copyright (C) 2002 PowerDNS.COM BV | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | */ | |
19 | #include <iostream> | |
20 | #include <cstdio> | |
21 | #include <cstring> | |
22 | #include <cstdlib> | |
23 | #include <unistd.h> | |
24 | #include <errno.h> | |
25 | #include <climits> | |
26 | #include <string> | |
27 | #include <map> | |
28 | #include <sys/mman.h> | |
29 | #include <fcntl.h> | |
30 | #include <sys/types.h> | |
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" | |
40 | using namespace std; | |
41 | ||
42 | ArgvMap &arg() | |
43 | { | |
44 | static ArgvMap arg; | |
45 | return arg; | |
46 | } | |
47 | ||
48 | StatBag S; | |
49 | ||
50 | int main(int argc, char **argv) | |
51 | { | |
52 | string s_programname="pdns"; | |
53 | string localdir; | |
54 | ||
55 | static char pietje[128]="!@@SYSCONFDIR@@:"; | |
56 | arg().set("config-dir","Location of configuration directory (pdns.conf)")= | |
57 | strcmp(pietje+1,"@@SYSCONFDIR@@:") ? pietje+strlen("@@SYSCONFDIR@@:")+1 : SYSCONFDIR; | |
58 | ||
59 | arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR; | |
60 | arg().set("config-name","Name of this virtual configuration - will rename the binary image")=""; | |
61 | arg().set("chroot","")=""; | |
62 | arg().laxParse(argc,argv); | |
63 | ||
64 | if(arg()["config-name"]!="") | |
65 | s_programname+="-"+arg()["config-name"]; | |
66 | ||
67 | string configname=arg()["config-dir"]+"/"+s_programname+".conf"; | |
68 | cleanSlashes(configname); | |
69 | ||
70 | arg().laxFile(configname.c_str()); | |
71 | string socketname=arg()["socket-dir"]+"/"+s_programname+".controlsocket"; | |
72 | if(arg()["chroot"].empty()) | |
73 | localdir="/tmp"; | |
74 | else | |
75 | localdir=dirname(strdup(socketname.c_str())); | |
76 | ||
77 | ||
78 | const vector<string>&commands=arg().getCommands(); | |
79 | ||
80 | if(commands.empty()) { | |
81 | cerr<<"No command passed"<<endl; | |
82 | return 0; | |
83 | } | |
84 | ||
85 | try { | |
86 | string command=commands[0]; | |
87 | ||
88 | DynMessenger D(localdir,socketname); | |
89 | ||
90 | string message; | |
91 | for(vector<string>::const_iterator i=commands.begin();i!=commands.end();++i) { | |
92 | if(i!=commands.begin()) | |
93 | message+=" "; | |
94 | message+=*i; | |
95 | } | |
96 | ||
97 | if(command=="show") { | |
98 | message="SHOW "; | |
99 | for(unsigned int n=1;n<commands.size();n++) { | |
100 | message+=commands[n]; | |
101 | message+=" "; | |
102 | } | |
103 | } | |
104 | else if(command=="list") { | |
105 | message="SHOW *"; | |
106 | command="show"; | |
107 | } | |
108 | else if(command=="quit" || command=="QUIT") { | |
109 | message="QUIT"; | |
110 | } | |
111 | else if(command=="status" || command=="STATUS") { | |
112 | message="STATUS"; | |
113 | } | |
114 | else if(command=="version" || command=="VERSION") { | |
115 | message="VERSION"; | |
116 | } | |
117 | ||
118 | ||
119 | if(D.send(message)<0) { | |
120 | cerr<<"Error sending command"<<endl; | |
121 | return 1; | |
122 | } | |
123 | ||
124 | string resp=D.receive(); | |
125 | ||
126 | cout<<resp<<endl; | |
127 | } | |
128 | catch(AhuException &ae) { | |
129 | cerr<<"Fatal error: "<<ae.reason<<endl; | |
130 | } | |
131 | return 0; | |
132 | } | |
133 | ||
134 |