check.c 109 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
15

#include <config.h>

16
#include <stdbool.h>
17
#include <stdlib.h>
18
#include <inttypes.h>
19

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

40
41
#include <pk11/site.h>

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

51
52
#include <dst/dst.h>

53
#include <isccfg/aclconf.h>
54
#include <isccfg/cfg.h>
55
56
#include <isccfg/grammar.h>
#include <isccfg/namedconf.h>
57
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
	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);
			result = ISC_R_FAILURE;
		}
	}

	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);
			result = ISC_R_FAILURE;
		}
	}

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

	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");
		result = ISC_R_FAILURE;
	}

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

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

	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);
		if (tresult != ISC_R_SUCCESS)
			result = tresult;
	}
	return (result);
}

180
static isc_result_t
181
182
183
184
185
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;
186
	const char *str;
187
188
189
190
191
192
193
194
195
196
197
198
199
	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)) {
200
201
		uint32_t val = cfg_obj_asuint32(obj);
		if (val > UINT16_MAX) {
202
203
204
205
206
207
208
209
210
211
212
213
214
215
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "port '%u' out of range", val);
			result = ISC_R_FAILURE;
		}
	}
	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);
216
		isc_buffer_constinit(&buffer, str, strlen(str));
217
		isc_buffer_add(&buffer, strlen(str));
218
		name = dns_fixedname_initname(&fixed);
219
		tresult = dns_name_fromtext(name, &buffer, dns_rootname,
220
					    0, NULL);
221
222
223
224
225
226
227
		if (tresult != ISC_R_SUCCESS) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "bad name '%s'", str);
			result = ISC_R_FAILURE;
		}
		obj = cfg_tuple_get(value, "port");
		if (cfg_obj_isuint32(obj)) {
228
229
			uint32_t val = cfg_obj_asuint32(obj);
			if (val > UINT16_MAX) {
230
231
232
233
234
235
236
237
238
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "port '%u' out of range", val);
				result = ISC_R_FAILURE;
			}
		}
	}
	return (result);
}

239
static isc_result_t
240
241
242
check_forward(const cfg_obj_t *options,  const cfg_obj_t *global,
	      isc_log_t *logctx)
{
243
244
	const cfg_obj_t *forward = NULL;
	const cfg_obj_t *forwarders = NULL;
245
246
247
248

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

249
250
251
252
253
254
255
256
257
	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);
	}
258
259
260
261
262
263
264
265
	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);
}

266
static isc_result_t
267
disabled_algorithms(const cfg_obj_t *disabled, isc_log_t *logctx) {
268
269
	isc_result_t result = ISC_R_SUCCESS;
	isc_result_t tresult;
270
	const cfg_listelt_t *element;
271
272
273
274
	const char *str;
	isc_buffer_t b;
	dns_fixedname_t fixed;
	dns_name_t *name;
275
	const cfg_obj_t *obj;
276

277
	name = dns_fixedname_initname(&fixed);
278
279
	obj = cfg_tuple_get(disabled, "name");
	str = cfg_obj_asstring(obj);
280
	isc_buffer_constinit(&b, str, strlen(str));
281
	isc_buffer_add(&b, strlen(str));
282
	tresult = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
	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;

298
		DE_CONST(cfg_obj_asstring(cfg_listelt_value(element)), r.base);
299
300
301
		r.length = strlen(r.base);

		tresult = dns_secalg_fromtext(&alg, &r);
Tinderbox User's avatar
Tinderbox User committed
302
		if (tresult != ISC_R_SUCCESS) {
303
			cfg_obj_log(cfg_listelt_value(element), logctx,
304
305
				    ISC_LOG_ERROR, "invalid algorithm '%s'",
				    r.base);
306
			result = tresult;
Tinderbox User's avatar
Tinderbox User committed
307
		}
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
	}
	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;

323
	name = dns_fixedname_initname(&fixed);
324
325
	obj = cfg_tuple_get(disabled, "name");
	str = cfg_obj_asstring(obj);
326
	isc_buffer_constinit(&b, str, strlen(str));
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
	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
