]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/bindparser.yy
some further empty dnsname checks, although I'm not sure this should be necessary
[thirdparty/pdns.git] / pdns / bindparser.yy
CommitLineData
caa6eefa
BH
1%{
2
12c86877
BH
3#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6#include <string>
7#include <iostream>
8#include <utility>
9#include <errno.h>
10#include "misc.hh"
5c409fa2 11#include "pdnsexception.hh"
9095085b 12#include "namespaces.hh"
12c86877
BH
13#define YYDEBUG 1
14extern int yydebug;
7c0cb150 15#include "bindparserclasses.hh"
12c86877
BH
16
17#define YYSTYPE char *
18
19extern "C"
20{
21 int yyparse(void);
22 int yylex(void);
caa6eefa 23 void yyrestart(FILE *);
12c86877
BH
24 int yywrap()
25 {
26 return 1;
27 }
12c86877 28}
caa6eefa 29
12c86877
BH
30
31extern int yydebug;
32const char *bind_directory;
33extern int linenumber;
34static void yyerror(const char *str)
35{
36 extern char *current_filename;
c761bae7 37 throw PDNSException("Error in bind configuration '"+string(current_filename)+"' on line "+itoa(linenumber)+": "+str);
12c86877
BH
38}
39
40extern FILE *yyin;
41static BindParser *parent;
42BindDomainInfo s_di;
43
44void BindParser::parse(const string &fname)
45{
46 yydebug=0;
47 yyin=fopen(fname.c_str(),"r");
bd11bd1d 48 yyrestart(yyin);
12c86877 49 if(!yyin)
c761bae7 50 throw PDNSException("Unable to open '"+fname+"': "+strerror(errno));
12c86877
BH
51
52 linenumber=1;
53 parent=this;
54 extern char *current_filename;
55 extern char *original_filename;
56
57 current_filename=original_filename=(char*)fname.c_str();
58
59 yyparse();
60
61// cerr<<"Need to parse "<<d_zonedomains.size()<<" zone statements"<<endl;
62}
63
64void BindParser::setDirectory(const string &dir)
65{
66 d_dir=dir;
67 bind_directory=d_dir.c_str();
68}
69
27d94a79
BH
70void BindParser::addAlsoNotify(const string & host)
71{
72 alsoNotify.insert(host);
73}
74
12c86877
BH
75const string &BindParser::getDirectory()
76{
77 return d_dir;
78}
79
80const vector<BindDomainInfo>& BindParser::getDomains()
81{
82 return d_zonedomains;
83}
84
85void BindParser::setVerbose(bool verbose)
86{
87 d_verbose=verbose;
88}
89
90void BindParser::commit(BindDomainInfo DI)
91{
92 if(DI.filename[0]!='/')
93 DI.filename=d_dir+"/"+DI.filename;
94
95 if(d_verbose)
efa2cfa0 96 cerr<<"Domain "<<DI.name.toStringNoDot()<<" lives in file '"<<DI.filename<<"'"<<endl;
12c86877
BH
97
98 d_zonedomains.push_back(DI);
99}
100
101%}
102
caa6eefa 103%token AWORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK
27d94a79 104%token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK ALSONOTIFYTOK
12c86877
BH
105
106%%
107
108root_commands:
109 |
110 root_commands root_command SEMICOLON
111 ;
112
df58857e 113root_command: command | acl_command | global_zone_command | global_options_command
12c86877
BH
114 ;
115
116commands:
117 |
118 commands command SEMICOLON
119 ;
120
121command:
122 terms
123 ;
124
df58857e 125global_zone_command:
12c86877
BH
126 ZONETOK quotedname zone_block
127 {
290a083d 128 s_di.name=DNSName(stripDot($2));
ef96aca0 129 free($2);
12c86877
BH
130 parent->commit(s_di);
131 s_di.clear();
132 }
133 |
caa6eefa 134 ZONETOK quotedname AWORD zone_block
12c86877 135 {
290a083d 136 s_di.name=DNSName(stripDot($2));
ef96aca0 137 free($2);
12c86877
BH
138 parent->commit(s_di);
139 s_di.clear();
140 }
141 ;
142
143
df58857e 144global_options_command:
12c86877
BH
145 OPTIONSTOK OBRACE options_commands EBRACE
146 |
147 LOGGINGTOK OBRACE options_commands EBRACE
148 ;
149
27d94a79 150
12c86877
BH
151acl_command:
152 ACLTOK quotedname acl_block | ACLTOK filename acl_block
153 ;
154
155acl_block: OBRACE acls EBRACE
156 ;
157
158acls:
159 |
160 acl SEMICOLON acls
161 ;
162
163acl:
caa6eefa 164 AWORD
12c86877
BH
165 ;
166
167options_commands:
168 |
169 options_command SEMICOLON options_commands
170 ;
171
df58857e
SB
172options_command: command | global_options_command
173 ;
174
175global_options_command: options_directory_command | also_notify_command
12c86877
BH
176 ;
177
178options_directory_command: DIRECTORYTOK quotedname
179 {
180 parent->setDirectory($2);
ef96aca0 181 free($2);
12c86877
BH
182 }
183 ;
184
27d94a79
BH
185also_notify_command: ALSONOTIFYTOK OBRACE also_notify_list EBRACE
186 ;
187
188also_notify_list:
189 |
190 also_notify SEMICOLON also_notify_list
191 ;
12c86877 192
27d94a79
BH
193also_notify: AWORD
194 {
195 parent->addAlsoNotify($1);
196 free($1);
197 }
198 ;
12c86877
BH
199terms: /* empty */
200 |
201 terms term
202 ;
203
caa6eefa 204term: AWORD | block | quotedname
12c86877
BH
205 ;
206block:
207 OBRACE commands EBRACE
208 ;
209
210zone_block:
211 OBRACE zone_commands EBRACE
212 ;
213
df58857e 214zone_commands:
12c86877
BH
215 |
216 zone_commands zone_command SEMICOLON
217 ;
218
df58857e
SB
219/* commands in zone
220 * in global scope also_notify_command is used instead of zone_also_notify_command
221 */
222zone_command: command | global_zone_command | zone_also_notify_command
223 ;
224
225/* zone commands that also are available at global scope */
226global_zone_command: zone_file_command | zone_type_command | zone_masters_command
12c86877
BH
227 ;
228
229zone_masters_command: MASTERTOK OBRACE masters EBRACE
230 ;
231
27d94a79
BH
232zone_also_notify_command: ALSONOTIFYTOK OBRACE zone_also_notify_list EBRACE
233 ;
234
235zone_also_notify_list:
236 |
237 zone_also_notify SEMICOLON zone_also_notify_list
238 ;
239
240zone_also_notify: AWORD
241 {
242 s_di.alsoNotify.insert($1);
243 free($1);
244 }
245 ;
246
12c86877
BH
247masters: /* empty */
248 |
249 masters master SEMICOLON
250 ;
251
caa6eefa 252master: AWORD
12c86877 253 {
e5b11b2f 254 s_di.masters.push_back($1);
ef96aca0 255 free($1);
12c86877
BH
256 }
257 ;
258
259zone_file_command:
260 FILETOK quotedname
261 {
262 // printf("Found a filename: '%s'\n",$2);
263 s_di.filename=$2;
ef96aca0 264 free($2);
12c86877
BH
265 }
266 ;
267
268zone_type_command:
caa6eefa 269TYPETOK AWORD
12c86877 270 {
973ad2b5 271 s_di.type=$2;
ef96aca0 272 free($2);
12c86877
BH
273 }
274 ;
275
276
277quotedname:
278 QUOTEDWORD
279 {
280 $$=$1;
281 }
282 ;
283
caa6eefa 284filename: AWORD
27d94a79 285 ;