]>
Commit | Line | Data |
---|---|---|
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 |
15 | extern int yydebug; | |
7c0cb150 | 16 | #include "bindparserclasses.hh" |
12c86877 BH |
17 | |
18 | #define YYSTYPE char * | |
19 | ||
20 | extern "C" | |
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 | |
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; | |
564db8c5 | 39 | throw PDNSException("Error in bind configuration '"+string(current_filename)+"' on line "+std::to_string(linenumber)+": "+str); |
12c86877 BH |
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"); | |
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 | ||
66 | void 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 |
75 | void BindParser::addAlsoNotify(const string & host) |
76 | { | |
77 | alsoNotify.insert(host); | |
78 | } | |
79 | ||
12c86877 BH |
80 | const string &BindParser::getDirectory() |
81 | { | |
82 | return d_dir; | |
83 | } | |
84 | ||
85 | const vector<BindDomainInfo>& BindParser::getDomains() | |
86 | { | |
87 | return d_zonedomains; | |
88 | } | |
89 | ||
90 | void BindParser::setVerbose(bool verbose) | |
91 | { | |
92 | d_verbose=verbose; | |
93 | } | |
94 | ||
95 | void 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 | ||
115 | root_commands: | |
116 | | | |
117 | root_commands root_command SEMICOLON | |
118 | ; | |
119 | ||
df58857e | 120 | root_command: command | acl_command | global_zone_command | global_options_command |
12c86877 BH |
121 | ; |
122 | ||
123 | commands: | |
124 | | | |
125 | commands command SEMICOLON | |
126 | ; | |
127 | ||
128 | command: | |
129 | terms | |
130 | ; | |
131 | ||
df58857e | 132 | global_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 | } | |
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 | 151 | global_options_command: |
12c86877 BH |
152 | OPTIONSTOK OBRACE options_commands EBRACE |
153 | | | |
154 | LOGGINGTOK OBRACE options_commands EBRACE | |
155 | ; | |
156 | ||
27d94a79 | 157 | |
12c86877 BH |
158 | acl_command: |
159 | ACLTOK quotedname acl_block | ACLTOK filename acl_block | |
160 | ; | |
161 | ||
162 | acl_block: OBRACE acls EBRACE | |
163 | ; | |
164 | ||
165 | acls: | |
166 | | | |
167 | acl SEMICOLON acls | |
168 | ; | |
169 | ||
170 | acl: | |
caa6eefa | 171 | AWORD |
12c86877 BH |
172 | ; |
173 | ||
174 | options_commands: | |
175 | | | |
176 | options_command SEMICOLON options_commands | |
177 | ; | |
178 | ||
df58857e SB |
179 | options_command: command | global_options_command |
180 | ; | |
181 | ||
182 | global_options_command: options_directory_command | also_notify_command | |
12c86877 BH |
183 | ; |
184 | ||
185 | options_directory_command: DIRECTORYTOK quotedname | |
186 | { | |
187 | parent->setDirectory($2); | |
ef96aca0 | 188 | free($2); |
12c86877 BH |
189 | } |
190 | ; | |
191 | ||
27d94a79 BH |
192 | also_notify_command: ALSONOTIFYTOK OBRACE also_notify_list EBRACE |
193 | ; | |
194 | ||
195 | also_notify_list: | |
196 | | | |
197 | also_notify SEMICOLON also_notify_list | |
198 | ; | |
12c86877 | 199 | |
27d94a79 BH |
200 | also_notify: AWORD |
201 | { | |
202 | parent->addAlsoNotify($1); | |
203 | free($1); | |
204 | } | |
205 | ; | |
12c86877 BH |
206 | terms: /* empty */ |
207 | | | |
208 | terms term | |
209 | ; | |
210 | ||
caa6eefa | 211 | term: AWORD | block | quotedname |
12c86877 BH |
212 | ; |
213 | block: | |
214 | OBRACE commands EBRACE | |
215 | ; | |
216 | ||
217 | zone_block: | |
218 | OBRACE zone_commands EBRACE | |
219 | ; | |
220 | ||
df58857e | 221 | zone_commands: |
12c86877 BH |
222 | | |
223 | zone_commands zone_command SEMICOLON | |
224 | ; | |
225 | ||
df58857e SB |
226 | /* commands in zone |
227 | * in global scope also_notify_command is used instead of zone_also_notify_command | |
228 | */ | |
229 | zone_command: command | global_zone_command | zone_also_notify_command | |
230 | ; | |
231 | ||
232 | /* zone commands that also are available at global scope */ | |
e63e16c1 | 233 | global_zone_command: zone_file_command | zone_type_command | zone_primaries_command |
12c86877 BH |
234 | ; |
235 | ||
e63e16c1 | 236 | zone_primaries_command: PRIMARYTOK OBRACE primaries EBRACE |
12c86877 BH |
237 | ; |
238 | ||
27d94a79 BH |
239 | zone_also_notify_command: ALSONOTIFYTOK OBRACE zone_also_notify_list EBRACE |
240 | ; | |
241 | ||
242 | zone_also_notify_list: | |
243 | | | |
244 | zone_also_notify SEMICOLON zone_also_notify_list | |
245 | ; | |
246 | ||
247 | zone_also_notify: AWORD | |
248 | { | |
249 | s_di.alsoNotify.insert($1); | |
250 | free($1); | |
251 | } | |
252 | ; | |
253 | ||
e63e16c1 | 254 | primaries: /* empty */ |
12c86877 | 255 | | |
e63e16c1 | 256 | primaries primary SEMICOLON |
12c86877 BH |
257 | ; |
258 | ||
e63e16c1 | 259 | primary: AWORD |
12c86877 | 260 | { |
d525b58b | 261 | s_di.primaries.push_back(ComboAddress($1, 53)); |
ef96aca0 | 262 | free($1); |
12c86877 BH |
263 | } |
264 | ; | |
265 | ||
266 | zone_file_command: | |
267 | FILETOK quotedname | |
268 | { | |
269 | // printf("Found a filename: '%s'\n",$2); | |
270 | s_di.filename=$2; | |
ef96aca0 | 271 | free($2); |
12c86877 BH |
272 | } |
273 | ; | |
274 | ||
275 | zone_type_command: | |
caa6eefa | 276 | TYPETOK AWORD |
12c86877 | 277 | { |
973ad2b5 | 278 | s_di.type=$2; |
ef96aca0 | 279 | free($2); |
12c86877 BH |
280 | } |
281 | ; | |
282 | ||
283 | ||
284 | quotedname: | |
285 | QUOTEDWORD | |
286 | { | |
287 | $$=$1; | |
288 | } | |
289 | ; | |
290 | ||
caa6eefa | 291 | filename: AWORD |
27d94a79 | 292 | ; |