check.c 122 KB
Newer Older
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
5
6
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9
 *
 * See the COPYRIGHT file distributed with this work for additional
 * information regarding copyright ownership.
10
11
 */

12
/*! \file */
13

14
#include <inttypes.h>
15
#include <stdbool.h>
16
#include <stdlib.h>
17

18
#include <isc/aes.h>
19
#include <isc/base64.h>
20
#include <isc/buffer.h>
21
#include <isc/file.h>
22
#include <isc/hex.h>
23
#include <isc/log.h>
24
#include <isc/md.h>
25
#include <isc/mem.h>
26
#include <isc/netaddr.h>
27
#include <isc/parseint.h>
28
#include <isc/platform.h>
29
#include <isc/print.h>
30
#include <isc/region.h>
31
#include <isc/result.h>
32
#include <isc/sockaddr.h>
Evan Hunt's avatar
Evan Hunt committed
33
#include <isc/string.h>
34
#include <isc/symtab.h>
Brian Wellington's avatar
Brian Wellington committed
35
#include <isc/util.h>
36

37
38
#include <pk11/site.h>

39
#include <dns/acl.h>
40
#include <dns/dnstap.h>
41
#include <dns/fixedname.h>
42
#include <dns/rbt.h>
Mark Andrews's avatar
Mark Andrews committed
43
44
#include <dns/rdataclass.h>
#include <dns/rdatatype.h>
45
#include <dns/rrl.h>
46
#include <dns/secalg.h>
47
#include <dns/ssu.h>
48

49
50
#include <dst/dst.h>

51
#include <isccfg/aclconf.h>
52
#include <isccfg/cfg.h>
53
54
#include <isccfg/grammar.h>
#include <isccfg/namedconf.h>
55

56
57
#include <ns/hooks.h>

58
#include <bind9/check.h>
59

Evan Hunt's avatar
Evan Hunt committed
60
61
static unsigned char dlviscorg_ndata[] = "\003dlv\003isc\003org";
static unsigned char dlviscorg_offsets[] = { 0, 4, 8, 12 };
62
static dns_name_t const dlviscorg =
Evan Hunt's avatar
Evan Hunt committed
63
64
	DNS_NAME_INITABSOLUTE(dlviscorg_ndata, dlviscorg_offsets);

65
static isc_result_t
66
fileexist(const cfg_obj_t *obj, isc_symtab_t *symtab, bool writeable,
67
68
	  isc_log_t *logctxlogc);

69
70
71
72
73
74
75
static void
freekey(char *key, unsigned int type, isc_symvalue_t value, void *userarg) {
	UNUSED(type);
	UNUSED(value);
	isc_mem_free(userarg, key);
}

Mark Andrews's avatar
Mark Andrews committed
76
static isc_result_t
77
check_orderent(const cfg_obj_t *ent, isc_log_t *logctx) {
Mark Andrews's avatar
Mark Andrews committed
78
79
80
81
	isc_result_t result = ISC_R_SUCCESS;
	isc_result_t tresult;
	isc_textregion_t r;
	dns_fixedname_t fixed;
82
	const cfg_obj_t *obj;
Mark Andrews's avatar
Mark Andrews committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
	dns_rdataclass_t rdclass;
	dns_rdatatype_t rdtype;
	isc_buffer_t b;
	const char *str;

	dns_fixedname_init(&fixed);
	obj = cfg_tuple_get(ent, "class");
	if (cfg_obj_isstring(obj)) {

		DE_CONST(cfg_obj_asstring(obj), r.base);
		r.length = strlen(r.base);
		tresult = dns_rdataclass_fromtext(&rdclass, &r);
		if (tresult != ISC_R_SUCCESS) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "rrset-order: invalid class '%s'",
				    r.base);
99
100
			if (result == ISC_R_SUCCESS)
				result = ISC_R_FAILURE;
Mark Andrews's avatar
Mark Andrews committed
101
102
103
104
105
106
107
108
109
110
111
112
		}
	}

	obj = cfg_tuple_get(ent, "type");
	if (cfg_obj_isstring(obj)) {
		DE_CONST(cfg_obj_asstring(obj), r.base);
		r.length = strlen(r.base);
		tresult = dns_rdatatype_fromtext(&rdtype, &r);
		if (tresult != ISC_R_SUCCESS) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "rrset-order: invalid type '%s'",
				    r.base);
113
114
			if (result == ISC_R_SUCCESS)
				result = ISC_R_FAILURE;
Mark Andrews's avatar
Mark Andrews committed
115
116
117
118
119
120
		}
	}

	obj = cfg_tuple_get(ent, "name");
	if (cfg_obj_isstring(obj)) {
		str = cfg_obj_asstring(obj);
121
		isc_buffer_constinit(&b, str, strlen(str));
Mark Andrews's avatar
Mark Andrews committed
122
123
		isc_buffer_add(&b, strlen(str));
		tresult = dns_name_fromtext(dns_fixedname_name(&fixed), &b,
124
					    dns_rootname, 0, NULL);
Mark Andrews's avatar
Mark Andrews committed
125
126
127
		if (tresult != ISC_R_SUCCESS) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "rrset-order: invalid name '%s'", str);
128
129
			if (result == ISC_R_SUCCESS)
				result = ISC_R_FAILURE;
Mark Andrews's avatar
Mark Andrews committed
130
131
132
133
134
135
136
137
		}
	}

	obj = cfg_tuple_get(ent, "order");
	if (!cfg_obj_isstring(obj) ||
	    strcasecmp("order", cfg_obj_asstring(obj)) != 0) {
		cfg_obj_log(ent, logctx, ISC_LOG_ERROR,
			    "rrset-order: keyword 'order' missing");
138
139
		if (result == ISC_R_SUCCESS)
			result = ISC_R_FAILURE;
Mark Andrews's avatar
Mark Andrews committed
140
141
142
143
144
145
	}

	obj = cfg_tuple_get(ent, "ordering");
	if (!cfg_obj_isstring(obj)) {
	    cfg_obj_log(ent, logctx, ISC_LOG_ERROR,
			"rrset-order: missing ordering");
146
147
		if (result == ISC_R_SUCCESS)
			result = ISC_R_FAILURE;
148
149
150
	} else if (strcasecmp(cfg_obj_asstring(obj), "fixed") == 0) {
#if !DNS_RDATASET_FIXED
		cfg_obj_log(obj, logctx, ISC_LOG_WARNING,
151
152
			    "rrset-order: order 'fixed' was disabled at "
			    "compilation time");
153
154
#endif
	} else if (strcasecmp(cfg_obj_asstring(obj), "random") != 0 &&
155
156
		   strcasecmp(cfg_obj_asstring(obj), "cyclic") != 0 &&
		   strcasecmp(cfg_obj_asstring(obj), "none") != 0) {
Mark Andrews's avatar
Mark Andrews committed
157
158
159
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "rrset-order: invalid order '%s'",
			    cfg_obj_asstring(obj));