349
350
		if (tresult != ISC_R_SUCCESS) {
			cfg_obj_log(cfg_listelt_value(element), logctx,
351
				    ISC_LOG_ERROR, "invalid digest type '%s'",
Tinderbox User's avatar
Tinderbox User committed
352
353
354
				    r.base);
			result = tresult;
		}
355
356
357
358
	}
	return (result);
}

359
static isc_result_t
360
361
362
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)
363
364
365
366
367
368
369
370
371
372
{
	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);
373
	symvalue.as_cpointer = obj;
374
375
376
377
378
	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);
379
380
		file = cfg_obj_file(symvalue.as_cpointer);
		line = cfg_obj_line(symvalue.as_cpointer);
381
382
383
384
385
386
387
388
389
390
391
392

		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);
}

393
static isc_result_t
394
mustbesecure(const cfg_obj_t *secure, isc_symtab_t *symtab, isc_log_t *logctx,
395
396
	     isc_mem_t *mctx)
{
397
	const cfg_obj_t *obj;
398
399
400
401
402
403
404
	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;

405
	name = dns_fixedname_initname(&fixed);
406
407
	obj = cfg_tuple_get(secure, "name");
	str = cfg_obj_asstring(obj);
408
	isc_buffer_constinit(&b, str, strlen(str));
409
	isc_buffer_add(&b, strlen(str));
410
	result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
411
	if (result != ISC_R_SUCCESS) {
412
413
414
415
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "bad domain name '%s'", str);
	} else {
		dns_name_format(name, namebuf, sizeof(namebuf));
416
417
418
419
		result = nameexist(secure, namebuf, 1, symtab,
				   "dnssec-must-be-secure '%s': already "
				   "exists previous definition: %s:%u",
				   logctx, mctx);
420
421
422
423
	}
	return (result);
}

424
static isc_result_t
425
426
427
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)
428
429
{
	isc_result_t result;
430
431
	const cfg_obj_t *aclobj = NULL;
	const cfg_obj_t *options;
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
	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);
448
	result = cfg_acl_fromconfig(aclobj, config, logctx,
Automatic Updater's avatar
Automatic Updater committed
449
				    actx, mctx, 0, &acl);
450
451
452
453
454
455
	if (acl != NULL)
		dns_acl_detach(&acl);
	return (result);
}

static isc_result_t
456
457
check_viewacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
	       const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx)
458
459
460
{
	isc_result_t result = ISC_R_SUCCESS, tresult;
	int i = 0;
Automatic Updater's avatar
Automatic Updater committed
461

462
	static const char *acls[] = { "allow-query", "allow-query-on",
Automatic Updater's avatar
Automatic Updater committed
463
		"allow-query-cache", "allow-query-cache-on",
464
465
		"blackhole", "keep-response-order", "match-clients",
		"match-destinations", "sortlist", "filter-aaaa", NULL };
466
467

	while (acls[i] != NULL) {
468
		tresult = checkacl(acls[i++], actx, NULL, voptions, config,
469
470
				   logctx, mctx);
		if (tresult != ISC_R_SUCCESS)
Automatic Updater's avatar
Automatic Updater committed
471
			result = tresult;
472
473
474
475
	}
	return (result);
}

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
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;

492
	static const char *acls[] = { "clients", "exclude", "mapped", NULL};
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

	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
519

520
521
522
523
524
525
526
527
528
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
567
568
569
570
571
572
573
574
		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;
			if (prefixlen >= 32 && prefixlen <= 64)
				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);
}

575
576
577
578
579
580
581
582
583
584
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
#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);
}
707

