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