160
161
		if (result == ISC_R_SUCCESS)
			result = ISC_R_FAILURE;
Mark Andrews's avatar
Mark Andrews committed
162
163
164
165
166
	}
	return (result);
}

static isc_result_t
167
check_order(const cfg_obj_t *options, isc_log_t *logctx) {
Mark Andrews's avatar
Mark Andrews committed
168
169
	isc_result_t result = ISC_R_SUCCESS;
	isc_result_t tresult;
170
171
	const cfg_listelt_t *element;
	const cfg_obj_t *obj = NULL;
Mark Andrews's avatar
Mark Andrews committed
172
173
174
175
176
177
178
179
180

	if (cfg_map_get(options, "rrset-order", &obj) != ISC_R_SUCCESS)
		return (result);

	for (element = cfg_list_first(obj);
	     element != NULL;
	     element = cfg_list_next(element))
	{
		tresult = check_orderent(cfg_listelt_value(element), logctx);
181
		if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS)
Mark Andrews's avatar
Mark Andrews committed
182
183
184
185
186
			result = tresult;
	}
	return (result);
}

187
static isc_result_t
188
189
190
191
192
check_dual_stack(const cfg_obj_t *options, isc_log_t *logctx) {
	const cfg_listelt_t *element;
	const cfg_obj_t *alternates = NULL;
	const cfg_obj_t *value;
	const cfg_obj_t *obj;
193
	const char *str;
194
195
196
197
198
199
200
201
202
203
204
205
206
	dns_fixedname_t fixed;
	dns_name_t *name;
	isc_buffer_t buffer;
	isc_result_t result = ISC_R_SUCCESS;
	isc_result_t tresult;

	(void)cfg_map_get(options, "dual-stack-servers", &alternates);

	if (alternates == NULL)
		return (ISC_R_SUCCESS);

	obj = cfg_tuple_get(alternates, "port");
	if (cfg_obj_isuint32(obj)) {
207
208
		uint32_t val = cfg_obj_asuint32(obj);
		if (val > UINT16_MAX) {
209
210
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "port '%u' out of range", val);
211
212
			if (result == ISC_R_SUCCESS)
				result = ISC_R_RANGE;
213
214
215
216
217
218
219
220
221
222
223
		}
	}
	obj = cfg_tuple_get(alternates, "addresses");
	for (element = cfg_list_first(obj);
	     element != NULL;
	     element = cfg_list_next(element)) {
		value = cfg_listelt_value(element);
		if (cfg_obj_issockaddr(value))
			continue;
		obj = cfg_tuple_get(value, "name");
		str = cfg_obj_asstring(obj);
224
		isc_buffer_constinit(&buffer, str, strlen(str));
225
		isc_buffer_add(&buffer, strlen(str));
226
		name = dns_fixedname_initname(&fixed);
227
		tresult = dns_name_fromtext(name, &buffer, dns_rootname,
228
					    0, NULL);
229
230
231
		if (tresult != ISC_R_SUCCESS) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "bad name '%s'", str);
232
233
			if (result == ISC_R_SUCCESS)
				result = tresult;
234
235
236
		}
		obj = cfg_tuple_get(value, "port");
		if (cfg_obj_isuint32(obj)) {
237
238
			uint32_t val = cfg_obj_asuint32(obj);
			if (val > UINT16_MAX) {
239
240
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "port '%u' out of range", val);
241
242
				if (result == ISC_R_SUCCESS)
					result = ISC_R_RANGE;
243
244
245
246
247
248
			}
		}
	}
	return (result);
}

249
static isc_result_t
250
251
252
check_forward(const cfg_obj_t *options,  const cfg_obj_t *global,
	      isc_log_t *logctx)
{
253
254
	const cfg_obj_t *forward = NULL;
	const cfg_obj_t *forwarders = NULL;
255
256
257
258

	(void)cfg_map_get(options, "forward", &forward);
	(void)cfg_map_get(options, "forwarders", &forwarders);

259
260
261
262
263
264
265
266
267
	if (forwarders != NULL && global != NULL) {
		const char *file = cfg_obj_file(global);
		unsigned int line = cfg_obj_line(global);
		cfg_obj_log(forwarders, logctx, ISC_LOG_ERROR,
			    "forwarders declared in root zone and "
			    "in general configuration: %s:%u",
			    file, line);
		return (ISC_R_FAILURE);
	}
268
269
270
271
272
273
274
275
	if (forward != NULL && forwarders == NULL) {
		cfg_obj_log(forward, logctx, ISC_LOG_ERROR,
			    "no matching 'forwarders' statement");
		return (ISC_R_FAILURE);
	}
	return (ISC_R_SUCCESS);
}

276
static isc_result_t
277
disabled_algorithms(const cfg_obj_t *disabled, isc_log_t *logctx) {
278
279
	isc_result_t result = ISC_R_SUCCESS;
	isc_result_t tresult;
280
	const cfg_listelt_t *element;
281
282
283
284
	const char *str;
	isc_buffer_t b;
	dns_fixedname_t fixed;
	dns_name_t *name;
285
	const cfg_obj_t *obj;
286

287
	name = dns_fixedname_initname(&fixed);
288
289
	obj = cfg_tuple_get(disabled, "name");
	str = cfg_obj_asstring(obj);
290
	isc_buffer_constinit(&b, str, strlen(str));
291
	isc_buffer_add(&b, strlen(str));
292
	tresult = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
	if (tresult != ISC_R_SUCCESS) {
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "bad domain name '%s'", str);
		result = tresult;
	}

	obj = cfg_tuple_get(disabled, "algorithms");

	for (element = cfg_list_first(obj);
	     element != NULL;
	     element = cfg_list_next(element))
	{
		isc_textregion_t r;
		dns_secalg_t alg;

308
		DE_CONST(cfg_obj_asstring(cfg_listelt_value(element)), r.base);
309
310
311
		r.length = strlen(r.base);

		tresult = dns_secalg_fromtext(&alg, &r);
Tinderbox User's avatar
Tinderbox User committed
312
		if (tresult != ISC_R_SUCCESS) {
313
			cfg_obj_log(cfg_listelt_value(element), logctx,
314
315
				    ISC_LOG_ERROR, "invalid algorithm '%s'",
				    r.base);
316
			result = tresult;
Tinderbox User's avatar
Tinderbox User committed
317
		}
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
	}
	return (result);
}