708
709
710
711
712
713
714
715
716
717
718
719
/*
 * 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;
720
	bool recursion;
721
722
723
724
	const char *forview = " for view ";
	int i = 0;

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

727
728
729
730
731
732
733
734
735
	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)
736
		recursion = true;
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
	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
757
		if (aclobj == NULL)
758
759
760
			continue;

		tresult = cfg_acl_fromconfig(aclobj, config, logctx,
761
					    actx, mctx, 0, &acl);
762
763

		if (tresult != ISC_R_SUCCESS)
Automatic Updater's avatar
Automatic Updater committed
764
			result = tresult;
765
766
767
768

		if (acl == NULL)
			continue;

769
		if (recursion == false && !dns_acl_isnone(acl)) {
770
771
772
773
774
775
776
777
			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
778
	}
779
780
781
782

	return (result);
}

783
784
785
786
787
static isc_result_t
check_filteraaaa(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)
{
Evan Hunt's avatar
Evan Hunt committed
788
	const cfg_obj_t *options, *aclobj, *obj;
789
	dns_acl_t *acl = NULL;
Evan Hunt's avatar
Evan Hunt committed
790
791
	isc_result_t result = ISC_R_SUCCESS;
	dns_aaaa_t filter4, filter6;
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
	const char *forview = " for view ";

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

	aclobj = options = NULL;
	acl = NULL;

	if (voptions != NULL)
		cfg_map_get(voptions, "filter-aaaa", &aclobj);
	if (config != NULL && aclobj == NULL) {
		options = NULL;
		cfg_map_get(config, "options", &options);
		if (options != NULL)
			cfg_map_get(options, "filter-aaaa", &aclobj);
	}
	if (aclobj == NULL)
		return (result);

Evan Hunt's avatar
Evan Hunt committed
813
	result = cfg_acl_fromconfig(aclobj, config, logctx,
814
				    actx, mctx, 0, &acl);
Evan Hunt's avatar
Evan Hunt committed
815
816
	if (result != ISC_R_SUCCESS)
		goto failure;
817

Evan Hunt's avatar
Evan Hunt committed
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
	obj = NULL;
	if (voptions != NULL)
		cfg_map_get(voptions, "filter-aaaa-on-v4", &obj);
	if (obj == NULL && config != NULL) {
		options = NULL;
		cfg_map_get(config, "options", &options);
		if (options != NULL)
			cfg_map_get(options, "filter-aaaa-on-v4", &obj);
	}

	if (obj == NULL)
		filter4 = dns_aaaa_ok;		/* default */
	else if (cfg_obj_isboolean(obj))
		filter4 = cfg_obj_asboolean(obj) ? dns_aaaa_filter :
						  dns_aaaa_ok;
	else
		filter4 = dns_aaaa_break_dnssec; 	/* break-dnssec */

	obj = NULL;
	if (voptions != NULL)
		cfg_map_get(voptions, "filter-aaaa-on-v6", &obj);
	if (obj == NULL && config != NULL) {
		options = NULL;
		cfg_map_get(config, "options", &options);
		if (options != NULL)
			cfg_map_get(options, "filter-aaaa-on-v6", &obj);
	}

	if (obj == NULL)
		filter6 = dns_aaaa_ok;		/* default */
	else if (cfg_obj_isboolean(obj))
		filter6 = cfg_obj_asboolean(obj) ? dns_aaaa_filter :
						  dns_aaaa_ok;
	else
		filter6 = dns_aaaa_break_dnssec; 	/* break-dnssec */

	if ((filter4 != dns_aaaa_ok || filter6 != dns_aaaa_ok) &&
	    dns_acl_isnone(acl))
	{
857
		cfg_obj_log(aclobj, logctx, ISC_LOG_WARNING,
Evan Hunt's avatar
Evan Hunt committed
858
859
860
			    "\"filter-aaaa\" is 'none;' but "
			    "either filter-aaaa-on-v4 or filter-aaaa-on-v6 "
			    "is enabled%s%s", forview, viewname);
861
		result = ISC_R_FAILURE;
Evan Hunt's avatar
Evan Hunt committed
862
863
864
	} else if (filter4 == dns_aaaa_ok && filter6 == dns_aaaa_ok &&
		   !dns_acl_isnone(acl))
	{
865
		cfg_obj_log(aclobj, logctx, ISC_LOG_WARNING,
Evan Hunt's avatar
Evan Hunt committed
866
867
868
			    "\"filter-aaaa\" is set but "
			    "neither filter-aaaa-on-v4 or filter-aaaa-on-v6 "
			    "is enabled%s%s", forview, viewname);
869
870
871
		result = ISC_R_FAILURE;
	}

Evan Hunt's avatar
Evan Hunt committed
872
 failure:
873
874
875
876
877
878
	if (acl != NULL)
		dns_acl_detach(&acl);

	return (result);
}

879
880
881
typedef struct {
	const char *name;
	unsigned int scale;
882
	unsigned int max;
883
884
} intervaltable;

885
#ifdef HAVE_DNSTAP
886
887
888
889
890
typedef struct {
	const char *name;
	unsigned int min;
	unsigned int max;
} fstrmtable;
891
#endif
892

893
894
895
896
897
898
899
typedef enum {
	optlevel_config,
	optlevel_options,
	optlevel_view,
	optlevel_zone
} optlevel_t;

Evan Hunt's avatar
Evan Hunt committed
900
901
902
903
904
905
906
907
908
909
910
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) {
911
	       uint32_t dscp = cfg_obj_asuint32(obj);
Evan Hunt's avatar
Evan Hunt committed
912
913
914
915
916
917
918
919
920
921
	       if (dscp >= 64) {
		       cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				   "'dscp' out of range (0-63)");
		       result = ISC_R_FAILURE;
	       }
       }

       return (result);
}

922
923
924
925
926
927
928
929
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));
}

930
static isc_result_t
931
932
933
check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx,
	      optlevel_t optlevel)
{
934
	isc_result_t result = ISC_R_SUCCESS;
935
	isc_result_t tresult;
936
	unsigned int i;
937
	const cfg_obj_t *obj = NULL;
938
	const cfg_obj_t *resignobj = NULL;
939
	const cfg_listelt_t *element;
940
	isc_symtab_t *symtab = NULL;
941
942
943
944
	dns_fixedname_t fixed;
	const char *str;
	dns_name_t *name;
	isc_buffer_t b;
945
	uint32_t lifetime = 3600;
946
947
948
949
950
#if defined(HAVE_OPENSSL_AES) || defined(HAVE_OPENSSL_EVP_AES)
	const char *ccalg = "aes";
#else
	const char *ccalg = "sha256";
#endif
951
952

	static intervaltable intervals[] = {
953
954
955
956
957
958
959
960
	{ "cleaning-interval", 60, 28 * 24 * 60 },	/* 28 days */
	{ "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 */
961
962
	};

963
964
965
966
967
968
	static const char *server_contact[] = {
		"empty-server", "empty-contact",
		"dns64-server", "dns64-contact",
		NULL
	};

969
#ifdef HAVE_DNSTAP
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
998
999
1000
1001
1002
1003
	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

1004
1005
1006
1007
1008
	/*
	 * Check that fields specified in units of time other than seconds
	 * have reasonable values.
	 */
	for (i = 0; i < sizeof(intervals) / sizeof(intervals[0]); i++) {
1009
		uint32_t val;
1010
		obj = NULL;
1011
1012
1013
1014
		(void)cfg_map_get(options, intervals[i].name, &obj);
		if (obj == NULL)
			continue;
		val = cfg_obj_asuint32(obj);
1015
1016
1017
1018
1019
1020
		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;
1021
		} else if (val > (UINT32_MAX / intervals[i].scale)) {
1022
1023
1024
1025
1026
1027
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "%s '%d' is out of range",
				    intervals[i].name, val);
			result = ISC_R_RANGE;
		}
	}
1028

1029
1030
1031
	obj = NULL;
	cfg_map_get(options, "max-rsa-exponent-size", &obj);
	if (obj != NULL) {
1032
		uint32_t val;
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042

		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;
		}
	}

1043
1044
1045
	obj = NULL;
	cfg_map_get(options, "sig-validity-interval", &obj);
	if (obj != NULL) {
1046
		uint32_t validity, resign = 0;
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078

		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;
			}
		}
	}

1079
1080
1081
	obj = NULL;
	(void)cfg_map_get(options, "preferred-glue", &obj);
	if (obj != NULL) {
Automatic Updater's avatar
Automatic Updater committed
1082
1083
		str = cfg_obj_asstring(obj);
		if (strcasecmp(str, "a") != 0 &&
1084
1085
1086
1087
1088
1089
		    strcasecmp(str, "aaaa") != 0 &&
		    strcasecmp(str, "none") != 0)
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "preferred-glue unexpected value '%s'",
				    str);
	}
