]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/bind9/lib/isccfg/namedconf.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / bind9 / lib / isccfg / namedconf.c
1 /*
2  * Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2002, 2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: namedconf.c,v 1.92 2008/09/27 23:35:31 jinmei Exp $ */
19
20 /*! \file */
21
22 #include <config.h>
23
24 #include <string.h>
25
26 #include <isc/lex.h>
27 #include <isc/result.h>
28 #include <isc/string.h>
29 #include <isc/util.h>
30
31 #include <isccfg/cfg.h>
32 #include <isccfg/grammar.h>
33 #include <isccfg/log.h>
34
35 #define TOKEN_STRING(pctx) (pctx->token.value.as_textregion.base)
36
37 /*% Check a return value. */
38 #define CHECK(op)                                               \
39         do { result = (op);                                     \
40                 if (result != ISC_R_SUCCESS) goto cleanup;      \
41         } while (0)
42
43 /*% Clean up a configuration object if non-NULL. */
44 #define CLEANUP_OBJ(obj) \
45         do { if ((obj) != NULL) cfg_obj_destroy(pctx, &(obj)); } while (0)
46
47
48 /*%
49  * Forward declarations of static functions.
50  */
51
52 static isc_result_t
53 parse_enum_or_other(cfg_parser_t *pctx, const cfg_type_t *enumtype,
54                     const cfg_type_t *othertype, cfg_obj_t **ret);
55
56 static isc_result_t
57 parse_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
58
59 static isc_result_t
60 parse_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);
61
62 static void
63 print_keyvalue(cfg_printer_t *pctx, const cfg_obj_t *obj);
64
65 static void
66 doc_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);
67
68 static void
69 doc_optional_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);
70
71 static cfg_type_t cfg_type_acl;
72 static cfg_type_t cfg_type_addrmatchelt;
73 static cfg_type_t cfg_type_bracketed_aml;
74 static cfg_type_t cfg_type_bracketed_namesockaddrkeylist;
75 static cfg_type_t cfg_type_bracketed_sockaddrlist;
76 static cfg_type_t cfg_type_bracketed_sockaddrnameportlist;
77 static cfg_type_t cfg_type_controls;
78 static cfg_type_t cfg_type_controls_sockaddr;
79 static cfg_type_t cfg_type_destinationlist;
80 static cfg_type_t cfg_type_dialuptype;
81 static cfg_type_t cfg_type_ixfrdifftype;
82 static cfg_type_t cfg_type_key;
83 static cfg_type_t cfg_type_logfile;
84 static cfg_type_t cfg_type_logging;
85 static cfg_type_t cfg_type_logseverity;
86 static cfg_type_t cfg_type_lwres;
87 static cfg_type_t cfg_type_masterselement;
88 static cfg_type_t cfg_type_nameportiplist;
89 static cfg_type_t cfg_type_negated;
90 static cfg_type_t cfg_type_notifytype;
91 static cfg_type_t cfg_type_optional_allow;
92 static cfg_type_t cfg_type_optional_class;
93 static cfg_type_t cfg_type_optional_facility;
94 static cfg_type_t cfg_type_optional_keyref;
95 static cfg_type_t cfg_type_optional_port;
96 static cfg_type_t cfg_type_options;
97 static cfg_type_t cfg_type_portiplist;
98 static cfg_type_t cfg_type_querysource4;
99 static cfg_type_t cfg_type_querysource6;
100 static cfg_type_t cfg_type_querysource;
101 static cfg_type_t cfg_type_server;
102 static cfg_type_t cfg_type_server_key_kludge;
103 static cfg_type_t cfg_type_size;
104 static cfg_type_t cfg_type_sizenodefault;
105 static cfg_type_t cfg_type_sockaddr4wild;
106 static cfg_type_t cfg_type_sockaddr6wild;
107 static cfg_type_t cfg_type_statschannels;
108 static cfg_type_t cfg_type_view;
109 static cfg_type_t cfg_type_viewopts;
110 static cfg_type_t cfg_type_zone;
111 static cfg_type_t cfg_type_zoneopts;
112 static cfg_type_t cfg_type_dynamically_loadable_zones;
113 static cfg_type_t cfg_type_dynamically_loadable_zones_opts;
114
115 /*
116  * Clauses that can be found in a 'dynamically loadable zones' statement
117  */
118 static cfg_clausedef_t
119 dynamically_loadable_zones_clauses[] = {
120         { "database", &cfg_type_astring, 0 },
121         { NULL, NULL, 0 }
122 };
123
124 /*
125  * A dynamically loadable zones statement.
126  */
127 static cfg_tuplefielddef_t dynamically_loadable_zones_fields[] = {
128         { "name", &cfg_type_astring, 0 },
129         { "options", &cfg_type_dynamically_loadable_zones_opts, 0 },
130         { NULL, NULL, 0 }
131 };
132
133 static cfg_type_t cfg_type_dynamically_loadable_zones = {
134         "dlz", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
135         &cfg_rep_tuple,
136         dynamically_loadable_zones_fields
137         };
138
139
140 /*% tkey-dhkey */
141
142 static cfg_tuplefielddef_t tkey_dhkey_fields[] = {
143         { "name", &cfg_type_qstring, 0 },
144         { "keyid", &cfg_type_uint32, 0 },
145         { NULL, NULL, 0 }
146 };
147
148 static cfg_type_t cfg_type_tkey_dhkey = {
149         "tkey-dhkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
150         tkey_dhkey_fields
151 };
152
153 /*% listen-on */
154
155 static cfg_tuplefielddef_t listenon_fields[] = {
156         { "port", &cfg_type_optional_port, 0 },
157         { "acl", &cfg_type_bracketed_aml, 0 },
158         { NULL, NULL, 0 }
159 };
160 static cfg_type_t cfg_type_listenon = {
161         "listenon", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, listenon_fields };
162
163 /*% acl */
164
165 static cfg_tuplefielddef_t acl_fields[] = {
166         { "name", &cfg_type_astring, 0 },
167         { "value", &cfg_type_bracketed_aml, 0 },
168         { NULL, NULL, 0 }
169 };
170
171 static cfg_type_t cfg_type_acl = {
172         "acl", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, acl_fields };
173
174 /*% masters */
175 static cfg_tuplefielddef_t masters_fields[] = {
176         { "name", &cfg_type_astring, 0 },
177         { "port", &cfg_type_optional_port, 0 },
178         { "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 },
179         { NULL, NULL, 0 }
180 };
181
182 static cfg_type_t cfg_type_masters = {
183         "masters", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, masters_fields };
184
185 /*%
186  * "sockaddrkeylist", a list of socket addresses with optional keys
187  * and an optional default port, as used in the masters option.
188  * E.g.,
189  *   "port 1234 { mymasters; 10.0.0.1 key foo; 1::2 port 69; }"
190  */
191
192 static cfg_tuplefielddef_t namesockaddrkey_fields[] = {
193         { "masterselement", &cfg_type_masterselement, 0 },
194         { "key", &cfg_type_optional_keyref, 0 },
195         { NULL, NULL, 0 },
196 };
197
198 static cfg_type_t cfg_type_namesockaddrkey = {
199         "namesockaddrkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
200         namesockaddrkey_fields
201 };
202
203 static cfg_type_t cfg_type_bracketed_namesockaddrkeylist = {
204         "bracketed_namesockaddrkeylist", cfg_parse_bracketed_list,
205         cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_namesockaddrkey
206 };
207
208 static cfg_tuplefielddef_t namesockaddrkeylist_fields[] = {
209         { "port", &cfg_type_optional_port, 0 },
210         { "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 },
211         { NULL, NULL, 0 }
212 };
213 static cfg_type_t cfg_type_namesockaddrkeylist = {
214         "sockaddrkeylist", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
215         namesockaddrkeylist_fields
216 };
217
218 /*%
219  * A list of socket addresses with an optional default port,
220  * as used in the also-notify option.  E.g.,
221  * "port 1234 { 10.0.0.1; 1::2 port 69; }"
222  */
223 static cfg_tuplefielddef_t portiplist_fields[] = {
224         { "port", &cfg_type_optional_port, 0 },
225         { "addresses", &cfg_type_bracketed_sockaddrlist, 0 },
226         { NULL, NULL, 0 }
227 };
228 static cfg_type_t cfg_type_portiplist = {
229         "portiplist", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
230         portiplist_fields
231 };
232
233 /*%
234  * A public key, as in the "pubkey" statement.
235  */
236 static cfg_tuplefielddef_t pubkey_fields[] = {
237         { "flags", &cfg_type_uint32, 0 },
238         { "protocol", &cfg_type_uint32, 0 },
239         { "algorithm", &cfg_type_uint32, 0 },
240         { "key", &cfg_type_qstring, 0 },
241         { NULL, NULL, 0 }
242 };
243 static cfg_type_t cfg_type_pubkey = {
244         "pubkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, pubkey_fields };
245
246 /*%
247  * A list of RR types, used in grant statements.
248  * Note that the old parser allows quotes around the RR type names.
249  */
250 static cfg_type_t cfg_type_rrtypelist = {
251         "rrtypelist", cfg_parse_spacelist, cfg_print_spacelist, cfg_doc_terminal,
252         &cfg_rep_list, &cfg_type_astring
253 };
254
255 static const char *mode_enums[] = { "grant", "deny", NULL };
256 static cfg_type_t cfg_type_mode = {
257         "mode", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
258         &mode_enums
259 };
260
261 static const char *matchtype_enums[] = {
262         "name", "subdomain", "wildcard", "self", "selfsub", "selfwild",
263         "krb5-self", "ms-self", "krb5-subdomain", "ms-subdomain",
264         "tcp-self", "6to4-self", NULL };
265 static cfg_type_t cfg_type_matchtype = {
266         "matchtype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
267         &matchtype_enums
268 };
269
270 /*%
271  * A grant statement, used in the update policy.
272  */
273 static cfg_tuplefielddef_t grant_fields[] = {
274         { "mode", &cfg_type_mode, 0 },
275         { "identity", &cfg_type_astring, 0 }, /* domain name */
276         { "matchtype", &cfg_type_matchtype, 0 },
277         { "name", &cfg_type_astring, 0 }, /* domain name */
278         { "types", &cfg_type_rrtypelist, 0 },
279         { NULL, NULL, 0 }
280 };
281 static cfg_type_t cfg_type_grant = {
282         "grant", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, grant_fields };
283
284 static cfg_type_t cfg_type_updatepolicy = {
285         "update_policy", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list,
286         &cfg_rep_list, &cfg_type_grant
287 };
288
289 /*%
290  * A view statement.
291  */
292 static cfg_tuplefielddef_t view_fields[] = {
293         { "name", &cfg_type_astring, 0 },
294         { "class", &cfg_type_optional_class, 0 },
295         { "options", &cfg_type_viewopts, 0 },
296         { NULL, NULL, 0 }
297 };
298 static cfg_type_t cfg_type_view = {
299         "view", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, view_fields };
300
301 /*%
302  * A zone statement.
303  */
304 static cfg_tuplefielddef_t zone_fields[] = {
305         { "name", &cfg_type_astring, 0 },
306         { "class", &cfg_type_optional_class, 0 },
307         { "options", &cfg_type_zoneopts, 0 },
308         { NULL, NULL, 0 }
309 };
310 static cfg_type_t cfg_type_zone = {
311         "zone", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, zone_fields };
312
313 /*%
314  * A "category" clause in the "logging" statement.
315  */
316 static cfg_tuplefielddef_t category_fields[] = {
317         { "name", &cfg_type_astring, 0 },
318         { "destinations", &cfg_type_destinationlist,0 },
319         { NULL, NULL, 0 }
320 };
321 static cfg_type_t cfg_type_category = {
322         "category", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, category_fields };
323
324
325 /*%
326  * A trusted key, as used in the "trusted-keys" statement.
327  */
328 static cfg_tuplefielddef_t trustedkey_fields[] = {
329         { "name", &cfg_type_astring, 0 },
330         { "flags", &cfg_type_uint32, 0 },
331         { "protocol", &cfg_type_uint32, 0 },
332         { "algorithm", &cfg_type_uint32, 0 },
333         { "key", &cfg_type_qstring, 0 },
334         { NULL, NULL, 0 }
335 };
336 static cfg_type_t cfg_type_trustedkey = {
337         "trustedkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
338         trustedkey_fields
339 };
340
341 static keyword_type_t wild_class_kw = { "class", &cfg_type_ustring };
342
343 static cfg_type_t cfg_type_optional_wild_class = {
344         "optional_wild_class", parse_optional_keyvalue, print_keyvalue,
345         doc_optional_keyvalue, &cfg_rep_string, &wild_class_kw
346 };
347
348 static keyword_type_t wild_type_kw = { "type", &cfg_type_ustring };
349
350 static cfg_type_t cfg_type_optional_wild_type = {
351         "optional_wild_type", parse_optional_keyvalue,
352         print_keyvalue, doc_optional_keyvalue, &cfg_rep_string, &wild_type_kw
353 };
354
355 static keyword_type_t wild_name_kw = { "name", &cfg_type_qstring };
356
357 static cfg_type_t cfg_type_optional_wild_name = {
358         "optional_wild_name", parse_optional_keyvalue,
359         print_keyvalue, doc_optional_keyvalue, &cfg_rep_string, &wild_name_kw
360 };
361
362 /*%
363  * An rrset ordering element.
364  */
365 static cfg_tuplefielddef_t rrsetorderingelement_fields[] = {
366         { "class", &cfg_type_optional_wild_class, 0 },
367         { "type", &cfg_type_optional_wild_type, 0 },
368         { "name", &cfg_type_optional_wild_name, 0 },
369         { "order", &cfg_type_ustring, 0 }, /* must be literal "order" */
370         { "ordering", &cfg_type_ustring, 0 },
371         { NULL, NULL, 0 }
372 };
373 static cfg_type_t cfg_type_rrsetorderingelement = {
374         "rrsetorderingelement", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
375         rrsetorderingelement_fields
376 };
377
378 /*%
379  * A global or view "check-names" option.  Note that the zone
380  * "check-names" option has a different syntax.
381  */
382
383 static const char *checktype_enums[] = { "master", "slave", "response", NULL };
384 static cfg_type_t cfg_type_checktype = {
385         "checktype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
386         &cfg_rep_string, &checktype_enums
387 };
388
389 static const char *checkmode_enums[] = { "fail", "warn", "ignore", NULL };
390 static cfg_type_t cfg_type_checkmode = {
391         "checkmode", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
392         &cfg_rep_string, &checkmode_enums
393 };
394
395 static cfg_tuplefielddef_t checknames_fields[] = {
396         { "type", &cfg_type_checktype, 0 },
397         { "mode", &cfg_type_checkmode, 0 },
398         { NULL, NULL, 0 }
399 };
400 static cfg_type_t cfg_type_checknames = {
401         "checknames", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
402         checknames_fields
403 };
404
405 static cfg_type_t cfg_type_bracketed_sockaddrlist = {
406         "bracketed_sockaddrlist", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list,
407         &cfg_rep_list, &cfg_type_sockaddr
408 };
409
410 static cfg_type_t cfg_type_rrsetorder = {
411         "rrsetorder", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list,
412         &cfg_rep_list, &cfg_type_rrsetorderingelement
413 };
414
415 static keyword_type_t port_kw = { "port", &cfg_type_uint32 };
416
417 static cfg_type_t cfg_type_optional_port = {
418         "optional_port", parse_optional_keyvalue, print_keyvalue,
419         doc_optional_keyvalue, &cfg_rep_uint32, &port_kw
420 };
421
422 /*% A list of keys, as in the "key" clause of the controls statement. */
423 static cfg_type_t cfg_type_keylist = {
424         "keylist", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list,
425         &cfg_type_astring
426 };
427
428 static cfg_type_t cfg_type_trustedkeys = {
429         "trusted-keys", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list,
430         &cfg_type_trustedkey
431 };
432
433 static const char *forwardtype_enums[] = { "first", "only", NULL };
434 static cfg_type_t cfg_type_forwardtype = {
435         "forwardtype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
436         &forwardtype_enums
437 };
438
439 static const char *zonetype_enums[] = {
440         "master", "slave", "stub", "hint", "forward", "delegation-only", NULL };
441 static cfg_type_t cfg_type_zonetype = {
442         "zonetype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
443         &cfg_rep_string, &zonetype_enums
444 };
445
446 static const char *loglevel_enums[] = {
447         "critical", "error", "warning", "notice", "info", "dynamic", NULL };
448 static cfg_type_t cfg_type_loglevel = {
449         "loglevel", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
450         &loglevel_enums
451 };
452
453 static const char *transferformat_enums[] = {
454         "many-answers", "one-answer", NULL };
455 static cfg_type_t cfg_type_transferformat = {
456         "transferformat", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
457         &transferformat_enums
458 };
459
460 /*%
461  * The special keyword "none", as used in the pid-file option.
462  */
463
464 static void
465 print_none(cfg_printer_t *pctx, const cfg_obj_t *obj) {
466         UNUSED(obj);
467         cfg_print_chars(pctx, "none", 4);
468 }
469
470 static cfg_type_t cfg_type_none = {
471         "none", NULL, print_none, NULL, &cfg_rep_void, NULL
472 };
473
474 /*%
475  * A quoted string or the special keyword "none".  Used in the pid-file option.
476  */
477 static isc_result_t
478 parse_qstringornone(cfg_parser_t *pctx, const cfg_type_t *type,
479                     cfg_obj_t **ret)
480 {
481         isc_result_t result;
482         CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
483         if (pctx->token.type == isc_tokentype_string &&
484             strcasecmp(TOKEN_STRING(pctx), "none") == 0)
485                 return (cfg_create_obj(pctx, &cfg_type_none, ret));
486         cfg_ungettoken(pctx);
487         return (cfg_parse_qstring(pctx, type, ret));
488  cleanup:
489         return (result);
490 }
491
492 static void
493 doc_qstringornone(cfg_printer_t *pctx, const cfg_type_t *type) {
494         UNUSED(type);
495         cfg_print_chars(pctx, "( <quoted_string> | none )", 26);
496 }
497
498 static cfg_type_t cfg_type_qstringornone = {
499         "qstringornone", parse_qstringornone, NULL, doc_qstringornone, NULL, NULL };
500
501 /*%
502  * keyword hostname
503  */
504
505 static void
506 print_hostname(cfg_printer_t *pctx, const cfg_obj_t *obj) {
507         UNUSED(obj);
508         cfg_print_chars(pctx, "hostname", 4);
509 }
510
511 static cfg_type_t cfg_type_hostname = {
512         "hostname", NULL, print_hostname, NULL, &cfg_rep_boolean, NULL
513 };
514
515 /*%
516  * "server-id" argument.
517  */
518
519 static isc_result_t
520 parse_serverid(cfg_parser_t *pctx, const cfg_type_t *type,
521                     cfg_obj_t **ret)
522 {
523         isc_result_t result;
524         CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
525         if (pctx->token.type == isc_tokentype_string &&
526             strcasecmp(TOKEN_STRING(pctx), "none") == 0)
527                 return (cfg_create_obj(pctx, &cfg_type_none, ret));
528         if (pctx->token.type == isc_tokentype_string &&
529             strcasecmp(TOKEN_STRING(pctx), "hostname") == 0) {
530                 return (cfg_create_obj(pctx, &cfg_type_hostname, ret));
531         }
532         cfg_ungettoken(pctx);
533         return (cfg_parse_qstring(pctx, type, ret));
534  cleanup:
535         return (result);
536 }
537
538 static void
539 doc_serverid(cfg_printer_t *pctx, const cfg_type_t *type) {
540         UNUSED(type);
541         cfg_print_chars(pctx, "( <quoted_string> | none | hostname )", 26);
542 }
543
544 static cfg_type_t cfg_type_serverid = {
545         "serverid", parse_serverid, NULL, doc_serverid, NULL, NULL };
546
547 /*%
548  * Port list.
549  */
550 static cfg_tuplefielddef_t porttuple_fields[] = {
551         { "loport", &cfg_type_uint32, 0 },
552         { "hiport", &cfg_type_uint32, 0 },
553         { NULL, NULL, 0 }
554 };
555 static cfg_type_t cfg_type_porttuple = {
556         "porttuple", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
557         &cfg_rep_tuple, porttuple_fields
558 };
559
560 static isc_result_t
561 parse_port(cfg_parser_t *pctx, cfg_obj_t **ret) {
562         isc_result_t result;
563
564         CHECK(cfg_parse_uint32(pctx, NULL, ret));
565         if ((*ret)->value.uint32 > 0xffff) {
566                 cfg_parser_error(pctx, CFG_LOG_NEAR, "invalid port");
567                 cfg_obj_destroy(pctx, ret);
568                 result = ISC_R_RANGE;
569         }
570
571  cleanup:
572         return (result);
573 }
574
575 static isc_result_t
576 parse_portrange(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
577         isc_result_t result;
578         cfg_obj_t *obj = NULL;
579
580         UNUSED(type);
581
582         CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
583         if (pctx->token.type == isc_tokentype_number)
584                 CHECK(parse_port(pctx, ret));
585         else {
586                 CHECK(cfg_gettoken(pctx, 0));
587                 if (pctx->token.type != isc_tokentype_string ||
588                     strcasecmp(TOKEN_STRING(pctx), "range") != 0) {
589                         cfg_parser_error(pctx, CFG_LOG_NEAR,
590                                          "expected integer or 'range'");
591                         return (ISC_R_UNEXPECTEDTOKEN);
592                 }
593                 CHECK(cfg_create_tuple(pctx, &cfg_type_porttuple, &obj));
594                 CHECK(parse_port(pctx, &obj->value.tuple[0]));
595                 CHECK(parse_port(pctx, &obj->value.tuple[1]));
596                 if (obj->value.tuple[0]->value.uint32 >
597                     obj->value.tuple[1]->value.uint32) {
598                         cfg_parser_error(pctx, CFG_LOG_NOPREP,
599                                          "low port '%u' must not be larger "
600                                          "than high port",
601                                          obj->value.tuple[0]->value.uint32);
602                         result = ISC_R_RANGE;
603                         goto cleanup;
604                 }
605                 *ret = obj;
606                 obj = NULL;
607         }
608
609  cleanup:
610         if (obj != NULL)
611                 cfg_obj_destroy(pctx, &obj);
612         return (result);
613 }
614
615 static cfg_type_t cfg_type_portrange = {
616         "portrange", parse_portrange, NULL, cfg_doc_terminal,
617         NULL, NULL
618 };
619
620 static cfg_type_t cfg_type_bracketed_portlist = {
621         "bracketed_sockaddrlist", cfg_parse_bracketed_list,
622         cfg_print_bracketed_list, cfg_doc_bracketed_list,
623         &cfg_rep_list, &cfg_type_portrange
624 };
625
626 /*%
627  * Clauses that can be found within the top level of the named.conf
628  * file only.
629  */
630 static cfg_clausedef_t
631 namedconf_clauses[] = {
632         { "options", &cfg_type_options, 0 },
633         { "controls", &cfg_type_controls, CFG_CLAUSEFLAG_MULTI },
634         { "acl", &cfg_type_acl, CFG_CLAUSEFLAG_MULTI },
635         { "masters", &cfg_type_masters, CFG_CLAUSEFLAG_MULTI },
636         { "logging", &cfg_type_logging, 0 },
637         { "view", &cfg_type_view, CFG_CLAUSEFLAG_MULTI },
638         { "lwres", &cfg_type_lwres, CFG_CLAUSEFLAG_MULTI },
639         { "statistics-channels", &cfg_type_statschannels,
640           CFG_CLAUSEFLAG_MULTI },
641         { NULL, NULL, 0 }
642 };
643
644 /*%
645  * Clauses that can occur at the top level or in the view
646  * statement, but not in the options block.
647  */
648 static cfg_clausedef_t
649 namedconf_or_view_clauses[] = {
650         { "key", &cfg_type_key, CFG_CLAUSEFLAG_MULTI },
651         { "zone", &cfg_type_zone, CFG_CLAUSEFLAG_MULTI },
652         /* only 1 DLZ per view allowed */
653         { "dlz", &cfg_type_dynamically_loadable_zones, 0 },
654         { "server", &cfg_type_server, CFG_CLAUSEFLAG_MULTI },
655         { "trusted-keys", &cfg_type_trustedkeys, CFG_CLAUSEFLAG_MULTI },
656         { NULL, NULL, 0 }
657 };
658
659 /*%
660  * Clauses that can be found within the 'options' statement.
661  */
662 static cfg_clausedef_t
663 options_clauses[] = {
664         { "use-v4-udp-ports", &cfg_type_bracketed_portlist, 0 },
665         { "use-v6-udp-ports", &cfg_type_bracketed_portlist, 0 },
666         { "avoid-v4-udp-ports", &cfg_type_bracketed_portlist, 0 },
667         { "avoid-v6-udp-ports", &cfg_type_bracketed_portlist, 0 },
668         { "blackhole", &cfg_type_bracketed_aml, 0 },
669         { "coresize", &cfg_type_size, 0 },
670         { "datasize", &cfg_type_size, 0 },
671         { "deallocate-on-exit", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
672         { "directory", &cfg_type_qstring, CFG_CLAUSEFLAG_CALLBACK },
673         { "dump-file", &cfg_type_qstring, 0 },
674         { "fake-iquery", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
675         { "files", &cfg_type_size, 0 },
676         { "has-old-clients", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
677         { "heartbeat-interval", &cfg_type_uint32, 0 },
678         { "host-statistics", &cfg_type_boolean, CFG_CLAUSEFLAG_NOTIMP },
679         { "host-statistics-max", &cfg_type_uint32, CFG_CLAUSEFLAG_NOTIMP },
680         { "hostname", &cfg_type_qstringornone, 0 },
681         { "interface-interval", &cfg_type_uint32, 0 },
682         { "listen-on", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
683         { "listen-on-v6", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
684         { "match-mapped-addresses", &cfg_type_boolean, 0 },
685         { "memstatistics-file", &cfg_type_qstring, 0 },
686         { "memstatistics", &cfg_type_boolean, 0 },
687         { "multiple-cnames", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
688         { "named-xfer", &cfg_type_qstring, CFG_CLAUSEFLAG_OBSOLETE },
689         { "pid-file", &cfg_type_qstringornone, 0 },
690         { "port", &cfg_type_uint32, 0 },
691         { "querylog", &cfg_type_boolean, 0 },
692         { "recursing-file", &cfg_type_qstring, 0 },
693         { "random-device", &cfg_type_qstring, 0 },
694         { "recursive-clients", &cfg_type_uint32, 0 },
695         { "reserved-sockets", &cfg_type_uint32, 0 },
696         { "serial-queries", &cfg_type_uint32, CFG_CLAUSEFLAG_OBSOLETE },
697         { "serial-query-rate", &cfg_type_uint32, 0 },
698         { "server-id", &cfg_type_serverid, 0 },
699         { "stacksize", &cfg_type_size, 0 },
700         { "statistics-file", &cfg_type_qstring, 0 },
701         { "statistics-interval", &cfg_type_uint32, CFG_CLAUSEFLAG_NYI },
702         { "tcp-clients", &cfg_type_uint32, 0 },
703         { "tcp-listen-queue", &cfg_type_uint32, 0 },
704         { "tkey-dhkey", &cfg_type_tkey_dhkey, 0 },
705         { "tkey-gssapi-credential", &cfg_type_qstring, 0 },
706         { "tkey-domain", &cfg_type_qstring, 0 },
707         { "transfers-per-ns", &cfg_type_uint32, 0 },
708         { "transfers-in", &cfg_type_uint32, 0 },
709         { "transfers-out", &cfg_type_uint32, 0 },
710         { "treat-cr-as-space", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
711         { "use-id-pool", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
712         { "use-ixfr", &cfg_type_boolean, 0 },
713         { "version", &cfg_type_qstringornone, 0 },
714         { "flush-zones-on-shutdown", &cfg_type_boolean, 0 },
715         { NULL, NULL, 0 }
716 };
717
718
719 static cfg_type_t cfg_type_namelist = {
720         "namelist", cfg_parse_bracketed_list, cfg_print_bracketed_list,
721         cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_qstring };
722
723 static keyword_type_t exclude_kw = { "exclude", &cfg_type_namelist };
724
725 static cfg_type_t cfg_type_optional_exclude = {
726         "optional_exclude", parse_optional_keyvalue, print_keyvalue,
727         doc_optional_keyvalue, &cfg_rep_list, &exclude_kw };
728
729 static cfg_type_t cfg_type_algorithmlist = {
730         "algorithmlist", cfg_parse_bracketed_list, cfg_print_bracketed_list,
731         cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_astring };
732
733 static cfg_tuplefielddef_t disablealgorithm_fields[] = {
734         { "name", &cfg_type_astring, 0 },
735         { "algorithms", &cfg_type_algorithmlist, 0 },
736         { NULL, NULL, 0 }
737 };
738
739 static cfg_type_t cfg_type_disablealgorithm = {
740         "disablealgorithm", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
741         &cfg_rep_tuple, disablealgorithm_fields
742 };
743
744 static cfg_tuplefielddef_t mustbesecure_fields[] = {
745         { "name", &cfg_type_astring, 0 },
746         { "value", &cfg_type_boolean, 0 },
747         { NULL, NULL, 0 }
748 };
749
750 static cfg_type_t cfg_type_mustbesecure = {
751         "mustbesecure", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
752         &cfg_rep_tuple, mustbesecure_fields
753 };
754
755 static const char *masterformat_enums[] = { "text", "raw", NULL };
756 static cfg_type_t cfg_type_masterformat = {
757         "masterformat", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
758         &cfg_rep_string, &masterformat_enums
759 };
760
761 /*%
762  * dnssec-lookaside
763  */
764
765 static keyword_type_t trustanchor_kw = { "trust-anchor", &cfg_type_astring };
766
767 static cfg_type_t cfg_type_trustanchor = {
768         "trust-anchor", parse_keyvalue, print_keyvalue, doc_keyvalue,
769         &cfg_rep_string, &trustanchor_kw
770 };
771
772 static cfg_tuplefielddef_t lookaside_fields[] = {
773         { "domain", &cfg_type_astring, 0 },
774         { "trust-anchor", &cfg_type_trustanchor, 0 },
775         { NULL, NULL, 0 }
776 };
777
778 static cfg_type_t cfg_type_lookaside = {
779         "lookaside", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
780         &cfg_rep_tuple, lookaside_fields
781 };
782
783 /*%
784  * Clauses that can be found within the 'view' statement,
785  * with defaults in the 'options' statement.
786  */
787
788 static cfg_clausedef_t
789 view_clauses[] = {
790         { "acache-cleaning-interval", &cfg_type_uint32, 0 },
791         { "acache-enable", &cfg_type_boolean, 0 },
792         { "additional-from-auth", &cfg_type_boolean, 0 },
793         { "additional-from-cache", &cfg_type_boolean, 0 },
794         { "allow-query-cache", &cfg_type_bracketed_aml, 0 },
795         { "allow-query-cache-on", &cfg_type_bracketed_aml, 0 },
796         { "allow-recursion", &cfg_type_bracketed_aml, 0 },
797         { "allow-recursion-on", &cfg_type_bracketed_aml, 0 },
798         { "allow-v6-synthesis", &cfg_type_bracketed_aml,
799           CFG_CLAUSEFLAG_OBSOLETE },
800         { "auth-nxdomain", &cfg_type_boolean, CFG_CLAUSEFLAG_NEWDEFAULT },
801         { "cache-file", &cfg_type_qstring, 0 },
802         { "check-names", &cfg_type_checknames, CFG_CLAUSEFLAG_MULTI },
803         { "cleaning-interval", &cfg_type_uint32, 0 },
804         { "clients-per-query", &cfg_type_uint32, 0 },
805         { "disable-algorithms", &cfg_type_disablealgorithm,
806           CFG_CLAUSEFLAG_MULTI },
807         { "disable-empty-zone", &cfg_type_astring, CFG_CLAUSEFLAG_MULTI },
808         { "dnssec-accept-expired", &cfg_type_boolean, 0 },
809         { "dnssec-enable", &cfg_type_boolean, 0 },
810         { "dnssec-lookaside", &cfg_type_lookaside, CFG_CLAUSEFLAG_MULTI },
811         { "dnssec-must-be-secure",  &cfg_type_mustbesecure,
812           CFG_CLAUSEFLAG_MULTI },
813         { "dnssec-validation", &cfg_type_boolean, 0 },
814         { "dual-stack-servers", &cfg_type_nameportiplist, 0 },
815         { "edns-udp-size", &cfg_type_uint32, 0 },
816         { "empty-contact", &cfg_type_astring, 0 },
817         { "empty-server", &cfg_type_astring, 0 },
818         { "empty-zones-enable", &cfg_type_boolean, 0 },
819         { "fetch-glue", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
820         { "ixfr-from-differences", &cfg_type_ixfrdifftype, 0 },
821         { "lame-ttl", &cfg_type_uint32, 0 },
822         { "max-acache-size", &cfg_type_sizenodefault, 0 },
823         { "max-cache-size", &cfg_type_sizenodefault, 0 },
824         { "max-cache-ttl", &cfg_type_uint32, 0 },
825         { "max-clients-per-query", &cfg_type_uint32, 0 },
826         { "max-ncache-ttl", &cfg_type_uint32, 0 },
827         { "max-udp-size", &cfg_type_uint32, 0 },
828         { "min-roots", &cfg_type_uint32, CFG_CLAUSEFLAG_NOTIMP },
829         { "minimal-responses", &cfg_type_boolean, 0 },
830         { "preferred-glue", &cfg_type_astring, 0 },
831         { "provide-ixfr", &cfg_type_boolean, 0 },
832         /*
833          * Note that the query-source option syntax is different
834          * from the other -source options.
835          */
836         { "query-source", &cfg_type_querysource4, 0 },
837         { "query-source-v6", &cfg_type_querysource6, 0 },
838         { "queryport-pool-ports", &cfg_type_uint32, CFG_CLAUSEFLAG_OBSOLETE },
839         { "queryport-pool-updateinterval", &cfg_type_uint32,
840           CFG_CLAUSEFLAG_OBSOLETE },
841         { "recursion", &cfg_type_boolean, 0 },
842         { "request-ixfr", &cfg_type_boolean, 0 },
843         { "request-nsid", &cfg_type_boolean, 0 },
844         { "rfc2308-type1", &cfg_type_boolean, CFG_CLAUSEFLAG_NYI },
845         { "root-delegation-only",  &cfg_type_optional_exclude, 0 },
846         { "rrset-order", &cfg_type_rrsetorder, 0 },
847         { "sortlist", &cfg_type_bracketed_aml, 0 },
848         { "suppress-initial-notify", &cfg_type_boolean, CFG_CLAUSEFLAG_NYI },
849         { "topology", &cfg_type_bracketed_aml, CFG_CLAUSEFLAG_NOTIMP },
850         { "transfer-format", &cfg_type_transferformat, 0 },
851         { "use-queryport-pool", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
852         { "zero-no-soa-ttl-cache", &cfg_type_boolean, 0 },
853         { NULL, NULL, 0 }
854 };
855
856 /*%
857  * Clauses that can be found within the 'view' statement only.
858  */
859 static cfg_clausedef_t
860 view_only_clauses[] = {
861         { "match-clients", &cfg_type_bracketed_aml, 0 },
862         { "match-destinations", &cfg_type_bracketed_aml, 0 },
863         { "match-recursive-only", &cfg_type_boolean, 0 },
864         { NULL, NULL, 0 }
865 };
866
867 /*%
868  * Sig-validity-interval.
869  */
870 static isc_result_t
871 parse_optional_uint32(cfg_parser_t *pctx, const cfg_type_t *type,
872                       cfg_obj_t **ret)
873 {
874         isc_result_t result;
875         UNUSED(type);
876
877         CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
878         if (pctx->token.type == isc_tokentype_number) {
879                 CHECK(cfg_parse_obj(pctx, &cfg_type_uint32, ret));
880         } else {
881                 CHECK(cfg_parse_obj(pctx, &cfg_type_void, ret));
882         }
883  cleanup:
884         return (result);
885 }
886
887 static void
888 doc_optional_uint32(cfg_printer_t *pctx, const cfg_type_t *type) {
889         UNUSED(type);
890         cfg_print_chars(pctx, "[ <integer> ]", 13);
891 }
892
893 static cfg_type_t cfg_type_optional_uint32 = {
894         "optional_uint32", parse_optional_uint32, NULL, doc_optional_uint32,
895         NULL, NULL };
896
897 static cfg_tuplefielddef_t validityinterval_fields[] = {
898         { "validity", &cfg_type_uint32, 0 },
899         { "re-sign", &cfg_type_optional_uint32, 0 },
900         { NULL, NULL, 0 }
901 };
902
903 static cfg_type_t cfg_type_validityinterval = {
904         "validityinterval", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
905         &cfg_rep_tuple, validityinterval_fields
906 };
907
908 /*%
909  * Clauses that can be found in a 'zone' statement,
910  * with defaults in the 'view' or 'options' statement.
911  */
912 static cfg_clausedef_t
913 zone_clauses[] = {
914         { "allow-notify", &cfg_type_bracketed_aml, 0 },
915         { "allow-query", &cfg_type_bracketed_aml, 0 },
916         { "allow-query-on", &cfg_type_bracketed_aml, 0 },
917         { "allow-transfer", &cfg_type_bracketed_aml, 0 },
918         { "allow-update", &cfg_type_bracketed_aml, 0 },
919         { "allow-update-forwarding", &cfg_type_bracketed_aml, 0 },
920         { "also-notify", &cfg_type_portiplist, 0 },
921         { "alt-transfer-source", &cfg_type_sockaddr4wild, 0 },
922         { "alt-transfer-source-v6", &cfg_type_sockaddr6wild, 0 },
923         { "check-integrity", &cfg_type_boolean, 0 },
924         { "check-mx", &cfg_type_checkmode, 0 },
925         { "check-mx-cname", &cfg_type_checkmode, 0 },
926         { "check-sibling", &cfg_type_boolean, 0 },
927         { "check-srv-cname", &cfg_type_checkmode, 0 },
928         { "check-wildcard", &cfg_type_boolean, 0 },
929         { "dialup", &cfg_type_dialuptype, 0 },
930         { "forward", &cfg_type_forwardtype, 0 },
931         { "forwarders", &cfg_type_portiplist, 0 },
932         { "key-directory", &cfg_type_qstring, 0 },
933         { "maintain-ixfr-base", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
934         { "masterfile-format", &cfg_type_masterformat, 0 },
935         { "max-ixfr-log-size", &cfg_type_size, CFG_CLAUSEFLAG_OBSOLETE },
936         { "max-journal-size", &cfg_type_sizenodefault, 0 },
937         { "max-refresh-time", &cfg_type_uint32, 0 },
938         { "max-retry-time", &cfg_type_uint32, 0 },
939         { "max-transfer-idle-in", &cfg_type_uint32, 0 },
940         { "max-transfer-idle-out", &cfg_type_uint32, 0 },
941         { "max-transfer-time-in", &cfg_type_uint32, 0 },
942         { "max-transfer-time-out", &cfg_type_uint32, 0 },
943         { "min-refresh-time", &cfg_type_uint32, 0 },
944         { "min-retry-time", &cfg_type_uint32, 0 },
945         { "multi-master", &cfg_type_boolean, 0 },
946         { "notify", &cfg_type_notifytype, 0 },
947         { "notify-delay", &cfg_type_uint32, 0 },
948         { "notify-source", &cfg_type_sockaddr4wild, 0 },
949         { "notify-source-v6", &cfg_type_sockaddr6wild, 0 },
950         { "notify-to-soa", &cfg_type_boolean, 0 },
951         { "nsec3-test-zone", &cfg_type_boolean, CFG_CLAUSEFLAG_TESTONLY },
952         { "sig-signing-nodes", &cfg_type_uint32, 0 },
953         { "sig-signing-signatures", &cfg_type_uint32, 0 },
954         { "sig-signing-type", &cfg_type_uint32, 0 },
955         { "sig-validity-interval", &cfg_type_validityinterval, 0 },
956         { "transfer-source", &cfg_type_sockaddr4wild, 0 },
957         { "transfer-source-v6", &cfg_type_sockaddr6wild, 0 },
958         { "try-tcp-refresh", &cfg_type_boolean, 0 },
959         { "update-check-ksk", &cfg_type_boolean, 0 },
960         { "use-alt-transfer-source", &cfg_type_boolean, 0 },
961         { "zero-no-soa-ttl", &cfg_type_boolean, 0 },
962         { "zone-statistics", &cfg_type_boolean, 0 },
963         { NULL, NULL, 0 }
964 };
965
966 /*%
967  * Clauses that can be found in a 'zone' statement
968  * only.
969  */
970 static cfg_clausedef_t
971 zone_only_clauses[] = {
972         { "type", &cfg_type_zonetype, 0 },
973         { "file", &cfg_type_qstring, 0 },
974         { "journal", &cfg_type_qstring, 0 },
975         { "ixfr-base", &cfg_type_qstring, CFG_CLAUSEFLAG_OBSOLETE },
976         { "ixfr-tmp-file", &cfg_type_qstring, CFG_CLAUSEFLAG_OBSOLETE },
977         { "masters", &cfg_type_namesockaddrkeylist, 0 },
978         { "pubkey", &cfg_type_pubkey,
979           CFG_CLAUSEFLAG_MULTI | CFG_CLAUSEFLAG_OBSOLETE },
980         { "update-policy", &cfg_type_updatepolicy, 0 },
981         { "database", &cfg_type_astring, 0 },
982         { "delegation-only", &cfg_type_boolean, 0 },
983         /*
984          * Note that the format of the check-names option is different between
985          * the zone options and the global/view options.  Ugh.
986          */
987         { "check-names", &cfg_type_checkmode, 0 },
988         { "ixfr-from-differences", &cfg_type_boolean, 0 },
989         { NULL, NULL, 0 }
990 };
991
992
993 /*% The top-level named.conf syntax. */
994
995 static cfg_clausedef_t *
996 namedconf_clausesets[] = {
997         namedconf_clauses,
998         namedconf_or_view_clauses,
999         NULL
1000 };
1001
1002 LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_namedconf = {
1003         "namedconf", cfg_parse_mapbody, cfg_print_mapbody, cfg_doc_mapbody,
1004         &cfg_rep_map, namedconf_clausesets
1005 };
1006
1007 /*% The "options" statement syntax. */
1008
1009 static cfg_clausedef_t *
1010 options_clausesets[] = {
1011         options_clauses,
1012         view_clauses,
1013         zone_clauses,
1014         NULL
1015 };
1016 static cfg_type_t cfg_type_options = {
1017         "options", cfg_parse_map, cfg_print_map, cfg_doc_map, &cfg_rep_map, options_clausesets };
1018
1019 /*% The "view" statement syntax. */
1020
1021 static cfg_clausedef_t *
1022 view_clausesets[] = {
1023         view_only_clauses,
1024         namedconf_or_view_clauses,
1025         view_clauses,
1026         zone_clauses,
1027         dynamically_loadable_zones_clauses,
1028         NULL
1029 };
1030 static cfg_type_t cfg_type_viewopts = {
1031         "view", cfg_parse_map, cfg_print_map, cfg_doc_map, &cfg_rep_map, view_clausesets };
1032
1033 /*% The "zone" statement syntax. */
1034
1035 static cfg_clausedef_t *
1036 zone_clausesets[] = {
1037         zone_only_clauses,
1038         zone_clauses,
1039         NULL
1040 };
1041 static cfg_type_t cfg_type_zoneopts = {
1042         "zoneopts", cfg_parse_map, cfg_print_map,
1043         cfg_doc_map, &cfg_rep_map, zone_clausesets };
1044
1045 /*% The "dynamically loadable zones" statement syntax. */
1046
1047 static cfg_clausedef_t *
1048 dynamically_loadable_zones_clausesets[] = {
1049         dynamically_loadable_zones_clauses,
1050         NULL
1051 };
1052 static cfg_type_t cfg_type_dynamically_loadable_zones_opts = {
1053         "dynamically_loadable_zones_opts", cfg_parse_map,
1054         cfg_print_map, cfg_doc_map, &cfg_rep_map,
1055         dynamically_loadable_zones_clausesets
1056 };
1057
1058 /*%
1059  * Clauses that can be found within the 'key' statement.
1060  */
1061 static cfg_clausedef_t
1062 key_clauses[] = {
1063         { "algorithm", &cfg_type_astring, 0 },
1064         { "secret", &cfg_type_astring, 0 },
1065         { NULL, NULL, 0 }
1066 };
1067
1068 static cfg_clausedef_t *
1069 key_clausesets[] = {
1070         key_clauses,
1071         NULL
1072 };
1073 static cfg_type_t cfg_type_key = {
1074         "key", cfg_parse_named_map, cfg_print_map,
1075         cfg_doc_map, &cfg_rep_map, key_clausesets
1076 };
1077
1078
1079 /*%
1080  * Clauses that can be found in a 'server' statement.
1081  */
1082 static cfg_clausedef_t
1083 server_clauses[] = {
1084         { "bogus", &cfg_type_boolean, 0 },
1085         { "provide-ixfr", &cfg_type_boolean, 0 },
1086         { "request-ixfr", &cfg_type_boolean, 0 },
1087         { "support-ixfr", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
1088         { "transfers", &cfg_type_uint32, 0 },
1089         { "transfer-format", &cfg_type_transferformat, 0 },
1090         { "keys", &cfg_type_server_key_kludge, 0 },
1091         { "edns", &cfg_type_boolean, 0 },
1092         { "edns-udp-size", &cfg_type_uint32, 0 },
1093         { "max-udp-size", &cfg_type_uint32, 0 },
1094         { "notify-source", &cfg_type_sockaddr4wild, 0 },
1095         { "notify-source-v6", &cfg_type_sockaddr6wild, 0 },
1096         { "query-source", &cfg_type_querysource4, 0 },
1097         { "query-source-v6", &cfg_type_querysource6, 0 },
1098         { "transfer-source", &cfg_type_sockaddr4wild, 0 },
1099         { "transfer-source-v6", &cfg_type_sockaddr6wild, 0 },
1100         { NULL, NULL, 0 }
1101 };
1102 static cfg_clausedef_t *
1103 server_clausesets[] = {
1104         server_clauses,
1105         NULL
1106 };
1107 static cfg_type_t cfg_type_server = {
1108         "server", cfg_parse_netprefix_map, cfg_print_map, cfg_doc_map, &cfg_rep_map,
1109         server_clausesets
1110 };
1111
1112
1113 /*%
1114  * Clauses that can be found in a 'channel' clause in the
1115  * 'logging' statement.
1116  *
1117  * These have some additional constraints that need to be
1118  * checked after parsing:
1119  *  - There must exactly one of file/syslog/null/stderr
1120  *
1121  */
1122 static cfg_clausedef_t
1123 channel_clauses[] = {
1124         /* Destinations.  We no longer require these to be first. */
1125         { "file", &cfg_type_logfile, 0 },
1126         { "syslog", &cfg_type_optional_facility, 0 },
1127         { "null", &cfg_type_void, 0 },
1128         { "stderr", &cfg_type_void, 0 },
1129         /* Options.  We now accept these for the null channel, too. */
1130         { "severity", &cfg_type_logseverity, 0 },
1131         { "print-time", &cfg_type_boolean, 0 },
1132         { "print-severity", &cfg_type_boolean, 0 },
1133         { "print-category", &cfg_type_boolean, 0 },
1134         { NULL, NULL, 0 }
1135 };
1136 static cfg_clausedef_t *
1137 channel_clausesets[] = {
1138         channel_clauses,
1139         NULL
1140 };
1141 static cfg_type_t cfg_type_channel = {
1142         "channel", cfg_parse_named_map, cfg_print_map, cfg_doc_map,
1143         &cfg_rep_map, channel_clausesets
1144 };
1145
1146 /*% A list of log destination, used in the "category" clause. */
1147 static cfg_type_t cfg_type_destinationlist = {
1148         "destinationlist", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list,
1149         &cfg_rep_list, &cfg_type_astring };
1150
1151 /*%
1152  * Clauses that can be found in a 'logging' statement.
1153  */
1154 static cfg_clausedef_t
1155 logging_clauses[] = {
1156         { "channel", &cfg_type_channel, CFG_CLAUSEFLAG_MULTI },
1157         { "category", &cfg_type_category, CFG_CLAUSEFLAG_MULTI },
1158         { NULL, NULL, 0 }
1159 };
1160 static cfg_clausedef_t *
1161 logging_clausesets[] = {
1162         logging_clauses,
1163         NULL
1164 };
1165 static cfg_type_t cfg_type_logging = {
1166         "logging", cfg_parse_map, cfg_print_map, cfg_doc_map, &cfg_rep_map, logging_clausesets };
1167
1168
1169 static isc_result_t
1170 parse_unitstring(char *str, isc_resourcevalue_t *valuep) {
1171         char *endp;
1172         unsigned int len;
1173         isc_uint64_t value;
1174         isc_uint64_t unit;
1175
1176         value = isc_string_touint64(str, &endp, 10);
1177         if (*endp == 0) {
1178                 *valuep = value;
1179                 return (ISC_R_SUCCESS);
1180         }
1181
1182         len = strlen(str);
1183         if (len < 2 || endp[1] != '\0')
1184                 return (ISC_R_FAILURE);
1185
1186         switch (str[len - 1]) {
1187         case 'k':
1188         case 'K':
1189                 unit = 1024;
1190                 break;
1191         case 'm':
1192         case 'M':
1193                 unit = 1024 * 1024;
1194                 break;
1195         case 'g':
1196         case 'G':
1197                 unit = 1024 * 1024 * 1024;
1198                 break;
1199         default:
1200                 return (ISC_R_FAILURE);
1201         }
1202         if (value > ISC_UINT64_MAX / unit)
1203                 return (ISC_R_FAILURE);
1204         *valuep = value * unit;
1205         return (ISC_R_SUCCESS);
1206 }
1207
1208 static isc_result_t
1209 parse_sizeval(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1210         isc_result_t result;
1211         cfg_obj_t *obj = NULL;
1212         isc_uint64_t val;
1213
1214         UNUSED(type);
1215
1216         CHECK(cfg_gettoken(pctx, 0));
1217         if (pctx->token.type != isc_tokentype_string) {
1218                 result = ISC_R_UNEXPECTEDTOKEN;
1219                 goto cleanup;
1220         }
1221         CHECK(parse_unitstring(TOKEN_STRING(pctx), &val));
1222
1223         CHECK(cfg_create_obj(pctx, &cfg_type_uint64, &obj));
1224         obj->value.uint64 = val;
1225         *ret = obj;
1226         return (ISC_R_SUCCESS);
1227
1228  cleanup:
1229         cfg_parser_error(pctx, CFG_LOG_NEAR, "expected integer and optional unit");
1230         return (result);
1231 }
1232
1233 /*%
1234  * A size value (number + optional unit).
1235  */
1236 static cfg_type_t cfg_type_sizeval = {
1237         "sizeval", parse_sizeval, cfg_print_uint64, cfg_doc_terminal,
1238         &cfg_rep_uint64, NULL };
1239
1240 /*%
1241  * A size, "unlimited", or "default".
1242  */
1243
1244 static isc_result_t
1245 parse_size(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1246         return (parse_enum_or_other(pctx, type, &cfg_type_sizeval, ret));
1247 }
1248
1249 static const char *size_enums[] = { "unlimited", "default", NULL };
1250 static cfg_type_t cfg_type_size = {
1251         "size", parse_size, cfg_print_ustring, cfg_doc_terminal,
1252         &cfg_rep_string, size_enums
1253 };
1254
1255 /*%
1256  * A size or "unlimited", but not "default".
1257  */
1258 static const char *sizenodefault_enums[] = { "unlimited", NULL };
1259 static cfg_type_t cfg_type_sizenodefault = {
1260         "size_no_default", parse_size, cfg_print_ustring, cfg_doc_terminal,
1261         &cfg_rep_string, sizenodefault_enums
1262 };
1263
1264 /*%
1265  * optional_keyvalue
1266  */
1267 static isc_result_t
1268 parse_maybe_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type,
1269                               isc_boolean_t optional, cfg_obj_t **ret)
1270 {
1271         isc_result_t result;
1272         cfg_obj_t *obj = NULL;
1273         const keyword_type_t *kw = type->of;
1274
1275         CHECK(cfg_peektoken(pctx, 0));
1276         if (pctx->token.type == isc_tokentype_string &&
1277             strcasecmp(TOKEN_STRING(pctx), kw->name) == 0) {
1278                 CHECK(cfg_gettoken(pctx, 0));
1279                 CHECK(kw->type->parse(pctx, kw->type, &obj));
1280                 obj->type = type; /* XXX kludge */
1281         } else {
1282                 if (optional) {
1283                         CHECK(cfg_parse_void(pctx, NULL, &obj));
1284                 } else {
1285                         cfg_parser_error(pctx, CFG_LOG_NEAR, "expected '%s'",
1286                                      kw->name);
1287                         result = ISC_R_UNEXPECTEDTOKEN;
1288                         goto cleanup;
1289                 }
1290         }
1291         *ret = obj;
1292  cleanup:
1293         return (result);
1294 }
1295
1296 static isc_result_t
1297 parse_enum_or_other(cfg_parser_t *pctx, const cfg_type_t *enumtype,
1298                     const cfg_type_t *othertype, cfg_obj_t **ret)
1299 {
1300         isc_result_t result;
1301         CHECK(cfg_peektoken(pctx, 0));
1302         if (pctx->token.type == isc_tokentype_string &&
1303             cfg_is_enum(TOKEN_STRING(pctx), enumtype->of)) {
1304                 CHECK(cfg_parse_enum(pctx, enumtype, ret));
1305         } else {
1306                 CHECK(cfg_parse_obj(pctx, othertype, ret));
1307         }
1308  cleanup:
1309         return (result);
1310 }
1311
1312 static void
1313 doc_enum_or_other(cfg_printer_t *pctx, const cfg_type_t *type) {
1314         cfg_doc_terminal(pctx, type);
1315 #if 0 /* XXX */
1316         cfg_print_chars(pctx, "( ", 2);...
1317 #endif
1318
1319 }
1320
1321 static isc_result_t
1322 parse_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1323         return (parse_maybe_optional_keyvalue(pctx, type, ISC_FALSE, ret));
1324 }
1325
1326 static isc_result_t
1327 parse_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1328         return (parse_maybe_optional_keyvalue(pctx, type, ISC_TRUE, ret));
1329 }
1330
1331 static void
1332 print_keyvalue(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1333         const keyword_type_t *kw = obj->type->of;
1334         cfg_print_cstr(pctx, kw->name);
1335         cfg_print_chars(pctx, " ", 1);
1336         kw->type->print(pctx, obj);
1337 }
1338
1339 static void
1340 doc_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type) {
1341         const keyword_type_t *kw = type->of;
1342         cfg_print_cstr(pctx, kw->name);
1343         cfg_print_chars(pctx, " ", 1);
1344         cfg_doc_obj(pctx, kw->type);
1345 }
1346
1347 static void
1348 doc_optional_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type) {
1349         const keyword_type_t *kw = type->of;
1350         cfg_print_chars(pctx, "[ ", 2);
1351         cfg_print_cstr(pctx, kw->name);
1352         cfg_print_chars(pctx, " ", 1);
1353         cfg_doc_obj(pctx, kw->type);
1354         cfg_print_chars(pctx, " ]", 2);
1355 }
1356
1357 static const char *dialup_enums[] = {
1358         "notify", "notify-passive", "refresh", "passive", NULL };
1359 static isc_result_t
1360 parse_dialup_type(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1361         return (parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
1362 }
1363 static cfg_type_t cfg_type_dialuptype = {
1364         "dialuptype", parse_dialup_type, cfg_print_ustring, doc_enum_or_other,
1365         &cfg_rep_string, dialup_enums
1366 };
1367
1368 static const char *notify_enums[] = { "explicit", "master-only", NULL };
1369 static isc_result_t
1370 parse_notify_type(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1371         return (parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
1372 }
1373 static cfg_type_t cfg_type_notifytype = {
1374         "notifytype", parse_notify_type, cfg_print_ustring, doc_enum_or_other,
1375         &cfg_rep_string, notify_enums,
1376 };
1377
1378 static const char *ixfrdiff_enums[] = { "master", "slave", NULL };
1379 static isc_result_t
1380 parse_ixfrdiff_type(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1381         return (parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
1382 }
1383 static cfg_type_t cfg_type_ixfrdifftype = {
1384         "ixfrdiff", parse_ixfrdiff_type, cfg_print_ustring, doc_enum_or_other,
1385         &cfg_rep_string, ixfrdiff_enums,
1386 };
1387
1388 static keyword_type_t key_kw = { "key", &cfg_type_astring };
1389
1390 LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_keyref = {
1391         "keyref", parse_keyvalue, print_keyvalue, doc_keyvalue,
1392         &cfg_rep_string, &key_kw
1393 };
1394
1395 static cfg_type_t cfg_type_optional_keyref = {
1396         "optional_keyref", parse_optional_keyvalue, print_keyvalue,
1397         doc_optional_keyvalue, &cfg_rep_string, &key_kw
1398 };
1399
1400 /*%
1401  * A "controls" statement is represented as a map with the multivalued
1402  * "inet" and "unix" clauses.
1403  */
1404
1405 static keyword_type_t controls_allow_kw = {
1406         "allow", &cfg_type_bracketed_aml };
1407
1408 static cfg_type_t cfg_type_controls_allow = {
1409         "controls_allow", parse_keyvalue,
1410         print_keyvalue, doc_keyvalue,
1411         &cfg_rep_list, &controls_allow_kw
1412 };
1413
1414 static keyword_type_t controls_keys_kw = {
1415         "keys", &cfg_type_keylist };
1416
1417 static cfg_type_t cfg_type_controls_keys = {
1418         "controls_keys", parse_optional_keyvalue,
1419         print_keyvalue, doc_optional_keyvalue,
1420         &cfg_rep_list, &controls_keys_kw
1421 };
1422
1423 static cfg_tuplefielddef_t inetcontrol_fields[] = {
1424         { "address", &cfg_type_controls_sockaddr, 0 },
1425         { "allow", &cfg_type_controls_allow, 0 },
1426         { "keys", &cfg_type_controls_keys, 0 },
1427         { NULL, NULL, 0 }
1428 };
1429
1430 static cfg_type_t cfg_type_inetcontrol = {
1431         "inetcontrol", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
1432         inetcontrol_fields
1433 };
1434
1435 static keyword_type_t controls_perm_kw = {
1436         "perm", &cfg_type_uint32 };
1437
1438 static cfg_type_t cfg_type_controls_perm = {
1439         "controls_perm", parse_keyvalue,
1440         print_keyvalue, doc_keyvalue,
1441         &cfg_rep_uint32, &controls_perm_kw
1442 };
1443
1444 static keyword_type_t controls_owner_kw = {
1445         "owner", &cfg_type_uint32 };
1446
1447 static cfg_type_t cfg_type_controls_owner = {
1448         "controls_owner", parse_keyvalue,
1449         print_keyvalue, doc_keyvalue,
1450         &cfg_rep_uint32, &controls_owner_kw
1451 };
1452
1453 static keyword_type_t controls_group_kw = {
1454         "group", &cfg_type_uint32 };
1455
1456 static cfg_type_t cfg_type_controls_group = {
1457         "controls_allow", parse_keyvalue,
1458         print_keyvalue, doc_keyvalue,
1459         &cfg_rep_uint32, &controls_group_kw
1460 };
1461
1462 static cfg_tuplefielddef_t unixcontrol_fields[] = {
1463         { "path", &cfg_type_qstring, 0 },
1464         { "perm", &cfg_type_controls_perm, 0 },
1465         { "owner", &cfg_type_controls_owner, 0 },
1466         { "group", &cfg_type_controls_group, 0 },
1467         { "keys", &cfg_type_controls_keys, 0 },
1468         { NULL, NULL, 0 }
1469 };
1470
1471 static cfg_type_t cfg_type_unixcontrol = {
1472         "unixcontrol", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
1473         unixcontrol_fields
1474 };
1475
1476 static cfg_clausedef_t
1477 controls_clauses[] = {
1478         { "inet", &cfg_type_inetcontrol, CFG_CLAUSEFLAG_MULTI },
1479         { "unix", &cfg_type_unixcontrol, CFG_CLAUSEFLAG_MULTI },
1480         { NULL, NULL, 0 }
1481 };
1482
1483 static cfg_clausedef_t *
1484 controls_clausesets[] = {
1485         controls_clauses,
1486         NULL
1487 };
1488 static cfg_type_t cfg_type_controls = {
1489         "controls", cfg_parse_map, cfg_print_map, cfg_doc_map, &cfg_rep_map,    &controls_clausesets
1490 };
1491
1492 /*%
1493  * A "statistics-channels" statement is represented as a map with the
1494  * multivalued "inet" clauses.
1495  */
1496 static void
1497 doc_optional_bracketed_list(cfg_printer_t *pctx, const cfg_type_t *type) {
1498         const keyword_type_t *kw = type->of;
1499         cfg_print_chars(pctx, "[ ", 2);
1500         cfg_print_cstr(pctx, kw->name);
1501         cfg_print_chars(pctx, " ", 1);
1502         cfg_doc_obj(pctx, kw->type);
1503         cfg_print_chars(pctx, " ]", 2);
1504 }
1505
1506 static cfg_type_t cfg_type_optional_allow = {
1507         "optional_allow", parse_optional_keyvalue, print_keyvalue,
1508         doc_optional_bracketed_list, &cfg_rep_list, &controls_allow_kw
1509 };
1510
1511 static cfg_tuplefielddef_t statserver_fields[] = {
1512         { "address", &cfg_type_controls_sockaddr, 0 }, /* reuse controls def */
1513         { "allow", &cfg_type_optional_allow, 0 },
1514         { NULL, NULL, 0 }
1515 };
1516
1517 static cfg_type_t cfg_type_statschannel = {
1518         "statschannel", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
1519         &cfg_rep_tuple, statserver_fields
1520 };
1521
1522 static cfg_clausedef_t
1523 statservers_clauses[] = {
1524         { "inet", &cfg_type_statschannel, CFG_CLAUSEFLAG_MULTI },
1525         { NULL, NULL, 0 }
1526 };
1527
1528 static cfg_clausedef_t *
1529 statservers_clausesets[] = {
1530         statservers_clauses,
1531         NULL
1532 };
1533
1534 static cfg_type_t cfg_type_statschannels = {
1535         "statistics-channels", cfg_parse_map, cfg_print_map, cfg_doc_map,
1536         &cfg_rep_map,   &statservers_clausesets
1537 };
1538
1539 /*%
1540  * An optional class, as used in view and zone statements.
1541  */
1542 static isc_result_t
1543 parse_optional_class(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1544         isc_result_t result;
1545         UNUSED(type);
1546         CHECK(cfg_peektoken(pctx, 0));
1547         if (pctx->token.type == isc_tokentype_string)
1548                 CHECK(cfg_parse_obj(pctx, &cfg_type_ustring, ret));
1549         else
1550                 CHECK(cfg_parse_obj(pctx, &cfg_type_void, ret));
1551  cleanup:
1552         return (result);
1553 }
1554
1555 static cfg_type_t cfg_type_optional_class = {
1556         "optional_class", parse_optional_class, NULL, cfg_doc_terminal,
1557         NULL, NULL
1558 };
1559
1560 static isc_result_t
1561 parse_querysource(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1562         isc_result_t result;
1563         cfg_obj_t *obj = NULL;
1564         isc_netaddr_t netaddr;
1565         in_port_t port;
1566         unsigned int have_address = 0;
1567         unsigned int have_port = 0;
1568         const unsigned int *flagp = type->of;
1569
1570         if ((*flagp & CFG_ADDR_V4OK) != 0)
1571                 isc_netaddr_any(&netaddr);
1572         else if ((*flagp & CFG_ADDR_V6OK) != 0)
1573                 isc_netaddr_any6(&netaddr);
1574         else
1575                 INSIST(0);
1576
1577         port = 0;
1578
1579         for (;;) {
1580                 CHECK(cfg_peektoken(pctx, 0));
1581                 if (pctx->token.type == isc_tokentype_string) {
1582                         if (strcasecmp(TOKEN_STRING(pctx),
1583                                        "address") == 0)
1584                         {
1585                                 /* read "address" */
1586                                 CHECK(cfg_gettoken(pctx, 0));
1587                                 CHECK(cfg_parse_rawaddr(pctx, *flagp,
1588                                                         &netaddr));
1589                                 have_address++;
1590                         } else if (strcasecmp(TOKEN_STRING(pctx), "port") == 0)
1591                         {
1592                                 /* read "port" */
1593                                 CHECK(cfg_gettoken(pctx, 0));
1594                                 CHECK(cfg_parse_rawport(pctx,
1595                                                         CFG_ADDR_WILDOK,
1596                                                         &port));
1597                                 have_port++;
1598                         } else if (have_port == 0 && have_address == 0) {
1599                                 return (cfg_parse_sockaddr(pctx, type, ret));
1600                         } else {
1601                                 cfg_parser_error(pctx, CFG_LOG_NEAR,
1602                                              "expected 'address' or 'port'");
1603                                 return (ISC_R_UNEXPECTEDTOKEN);
1604                         }
1605                 } else
1606                         break;
1607         }
1608         if (have_address > 1 || have_port > 1 ||
1609             have_address + have_port == 0) {
1610                 cfg_parser_error(pctx, 0, "expected one address and/or port");
1611                 return (ISC_R_UNEXPECTEDTOKEN);
1612         }
1613
1614         CHECK(cfg_create_obj(pctx, &cfg_type_querysource, &obj));
1615         isc_sockaddr_fromnetaddr(&obj->value.sockaddr, &netaddr, port);
1616         *ret = obj;
1617         return (ISC_R_SUCCESS);
1618
1619  cleanup:
1620         cfg_parser_error(pctx, CFG_LOG_NEAR, "invalid query source");
1621         CLEANUP_OBJ(obj);
1622         return (result);
1623 }
1624
1625 static void
1626 print_querysource(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1627         isc_netaddr_t na;
1628         isc_netaddr_fromsockaddr(&na, &obj->value.sockaddr);
1629         cfg_print_chars(pctx, "address ", 8);
1630         cfg_print_rawaddr(pctx, &na);
1631         cfg_print_chars(pctx, " port ", 6);
1632         cfg_print_rawuint(pctx, isc_sockaddr_getport(&obj->value.sockaddr));
1633 }
1634
1635 static unsigned int sockaddr4wild_flags = CFG_ADDR_WILDOK | CFG_ADDR_V4OK;
1636 static unsigned int sockaddr6wild_flags = CFG_ADDR_WILDOK | CFG_ADDR_V6OK;
1637
1638 static cfg_type_t cfg_type_querysource4 = {
1639         "querysource4", parse_querysource, NULL, cfg_doc_terminal,
1640         NULL, &sockaddr4wild_flags
1641 };
1642
1643 static cfg_type_t cfg_type_querysource6 = {
1644         "querysource6", parse_querysource, NULL, cfg_doc_terminal,
1645         NULL, &sockaddr6wild_flags
1646 };
1647
1648 static cfg_type_t cfg_type_querysource = {
1649         "querysource", NULL, print_querysource, NULL, &cfg_rep_sockaddr, NULL
1650 };
1651
1652 /*% addrmatchelt */
1653
1654 static isc_result_t
1655 parse_addrmatchelt(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1656         isc_result_t result;
1657         UNUSED(type);
1658
1659         CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
1660
1661         if (pctx->token.type == isc_tokentype_string ||
1662             pctx->token.type == isc_tokentype_qstring) {
1663                 if (pctx->token.type == isc_tokentype_string &&
1664                     (strcasecmp(TOKEN_STRING(pctx), "key") == 0)) {
1665                         CHECK(cfg_parse_obj(pctx, &cfg_type_keyref, ret));
1666                 } else {
1667                         if (cfg_lookingat_netaddr(pctx, CFG_ADDR_V4OK |
1668                                                   CFG_ADDR_V4PREFIXOK |
1669                                                   CFG_ADDR_V6OK))
1670                         {
1671                                 CHECK(cfg_parse_netprefix(pctx, NULL, ret));
1672                         } else {
1673                                 CHECK(cfg_parse_astring(pctx, NULL, ret));
1674                         }
1675                 }
1676         } else if (pctx->token.type == isc_tokentype_special) {
1677                 if (pctx->token.value.as_char == '{') {
1678                         /* Nested match list. */
1679                         CHECK(cfg_parse_obj(pctx, &cfg_type_bracketed_aml, ret));
1680                 } else if (pctx->token.value.as_char == '!') {
1681                         CHECK(cfg_gettoken(pctx, 0)); /* read "!" */
1682                         CHECK(cfg_parse_obj(pctx, &cfg_type_negated, ret));
1683                 } else {
1684                         goto bad;
1685                 }
1686         } else {
1687         bad:
1688                 cfg_parser_error(pctx, CFG_LOG_NEAR,
1689                              "expected IP match list element");
1690                 return (ISC_R_UNEXPECTEDTOKEN);
1691         }
1692  cleanup:
1693         return (result);
1694 }
1695
1696 /*%
1697  * A negated address match list element (like "! 10.0.0.1").
1698  * Somewhat sneakily, the caller is expected to parse the
1699  * "!", but not to print it.
1700  */
1701
1702 static cfg_tuplefielddef_t negated_fields[] = {
1703         { "value", &cfg_type_addrmatchelt, 0 },
1704         { NULL, NULL, 0 }
1705 };
1706
1707 static void
1708 print_negated(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1709         cfg_print_chars(pctx, "!", 1);
1710         cfg_print_tuple(pctx, obj);
1711 }
1712
1713 static cfg_type_t cfg_type_negated = {
1714         "negated", cfg_parse_tuple, print_negated, NULL, &cfg_rep_tuple,
1715         &negated_fields
1716 };
1717
1718 /*% An address match list element */
1719
1720 static cfg_type_t cfg_type_addrmatchelt = {
1721         "address_match_element", parse_addrmatchelt, NULL, cfg_doc_terminal,
1722         NULL, NULL
1723 };
1724
1725 /*% A bracketed address match list */
1726
1727 static cfg_type_t cfg_type_bracketed_aml = {
1728         "bracketed_aml", cfg_parse_bracketed_list, cfg_print_bracketed_list,
1729         cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_addrmatchelt
1730 };
1731
1732 /*%
1733  * The socket address syntax in the "controls" statement is silly.
1734  * It allows both socket address families, but also allows "*",
1735  * whis is gratuitously interpreted as the IPv4 wildcard address.
1736  */
1737 static unsigned int controls_sockaddr_flags =
1738         CFG_ADDR_V4OK | CFG_ADDR_V6OK | CFG_ADDR_WILDOK;
1739 static cfg_type_t cfg_type_controls_sockaddr = {
1740         "controls_sockaddr", cfg_parse_sockaddr, cfg_print_sockaddr,
1741         cfg_doc_sockaddr, &cfg_rep_sockaddr, &controls_sockaddr_flags
1742 };
1743
1744 /*%
1745  * Handle the special kludge syntax of the "keys" clause in the "server"
1746  * statement, which takes a single key with or without braces and semicolon.
1747  */
1748 static isc_result_t
1749 parse_server_key_kludge(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
1750 {
1751         isc_result_t result;
1752         isc_boolean_t braces = ISC_FALSE;
1753         UNUSED(type);
1754
1755         /* Allow opening brace. */
1756         CHECK(cfg_peektoken(pctx, 0));
1757         if (pctx->token.type == isc_tokentype_special &&
1758             pctx->token.value.as_char == '{') {
1759                 result = cfg_gettoken(pctx, 0);
1760                 braces = ISC_TRUE;
1761         }
1762
1763         CHECK(cfg_parse_obj(pctx, &cfg_type_astring, ret));
1764
1765         if (braces) {
1766                 /* Skip semicolon if present. */
1767                 CHECK(cfg_peektoken(pctx, 0));
1768                 if (pctx->token.type == isc_tokentype_special &&
1769                     pctx->token.value.as_char == ';')
1770                         CHECK(cfg_gettoken(pctx, 0));
1771
1772                 CHECK(cfg_parse_special(pctx, '}'));
1773         }
1774  cleanup:
1775         return (result);
1776 }
1777 static cfg_type_t cfg_type_server_key_kludge = {
1778         "server_key", parse_server_key_kludge, NULL, cfg_doc_terminal,
1779         NULL, NULL
1780 };
1781
1782
1783 /*%
1784  * An optional logging facility.
1785  */
1786
1787 static isc_result_t
1788 parse_optional_facility(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret)
1789 {
1790         isc_result_t result;
1791         UNUSED(type);
1792
1793         CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
1794         if (pctx->token.type == isc_tokentype_string ||
1795             pctx->token.type == isc_tokentype_qstring) {
1796                 CHECK(cfg_parse_obj(pctx, &cfg_type_astring, ret));
1797         } else {
1798                 CHECK(cfg_parse_obj(pctx, &cfg_type_void, ret));
1799         }
1800  cleanup:
1801         return (result);
1802 }
1803
1804 static cfg_type_t cfg_type_optional_facility = {
1805         "optional_facility", parse_optional_facility, NULL, cfg_doc_terminal,
1806         NULL, NULL };
1807
1808
1809 /*%
1810  * A log severity.  Return as a string, except "debug N",
1811  * which is returned as a keyword object.
1812  */
1813
1814 static keyword_type_t debug_kw = { "debug", &cfg_type_uint32 };
1815 static cfg_type_t cfg_type_debuglevel = {
1816         "debuglevel", parse_keyvalue,
1817         print_keyvalue, doc_keyvalue,
1818         &cfg_rep_uint32, &debug_kw
1819 };
1820
1821 static isc_result_t
1822 parse_logseverity(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1823         isc_result_t result;
1824         UNUSED(type);
1825
1826         CHECK(cfg_peektoken(pctx, 0));
1827         if (pctx->token.type == isc_tokentype_string &&
1828             strcasecmp(TOKEN_STRING(pctx), "debug") == 0) {
1829                 CHECK(cfg_gettoken(pctx, 0)); /* read "debug" */
1830                 CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER));
1831                 if (pctx->token.type == isc_tokentype_number) {
1832                         CHECK(cfg_parse_uint32(pctx, NULL, ret));
1833                 } else {
1834                         /*
1835                          * The debug level is optional and defaults to 1.
1836                          * This makes little sense, but we support it for
1837                          * compatibility with BIND 8.
1838                          */
1839                         CHECK(cfg_create_obj(pctx, &cfg_type_uint32, ret));
1840                         (*ret)->value.uint32 = 1;
1841                 }
1842                 (*ret)->type = &cfg_type_debuglevel; /* XXX kludge */
1843         } else {
1844                 CHECK(cfg_parse_obj(pctx, &cfg_type_loglevel, ret));
1845         }
1846  cleanup:
1847         return (result);
1848 }
1849
1850 static cfg_type_t cfg_type_logseverity = {
1851         "log_severity", parse_logseverity, NULL, cfg_doc_terminal,
1852         NULL, NULL };
1853
1854 /*%
1855  * The "file" clause of the "channel" statement.
1856  * This is yet another special case.
1857  */
1858
1859 static const char *logversions_enums[] = { "unlimited", NULL };
1860 static isc_result_t
1861 parse_logversions(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1862         return (parse_enum_or_other(pctx, type, &cfg_type_uint32, ret));
1863 }
1864
1865 static cfg_type_t cfg_type_logversions = {
1866         "logversions", parse_logversions, cfg_print_ustring, cfg_doc_terminal,
1867         &cfg_rep_string, logversions_enums
1868 };
1869
1870 static cfg_tuplefielddef_t logfile_fields[] = {
1871         { "file", &cfg_type_qstring, 0 },
1872         { "versions", &cfg_type_logversions, 0 },
1873         { "size", &cfg_type_size, 0 },
1874         { NULL, NULL, 0 }
1875 };
1876
1877 static isc_result_t
1878 parse_logfile(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
1879         isc_result_t result;
1880         cfg_obj_t *obj = NULL;
1881         const cfg_tuplefielddef_t *fields = type->of;
1882
1883         CHECK(cfg_create_tuple(pctx, type, &obj));
1884
1885         /* Parse the mandatory "file" field */
1886         CHECK(cfg_parse_obj(pctx, fields[0].type, &obj->value.tuple[0]));
1887
1888         /* Parse "versions" and "size" fields in any order. */
1889         for (;;) {
1890                 CHECK(cfg_peektoken(pctx, 0));
1891                 if (pctx->token.type == isc_tokentype_string) {
1892                         CHECK(cfg_gettoken(pctx, 0));
1893                         if (strcasecmp(TOKEN_STRING(pctx),
1894                                        "versions") == 0 &&
1895                             obj->value.tuple[1] == NULL) {
1896                                 CHECK(cfg_parse_obj(pctx, fields[1].type,
1897                                             &obj->value.tuple[1]));
1898                         } else if (strcasecmp(TOKEN_STRING(pctx),
1899                                               "size") == 0 &&
1900                                    obj->value.tuple[2] == NULL) {
1901                                 CHECK(cfg_parse_obj(pctx, fields[2].type,
1902                                             &obj->value.tuple[2]));
1903                         } else {
1904                                 break;
1905                         }
1906                 } else {
1907                         break;
1908                 }
1909         }
1910
1911         /* Create void objects for missing optional values. */
1912         if (obj->value.tuple[1] == NULL)
1913                 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[1]));
1914         if (obj->value.tuple[2] == NULL)
1915                 CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[2]));
1916
1917         *ret = obj;
1918         return (ISC_R_SUCCESS);
1919
1920  cleanup:
1921         CLEANUP_OBJ(obj);
1922         return (result);
1923 }
1924
1925 static void
1926 print_logfile(cfg_printer_t *pctx, const cfg_obj_t *obj) {
1927         cfg_print_obj(pctx, obj->value.tuple[0]); /* file */
1928         if (obj->value.tuple[1]->type->print != cfg_print_void) {
1929                 cfg_print_chars(pctx, " versions ", 10);
1930                 cfg_print_obj(pctx, obj->value.tuple[1]);
1931         }
1932         if (obj->value.tuple[2]->type->print != cfg_print_void) {
1933                 cfg_print_chars(pctx, " size ", 6);
1934                 cfg_print_obj(pctx, obj->value.tuple[2]);
1935         }
1936 }
1937
1938
1939 static void
1940 doc_logfile(cfg_printer_t *pctx, const cfg_type_t *type) {
1941         UNUSED(type);
1942         cfg_print_cstr(pctx, "<quoted_string>");
1943         cfg_print_chars(pctx, " ", 1);
1944         cfg_print_cstr(pctx, "[ versions ( \"unlimited\" | <integer> ) ]");
1945         cfg_print_chars(pctx, " ", 1);
1946         cfg_print_cstr(pctx, "[ size <size> ]");
1947 }
1948
1949 static cfg_type_t cfg_type_logfile = {
1950         "log_file", parse_logfile, print_logfile, doc_logfile,
1951         &cfg_rep_tuple, logfile_fields
1952 };
1953
1954 /*% An IPv4 address with optional port, "*" accepted as wildcard. */
1955 static cfg_type_t cfg_type_sockaddr4wild = {
1956         "sockaddr4wild", cfg_parse_sockaddr, cfg_print_sockaddr,
1957         cfg_doc_sockaddr, &cfg_rep_sockaddr, &sockaddr4wild_flags
1958 };
1959
1960 /*% An IPv6 address with optional port, "*" accepted as wildcard. */
1961 static cfg_type_t cfg_type_sockaddr6wild = {
1962         "v6addrportwild", cfg_parse_sockaddr, cfg_print_sockaddr,
1963         cfg_doc_sockaddr, &cfg_rep_sockaddr, &sockaddr6wild_flags
1964 };
1965
1966 /*%
1967  * lwres
1968  */
1969
1970 static cfg_tuplefielddef_t lwres_view_fields[] = {
1971         { "name", &cfg_type_astring, 0 },
1972         { "class", &cfg_type_optional_class, 0 },
1973         { NULL, NULL, 0 }
1974 };
1975 static cfg_type_t cfg_type_lwres_view = {
1976         "lwres_view", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
1977         lwres_view_fields
1978 };
1979
1980 static cfg_type_t cfg_type_lwres_searchlist = {
1981         "lwres_searchlist", cfg_parse_bracketed_list, cfg_print_bracketed_list,
1982         cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_astring };
1983
1984 static cfg_clausedef_t
1985 lwres_clauses[] = {
1986         { "listen-on", &cfg_type_portiplist, 0 },
1987         { "view", &cfg_type_lwres_view, 0 },
1988         { "search", &cfg_type_lwres_searchlist, 0 },
1989         { "ndots", &cfg_type_uint32, 0 },
1990         { NULL, NULL, 0 }
1991 };
1992
1993 static cfg_clausedef_t *
1994 lwres_clausesets[] = {
1995         lwres_clauses,
1996         NULL
1997 };
1998 static cfg_type_t cfg_type_lwres = {
1999         "lwres", cfg_parse_map, cfg_print_map, cfg_doc_map, &cfg_rep_map,
2000         lwres_clausesets
2001 };
2002
2003 /*%
2004  * rndc
2005  */
2006
2007 static cfg_clausedef_t
2008 rndcconf_options_clauses[] = {
2009         { "default-key", &cfg_type_astring, 0 },
2010         { "default-port", &cfg_type_uint32, 0 },
2011         { "default-server", &cfg_type_astring, 0 },
2012         { "default-source-address", &cfg_type_netaddr4wild, 0 },
2013         { "default-source-address-v6", &cfg_type_netaddr6wild, 0 },
2014         { NULL, NULL, 0 }
2015 };
2016
2017 static cfg_clausedef_t *
2018 rndcconf_options_clausesets[] = {
2019         rndcconf_options_clauses,
2020         NULL
2021 };
2022
2023 static cfg_type_t cfg_type_rndcconf_options = {
2024         "rndcconf_options", cfg_parse_map, cfg_print_map, cfg_doc_map,
2025         &cfg_rep_map, rndcconf_options_clausesets
2026 };
2027
2028 static cfg_clausedef_t
2029 rndcconf_server_clauses[] = {
2030         { "key", &cfg_type_astring, 0 },
2031         { "port", &cfg_type_uint32, 0 },
2032         { "source-address", &cfg_type_netaddr4wild, 0 },
2033         { "source-address-v6", &cfg_type_netaddr6wild, 0 },
2034         { "addresses", &cfg_type_bracketed_sockaddrnameportlist, 0 },
2035         { NULL, NULL, 0 }
2036 };
2037
2038 static cfg_clausedef_t *
2039 rndcconf_server_clausesets[] = {
2040         rndcconf_server_clauses,
2041         NULL
2042 };
2043
2044 static cfg_type_t cfg_type_rndcconf_server = {
2045         "rndcconf_server", cfg_parse_named_map, cfg_print_map, cfg_doc_map,
2046         &cfg_rep_map, rndcconf_server_clausesets
2047 };
2048
2049 static cfg_clausedef_t
2050 rndcconf_clauses[] = {
2051         { "key", &cfg_type_key, CFG_CLAUSEFLAG_MULTI },
2052         { "server", &cfg_type_rndcconf_server, CFG_CLAUSEFLAG_MULTI },
2053         { "options", &cfg_type_rndcconf_options, 0 },
2054         { NULL, NULL, 0 }
2055 };
2056
2057 static cfg_clausedef_t *
2058 rndcconf_clausesets[] = {
2059         rndcconf_clauses,
2060         NULL
2061 };
2062
2063 LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_rndcconf = {
2064         "rndcconf", cfg_parse_mapbody, cfg_print_mapbody, cfg_doc_mapbody,
2065         &cfg_rep_map, rndcconf_clausesets
2066 };
2067
2068 static cfg_clausedef_t
2069 rndckey_clauses[] = {
2070         { "key", &cfg_type_key, 0 },
2071         { NULL, NULL, 0 }
2072 };
2073
2074 static cfg_clausedef_t *
2075 rndckey_clausesets[] = {
2076         rndckey_clauses,
2077         NULL
2078 };
2079
2080 LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_rndckey = {
2081         "rndckey", cfg_parse_mapbody, cfg_print_mapbody, cfg_doc_mapbody,
2082         &cfg_rep_map, rndckey_clausesets
2083 };
2084
2085 static cfg_tuplefielddef_t nameport_fields[] = {
2086         { "name", &cfg_type_astring, 0 },
2087         { "port", &cfg_type_optional_port, 0 },
2088         { NULL, NULL, 0 }
2089 };
2090 static cfg_type_t cfg_type_nameport = {
2091         "nameport", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
2092         &cfg_rep_tuple, nameport_fields
2093 };
2094
2095 static void
2096 doc_sockaddrnameport(cfg_printer_t *pctx, const cfg_type_t *type) {
2097         UNUSED(type);
2098         cfg_print_chars(pctx, "( ", 2);
2099         cfg_print_cstr(pctx, "<quoted_string>");
2100         cfg_print_chars(pctx, " ", 1);
2101         cfg_print_cstr(pctx, "[ port <integer> ]");
2102         cfg_print_chars(pctx, " | ", 3);
2103         cfg_print_cstr(pctx, "<ipv4_address>");
2104         cfg_print_chars(pctx, " ", 1);
2105         cfg_print_cstr(pctx, "[ port <integer> ]");
2106         cfg_print_chars(pctx, " | ", 3);
2107         cfg_print_cstr(pctx, "<ipv6_address>");
2108         cfg_print_chars(pctx, " ", 1);
2109         cfg_print_cstr(pctx, "[ port <integer> ]");
2110         cfg_print_chars(pctx, " )", 2);
2111 }
2112
2113 static isc_result_t
2114 parse_sockaddrnameport(cfg_parser_t *pctx, const cfg_type_t *type,
2115                        cfg_obj_t **ret)
2116 {
2117         isc_result_t result;
2118         cfg_obj_t *obj = NULL;
2119         UNUSED(type);
2120
2121         CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
2122         if (pctx->token.type == isc_tokentype_string ||
2123             pctx->token.type == isc_tokentype_qstring) {
2124                 if (cfg_lookingat_netaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V6OK))
2125                         CHECK(cfg_parse_sockaddr(pctx, &cfg_type_sockaddr, ret));
2126                 else {
2127                         const cfg_tuplefielddef_t *fields =
2128                                                    cfg_type_nameport.of;
2129                         CHECK(cfg_create_tuple(pctx, &cfg_type_nameport,
2130                                                &obj));
2131                         CHECK(cfg_parse_obj(pctx, fields[0].type,
2132                                             &obj->value.tuple[0]));
2133                         CHECK(cfg_parse_obj(pctx, fields[1].type,
2134                                             &obj->value.tuple[1]));
2135                         *ret = obj;
2136                         obj = NULL;
2137                 }
2138         } else {
2139                 cfg_parser_error(pctx, CFG_LOG_NEAR,
2140                              "expected IP address or hostname");
2141                 return (ISC_R_UNEXPECTEDTOKEN);
2142         }
2143  cleanup:
2144         CLEANUP_OBJ(obj);
2145         return (result);
2146 }
2147
2148 static cfg_type_t cfg_type_sockaddrnameport = {
2149         "sockaddrnameport_element", parse_sockaddrnameport, NULL,
2150          doc_sockaddrnameport, NULL, NULL
2151 };
2152
2153 static cfg_type_t cfg_type_bracketed_sockaddrnameportlist = {
2154         "bracketed_sockaddrnameportlist", cfg_parse_bracketed_list,
2155         cfg_print_bracketed_list, cfg_doc_bracketed_list,
2156         &cfg_rep_list, &cfg_type_sockaddrnameport
2157 };
2158
2159 /*%
2160  * A list of socket addresses or name with an optional default port,
2161  * as used in the dual-stack-servers option.  E.g.,
2162  * "port 1234 { dual-stack-servers.net; 10.0.0.1; 1::2 port 69; }"
2163  */
2164 static cfg_tuplefielddef_t nameportiplist_fields[] = {
2165         { "port", &cfg_type_optional_port, 0 },
2166         { "addresses", &cfg_type_bracketed_sockaddrnameportlist, 0 },
2167         { NULL, NULL, 0 }
2168 };
2169
2170 static cfg_type_t cfg_type_nameportiplist = {
2171         "nameportiplist", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
2172         &cfg_rep_tuple, nameportiplist_fields
2173 };
2174
2175 /*%
2176  * masters element.
2177  */
2178
2179 static void
2180 doc_masterselement(cfg_printer_t *pctx, const cfg_type_t *type) {
2181         UNUSED(type);
2182         cfg_print_chars(pctx, "( ", 2);
2183         cfg_print_cstr(pctx, "<masters>");
2184         cfg_print_chars(pctx, " | ", 3);
2185         cfg_print_cstr(pctx, "<ipv4_address>");
2186         cfg_print_chars(pctx, " ", 1);
2187         cfg_print_cstr(pctx, "[ port <integer> ]");
2188         cfg_print_chars(pctx, " | ", 3);
2189         cfg_print_cstr(pctx, "<ipv6_address>");
2190         cfg_print_chars(pctx, " ", 1);
2191         cfg_print_cstr(pctx, "[ port <integer> ]");
2192         cfg_print_chars(pctx, " )", 2);
2193 }
2194
2195 static isc_result_t
2196 parse_masterselement(cfg_parser_t *pctx, const cfg_type_t *type,
2197                      cfg_obj_t **ret)
2198 {
2199         isc_result_t result;
2200         cfg_obj_t *obj = NULL;
2201         UNUSED(type);
2202
2203         CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING));
2204         if (pctx->token.type == isc_tokentype_string ||
2205             pctx->token.type == isc_tokentype_qstring) {
2206                 if (cfg_lookingat_netaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V6OK))
2207                         CHECK(cfg_parse_sockaddr(pctx, &cfg_type_sockaddr, ret));
2208                 else
2209                         CHECK(cfg_parse_astring(pctx, &cfg_type_astring, ret));
2210         } else {
2211                 cfg_parser_error(pctx, CFG_LOG_NEAR,
2212                              "expected IP address or masters name");
2213                 return (ISC_R_UNEXPECTEDTOKEN);
2214         }
2215  cleanup:
2216         CLEANUP_OBJ(obj);
2217         return (result);
2218 }
2219
2220 static cfg_type_t cfg_type_masterselement = {
2221         "masters_element", parse_masterselement, NULL,
2222          doc_masterselement, NULL, NULL
2223 };