static isc_result_t
disabled_ds_digests(const cfg_obj_t *disabled, isc_log_t *logctx) {
	isc_result_t result = ISC_R_SUCCESS;
	isc_result_t tresult;
	const cfg_listelt_t *element;
	const char *str;
	isc_buffer_t b;
	dns_fixedname_t fixed;
	dns_name_t *name;
	const cfg_obj_t *obj;

333
	name = dns_fixedname_initname(&fixed);
334
335
	obj = cfg_tuple_get(disabled, "name");
	str = cfg_obj_asstring(obj);
336
	isc_buffer_constinit(&b, str, strlen(str));
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
	isc_buffer_add(&b, strlen(str));
	tresult = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
	if (tresult != ISC_R_SUCCESS) {
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "bad domain name '%s'", str);
		result = tresult;
	}

	obj = cfg_tuple_get(disabled, "digests");

	for (element = cfg_list_first(obj);
	     element != NULL;
	     element = cfg_list_next(element))
	{
		isc_textregion_t r;
		dns_dsdigest_t digest;

		DE_CONST(cfg_obj_asstring(cfg_listelt_value(element)), r.base);
		r.length = strlen(r.base);

		/* works with a numeric argument too */
		tresult = dns_dsdigest_fromtext(&digest, &r);
Tinderbox User's avatar
Tinderbox User committed
359
360
		if (tresult != ISC_R_SUCCESS) {
			cfg_obj_log(cfg_listelt_value(element), logctx,
361
				    ISC_LOG_ERROR, "invalid digest type '%s'",
Tinderbox User's avatar
Tinderbox User committed
362
363
364
				    r.base);
			result = tresult;
		}
365
366
367
368
	}
	return (result);
}

369
static isc_result_t
370
371
372
nameexist(const cfg_obj_t *obj, const char *name, int value,
	  isc_symtab_t *symtab, const char *fmt, isc_log_t *logctx,
	  isc_mem_t *mctx)
373
374
375
376
377
378
379
380
381
382
{
	char *key;
	const char *file;
	unsigned int line;
	isc_result_t result;
	isc_symvalue_t symvalue;

	key = isc_mem_strdup(mctx, name);
	if (key == NULL)
		return (ISC_R_NOMEMORY);
383
	symvalue.as_cpointer = obj;
384
385
386
387
388
	result = isc_symtab_define(symtab, key, value, symvalue,
				   isc_symexists_reject);
	if (result == ISC_R_EXISTS) {
		RUNTIME_CHECK(isc_symtab_lookup(symtab, key, value,
						&symvalue) == ISC_R_SUCCESS);
389
390
		file = cfg_obj_file(symvalue.as_cpointer);
		line = cfg_obj_line(symvalue.as_cpointer);
391
392
393
394
395
396
397
398
399
400
401
402

		if (file == NULL)
			file = "<unknown file>";
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR, fmt, key, file, line);
		isc_mem_free(mctx, key);
		result = ISC_R_EXISTS;
	} else if (result != ISC_R_SUCCESS) {
		isc_mem_free(mctx, key);
	}
	return (result);
}

403
static isc_result_t
404
mustbesecure(const cfg_obj_t *secure, isc_symtab_t *symtab, isc_log_t *logctx,
405
406
	     isc_mem_t *mctx)
{
407
	const cfg_obj_t *obj;
408
409
410
411
412
413
414
	char namebuf[DNS_NAME_FORMATSIZE];
	const char *str;
	dns_fixedname_t fixed;
	dns_name_t *name;
	isc_buffer_t b;
	isc_result_t result = ISC_R_SUCCESS;

415
	name = dns_fixedname_initname(&fixed);
416
417
	obj = cfg_tuple_get(secure, "name");
	str = cfg_obj_asstring(obj);
418
	isc_buffer_constinit(&b, str, strlen(str));
419
	isc_buffer_add(&b, strlen(str));
420
	result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
421
	if (result != ISC_R_SUCCESS) {
422
423
424
425
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "bad domain name '%s'", str);
	} else {
		dns_name_format(name, namebuf, sizeof(namebuf));
426
427
428
429
		result = nameexist(secure, namebuf, 1, symtab,
				   "dnssec-must-be-secure '%s': already "
				   "exists previous definition: %s:%u",
				   logctx, mctx);
430
431
432
433
	}
	return (result);
}

434
static isc_result_t
435
436
437
checkacl(const char *aclname, cfg_aclconfctx_t *actx, const cfg_obj_t *zconfig,
	 const cfg_obj_t *voptions, const cfg_obj_t *config,
	 isc_log_t *logctx, isc_mem_t *mctx)
438
439
{
	isc_result_t result;
440
441
	const cfg_obj_t *aclobj = NULL;
	const cfg_obj_t *options;
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
	dns_acl_t *acl = NULL;

	if (zconfig != NULL) {
		options = cfg_tuple_get(zconfig, "options");
		cfg_map_get(options, aclname, &aclobj);
	}
	if (voptions != NULL && aclobj == NULL)
		cfg_map_get(voptions, aclname, &aclobj);
	if (config != NULL && aclobj == NULL) {
		options = NULL;
		cfg_map_get(config, "options", &options);
		if (options != NULL)
			cfg_map_get(options, aclname, &aclobj);
	}
	if (aclobj == NULL)
		return (ISC_R_SUCCESS);
458
	result = cfg_acl_fromconfig(aclobj, config, logctx,
Automatic Updater's avatar
Automatic Updater committed
459
				    actx, mctx, 0, &acl);
460
461
462
463
464
465
	if (acl != NULL)
		dns_acl_detach(&acl);
	return (result);
}

static isc_result_t
466
467
check_viewacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
	       const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx)