1090

1091
1092
1093
1094
1095
1096
1097
	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)) {
1098
1099
				const cfg_obj_t *exclude;

1100
1101
				exclude = cfg_listelt_value(element);
				str = cfg_obj_asstring(exclude);
1102
				tresult = check_name(str);
1103
1104
1105
1106
1107
1108
1109
1110
1111
				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
1112

1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
	/*
	 * 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;
		}
	}

1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
	/*
	 * 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;
		}
	}

1147
	name = dns_fixedname_initname(&fixed);
1148

1149
1150
1151
1152
1153
1154
	/*
	 * Check the DLV zone name.
	 */
	obj = NULL;
	(void)cfg_map_get(options, "dnssec-lookaside", &obj);
	if (obj != NULL) {
1155
		tresult = isc_symtab_create(mctx, 100, freekey, mctx,
1156
					    false, &symtab);
1157
		if (tresult != ISC_R_SUCCESS)
1158
			result = tresult;
1159
1160
1161
1162
1163
		for (element = cfg_list_first(obj);
		     element != NULL;
		     element = cfg_list_next(element))
		{
			const char *dlv;
1164
			const cfg_obj_t *dlvobj, *anchor;
1165
1166
1167

			obj = cfg_listelt_value(element);

1168
			anchor = cfg_tuple_get(obj, "trust-anchor");
1169
1170
			dlvobj = cfg_tuple_get(obj, "domain");
			dlv = cfg_obj_asstring(dlvobj);
1171
1172

			/*
1173
1174
			 * If domain is "auto" or "no" and trust anchor
			 * is missing, skip remaining tests
Automatic Updater's avatar
Automatic Updater committed
1175
			 */
1176
			if (cfg_obj_isvoid(anchor)) {
Evan Hunt's avatar
Evan Hunt committed
1177
1178
1179
1180
1181
1182
1183
1184
				if (!strcasecmp(dlv, "no")) {
					continue;
				}
				if (!strcasecmp(dlv, "auto")) {
					cfg_obj_log(obj, logctx,
						    ISC_LOG_WARNING,
						    "dnssec-lookaside 'auto' "
						    "is no longer supported");
1185
					continue;
Evan Hunt's avatar
Evan Hunt committed
1186
				}
1187
			}
1188

1189
			tresult = dns_name_fromstring(name, dlv, 0, NULL);
1190
1191
1192
1193
			if (tresult != ISC_R_SUCCESS) {
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "bad domain name '%s'", dlv);
				result = tresult;
1194
				continue;
1195
1196
1197
1198
			}
			if (symtab != NULL) {
				tresult = nameexist(obj, dlv, 1, symtab,
						    "dnssec-lookaside '%s': "
Evan Hunt's avatar
Evan Hunt committed
1199
						    "already exists; previous "
1200
1201
1202
1203
1204
1205
						    "definition: %s:%u",
						    logctx, mctx);
				if (tresult != ISC_R_SUCCESS &&
				    result == ISC_R_SUCCESS)
					result = tresult;
			}
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
			/*
			 * 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;
			}
1218

Evan Hunt's avatar
Evan Hunt committed
1219
			if (cfg_obj_isvoid(anchor)) {
1220
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
Evan Hunt's avatar
Evan Hunt committed
1221
1222
1223
					    "dnssec-lookaside requires "
					    "either or 'no' or a "
					    "domain and trust anchor");
1224
				if (result == ISC_R_SUCCESS)
1225
					result = ISC_R_FAILURE;
Evan Hunt's avatar
Evan Hunt committed
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
				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)) {
				cfg_obj_log(anchor, logctx, ISC_LOG_WARNING,
					    "dlv.isc.org has been shut down: "
					    "dnssec-lookaside ignored");
				continue;
1243
			}
1244
		}
1245

1246
1247
		if (symtab != NULL)
			isc_symtab_destroy(&symtab);
1248
	}
1249

1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
	/*
	 * 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");
			result = ISC_R_FAILURE;
		}
	}

1265
1266
1267
1268
1269
1270
1271
	/*
	 * 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,
1272
					    false, &symtab);
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
		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);
			if (tresult != ISC_R_SUCCESS)
				result = tresult;
		}
		if (symtab != NULL)
			isc_symtab_destroy(&symtab);
	}

1288
	/*
1289
	 * Check server/contacts for syntactic validity.
1290
	 */
1291
1292
1293
1294
1295
	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);
1296
			if (check_name(str) != ISC_R_SUCCESS) {
1297
1298
1299
1300
1301
				cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
					    "%s: invalid name '%s'",
					    server_contact[i], str);
				result = ISC_R_FAILURE;
			}
