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