468
469
470
{
	isc_result_t result = ISC_R_SUCCESS, tresult;
	int i = 0;
Automatic Updater's avatar
Automatic Updater committed
471

472
	static const char *acls[] = { "allow-query", "allow-query-on",
Automatic Updater's avatar
Automatic Updater committed
473
		"allow-query-cache", "allow-query-cache-on",
474
		"blackhole", "keep-response-order", "match-clients",
475
		"match-destinations", "sortlist", NULL };
476
477

	while (acls[i] != NULL) {
478
		tresult = checkacl(acls[i++], actx, NULL, voptions, config,
479
480
				   logctx, mctx);
		if (tresult != ISC_R_SUCCESS)
Automatic Updater's avatar
Automatic Updater committed
481
			result = tresult;
482
483
484
485
	}
	return (result);
}

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
static const unsigned char zeros[16];

static isc_result_t
check_dns64(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
	    const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx)
{
	isc_result_t result = ISC_R_SUCCESS;
	const cfg_obj_t *dns64 = NULL;
	const cfg_obj_t *options;
	const cfg_listelt_t *element;
	const cfg_obj_t *map, *obj;
	isc_netaddr_t na, sa;
	unsigned int prefixlen;
	int nbytes;
	int i;

502
	static const char *acls[] = { "clients", "exclude", "mapped", NULL};
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528

	if (voptions != NULL)
		cfg_map_get(voptions, "dns64", &dns64);
	if (config != NULL && dns64 == NULL) {
		options = NULL;
		cfg_map_get(config, "options", &options);
		if (options != NULL)
			cfg_map_get(options, "dns64", &dns64);
	}
	if (dns64 == NULL)
		return (ISC_R_SUCCESS);

	for (element = cfg_list_first(dns64);
	     element != NULL;
	     element = cfg_list_next(element))
	{
		map = cfg_listelt_value(element);
		obj = cfg_map_getname(map);

		cfg_obj_asnetprefix(obj, &na, &prefixlen);
		if (na.family != AF_INET6) {
			cfg_obj_log(map, logctx, ISC_LOG_ERROR,
				    "dns64 requires a IPv6 prefix");
			result = ISC_R_FAILURE;
			continue;
		}
Automatic Updater's avatar
Automatic Updater committed
529

530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
		if (prefixlen != 32 && prefixlen != 40 && prefixlen != 48 &&
		    prefixlen != 56 && prefixlen != 64 && prefixlen != 96) {
			cfg_obj_log(map, logctx, ISC_LOG_ERROR,
				    "bad prefix length %u [32/40/48/56/64/96]",
				    prefixlen);
			result = ISC_R_FAILURE;
			continue;
		}

		for (i = 0; acls[i] != NULL; i++) {
			obj = NULL;
			(void)cfg_map_get(map, acls[i], &obj);
			if (obj != NULL) {
				dns_acl_t *acl = NULL;
				isc_result_t tresult;

				tresult = cfg_acl_fromconfig(obj, config,
							     logctx, actx,
							     mctx, 0, &acl);
				if (acl != NULL)
					dns_acl_detach(&acl);
				if (tresult != ISC_R_SUCCESS)
					result = tresult;
			}
		}

		obj = NULL;
		(void)cfg_map_get(map, "suffix", &obj);
		if (obj != NULL) {
			isc_netaddr_fromsockaddr(&sa, cfg_obj_assockaddr(obj));
			if (sa.family != AF_INET6) {
				cfg_obj_log(map, logctx, ISC_LOG_ERROR,
					    "dns64 requires a IPv6 suffix");
				result = ISC_R_FAILURE;
				continue;
			}
			nbytes = prefixlen / 8 + 4;
Mark Andrews's avatar
Mark Andrews committed
567
			if (prefixlen <= 64)
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
				nbytes++;
			if (memcmp(sa.type.in6.s6_addr, zeros, nbytes) != 0) {
				char netaddrbuf[ISC_NETADDR_FORMATSIZE];
				isc_netaddr_format(&sa, netaddrbuf,
						   sizeof(netaddrbuf));
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "bad suffix '%s' leading "
					    "%u octets not zeros",
					    netaddrbuf, nbytes);
				result = ISC_R_FAILURE;
			}
		}
	}

	return (result);
}

585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#define CHECK_RRL(cond, pat, val1, val2)				\
	do {								\
		if (!(cond)) {						\
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,		\
				    pat, val1, val2);			\
			if (result == ISC_R_SUCCESS)			\
				result = ISC_R_RANGE;			\
		    }							\
	} while (0)

#define CHECK_RRL_RATE(rate, def, max_rate, name)			\
	do {								\
		obj = NULL;						\
		mresult = cfg_map_get(map, name, &obj);			\
		if (mresult == ISC_R_SUCCESS) {				\
			rate = cfg_obj_asuint32(obj);			\
			CHECK_RRL(rate <= max_rate, name" %d > %d",	\
				  rate, max_rate);			\
		}							\
	} while (0)

