namedconf.c 94.6 KB
Newer Older
1
/*
2
 * Copyright (C) 2004-2015  Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
3
 * Copyright (C) 2002, 2003  Internet Software Consortium.
4
 *
Automatic Updater's avatar
Automatic Updater committed
5
 * Permission to use, copy, modify, and/or distribute this software for any
6
7
8
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
Mark Andrews's avatar
Mark Andrews committed
9
10
11
12
13
14
15
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
16
17
 */

18
/*! \file */
19
20
21
22
23
24

#include <config.h>

#include <string.h>

#include <isc/lex.h>
25
#include <isc/mem.h>
26
27
28
29
#include <isc/result.h>
#include <isc/string.h>
#include <isc/util.h>

Evan Hunt's avatar
Evan Hunt committed
30
31
32
#include <dns/ttl.h>
#include <dns/result.h>

33
34
35
36
#include <isccfg/cfg.h>
#include <isccfg/grammar.h>
#include <isccfg/log.h>

37
38
#define TOKEN_STRING(pctx) (pctx->token.value.as_textregion.base)

39
/*% Check a return value. */
40
41
42
#define CHECK(op)						\
	do { result = (op);					\
		if (result != ISC_R_SUCCESS) goto cleanup;	\
43
44
	} while (0)

45
/*% Clean up a configuration object if non-NULL. */
46
47
48
49
#define CLEANUP_OBJ(obj) \
	do { if ((obj) != NULL) cfg_obj_destroy(pctx, &(obj)); } while (0)


50
/*%
51
52
53
54
55
56
57
 * Forward declarations of static functions.
 */

static isc_result_t
parse_enum_or_other(cfg_parser_t *pctx, const cfg_type_t *enumtype,
		    const cfg_type_t *othertype, cfg_obj_t **ret);

58
59
60
static void
doc_enum_or_other(cfg_printer_t *pctx, const cfg_type_t *type);

61
62
63
64
static isc_result_t
parse_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);

static isc_result_t
65
66
67
68
69
70
parse_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type,
			cfg_obj_t **ret);

static isc_result_t
parse_updatepolicy(cfg_parser_t *pctx, const cfg_type_t *type,
		   cfg_obj_t **ret);
Mark Andrews's avatar
Mark Andrews committed
71
72
static void
print_updatepolicy(cfg_printer_t *pctx, const cfg_obj_t *obj);
73
74
75

static void
doc_updatepolicy(cfg_printer_t *pctx, const cfg_type_t *type);
76
77

static void
78
print_keyvalue(cfg_printer_t *pctx, const cfg_obj_t *obj);
79
80
81
82
83
84
85

static void
doc_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);

static void
doc_optional_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);

86
#ifdef HAVE_GEOIP
Evan Hunt's avatar
Evan Hunt committed
87
88
89
90
91
92
93
94
static isc_result_t
parse_geoip(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);

static void
print_geoip(cfg_printer_t *pctx, const cfg_obj_t *obj);

static void
doc_geoip(cfg_printer_t *pctx, const cfg_type_t *type);
95
#endif /* HAVE_GEOIP */
Evan Hunt's avatar
Evan Hunt committed
96

97
static cfg_type_t cfg_type_acl;
98
99
static cfg_type_t cfg_type_addrmatchelt;
static cfg_type_t cfg_type_bracketed_aml;
100
static cfg_type_t cfg_type_bracketed_namesockaddrkeylist;
Evan Hunt's avatar
Evan Hunt committed
101
static cfg_type_t cfg_type_bracketed_dscpsockaddrlist;
102
static cfg_type_t cfg_type_bracketed_sockaddrlist;
103
static cfg_type_t cfg_type_bracketed_sockaddrnameportlist;
104
105
106
107
static cfg_type_t cfg_type_controls;
static cfg_type_t cfg_type_controls_sockaddr;
static cfg_type_t cfg_type_destinationlist;
static cfg_type_t cfg_type_dialuptype;
108
static cfg_type_t cfg_type_ixfrdifftype;
109
110
111
112
113
static cfg_type_t cfg_type_key;
static cfg_type_t cfg_type_logfile;
static cfg_type_t cfg_type_logging;
static cfg_type_t cfg_type_logseverity;
static cfg_type_t cfg_type_lwres;
114
static cfg_type_t cfg_type_masterselement;
Evan Hunt's avatar
Evan Hunt committed
115
static cfg_type_t cfg_type_maxttl;
116
117
118
static cfg_type_t cfg_type_nameportiplist;
static cfg_type_t cfg_type_negated;
static cfg_type_t cfg_type_notifytype;
119
static cfg_type_t cfg_type_optional_allow;
120
121
static cfg_type_t cfg_type_optional_class;
static cfg_type_t cfg_type_optional_facility;
122
static cfg_type_t cfg_type_optional_keyref;
123
static cfg_type_t cfg_type_optional_port;
Evan Hunt's avatar
Evan Hunt committed
124
static cfg_type_t cfg_type_optional_dscp;
Evan Hunt's avatar
Evan Hunt committed
125
static cfg_type_t cfg_type_optional_uint32;
126
static cfg_type_t cfg_type_options;
127
static cfg_type_t cfg_type_portiplist;
128
129
130
static cfg_type_t cfg_type_querysource4;
static cfg_type_t cfg_type_querysource6;
static cfg_type_t cfg_type_querysource;
131
132
133
134
static cfg_type_t cfg_type_server;
static cfg_type_t cfg_type_server_key_kludge;
static cfg_type_t cfg_type_size;
static cfg_type_t cfg_type_sizenodefault;
135
136
static cfg_type_t cfg_type_sockaddr4wild;
static cfg_type_t cfg_type_sockaddr6wild;
137
static cfg_type_t cfg_type_statschannels;
Evan Hunt's avatar
Evan Hunt committed
138
static cfg_type_t cfg_type_ttlval;
139
140
static cfg_type_t cfg_type_view;
static cfg_type_t cfg_type_viewopts;
141
142
static cfg_type_t cfg_type_zone;
static cfg_type_t cfg_type_zoneopts;
Evan Hunt's avatar
Evan Hunt committed
143
static cfg_type_t cfg_type_filter_aaaa;
144
static cfg_type_t cfg_type_dlz;
145

146
/*% tkey-dhkey */
147
148
149
150
151
152
153
154
155
156
157
158