1302
1303
1304
		}
	}

1305
1306
1307
	/*
	 * Check empty zone configuration.
	 */
1308
1309
1310
1311
1312
1313
1314
1315
	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);
1316
		if (check_name(str) != ISC_R_SUCCESS) {
1317
1318
1319
1320
1321
1322
1323
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "disable-empty-zone: invalid name '%s'",
				    str);
			result = ISC_R_FAILURE;
		}
	}

1324
1325
1326
1327
1328
1329
1330
	/*
	 * 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
1331
	    strlen(cfg_obj_asstring(obj)) > 1024U) {
1332
1333
1334
1335
1336
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "'server-id' too big (>1024 bytes)");
		result = ISC_R_FAILURE;
	}

Evan Hunt's avatar
Evan Hunt committed
1337
1338
1339
1340
	tresult = check_dscp(options, logctx);
	if (tresult != ISC_R_SUCCESS)
		result = tresult;

Evan Hunt's avatar
Evan Hunt committed
1341
1342
1343
1344
	obj = NULL;
	(void)cfg_map_get(options, "nta-lifetime", &obj);
	if (obj != NULL) {
		lifetime = cfg_obj_asuint32(obj);
1345
		if (lifetime > 604800) {	/* 7 days */
Evan Hunt's avatar
Evan Hunt committed
1346
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
1347
				    "'nta-lifetime' cannot exceed one week");
Evan Hunt's avatar
Evan Hunt committed
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
			result = ISC_R_RANGE;
		} else if (lifetime == 0) {
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
				    "'nta-lifetime' may not be zero");
			result = ISC_R_RANGE;
		}
	}

	obj = NULL;
	(void)cfg_map_get(options, "nta-recheck", &obj);
	if (obj != NULL) {
1359
		uint32_t recheck = cfg_obj_asuint32(obj);
1360
		if (recheck > 604800) {		/* 7 days */
Evan Hunt's avatar
Evan Hunt committed
1361
			cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
1362
				    "'nta-recheck' cannot exceed one week");
Evan Hunt's avatar
Evan Hunt committed
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
			result = ISC_R_RANGE;
		}

		if (recheck > lifetime)
			cfg_obj_log(obj, logctx, ISC_LOG_WARNING,
				    "'nta-recheck' (%d seconds) is "
				    "greater than 'nta-lifetime' "
				    "(%d seconds)", recheck, lifetime);
	}

Tinderbox User's avatar
Tinderbox User committed
1373
	obj = NULL;
1374
	(void) cfg_map_get(options, "cookie-algorithm", &obj);
1375
1376
1377
	if (obj != NULL)
		ccalg = cfg_obj_asstring(obj);
#if !defined(HAVE_OPENSSL_AES) && !defined(HAVE_OPENSSL_EVP_AES)
1378
	if (strcasecmp(ccalg, "aes") == 0) {
1379
1380
		cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
			    "cookie-algorithm: '%s' not supported", ccalg);
1381
1382
		result = ISC_R_NOTIMPLEMENTED;
	}
1383
1384
1385
1386
#endif

	obj = NULL;
	(void) cfg_map_get(options, "cookie-secret", &obj);
Tinderbox User's avatar
Tinderbox User committed
1387
	if (obj != NULL) {
1388
1389
		unsigned char secret[32];

1390
1391
1392
1393
		for (element = cfg_list_first(obj);
		     element != NULL;
		     element = cfg_list_next(element)) {
			unsigned int usedlength;