static isc_result_t
check_ratelimit(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
		const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx)
{
	isc_result_t result = ISC_R_SUCCESS;
	isc_result_t mresult;
	const cfg_obj_t *map = NULL;
	const cfg_obj_t *options;
	const cfg_obj_t *obj;
	int min_entries, i;
	int all_per_second;
	int errors_per_second;
	int nodata_per_second;
	int nxdomains_per_second;
	int referrals_per_second;
	int responses_per_second;
	int slip;

	if (voptions != NULL)
		cfg_map_get(voptions, "rate-limit", &map);
	if (config != NULL && map == NULL) {
		options = NULL;
		cfg_map_get(config, "options", &options);
		if (options != NULL)
			cfg_map_get(options, "rate-limit", &map);
	}
	if (map == NULL)
		return (ISC_R_SUCCESS);

	min_entries = 500;
	obj = NULL;
	mresult = cfg_map_get(map, "min-table-size", &obj);
	if (mresult == ISC_R_SUCCESS) {
		min_entries = cfg_obj_asuint32(obj);
		if (min_entries < 1)
			min_entries = 1;
	}

	obj = NULL;
	mresult = cfg_map_get(map, "max-table-size", &obj);
	if (mresult == ISC_R_SUCCESS) {
		i = cfg_obj_asuint32(obj);
		CHECK_RRL(i >= min_entries,
			  "max-table-size %d < min-table-size %d",
			  i, min_entries);
	}

	CHECK_RRL_RATE(responses_per_second, 0, DNS_RRL_MAX_RATE,
		       "responses-per-second");

	CHECK_RRL_RATE(referrals_per_second, responses_per_second,
		       DNS_RRL_MAX_RATE, "referrals-per-second");
	CHECK_RRL_RATE(nodata_per_second, responses_per_second,
		       DNS_RRL_MAX_RATE, "nodata-per-second");
	CHECK_RRL_RATE(nxdomains_per_second, responses_per_second,
		       DNS_RRL_MAX_RATE, "nxdomains-per-second");
	CHECK_RRL_RATE(errors_per_second, responses_per_second,
		       DNS_RRL_MAX_RATE, "errors-per-second");

	CHECK_RRL_RATE(all_per_second, 0, DNS_RRL_MAX_RATE, "all-per-second");

	CHECK_RRL_RATE(slip, 2, DNS_RRL_MAX_SLIP, "slip");

	obj = NULL;
	mresult = cfg_map_get(map, "window", &obj);
	if (mresult == ISC_R_SUCCESS) {
		i = cfg_obj_asuint32(obj);
		CHECK_RRL(i >= 1 && i <= DNS_RRL_MAX_WINDOW,
			  "window %d < 1 or > %d", i, DNS_RRL_MAX_WINDOW);
	}

	obj = NULL;
	mresult = cfg_map_get(map, "qps-scale", &obj);
	if (mresult == ISC_R_SUCCESS) {
		i = cfg_obj_asuint32(obj);
		CHECK_RRL(i >= 1, "invalid 'qps-scale %d'%s", i, "");
	}

	obj = NULL;
	mresult = cfg_map_get(map, "ipv4-prefix-length", &obj);
	if (mresult == ISC_R_SUCCESS) {
		i = cfg_obj_asuint32(obj);
		CHECK_RRL(i >= 8 && i <= 32,
			  "invalid 'ipv4-prefix-length %d'%s", i, "");
	}

	obj = NULL;
	mresult = cfg_map_get(map, "ipv6-prefix-length", &obj);
	if (mresult == ISC_R_SUCCESS) {
		i = cfg_obj_asuint32(obj);
		CHECK_RRL(i >= 16 && i <= DNS_RRL_MAX_PREFIX,
			  "ipv6-prefix-length %d < 16 or > %d",
			  i, DNS_RRL_MAX_PREFIX);
	}

	obj = NULL;
	(void)cfg_map_get(map, "exempt-clients", &obj);
	if (obj != NULL) {
		dns_acl_t *acl = NULL;
		isc_result_t tresult;

		tresult = cfg_acl_fromconfig(obj, config, logctx, actx,
					     mctx, 0, &acl);
		if (acl != NULL)
			dns_acl_detach(&acl);
		if (result == ISC_R_SUCCESS)
			result = tresult;
	}

	return (result);
}
717

718
719
720
721
722
723
724
725
726
727
728
729
/*
 * Check allow-recursion and allow-recursion-on acls, and also log a
 * warning if they're inconsistent with the "recursion" option.
 */
static isc_result_t
check_recursionacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
		    const char *viewname, const cfg_obj_t *config,
		    isc_log_t *logctx, isc_mem_t *mctx)
{
	const cfg_obj_t *options, *aclobj, *obj = NULL;
	dns_acl_t *acl = NULL;
	isc_result_t result = ISC_R_SUCCESS, tresult;
730
	bool recursion;
731
732
733
734
	const char *forview = " for view ";
	int i = 0;

	static const char *acls[] = { "allow-recursion", "allow-recursion-on",
Automatic Updater's avatar
Automatic Updater committed
735
736
				      NULL };

737
738
739
740
741
742
743
744
745
	if (voptions != NULL)
		cfg_map_get(voptions, "recursion", &obj);
	if (obj == NULL && config != NULL) {
		options = NULL;
		cfg_map_get(config, "options", &options);
		if (options != NULL)
			cfg_map_get(options, "recursion", &obj);
	}
	if (obj == NULL)
746
		recursion = true;
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
	else
		recursion = cfg_obj_asboolean(obj);

	if (viewname == NULL) {
		viewname = "";
		forview = "";
	}

	for (i = 0; acls[i] != NULL; i++) {
		aclobj = options = NULL;
		acl = NULL;

		if (voptions != NULL)
			cfg_map_get(voptions, acls[i], &aclobj);
		if (config != NULL && aclobj == NULL) {
			options = NULL;
			cfg_map_get(config, "options", &options);
			if (options != NULL)
				cfg_map_get(options, acls[i], &aclobj);
		}
Automatic Updater's avatar
Automatic Updater committed
767
		if (aclobj == NULL)
768
769
770
			continue;

		tresult = cfg_acl_fromconfig(aclobj, config, logctx,
771
					    actx, mctx, 0, &acl);
772
773

		if (tresult != ISC_R_SUCCESS)
Automatic Updater's avatar
Automatic Updater committed
774
			result = tresult;
775
776
777
778

		if (acl == NULL)
			continue;

779
		if (recursion == false && !dns_acl_isnone(acl)) {
780
781
782
783
784
785
786
787
			cfg_obj_log(aclobj, logctx, ISC_LOG_WARNING,
				    "both \"recursion no;\" and "
				    "\"%s\" active%s%s",
				    acls[i], forview, viewname);
		}

		if (acl != NULL)
			dns_acl_detach(&acl);
Automatic Updater's avatar
Automatic Updater committed
788
	}
789
790
791
792

	return (result);
}

793
794
795
typedef struct {
	const char *name;
	unsigned int scale;
796
	unsigned int max;
797
798
} intervaltable;

799
#ifdef HAVE_DNSTAP
800
801
802
803
804
typedef struct {
	const char *name;
	unsigned int min;
	unsigned int max;
} fstrmtable;
805
#endif
806

807
808
809
810
811
812
813
typedef enum {
	optlevel_config,
	optlevel_options,
	optlevel_view,
	optlevel_zone
} optlevel_t;

Evan Hunt's avatar
Evan Hunt committed
814
815
816
817
818
819
820
821
822
823
824
static isc_result_t
check_dscp(const cfg_obj_t *options, isc_log_t *logctx) {
       isc_result_t result = ISC_R_SUCCESS;
       const cfg_obj_t *obj = NULL;

       /*
	* Check that DSCP setting is within range
	*/
       obj = NULL;
       (void)cfg_map_get(options, "dscp", &obj);
       if (obj != NULL) {
825
	       uint32_t dscp = cfg_obj_asuint32(obj);
Evan Hunt's avatar
Evan Hunt committed
826
827
828
829
830
831
832
833
834
835
	       if (dscp >= 64) {
		       cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				   "'dscp' out of range (0-63)");
		       result = ISC_R_FAILURE;
	       }
       }

       return (result);
}