static cfg_tuplefielddef_t tkey_dhkey_fields[] = {
	{ "name", &cfg_type_qstring, 0 },
	{ "keyid", &cfg_type_uint32, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_tkey_dhkey = {
	"tkey-dhkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
	tkey_dhkey_fields
};

159
/*% listen-on */
160
161
162

static cfg_tuplefielddef_t listenon_fields[] = {
	{ "port", &cfg_type_optional_port, 0 },
Evan Hunt's avatar
Evan Hunt committed
163
	{ "dscp", &cfg_type_optional_dscp, 0 },
164
165
166
	{ "acl", &cfg_type_bracketed_aml, 0 },
	{ NULL, NULL, 0 }
};
Evan Hunt's avatar
Evan Hunt committed
167

168
static cfg_type_t cfg_type_listenon = {
Evan Hunt's avatar
Evan Hunt committed
169
170
171
	"listenon", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, listenon_fields
};
172

173
/*% acl */
174
175
176
177
178
179
180
181
182
183

static cfg_tuplefielddef_t acl_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "value", &cfg_type_bracketed_aml, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_acl = {
	"acl", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, acl_fields };

184
/*% masters */
185
186
187
static cfg_tuplefielddef_t masters_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "port", &cfg_type_optional_port, 0 },
Evan Hunt's avatar
Evan Hunt committed
188
	{ "dscp", &cfg_type_optional_dscp, 0 },
189
190
191
192
193
194
	{ "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_masters = {
	"masters", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, masters_fields };
195

196
/*%
197
198
199
 * "sockaddrkeylist", a list of socket addresses with optional keys
 * and an optional default port, as used in the masters option.
 * E.g.,
200
 *   "port 1234 { mymasters; 10.0.0.1 key foo; 1::2 port 69; }"
201
202
 */

203
204
static cfg_tuplefielddef_t namesockaddrkey_fields[] = {
	{ "masterselement", &cfg_type_masterselement, 0 },
205
206
207
208
	{ "key", &cfg_type_optional_keyref, 0 },
	{ NULL, NULL, 0 },
};

209
210
211
static cfg_type_t cfg_type_namesockaddrkey = {
	"namesockaddrkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
	namesockaddrkey_fields
212
213
};

214
215
216
static cfg_type_t cfg_type_bracketed_namesockaddrkeylist = {
	"bracketed_namesockaddrkeylist", cfg_parse_bracketed_list,
	cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_namesockaddrkey
217
218
};

219
static cfg_tuplefielddef_t namesockaddrkeylist_fields[] = {
220
	{ "port", &cfg_type_optional_port, 0 },
Evan Hunt's avatar
Evan Hunt committed
221
	{ "dscp", &cfg_type_optional_dscp, 0 },
222
	{ "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 },
223
224
	{ NULL, NULL, 0 }
};
225
static cfg_type_t cfg_type_namesockaddrkeylist = {
226
	"sockaddrkeylist", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
227
	namesockaddrkeylist_fields
228
229
};

230
/*%
231
232
 * A list of socket addresses with an optional default port, as used
 * in the lwresd 'listen-on' option.  E.g., "{ 10.0.0.1; 1::2 port 69; }"
233
234
235
 */
static cfg_tuplefielddef_t portiplist_fields[] = {
	{ "port", &cfg_type_optional_port, 0 },
Evan Hunt's avatar
Evan Hunt committed
236
237
	{ "dscp", &cfg_type_optional_dscp, 0 },
	{ "addresses", &cfg_type_bracketed_dscpsockaddrlist, 0 },
238
239
240
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_portiplist = {
241
242
	"portiplist", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, portiplist_fields
243
244
};

245
/*%
246
247
248
249
250
251
252
253
254
255
 * A public key, as in the "pubkey" statement.
 */
static cfg_tuplefielddef_t pubkey_fields[] = {
	{ "flags", &cfg_type_uint32, 0 },
	{ "protocol", &cfg_type_uint32, 0 },
	{ "algorithm", &cfg_type_uint32, 0 },
	{ "key", &cfg_type_qstring, 0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_pubkey = {
256
257
	"pubkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, pubkey_fields };
258

259
/*%
260
261
262
263
 * A list of RR types, used in grant statements.
 * Note that the old parser allows quotes around the RR type names.
 */
static cfg_type_t cfg_type_rrtypelist = {
264
	"rrtypelist", cfg_parse_spacelist, cfg_print_spacelist,
Automatic Updater's avatar
Automatic Updater committed
265
	cfg_doc_terminal, &cfg_rep_list, &cfg_type_astring
266
267
268
269
};

static const char *mode_enums[] = { "grant", "deny", NULL };
static cfg_type_t cfg_type_mode = {
Automatic Updater's avatar
Automatic Updater committed
270
	"mode", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
271
	&cfg_rep_string, &mode_enums
272
273
};

274
275
276
277
278
279
280
281
static isc_result_t
parse_matchtype(cfg_parser_t *pctx, const cfg_type_t *type,
		cfg_obj_t **ret) {
	isc_result_t result;

	CHECK(cfg_peektoken(pctx, 0));
	if (pctx->token.type == isc_tokentype_string &&
	    strcasecmp(TOKEN_STRING(pctx), "zonesub") == 0) {
Automatic Updater's avatar
Automatic Updater committed
282
		pctx->flags |= CFG_PCTX_SKIP;
283
284
285
286
287
288
289
290
	}
	return (cfg_parse_enum(pctx, type, ret));

 cleanup:
	return (result);
}

static isc_result_t
291
parse_matchname(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
292
293
294
295
296
297
298
299
300
301
302
303
304
305
	isc_result_t result;
	cfg_obj_t *obj = NULL;

	if ((pctx->flags & CFG_PCTX_SKIP) != 0) {
		pctx->flags &= ~CFG_PCTX_SKIP;
		CHECK(cfg_parse_void(pctx, NULL, &obj));
	} else
		result = cfg_parse_astring(pctx, type, &obj);

	*ret = obj;
 cleanup:
	return (result);
}

306
307
static void
doc_matchname(cfg_printer_t *pctx, const cfg_type_t *type) {
308
	cfg_print_cstr(pctx, "[ ");
309
	cfg_doc_obj(pctx, type->of);
310
	cfg_print_cstr(pctx, " ]");
311
312
}

313
static const char *matchtype_enums[] = {
Automatic Updater's avatar
Automatic Updater committed
314
	"name", "subdomain", "wildcard", "self", "selfsub", "selfwild",
315
	"krb5-self", "ms-self", "krb5-subdomain", "ms-subdomain",
316
	"tcp-self", "6to4-self", "zonesub", "external", NULL };
317

318
static cfg_type_t cfg_type_matchtype = {
319
	"matchtype", parse_matchtype, cfg_print_ustring,
Automatic Updater's avatar
Automatic Updater committed
320
	cfg_doc_enum, &cfg_rep_string, &matchtype_enums
321
322
323
324
};

static cfg_type_t cfg_type_matchname = {
	"optional_matchname", parse_matchname, cfg_print_ustring,
325
	&doc_matchname, &cfg_rep_tuple, &cfg_type_ustring
326
327
};

328
/*%
329
330
331
332
 * A grant statement, used in the update policy.
 */
static cfg_tuplefielddef_t grant_fields[] = {
	{ "mode", &cfg_type_mode, 0 },
Automatic Updater's avatar
Automatic Updater committed
333
	{ "identity", &cfg_type_astring, 0 }, /* domain name */
334
	{ "matchtype", &cfg_type_matchtype, 0 },
335
	{ "name", &cfg_type_matchname, 0 }, /* domain name */
336
337
338
339
	{ "types", &cfg_type_rrtypelist, 0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_grant = {
340
341
342
	"grant", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	 &cfg_rep_tuple, grant_fields
};
343
344

static cfg_type_t cfg_type_updatepolicy = {
Mark Andrews's avatar
Mark Andrews committed
345
346
	"update_policy", parse_updatepolicy, print_updatepolicy,
	doc_updatepolicy, &cfg_rep_list, &cfg_type_grant
347
348
};

349
350
351
352
353
354
355
static isc_result_t
parse_updatepolicy(cfg_parser_t *pctx, const cfg_type_t *type,
		   cfg_obj_t **ret) {
	isc_result_t result;
	CHECK(cfg_gettoken(pctx, 0));
	if (pctx->token.type == isc_tokentype_special &&
	    pctx->token.value.as_char == '{') {
356
		cfg_ungettoken(pctx);
357
358
359
360
361
362
363
364
365
366
367
368
369
370
		return (cfg_parse_bracketed_list(pctx, type, ret));
	}

	if (pctx->token.type == isc_tokentype_string &&
	    strcasecmp(TOKEN_STRING(pctx), "local") == 0) {
		cfg_obj_t *obj = NULL;
		CHECK(cfg_create_obj(pctx, &cfg_type_ustring, &obj));
		obj->value.string.length = strlen("local");
		obj->value.string.base	= isc_mem_get(pctx->mctx,
						obj->value.string.length + 1);
		if (obj->value.string.base == NULL) {
			isc_mem_put(pctx->mctx, obj, sizeof(*obj));
			return (ISC_R_NOMEMORY);
		}
371
		memmove(obj->value.string.base, "local", 5);
372
373
374
375
376
377
378
379
380
381
382
383
		obj->value.string.base[5] = '\0';
		*ret = obj;
		return (ISC_R_SUCCESS);
	}

	cfg_ungettoken(pctx);
	return (ISC_R_UNEXPECTEDTOKEN);

 cleanup:
	return (result);
}

Mark Andrews's avatar
Mark Andrews committed
384
385
386
387
388
389
390
391
static void
print_updatepolicy(cfg_printer_t *pctx, const cfg_obj_t *obj) {
	if (cfg_obj_isstring(obj))
		cfg_print_ustring(pctx, obj);
	else
		cfg_print_bracketed_list(pctx, obj);
}

392
393
static void
doc_updatepolicy(cfg_printer_t *pctx, const cfg_type_t *type) {
394
	cfg_print_cstr(pctx, "( local | { ");
395
	cfg_doc_obj(pctx, type->of);
396
	cfg_print_cstr(pctx, "; ... }");
397
398
}

399
/*%
400
401
402
403
404
405
406
407
408
 * A view statement.
 */
static cfg_tuplefielddef_t view_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "class", &cfg_type_optional_class, 0 },
	{ "options", &cfg_type_viewopts, 0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_view = {
409
410
411
	"view", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	 &cfg_rep_tuple, view_fields
};
412

413
/*%
414
415
416
417
418
419
420
421
422
 * A zone statement.
 */
static cfg_tuplefielddef_t zone_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "class", &cfg_type_optional_class, 0 },
	{ "options", &cfg_type_zoneopts, 0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_zone = {
423
424
425
	"zone", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, zone_fields
};
426

427
/*%
428
429
430
431
432
433
434
435
 * A "category" clause in the "logging" statement.
 */
static cfg_tuplefielddef_t category_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "destinations", &cfg_type_destinationlist,0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_category = {
436
437
438
	"category", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, category_fields
};
439
440


441
/*%
442
 * A dnssec key, as used in the "trusted-keys" statement.
443
 */
444
static cfg_tuplefielddef_t dnsseckey_fields[] = {
445
446
447
448
449
450
451
	{ "name", &cfg_type_astring, 0 },
	{ "flags", &cfg_type_uint32, 0 },
	{ "protocol", &cfg_type_uint32, 0 },
	{ "algorithm", &cfg_type_uint32, 0 },
	{ "key", &cfg_type_qstring, 0 },
	{ NULL, NULL, 0 }
};
452
453
454
static cfg_type_t cfg_type_dnsseckey = {
	"dnsseckey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, dnsseckey_fields
455
456
};

457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/*%
 * A managed key initialization specifier, as used in the
 * "managed-keys" statement.
 */
static cfg_tuplefielddef_t managedkey_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "init", &cfg_type_ustring, 0 },   /* must be literal "initial-key" */
	{ "flags", &cfg_type_uint32, 0 },
	{ "protocol", &cfg_type_uint32, 0 },
	{ "algorithm", &cfg_type_uint32, 0 },
	{ "key", &cfg_type_qstring, 0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_managedkey = {
	"managedkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, managedkey_fields
};

475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
static keyword_type_t wild_class_kw = { "class", &cfg_type_ustring };

static cfg_type_t cfg_type_optional_wild_class = {
	"optional_wild_class", parse_optional_keyvalue, print_keyvalue,
	doc_optional_keyvalue, &cfg_rep_string, &wild_class_kw
};

static keyword_type_t wild_type_kw = { "type", &cfg_type_ustring };

static cfg_type_t cfg_type_optional_wild_type = {
	"optional_wild_type", parse_optional_keyvalue,
	print_keyvalue, doc_optional_keyvalue, &cfg_rep_string, &wild_type_kw
};

static keyword_type_t wild_name_kw = { "name", &cfg_type_qstring };

static cfg_type_t cfg_type_optional_wild_name = {
	"optional_wild_name", parse_optional_keyvalue,
	print_keyvalue, doc_optional_keyvalue, &cfg_rep_string, &wild_name_kw
};

496
/*%
497
498
499
500
501
502
 * An rrset ordering element.
 */
static cfg_tuplefielddef_t rrsetorderingelement_fields[] = {
	{ "class", &cfg_type_optional_wild_class, 0 },
	{ "type", &cfg_type_optional_wild_type, 0 },
	{ "name", &cfg_type_optional_wild_name, 0 },
Automatic Updater's avatar
Automatic Updater committed
503
	{ "order", &cfg_type_ustring, 0 }, /* must be literal "order" */
504
505
506
507
508
509
510
511
	{ "ordering", &cfg_type_ustring, 0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_rrsetorderingelement = {
	"rrsetorderingelement", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple,
	rrsetorderingelement_fields
};

512
/*%
513
514
515
 * A global or view "check-names" option.  Note that the zone
 * "check-names" option has a different syntax.
 */
516
517
518
519
520
521
522
523
524
525
526
527
528

static const char *checktype_enums[] = { "master", "slave", "response", NULL };
static cfg_type_t cfg_type_checktype = {
	"checktype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &checktype_enums
};

static const char *checkmode_enums[] = { "fail", "warn", "ignore", NULL };
static cfg_type_t cfg_type_checkmode = {
	"checkmode", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &checkmode_enums
};

529
530
531
532
533
534
static const char *warn_enums[] = { "warn", "ignore", NULL };
static cfg_type_t cfg_type_warn = {
	"warn", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &warn_enums
};

535
static cfg_tuplefielddef_t checknames_fields[] = {
536
537
	{ "type", &cfg_type_checktype, 0 },
	{ "mode", &cfg_type_checkmode, 0 },
538
539
	{ NULL, NULL, 0 }
};
540

541
static cfg_type_t cfg_type_checknames = {
Evan Hunt's avatar
Evan Hunt committed
542
543
544
545
546
547
548
549
	"checknames", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, checknames_fields
};

static cfg_type_t cfg_type_bracketed_dscpsockaddrlist = {
	"bracketed_sockaddrlist", cfg_parse_bracketed_list,
	cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list,
	&cfg_type_sockaddrdscp
550
551
552
};

static cfg_type_t cfg_type_bracketed_sockaddrlist = {
Evan Hunt's avatar
Evan Hunt committed
553
554
555
	"bracketed_sockaddrlist", cfg_parse_bracketed_list,
	cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list,
	&cfg_type_sockaddr
556
557
};

558
static const char *autodnssec_enums[] = { "allow", "maintain", "off", NULL };
559
560
561
562
563
static cfg_type_t cfg_type_autodnssec = {
	"autodnssec", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &autodnssec_enums
};

564
565
566
567
568
569
static const char *dnssecupdatemode_enums[] = { "maintain", "no-resign", NULL };
static cfg_type_t cfg_type_dnssecupdatemode = {
	"dnssecupdatemode", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &dnssecupdatemode_enums
};

570
571
static const char *updatemethods_enums[] = {
	"increment", "unixtime", "date", NULL };
572
573
574
575
576
static cfg_type_t cfg_type_updatemethod = {
	"updatemethod", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &updatemethods_enums
};

577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*
 * zone-statistics: full, terse, or none.
 *
 * for backward compatibility, we also support boolean values.
 * yes represents "full", no represents "terse". in the future we
 * may change no to mean "none".
 */
static const char *zonestat_enums[] = { "full", "terse", "none", NULL };
static isc_result_t
parse_zonestat(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
	return (parse_enum_or_other(pctx, type, &cfg_type_boolean, ret));
}
static cfg_type_t cfg_type_zonestat = {
	"zonestat", parse_zonestat, cfg_print_ustring, doc_enum_or_other,
	&cfg_rep_string, zonestat_enums
};

594
static cfg_type_t cfg_type_rrsetorder = {
Evan Hunt's avatar
Evan Hunt committed
595
596
597
598
599
600
601
602
603
	"rrsetorder", cfg_parse_bracketed_list, cfg_print_bracketed_list,
	cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_rrsetorderingelement
};

static keyword_type_t dscp_kw = { "dscp", &cfg_type_uint32 };

static cfg_type_t cfg_type_optional_dscp = {
	"optional_dscp", parse_optional_keyvalue, print_keyvalue,
	doc_optional_keyvalue, &cfg_rep_uint32, &dscp_kw
604
605
606
607
608
609
610
611
612
};

static keyword_type_t port_kw = { "port", &cfg_type_uint32 };

static cfg_type_t cfg_type_optional_port = {
	"optional_port", parse_optional_keyvalue, print_keyvalue,
	doc_optional_keyvalue, &cfg_rep_uint32, &port_kw
};

613
/*% A list of keys, as in the "key" clause of the controls statement. */
614
static cfg_type_t cfg_type_keylist = {
615
616
	"keylist", cfg_parse_bracketed_list, cfg_print_bracketed_list,
	cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_astring
617
618
};

619
/*% A list of dnssec keys, as in "trusted-keys" */
620
621
622
static cfg_type_t cfg_type_dnsseckeys = {
	"dnsseckeys", cfg_parse_bracketed_list, cfg_print_bracketed_list,
	cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_dnsseckey
623
624
};

625
626
627
628
629
630
631
632
633
634
635
636
637
/*%
 * A list of managed key entries, as in "trusted-keys".  Currently
 * (9.7.0) this has a format similar to dnssec keys, except the keyname
 * is followed by the keyword "initial-key".  In future releases, this
 * keyword may take other values indicating different methods for the
 * key to be initialized.
 */

static cfg_type_t cfg_type_managedkeys = {
	"managedkeys", cfg_parse_bracketed_list, cfg_print_bracketed_list,
	cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_managedkey
};

638
639
640
641
642
643
644
static const char *forwardtype_enums[] = { "first", "only", NULL };
static cfg_type_t cfg_type_forwardtype = {
	"forwardtype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
	&forwardtype_enums
};

static const char *zonetype_enums[] = {
645
	"master", "slave", "stub", "static-stub", "hint", "forward",
646
	"delegation-only", "redirect", NULL };
647
static cfg_type_t cfg_type_zonetype = {
648
649
	"zonetype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &zonetype_enums
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
};

static const char *loglevel_enums[] = {
	"critical", "error", "warning", "notice", "info", "dynamic", NULL };
static cfg_type_t cfg_type_loglevel = {
	"loglevel", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
	&loglevel_enums
};

static const char *transferformat_enums[] = {
	"many-answers", "one-answer", NULL };
static cfg_type_t cfg_type_transferformat = {
	"transferformat", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string,
	&transferformat_enums
};

666
/*%
667
668
669
670
 * The special keyword "none", as used in the pid-file option.
 */

static void
671
print_none(cfg_printer_t *pctx, const cfg_obj_t *obj) {
672
	UNUSED(obj);
673
	cfg_print_cstr(pctx, "none");
674
675
676
677
678
679
}

static cfg_type_t cfg_type_none = {
	"none", NULL, print_none, NULL, &cfg_rep_void, NULL
};

680
/*%
681
682
683
684
685
686
687
 * A quoted string or the special keyword "none".  Used in the pid-file option.
 */
static isc_result_t
parse_qstringornone(cfg_parser_t *pctx, const cfg_type_t *type,
		    cfg_obj_t **ret)
{
	isc_result_t result;
688

689
690
	CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
	if (pctx->token.type == isc_tokentype_string &&
691
	    strcasecmp(TOKEN_STRING(pctx), "none") == 0)
692
693
694
695
696
697
698
699
700
701
		return (cfg_create_obj(pctx, &cfg_type_none, ret));
	cfg_ungettoken(pctx);
	return (cfg_parse_qstring(pctx, type, ret));
 cleanup:
	return (result);
}

static void
doc_qstringornone(cfg_printer_t *pctx, const cfg_type_t *type) {
	UNUSED(type);
702
	cfg_print_cstr(pctx, "( <quoted_string> | none )");
703
704
705
}

static cfg_type_t cfg_type_qstringornone = {
706
707
708
	"qstringornone", parse_qstringornone, NULL, doc_qstringornone,
	NULL, NULL
};
709

710
/*%
711
712
 * A boolean ("yes" or "no"), or the special keyword "auto".
 * Used in the dnssec-validation option.
713
 */
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
static void
print_auto(cfg_printer_t *pctx, const cfg_obj_t *obj) {
	UNUSED(obj);
	cfg_print_cstr(pctx, "auto");
}

static cfg_type_t cfg_type_auto = {
	"auto", NULL, print_auto, NULL, &cfg_rep_void, NULL
};

static isc_result_t
parse_boolorauto(cfg_parser_t *pctx, const cfg_type_t *type,
		    cfg_obj_t **ret)
{
	isc_result_t result;

	CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
	if (pctx->token.type == isc_tokentype_string &&
	    strcasecmp(TOKEN_STRING(pctx), "auto") == 0)
		return (cfg_create_obj(pctx, &cfg_type_auto, ret));
	cfg_ungettoken(pctx);
	return (cfg_parse_boolean(pctx, type, ret));
 cleanup:
	return (result);
}

static void
print_boolorauto(cfg_printer_t *pctx, const cfg_obj_t *obj) {
	if (obj->type->rep == &cfg_rep_void)
743
		cfg_print_cstr(pctx, "auto");
744
	else if (obj->value.boolean)
745
		cfg_print_cstr(pctx, "yes");
746
	else
747
		cfg_print_cstr(pctx, "no");
748
749
750
751
752
753
754
755
756
757
758
759
}

static void
doc_boolorauto(cfg_printer_t *pctx, const cfg_type_t *type) {
	UNUSED(type);
	cfg_print_cstr(pctx, "( yes | no | auto )");
}

static cfg_type_t cfg_type_boolorauto = {
	"boolorauto", parse_boolorauto, print_boolorauto,
	doc_boolorauto, NULL, NULL
};
760

761
762
763
/*%
 * keyword hostname
 */
764
static void
765
print_hostname(cfg_printer_t *pctx, const cfg_obj_t *obj) {
766
	UNUSED(obj);
767
	cfg_print_cstr(pctx, "hostname");
768
769
770
771
772
773
}

static cfg_type_t cfg_type_hostname = {
	"hostname", NULL, print_hostname, NULL, &cfg_rep_boolean, NULL
};

774
/*%
Mark Andrews's avatar
Mark Andrews committed
775
 * "server-id" argument.
776
777
778
779
780
781
782
783
784
785
786
787
788
 */

static isc_result_t
parse_serverid(cfg_parser_t *pctx, const cfg_type_t *type,
		    cfg_obj_t **ret)
{
	isc_result_t result;
	CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING));
	if (pctx->token.type == isc_tokentype_string &&
	    strcasecmp(TOKEN_STRING(pctx), "none") == 0)
		return (cfg_create_obj(pctx, &cfg_type_none, ret));
	if (pctx->token.type == isc_tokentype_string &&
	    strcasecmp(TOKEN_STRING(pctx), "hostname") == 0) {
789
790
791
792
		result = cfg_create_obj(pctx, &cfg_type_hostname, ret);
		if (result == ISC_R_SUCCESS)
			(*ret)->value.boolean = ISC_TRUE;
		return (result);
793
794
795
796
797
798
799
800
801
802
	}
	cfg_ungettoken(pctx);
	return (cfg_parse_qstring(pctx, type, ret));
 cleanup:
	return (result);
}

static void
doc_serverid(cfg_printer_t *pctx, const cfg_type_t *type) {
	UNUSED(type);
803
	cfg_print_cstr(pctx, "( <quoted_string> | none | hostname )");
804
805
806
807
808
}

static cfg_type_t cfg_type_serverid = {
	"serverid", parse_serverid, NULL, doc_serverid, NULL, NULL };

809
/*%
810
811
 * Port list.
 */
812
813
814
815
816
817
818
819
820
821
static cfg_tuplefielddef_t porttuple_fields[] = {
	{ "loport", &cfg_type_uint32, 0 },
	{ "hiport", &cfg_type_uint32, 0 },
	{ NULL, NULL, 0 }
};
static cfg_type_t cfg_type_porttuple = {
	"porttuple", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, porttuple_fields
};

822
static isc_result_t
823
parse_port(cfg_parser_t *pctx, cfg_obj_t **ret) {
824
	isc_result_t result;
Automatic Updater's avatar
Automatic Updater committed
825

826
827
828
829
830
831
	CHECK(cfg_parse_uint32(pctx, NULL, ret));
	if ((*ret)->value.uint32 > 0xffff) {
		cfg_parser_error(pctx, CFG_LOG_NEAR, "invalid port");
		cfg_obj_destroy(pctx, ret);
		result = ISC_R_RANGE;
	}
Automatic Updater's avatar
Automatic Updater committed
832

833
834
835
836
 cleanup:
	return (result);
}

837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
static isc_result_t
parse_portrange(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) {
	isc_result_t result;
	cfg_obj_t *obj = NULL;

	UNUSED(type);

	CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER));
	if (pctx->token.type == isc_tokentype_number)
		CHECK(parse_port(pctx, ret));
	else {
		CHECK(cfg_gettoken(pctx, 0));
		if (pctx->token.type != isc_tokentype_string ||
		    strcasecmp(TOKEN_STRING(pctx), "range") != 0) {
			cfg_parser_error(pctx, CFG_LOG_NEAR,
					 "expected integer or 'range'");
			return (ISC_R_UNEXPECTEDTOKEN);
		}
		CHECK(cfg_create_tuple(pctx, &cfg_type_porttuple, &obj));
		CHECK(parse_port(pctx, &obj->value.tuple[0]));
		CHECK(parse_port(pctx, &obj->value.tuple[1]));
		if (obj->value.tuple[0]->value.uint32 >
		    obj->value.tuple[1]->value.uint32) {
			cfg_parser_error(pctx, CFG_LOG_NOPREP,
					 "low port '%u' must not be larger "
					 "than high port",
					 obj->value.tuple[0]->value.uint32);
			result = ISC_R_RANGE;
			goto cleanup;
		}
		*ret = obj;
		obj = NULL;
	}

 cleanup:
	if (obj != NULL)
		cfg_obj_destroy(pctx, &obj);
	return (result);
}

static cfg_type_t cfg_type_portrange = {
	"portrange", parse_portrange, NULL, cfg_doc_terminal,
879
880
881
882
	NULL, NULL
};

static cfg_type_t cfg_type_bracketed_portlist = {
883
884
885
	"bracketed_sockaddrlist", cfg_parse_bracketed_list,
	cfg_print_bracketed_list, cfg_doc_bracketed_list,
	&cfg_rep_list, &cfg_type_portrange
886
887
};

888
889
890
891
892
static const char *cookiealg_enums[] = { "aes", "sha1", "sha256", NULL };
static cfg_type_t cfg_type_cookiealg = {
	"cookiealg", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &cookiealg_enums };

Evan Hunt's avatar
Evan Hunt committed
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
/*%
 * fetch-quota-params
 */

static cfg_tuplefielddef_t fetchquota_fields[] = {
	{ "frequency", &cfg_type_uint32, 0 },
	{ "low", &cfg_type_fixedpoint, 0 },
	{ "high", &cfg_type_fixedpoint, 0 },
	{ "discount", &cfg_type_fixedpoint, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_fetchquota = {
	"fetchquota", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, fetchquota_fields
};

/*%
 * fetches-per-server or fetches-per-zone
 */

static const char *response_enums[] = { "drop", "fail", NULL };

static isc_result_t
parse_optional_response(cfg_parser_t *pctx, const cfg_type_t *type,
			cfg_obj_t **ret)
{
	return (parse_enum_or_other(pctx, type, &cfg_type_void, ret));
}

static void
doc_optional_response(cfg_printer_t *pctx, const cfg_type_t *type) {
	UNUSED(type);
	cfg_print_cstr(pctx, "[ ( drop | fail ) ]");
}

static cfg_type_t cfg_type_responsetype = {
	"responsetype", parse_optional_response, cfg_print_ustring,
	doc_optional_response, &cfg_rep_string, response_enums
};

static cfg_tuplefielddef_t fetchesper_fields[] = {
	{ "fetches", &cfg_type_uint32, 0 },
	{ "response", &cfg_type_responsetype, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_fetchesper = {
	"fetchesper", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, fetchesper_fields
};

945
/*%
946
947
948
949
950
951
952
953
 * Clauses that can be found within the top level of the named.conf
 * file only.
 */
static cfg_clausedef_t
namedconf_clauses[] = {
	{ "options", &cfg_type_options, 0 },
	{ "controls", &cfg_type_controls, CFG_CLAUSEFLAG_MULTI },
	{ "acl", &cfg_type_acl, CFG_CLAUSEFLAG_MULTI },
954
	{ "masters", &cfg_type_masters, CFG_CLAUSEFLAG_MULTI },
955
956
957
	{ "logging", &cfg_type_logging, 0 },
	{ "view", &cfg_type_view, CFG_CLAUSEFLAG_MULTI },
	{ "lwres", &cfg_type_lwres, CFG_CLAUSEFLAG_MULTI },
958
959
	{ "statistics-channels", &cfg_type_statschannels,
	  CFG_CLAUSEFLAG_MULTI },
960
961
962
	{ NULL, NULL, 0 }
};

963
/*%
964
965
966
967
968
969
970
 * Clauses that can occur at the top level or in the view
 * statement, but not in the options block.
 */
static cfg_clausedef_t
namedconf_or_view_clauses[] = {
	{ "key", &cfg_type_key, CFG_CLAUSEFLAG_MULTI },
	{ "zone", &cfg_type_zone, CFG_CLAUSEFLAG_MULTI },
971
	{ "dlz", &cfg_type_dlz, CFG_CLAUSEFLAG_MULTI },
972
	{ "server", &cfg_type_server, CFG_CLAUSEFLAG_MULTI },
973
	{ "trusted-keys", &cfg_type_dnsseckeys, CFG_CLAUSEFLAG_MULTI },
974
	{ "managed-keys", &cfg_type_managedkeys, CFG_CLAUSEFLAG_MULTI },
975
976
977
	{ NULL, NULL, 0 }
};

978
979
980
981
982
/*%
 * Clauses that can occur in the bind.keys file.
 */
static cfg_clausedef_t
bindkeys_clauses[] = {
983
	{ "trusted-keys", &cfg_type_dnsseckeys, CFG_CLAUSEFLAG_MULTI },
984
	{ "managed-keys", &cfg_type_managedkeys, CFG_CLAUSEFLAG_MULTI },
985
986
987
	{ NULL, NULL, 0 }
};

988
/*%
989
990
991
992
 * Clauses that can be found within the 'options' statement.
 */
static cfg_clausedef_t
options_clauses[] = {
993
	{ "automatic-interface-scan", &cfg_type_boolean, 0 },
994
995
	{ "avoid-v4-udp-ports", &cfg_type_bracketed_portlist, 0 },
	{ "avoid-v6-udp-ports", &cfg_type_bracketed_portlist, 0 },
996
	{ "bindkeys-file", &cfg_type_qstring, 0 },
997
	{ "blackhole", &cfg_type_bracketed_aml, 0 },
998
999
	{ "cookie-secret", &cfg_type_sstring, 0 },
	{ "cookie-algorithm", &cfg_type_cookiealg, 0 },
1000
1001
	{ "coresize", &cfg_type_size, 0 },
	{ "datasize", &cfg_type_size, 0 },
1002
1003
1004
	{ "session-keyfile", &cfg_type_qstringornone, 0 },
	{ "session-keyname", &cfg_type_astring, 0 },
	{ "session-keyalg", &cfg_type_astring, 0 },
1005
1006
	{ "deallocate-on-exit", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
	{ "directory", &cfg_type_qstring, CFG_CLAUSEFLAG_CALLBACK },
Evan Hunt's avatar
Evan Hunt committed
1007
	{ "dscp", &cfg_type_uint32, 0 },
1008
1009
1010
	{ "dump-file", &cfg_type_qstring, 0 },
	{ "fake-iquery", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
	{ "files", &cfg_type_size, 0 },
1011
	{ "flush-zones-on-shutdown", &cfg_type_boolean, 0 },
1012
#ifdef HAVE_GEOIP
Evan Hunt's avatar
Evan Hunt committed
1013
	{ "geoip-directory", &cfg_type_qstringornone, 0 },
Evan Hunt's avatar
Evan Hunt committed
1014
	{ "geoip-use-ecs", &cfg_type_boolean, 0 },
1015
1016
1017
#else
	{ "geoip-directory", &cfg_type_qstringornone,
	  CFG_CLAUSEFLAG_NOTCONFIGURED },
Evan Hunt's avatar
Evan Hunt committed
1018
1019
	{ "geoip-use-ecs", &cfg_type_qstringornone,
	  CFG_CLAUSEFLAG_NOTCONFIGURED },
1020
#endif /* HAVE_GEOIP */
1021
1022
1023
	{ "has-old-clients", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
	{ "heartbeat-interval", &cfg_type_uint32, 0 },
	{ "host-statistics", &cfg_type_boolean, CFG_CLAUSEFLAG_NOTIMP },
1024
	{ "host-statistics-max", &cfg_type_uint32, CFG_CLAUSEFLAG_NOTIMP },
1025
1026
	{ "hostname", &cfg_type_qstringornone, 0 },
	{ "interface-interval", &cfg_type_uint32, 0 },
1027
	{ "keep-response-order", &cfg_type_bracketed_aml, 0 },
1028
1029
	{ "listen-on", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
	{ "listen-on-v6", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
1030
	{ "lock-file", &cfg_type_qstringornone, 0 },
1031
	{ "sit-secret", &cfg_type_sstring, CFG_CLAUSEFLAG_OBSOLETE },
1032
	{ "managed-keys-directory", &cfg_type_qstring, 0 },
1033
	{ "match-mapped-addresses", &cfg_type_boolean, 0 },
1034
	{ "max-rsa-exponent-size", &cfg_type_uint32, 0 },
1035
	{ "memstatistics-file", &cfg_type_qstring, 0 },
1036
	{ "memstatistics", &cfg_type_boolean, 0 },
1037
1038
	{ "multiple-cnames", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
	{ "named-xfer", &cfg_type_qstring, CFG_CLAUSEFLAG_OBSOLETE },
1039
	{ "notify-rate", &cfg_type_uint32, 0 },
1040
1041
	{ "pid-file", &cfg_type_qstringornone, 0 },
	{ "port", &cfg_type_uint32, 0 },
1042
	{ "querylog", &cfg_type_boolean, 0 },
1043
	{ "recursing-file", &cfg_type_qstring, 0 },
1044
1045
	{ "random-device", &cfg_type_qstring, 0 },
	{ "recursive-clients", &cfg_type_uint32, 0 },
1046
	{ "reserved-sockets", &cfg_type_uint32, 0 },
1047
	{ "secroots-file", &cfg_type_qstring, 0 },
1048
1049
	{ "serial-queries", &cfg_type_uint32, CFG_CLAUSEFLAG_OBSOLETE },
	{ "serial-query-rate", &cfg_type_uint32, 0 },
1050
	{ "server-id", &cfg_type_serverid, 0 },
1051
	{ "stacksize", &cfg_type_size, 0 },
1052
	{ "startup-notify-rate", &cfg_type_uint32, 0 },
1053
1054
1055
	{ "statistics-file", &cfg_type_qstring, 0 },
	{ "statistics-interval", &cfg_type_uint32, CFG_CLAUSEFLAG_NYI },
	{ "tcp-clients", &cfg_type_uint32, 0 },
Michael Graff's avatar
Michael Graff committed
1056
	{ "tcp-listen-queue", &cfg_type_uint32, 0 },
1057
1058
	{ "tkey-dhkey", &cfg_type_tkey_dhkey, 0 },
	{ "tkey-gssapi-credential", &cfg_type_qstring, 0 },
1059
	{ "tkey-gssapi-keytab", &cfg_type_qstring, 0 },
1060
1061
1062
1063
1064
1065
1066
	{ "tkey-domain", &cfg_type_qstring, 0 },
	{ "transfers-per-ns", &cfg_type_uint32, 0 },
	{ "transfers-in", &cfg_type_uint32, 0 },
	{ "transfers-out", &cfg_type_uint32, 0 },
	{ "treat-cr-as-space", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
	{ "use-id-pool", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
	{ "use-ixfr", &cfg_type_boolean, 0 },
1067
1068
	{ "use-v4-udp-ports", &cfg_type_bracketed_portlist, 0 },
	{ "use-v6-udp-ports", &cfg_type_bracketed_portlist, 0 },
1069
1070
1071
1072
	{ "version", &cfg_type_qstringornone, 0 },
	{ NULL, NULL, 0 }
};

1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
static cfg_type_t cfg_type_namelist = {
	"namelist", cfg_parse_bracketed_list, cfg_print_bracketed_list,
	cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_qstring };

static keyword_type_t exclude_kw = { "exclude", &cfg_type_namelist };

static cfg_type_t cfg_type_optional_exclude = {
	"optional_exclude", parse_optional_keyvalue, print_keyvalue,
	doc_optional_keyvalue, &cfg_rep_list, &exclude_kw };

1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
static keyword_type_t exceptionnames_kw = { "except-from", &cfg_type_namelist };

static cfg_type_t cfg_type_optional_exceptionnames = {
	"optional_allow", parse_optional_keyvalue, print_keyvalue,
	doc_optional_keyvalue, &cfg_rep_list, &exceptionnames_kw };

static cfg_tuplefielddef_t denyaddresses_fields[] = {
	{ "acl", &cfg_type_bracketed_aml, 0 },
	{ "except-from", &cfg_type_optional_exceptionnames, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_denyaddresses = {
	"denyaddresses", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, denyaddresses_fields
};

static cfg_tuplefielddef_t denyaliases_fields[] = {
	{ "name", &cfg_type_namelist, 0 },
	{ "except-from", &cfg_type_optional_exceptionnames, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_denyaliases = {
	"denyaliases", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, denyaliases_fields
};

1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
static cfg_type_t cfg_type_algorithmlist = {
	"algorithmlist", cfg_parse_bracketed_list, cfg_print_bracketed_list,
	cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_astring };

static cfg_tuplefielddef_t disablealgorithm_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "algorithms", &cfg_type_algorithmlist, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_disablealgorithm = {
	"disablealgorithm", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, disablealgorithm_fields
};

1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
static cfg_type_t cfg_type_dsdigestlist = {
	"dsdigestlist", cfg_parse_bracketed_list, cfg_print_bracketed_list,
	cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_astring };

static cfg_tuplefielddef_t disabledsdigest_fields[] = {
	{ "name", &cfg_type_astring, 0 },
	{ "digests", &cfg_type_dsdigestlist, 0 },
	{ NULL, NULL, 0 }
};

static cfg_type_t cfg_type_disabledsdigest = {
	"disabledsdigest", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, disabledsdigest_fields
};

1141
static cfg_tuplefielddef_t mustbesecure_fields[] = {
Automatic Updater's avatar
Automatic Updater committed
1142
1143
1144
	{ "name", &cfg_type_astring, 0 },
	{ "value", &cfg_type_boolean, 0 },
	{ NULL, NULL, 0 }
1145
1146
1147
1148
1149
1150
1151
};

static cfg_type_t cfg_type_mustbesecure = {
	"mustbesecure", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple,
	&cfg_rep_tuple, mustbesecure_fields
};

Evan Hunt's avatar
Evan Hunt committed
1152
static const char *masterformat_enums[] = { "text", "raw", "map", NULL };
1153
1154
1155
1156
1157
static cfg_type_t cfg_type_masterformat = {
	"masterformat", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &masterformat_enums
};

Evan Hunt's avatar
Evan Hunt committed
1158
1159
1160
1161
1162
static const char *masterstyle_enums[] = { "full", "relative", NULL };
static cfg_type_t cfg_type_masterstyle = {
	"masterstyle", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum,
	&cfg_rep_string, &masterstyle_enums
};
1163
1164


1165
/*%
1166
 *  response-policy {
Evan Hunt's avatar
Evan Hunt committed
1167
 *	zone <string> [ policy (given|disabled|passthru|drop|tcp-only|
1168
 *					nxdomain|nodata|cname <domain> ) ]
1169
1170
 *		      [ recursive-only yes|no ] [ log yes|no ]
 *		      [ max-policy-ttl number ] ;
Mark Andrews's avatar
Mark Andrews committed
1171
 *  } [ recursive-only yes|no ] [ max-policy-ttl number ]
1172
 *	 [ break-dnssec yes|no ] [ min-ns-dots number ]
Mark Andrews's avatar
Mark Andrews committed
1173
 *	 [ qname-wait-recurse yes|no ] ;
1174
 */
1175

1176
static void
1177
doc_rpz_policy(cfg_printer_t *pctx, const cfg_type_t *type) {
1178
	const char * const *p;
1179
1180
1181
	/*
	 * This is cfg_doc_enum() without the trailing " )".
	 */
1182
	cfg_print_cstr(pctx, "( ");
1183
	for (p = type->of; *p != NULL; p++) {
1184
1185
		cfg_print_cstr(pctx, *p);
		if (p[1] != NULL)
1186
			cfg_print_cstr(pctx, " | ");
1187
1188
1189
1190
1191
1192
	}
}

static void
doc_rpz_cname(cfg_printer_t *pctx, const cfg_type_t *type) {
	cfg_doc_terminal(pctx, type);
1193
	cfg_print_cstr(pctx, " )");
1194
1195
}

1196
1197
/*
 * Parse
Evan Hunt's avatar
Evan Hunt committed
1198
 *	given|disabled|passthru|drop|tcp-only|nxdomain|nodata|cname <domain>
1199
 */
1200
static isc_result_t
1201
1202
1203
cfg_parse_rpz_policy(cfg_parser_t *pctx, const cfg_type_t *type,
		     cfg_obj_t **ret)
{
1204
	isc_result_t result;
1205
1206
	cfg_obj_t *obj;
	const cfg_tuplefielddef_t *fields;
1207
1208

	CHECK(cfg_create_tuple(pctx, type, &obj));
1209
1210

	fields = type->of;
1211
1212
1213
1214
	CHECK(cfg_parse_obj(pctx, fields[0].type, &obj->value.tuple[0]));
	/*
	 * parse cname domain only after "policy cname"
	 */
1215
1216
	if (strcasecmp("cname", cfg_obj_asstring(obj->value.tuple[0])) != 0) {
		CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[1]));
1217
	} else {
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
		CHECK(cfg_parse_obj(pctx, fields[1].type,
				    &obj->value.tuple[1]));
	}

	*ret = obj;
	return (ISC_R_SUCCESS);

cleanup:
	CLEANUP_OBJ(obj);
	return (result);
}

/*
Evan Hunt's avatar
Evan Hunt committed
1231
 * Parse a tuple consisting of any kind of required field followed
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251