836
837
838
839
840
841
842
843
static isc_result_t
check_name(const char *str) {
	dns_fixedname_t fixed;

	dns_fixedname_init(&fixed);
	return (dns_name_fromstring(dns_fixedname_name(&fixed), str, 0, NULL));
}

844
static isc_result_t
845
846
847
check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx,
	      optlevel_t optlevel)
{
848
	isc_result_t result = ISC_R_SUCCESS;
849
	isc_result_t tresult;
850
	unsigned int i;
851
	const cfg_obj_t *obj = NULL;
852
	const cfg_obj_t *resignobj = NULL;
853
	const cfg_listelt_t *element;
854
	isc_symtab_t *symtab = NULL;
855
856
857
858
	dns_fixedname_t fixed;
	const char *str;
	dns_name_t *name;
	isc_buffer_t b;
859
	uint32_t lifetime = 3600;
860
	const char *ccalg = "aes";
861

862
863
864
865
	/*
	 * { "name", scale, value }
	 * (scale * value) <= UINT32_MAX
	 */
866
	static intervaltable intervals[] = {
867
868
869
870
871
872
873
874
875
876
877
878
879
		{ "heartbeat-interval", 60, 28 * 24 * 60 },	/* 28 days */
		{ "interface-interval", 60, 28 * 24 * 60 },	/* 28 days */
		{ "max-transfer-idle-in", 60, 28 * 24 * 60 },	/* 28 days */
		{ "max-transfer-idle-out", 60, 28 * 24 * 60 },	/* 28 days */
		{ "max-transfer-time-in", 60, 28 * 24 * 60 },	/* 28 days */
		{ "max-transfer-time-out", 60, 28 * 24 * 60 },	/* 28 days */
		{ "statistics-interval", 60, 28 * 24 * 60 },	/* 28 days */

		/* minimum and maximum cache and negative cache TTLs */
		{ "min-cache-ttl", 1, MAX_MIN_CACHE_TTL },	/* 90 secs */
		{ "max-cache-ttl", 1, UINT32_MAX },		/* no limit */
		{ "min-ncache-ttl", 1, MAX_MIN_NCACHE_TTL},	/* 90 secs */
		{ "max-ncache-ttl", 1, MAX_MAX_NCACHE_TTL },	/*  7 days */
880
881
	};

882
883
884
885
886
887
	static const char *server_contact[] = {
		"empty-server", "empty-contact",
		"dns64-server", "dns64-contact",
		NULL
	};

888
#ifdef HAVE_DNSTAP
889
890
891
892
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
	static fstrmtable fstrm[] = {
		{
			"fstrm-set-buffer-hint",
			FSTRM_IOTHR_BUFFER_HINT_MIN,
			FSTRM_IOTHR_BUFFER_HINT_MAX
		},
		{
			"fstrm-set-flush-timeout",
			FSTRM_IOTHR_FLUSH_TIMEOUT_MIN,
			FSTRM_IOTHR_FLUSH_TIMEOUT_MAX
		},
		{
			"fstrm-set-input-queue-size",
			FSTRM_IOTHR_INPUT_QUEUE_SIZE_MIN,
			FSTRM_IOTHR_INPUT_QUEUE_SIZE_MAX
		},
		{
			"fstrm-set-output-notify-threshold",
			FSTRM_IOTHR_QUEUE_NOTIFY_THRESHOLD_MIN,
			0
		},
		{
			"fstrm-set-output-queue-size",
			FSTRM_IOTHR_OUTPUT_QUEUE_SIZE_MIN,
			FSTRM_IOTHR_OUTPUT_QUEUE_SIZE_MAX
		},
		{
			"fstrm-set-reopen-interval",
			FSTRM_IOTHR_REOPEN_INTERVAL_MIN,
			FSTRM_IOTHR_REOPEN_INTERVAL_MAX
		}
	};
#endif

923
924
925
926
927
	/*
	 * Check that fields specified in units of time other than seconds
	 * have reasonable values.
	 */
	for (i = 0; i < sizeof(intervals) / sizeof(intervals[0]); i++) {
928
		uint32_t val;
929
		obj = NULL;
930
931
932
933
		(void)cfg_map_get(options, intervals[i].name, &obj);
		if (obj == NULL)
			continue;
		val = cfg_obj_asuint32(obj);
934
935
936
937
938
939
		if (val > intervals[i].max) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "%s '%u' is out of range (0..%u)",
				    intervals[i].name, val,
				    intervals[i].max);
			result = ISC_R_RANGE;
940
		} else if (val > (UINT32_MAX / intervals[i].scale)) {
941
942
943
944
945
946
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "%s '%d' is out of range",
				    intervals[i].name, val);
			result = ISC_R_RANGE;
		}
	}
947

948
949
950
	obj = NULL;
	cfg_map_get(options, "max-rsa-exponent-size", &obj);
	if (obj != NULL) {
951
		uint32_t val;
952
953
954
955
956
957
958
959
960
961

		val = cfg_obj_asuint32(obj);
		if (val != 0 && (val < 35 || val > 4096)) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "max-rsa-exponent-size '%u' is out of "
				    "range (35..4096)", val);
			result = ISC_R_RANGE;
		}
	}

962
963
964
	obj = NULL;
	cfg_map_get(options, "sig-validity-interval", &obj);
	if (obj != NULL) {
965
		uint32_t validity, resign = 0;
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997

		validity = cfg_obj_asuint32(cfg_tuple_get(obj, "validity"));
		resignobj = cfg_tuple_get(obj, "re-sign");
		if (!cfg_obj_isvoid(resignobj))
			resign = cfg_obj_asuint32(resignobj);

		if (validity > 3660 || validity == 0) { /* 10 years */
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "%s '%u' is out of range (1..3660)",
				    "sig-validity-interval", validity);
			result = ISC_R_RANGE;
		}

		if (!cfg_obj_isvoid(resignobj)) {
			if (resign > 3660 || resign == 0) { /* 10 years */
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "%s '%u' is out of range (1..3660)",
					    "sig-validity-interval (re-sign)",
					    validity);
				result = ISC_R_RANGE;
			} else if ((validity > 7 && validity < resign) ||
				   (validity <= 7 && validity * 24 < resign)) {
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "validity interval (%u days) "
					    "less than re-signing interval "
					    "(%u %s)", validity, resign,
					    (validity > 7) ? "days" : "hours");
				result = ISC_R_RANGE;
			}
		}
	}

Evan Hunt's avatar
Evan Hunt committed
998
999
1000
	obj = NULL;
	cfg_map_get(options, "dnskey-sig-validity", &obj);
	if (obj != NULL) {
1001
		uint32_t keyvalidity;
Evan Hunt's avatar
Evan Hunt committed
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013

		keyvalidity = cfg_obj_asuint32(obj);
		if (keyvalidity > 3660 || keyvalidity == 0) { /* 10 years */
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "%s '%u' is out of range (1..3660)",
				    "dnskey-sig-validity",
				    keyvalidity);
			result = ISC_R_RANGE;
		}

	}

1014
1015
1016
	obj = NULL;
	(void)cfg_map_get(options, "preferred-glue", &obj);
	if (obj != NULL) {
Automatic Updater's avatar
Automatic Updater committed
1017
1018
		str = cfg_obj_asstring(obj);
		if (strcasecmp(str, "a") != 0 &&
1019
1020
1021
1022
1023
1024
		    strcasecmp(str, "aaaa") != 0 &&
		    strcasecmp(str, "none") != 0)
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "preferred-glue unexpected value '%s'",
				    str);
	}
1025

1026
1027
1028
1029
1030
1031
1032
	obj = NULL;
	(void)cfg_map_get(options, "root-delegation-only", &obj);
	if (obj != NULL) {
		if (!cfg_obj_isvoid(obj)) {
			for (element = cfg_list_first(obj);
			     element != NULL;
			     element = cfg_list_next(element)) {
1033
1034
				const cfg_obj_t *exclude;

1035
1036
				exclude = cfg_listelt_value(element);
				str = cfg_obj_asstring(exclude);
1037
				tresult = check_name(str);
1038
1039
1040
1041
1042
1043
1044
1045
1046
				if (tresult != ISC_R_SUCCESS) {
					cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
						    "bad domain name '%s'",
						    str);
					result = tresult;
				}
			}
		}
	}
Automatic Updater's avatar
Automatic Updater committed
1047

1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
	/*
	 * Set supported DNSSEC algorithms.
	 */
	obj = NULL;
	(void)cfg_map_get(options, "disable-algorithms", &obj);
	if (obj != NULL) {
		for (element = cfg_list_first(obj);
		     element != NULL;
		     element = cfg_list_next(element))
		{
			obj = cfg_listelt_value(element);
			tresult = disabled_algorithms(obj, logctx);
			if (tresult != ISC_R_SUCCESS)
				result = tresult;
		}
	}

1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
	/*
	 * Set supported DS/DLV digest types.
	 */
	obj = NULL;
	(void)cfg_map_get(options, "disable-ds-digests", &obj);
	if (obj != NULL) {
		for (element = cfg_list_first(obj);
		     element != NULL;
		     element = cfg_list_next(element))
		{
			obj = cfg_listelt_value(element);
			tresult = disabled_ds_digests(obj, logctx);
			if (tresult != ISC_R_SUCCESS)
				result = tresult;
		}
	}

1082
	name = dns_fixedname_initname(&fixed);
1083

1084
1085
1086
1087
1088
1089
	/*
	 * Check the DLV zone name.
	 */
	obj = NULL;
	(void)cfg_map_get(options, "dnssec-lookaside", &obj);
	if (obj != NULL) {
1090
		tresult = isc_symtab_create(mctx, 100, freekey, mctx,
1091
					    false, &symtab);
1092
		if (tresult != ISC_R_SUCCESS)
1093
			result = tresult;
1094
1095
1096
1097
1098
		for (element = cfg_list_first(obj);
		     element != NULL;
		     element = cfg_list_next(element))
		{
			const char *dlv;
1099
			const cfg_obj_t *dlvobj, *anchor;
1100
1101
1102

			obj = cfg_listelt_value(element);

1103
			anchor = cfg_tuple_get(obj, "trust-anchor");
1104
1105
			dlvobj = cfg_tuple_get(obj, "domain");
			dlv = cfg_obj_asstring(dlvobj);
1106
1107

			/*
1108
1109
			 * If domain is "auto" or "no" and trust anchor
			 * is missing, skip remaining tests
Automatic Updater's avatar
Automatic Updater committed
1110
			 */
1111
			if (cfg_obj_isvoid(anchor)) {
Evan Hunt's avatar
Evan Hunt committed
1112
				if (!strcasecmp(dlv, "no")) {
1113
					continue;
Evan Hunt's avatar
Evan Hunt committed
1114
1115
				}
				if (!strcasecmp(dlv, "auto")) {
1116
					cfg_obj_log(obj, logctx, ISC_LOG_WARNING,
Evan Hunt's avatar
Evan Hunt committed
1117
1118
1119
1120
						    "dnssec-lookaside 'auto' "
						    "is no longer supported");
					continue;
				}
1121
			}
1122

1123
			tresult = dns_name_fromstring(name, dlv, 0, NULL);
1124
1125
1126
1127
			if (tresult != ISC_R_SUCCESS) {
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "bad domain name '%s'", dlv);
				result = tresult;
1128
				continue;
1129
1130
1131
1132
			}
			if (symtab != NULL) {
				tresult = nameexist(obj, dlv, 1, symtab,
						    "dnssec-lookaside '%s': "
Evan Hunt's avatar
Evan Hunt committed
1133
						    "already exists; previous "
1134
1135
1136
1137
1138
1139
						    "definition: %s:%u",
						    logctx, mctx);
				if (tresult != ISC_R_SUCCESS &&
				    result == ISC_R_SUCCESS)
					result = tresult;
			}
1140

1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
			/*
			 * XXXMPA to be removed when multiple lookaside
			 * namespaces are supported.
			 */
			if (!dns_name_equal(dns_rootname, name)) {
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "dnssec-lookaside '%s': "
					    "non-root not yet supported", dlv);
				if (result == ISC_R_SUCCESS)
					result = ISC_R_FAILURE;
			}
1152

Evan Hunt's avatar
Evan Hunt committed
1153
			if (cfg_obj_isvoid(anchor)) {
1154
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
Evan Hunt's avatar
Evan Hunt committed
1155
1156
1157
					    "dnssec-lookaside requires "
					    "either or 'no' or a "
					    "domain and trust anchor");
1158
				if (result == ISC_R_SUCCESS)
1159
					result = ISC_R_FAILURE;
Evan Hunt's avatar
Evan Hunt committed
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
				continue;
			}

			dlv = cfg_obj_asstring(anchor);
			tresult = dns_name_fromstring(name, dlv, 0, NULL);
			if (tresult != ISC_R_SUCCESS) {
				cfg_obj_log(anchor, logctx, ISC_LOG_ERROR,
					    "bad domain name '%s'", dlv);
				if (result == ISC_R_SUCCESS)
					result = tresult;
				continue;
			}
			if (dns_name_equal(&dlviscorg, name)) {
1173
				cfg_obj_log(anchor, logctx, ISC_LOG_WARNING,
Evan Hunt's avatar
Evan Hunt committed
1174
1175
					    "dlv.isc.org has been shut down");
				continue;
1176
			}
1177
		}
1178

1179
1180
		if (symtab != NULL)
			isc_symtab_destroy(&symtab);
1181
	}
1182

1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
	/*
	 * Check auto-dnssec at the view/options level
	 */
	obj = NULL;
	(void)cfg_map_get(options, "auto-dnssec", &obj);
	if (obj != NULL) {
		const char *arg = cfg_obj_asstring(obj);
		if (optlevel != optlevel_zone && strcasecmp(arg, "off") != 0) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "auto-dnssec may only be activated at the "
				    "zone level");
1194
1195
			if (result == ISC_R_SUCCESS)
				result = ISC_R_FAILURE;
1196
1197
1198
		}
	}

1199
1200
1201
1202
1203
1204
1205
	/*
	 * Check dnssec-must-be-secure.
	 */
	obj = NULL;
	(void)cfg_map_get(options, "dnssec-must-be-secure", &obj);
	if (obj != NULL) {
		tresult = isc_symtab_create(mctx, 100, freekey, mctx,
1206
					    false, &symtab);
1207
1208
1209
1210
1211
1212
1213
1214
		if (tresult != ISC_R_SUCCESS)
			result = tresult;
		for (element = cfg_list_first(obj);
		     element != NULL;
		     element = cfg_list_next(element))
		{
			obj = cfg_listelt_value(element);
			tresult = mustbesecure(obj, symtab, logctx, mctx);
1215
			if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS)
1216
1217
1218
1219
1220
1221
				result = tresult;
		}
		if (symtab != NULL)
			isc_symtab_destroy(&symtab);
	}

1222
	/*
1223
	 * Check server/contacts for syntactic validity.
1224
	 */
1225
1226
1227
1228
1229
	for (i= 0; server_contact[i] != NULL; i++) {
		obj = NULL;
		(void)cfg_map_get(options, server_contact[i], &obj);
		if (obj != NULL) {
			str = cfg_obj_asstring(obj);
1230
			if (check_name(str) != ISC_R_SUCCESS) {
1231
1232
1233
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "%s: invalid name '%s'",
					    server_contact[i], str);
1234
1235
				if (result == ISC_R_SUCCESS)
					result = ISC_R_FAILURE;
1236
			}
1237
1238
1239
		}
	}

1240
1241
1242
	/*
	 * Check empty zone configuration.
	 */
1243
1244
1245
1246
1247
1248
1249
1250
	obj = NULL;
	(void)cfg_map_get(options, "disable-empty-zone", &obj);
	for (element = cfg_list_first(obj);
	     element != NULL;
	     element = cfg_list_next(element))
	{
		obj = cfg_listelt_value(element);
		str = cfg_obj_asstring(obj);
1251
		if (check_name(str) != ISC_R_SUCCESS) {
1252
1253
1254
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "disable-empty-zone: invalid name '%s'",
				    str);
1255
1256
			if (result == ISC_R_SUCCESS)
				result = ISC_R_FAILURE;
1257
1258
1259
		}
	}

1260
1261
1262
1263
1264
1265
1266
	/*
	 * Check that server-id is not too long.
	 * 1024 bytes should be big enough.
	 */
	obj = NULL;
	(void)cfg_map_get(options, "server-id", &obj);
	if (obj != NULL && cfg_obj_isstring(obj) &&
Mark Andrews's avatar
Mark Andrews committed
1267
	    strlen(cfg_obj_asstring(obj)) > 1024U) {
1268
1269
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "'server-id' too big (>1024 bytes)");
1270
1271
		if (result == ISC_R_SUCCESS)
			result = ISC_R_FAILURE;
1272
1273
	}

Evan Hunt's avatar
Evan Hunt committed
1274
	tresult = check_dscp(options, logctx);
1275
	if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS)
Evan Hunt's avatar
Evan Hunt committed
1276
1277
		result = tresult;

Evan Hunt's avatar
Evan Hunt committed
1278
1279
1280
1281
	obj = NULL;
	(void)cfg_map_get(options, "nta-lifetime", &obj);
	if (obj != NULL) {
		lifetime = cfg_obj_asuint32(obj);
1282
		if (lifetime > 604800) {	/* 7 days */
Evan Hunt's avatar
Evan Hunt committed
1283
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
1284
				    "'nta-lifetime' cannot exceed one week");
1285
1286
			if (result == ISC_R_SUCCESS)
				result = ISC_R_RANGE;
Evan Hunt's avatar
Evan Hunt committed
1287
1288
1289
		} else if (lifetime == 0) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "'nta-lifetime' may not be zero");
1290
1291
			if (result == ISC_R_SUCCESS)
				result = ISC_R_RANGE;
Evan Hunt's avatar
Evan Hunt committed
1292
1293
1294
1295
1296
1297
		}
	}

	obj = NULL;
	(void)cfg_map_get(options, "nta-recheck", &obj);
	if (obj != NULL) {
1298
		uint32_t recheck = cfg_obj_asuint32(obj);
1299
		if (recheck > 604800) {		/* 7 days */
Evan Hunt's avatar
Evan Hunt committed
1300
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
1301
				    "'nta-recheck' cannot exceed one week");
1302
1303
			if (result == ISC_R_SUCCESS)
				result = ISC_R_RANGE;
Evan Hunt's avatar
Evan Hunt committed
1304
1305
1306
1307
1308
1309
1310
1311
1312
		}

		if (recheck > lifetime)
			cfg_obj_log<