2 * Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: zoneconf.c,v 1.110.18.23 2006/05/16 03:39:57 marka Exp $ */
24 #include <isc/buffer.h>
27 #include <isc/print.h>
28 #include <isc/string.h> /* Required for HP/UX (and others?) */
32 #include <dns/fixedname.h>
35 #include <dns/rdatatype.h>
40 #include <named/client.h>
41 #include <named/config.h>
42 #include <named/globals.h>
43 #include <named/log.h>
44 #include <named/server.h>
45 #include <named/zoneconf.h>
48 * These are BIND9 server defaults, not necessarily identical to the
49 * library defaults defined in zone.c.
51 #define RETERR(x) do { \
52 isc_result_t _r = (x); \
53 if (_r != ISC_R_SUCCESS) \
58 * Convenience function for configuring a single zone ACL.
61 configure_zone_acl(const cfg_obj_t
*zconfig
, const cfg_obj_t
*vconfig
,
62 const cfg_obj_t
*config
, const char *aclname
,
63 cfg_aclconfctx_t
*actx
, dns_zone_t
*zone
,
64 void (*setzacl
)(dns_zone_t
*, dns_acl_t
*),
65 void (*clearzacl
)(dns_zone_t
*))
68 const cfg_obj_t
*maps
[5];
69 const cfg_obj_t
*aclobj
= NULL
;
71 dns_acl_t
*dacl
= NULL
;
74 maps
[i
++] = cfg_tuple_get(zconfig
, "options");
76 maps
[i
++] = cfg_tuple_get(vconfig
, "options");
78 const cfg_obj_t
*options
= NULL
;
79 (void)cfg_map_get(config
, "options", &options
);
83 maps
[i
++] = ns_g_defaults
;
86 result
= ns_config_get(maps
, aclname
, &aclobj
);
89 return (ISC_R_SUCCESS
);
92 result
= cfg_acl_fromconfig(aclobj
, config
, ns_g_lctx
, actx
,
93 dns_zone_getmctx(zone
), &dacl
);
94 if (result
!= ISC_R_SUCCESS
)
96 (*setzacl
)(zone
, dacl
);
97 dns_acl_detach(&dacl
);
98 return (ISC_R_SUCCESS
);
102 * Parse the zone update-policy statement.
105 configure_zone_ssutable(const cfg_obj_t
*zconfig
, dns_zone_t
*zone
) {
106 const cfg_obj_t
*updatepolicy
= NULL
;
107 const cfg_listelt_t
*element
, *element2
;
108 dns_ssutable_t
*table
= NULL
;
109 isc_mem_t
*mctx
= dns_zone_getmctx(zone
);
112 (void)cfg_map_get(zconfig
, "update-policy", &updatepolicy
);
113 if (updatepolicy
== NULL
) {
114 dns_zone_setssutable(zone
, NULL
);
115 return (ISC_R_SUCCESS
);
118 result
= dns_ssutable_create(mctx
, &table
);
119 if (result
!= ISC_R_SUCCESS
)
122 for (element
= cfg_list_first(updatepolicy
);
124 element
= cfg_list_next(element
))
126 const cfg_obj_t
*stmt
= cfg_listelt_value(element
);
127 const cfg_obj_t
*mode
= cfg_tuple_get(stmt
, "mode");
128 const cfg_obj_t
*identity
= cfg_tuple_get(stmt
, "identity");
129 const cfg_obj_t
*matchtype
= cfg_tuple_get(stmt
, "matchtype");
130 const cfg_obj_t
*dname
= cfg_tuple_get(stmt
, "name");
131 const cfg_obj_t
*typelist
= cfg_tuple_get(stmt
, "types");
133 isc_boolean_t grant
= ISC_FALSE
;
134 unsigned int mtype
= DNS_SSUMATCHTYPE_NAME
;
135 dns_fixedname_t fname
, fident
;
137 dns_rdatatype_t
*types
;
140 str
= cfg_obj_asstring(mode
);
141 if (strcasecmp(str
, "grant") == 0)
143 else if (strcasecmp(str
, "deny") == 0)
148 str
= cfg_obj_asstring(matchtype
);
149 if (strcasecmp(str
, "name") == 0)
150 mtype
= DNS_SSUMATCHTYPE_NAME
;
151 else if (strcasecmp(str
, "subdomain") == 0)
152 mtype
= DNS_SSUMATCHTYPE_SUBDOMAIN
;
153 else if (strcasecmp(str
, "wildcard") == 0)
154 mtype
= DNS_SSUMATCHTYPE_WILDCARD
;
155 else if (strcasecmp(str
, "self") == 0)
156 mtype
= DNS_SSUMATCHTYPE_SELF
;
157 else if (strcasecmp(str
, "selfsub") == 0)
158 mtype
= DNS_SSUMATCHTYPE_SELFSUB
;
159 else if (strcasecmp(str
, "selfwild") == 0)
160 mtype
= DNS_SSUMATCHTYPE_SELFWILD
;
164 dns_fixedname_init(&fident
);
165 str
= cfg_obj_asstring(identity
);
166 isc_buffer_init(&b
, str
, strlen(str
));
167 isc_buffer_add(&b
, strlen(str
));
168 result
= dns_name_fromtext(dns_fixedname_name(&fident
), &b
,
169 dns_rootname
, ISC_FALSE
, NULL
);
170 if (result
!= ISC_R_SUCCESS
) {
171 cfg_obj_log(identity
, ns_g_lctx
, ISC_LOG_ERROR
,
172 "'%s' is not a valid name", str
);
176 dns_fixedname_init(&fname
);
177 str
= cfg_obj_asstring(dname
);
178 isc_buffer_init(&b
, str
, strlen(str
));
179 isc_buffer_add(&b
, strlen(str
));
180 result
= dns_name_fromtext(dns_fixedname_name(&fname
), &b
,
181 dns_rootname
, ISC_FALSE
, NULL
);
182 if (result
!= ISC_R_SUCCESS
) {
183 cfg_obj_log(identity
, ns_g_lctx
, ISC_LOG_ERROR
,
184 "'%s' is not a valid name", str
);
188 n
= ns_config_listcount(typelist
);
192 types
= isc_mem_get(mctx
, n
* sizeof(dns_rdatatype_t
));
194 result
= ISC_R_NOMEMORY
;
200 for (element2
= cfg_list_first(typelist
);
202 element2
= cfg_list_next(element2
))
204 const cfg_obj_t
*typeobj
;
209 typeobj
= cfg_listelt_value(element2
);
210 str
= cfg_obj_asstring(typeobj
);
211 DE_CONST(str
, r
.base
);
212 r
.length
= strlen(str
);
214 result
= dns_rdatatype_fromtext(&types
[i
++], &r
);
215 if (result
!= ISC_R_SUCCESS
) {
216 cfg_obj_log(identity
, ns_g_lctx
, ISC_LOG_ERROR
,
217 "'%s' is not a valid type", str
);
218 isc_mem_put(mctx
, types
,
219 n
* sizeof(dns_rdatatype_t
));
225 result
= dns_ssutable_addrule(table
, grant
,
226 dns_fixedname_name(&fident
),
228 dns_fixedname_name(&fname
),
231 isc_mem_put(mctx
, types
, n
* sizeof(dns_rdatatype_t
));
232 if (result
!= ISC_R_SUCCESS
) {
238 result
= ISC_R_SUCCESS
;
239 dns_zone_setssutable(zone
, table
);
242 dns_ssutable_detach(&table
);
247 * Convert a config file zone type into a server zone type.
249 static inline dns_zonetype_t
250 zonetype_fromconfig(const cfg_obj_t
*map
) {
251 const cfg_obj_t
*obj
= NULL
;
254 result
= cfg_map_get(map
, "type", &obj
);
255 INSIST(result
== ISC_R_SUCCESS
);
256 return (ns_config_getzonetype(obj
));
260 * Helper function for strtoargv(). Pardon the gratuitous recursion.
263 strtoargvsub(isc_mem_t
*mctx
, char *s
, unsigned int *argcp
,
264 char ***argvp
, unsigned int n
)
268 /* Discard leading whitespace. */
269 while (*s
== ' ' || *s
== '\t')
273 /* We have reached the end of the string. */
275 *argvp
= isc_mem_get(mctx
, n
* sizeof(char *));
277 return (ISC_R_NOMEMORY
);
280 while (*p
!= ' ' && *p
!= '\t' && *p
!= '\0')
285 result
= strtoargvsub(mctx
, p
, argcp
, argvp
, n
+ 1);
286 if (result
!= ISC_R_SUCCESS
)
290 return (ISC_R_SUCCESS
);
294 * Tokenize the string "s" into whitespace-separated words,
295 * return the number of words in '*argcp' and an array
296 * of pointers to the words in '*argvp'. The caller
297 * must free the array using isc_mem_put(). The string
298 * is modified in-place.
301 strtoargv(isc_mem_t
*mctx
, char *s
, unsigned int *argcp
, char ***argvp
) {
302 return (strtoargvsub(mctx
, s
, argcp
, argvp
, 0));
306 checknames(dns_zonetype_t ztype
, const cfg_obj_t
**maps
,
307 const cfg_obj_t
**objp
)
309 const char *zone
= NULL
;
313 case dns_zone_slave
: zone
= "slave"; break;
314 case dns_zone_master
: zone
= "master"; break;
318 result
= ns_checknames_get(maps
, zone
, objp
);
319 INSIST(result
== ISC_R_SUCCESS
);
323 ns_zone_configure(const cfg_obj_t
*config
, const cfg_obj_t
*vconfig
,
324 const cfg_obj_t
*zconfig
, cfg_aclconfctx_t
*ac
,
329 dns_rdataclass_t zclass
;
330 dns_rdataclass_t vclass
;
331 const cfg_obj_t
*maps
[5];
332 const cfg_obj_t
*zoptions
= NULL
;
333 const cfg_obj_t
*options
= NULL
;
334 const cfg_obj_t
*obj
;
335 const char *filename
= NULL
;
336 dns_notifytype_t notifytype
= dns_notifytype_yes
;
337 isc_sockaddr_t
*addrs
;
338 dns_name_t
**keynames
;
343 static char default_dbtype
[] = "rbt";
344 isc_mem_t
*mctx
= dns_zone_getmctx(zone
);
345 dns_dialuptype_t dialup
= dns_dialuptype_no
;
346 dns_zonetype_t ztype
;
348 isc_int32_t journal_size
;
352 isc_boolean_t check
= ISC_FALSE
, fail
= ISC_FALSE
;
353 isc_boolean_t warn
= ISC_FALSE
, ignore
= ISC_FALSE
;
354 isc_boolean_t ixfrdiff
;
355 dns_masterformat_t masterformat
;
358 if (zconfig
!= NULL
) {
359 zoptions
= cfg_tuple_get(zconfig
, "options");
360 maps
[i
++] = zoptions
;
363 maps
[i
++] = cfg_tuple_get(vconfig
, "options");
364 if (config
!= NULL
) {
365 (void)cfg_map_get(config
, "options", &options
);
369 maps
[i
++] = ns_g_defaults
;
373 RETERR(ns_config_getclass(cfg_tuple_get(vconfig
, "class"),
374 dns_rdataclass_in
, &vclass
));
376 vclass
= dns_rdataclass_in
;
379 * Configure values common to all zone types.
382 zname
= cfg_obj_asstring(cfg_tuple_get(zconfig
, "name"));
384 RETERR(ns_config_getclass(cfg_tuple_get(zconfig
, "class"),
386 dns_zone_setclass(zone
, zclass
);
388 ztype
= zonetype_fromconfig(zoptions
);
389 dns_zone_settype(zone
, ztype
);
392 result
= cfg_map_get(zoptions
, "database", &obj
);
393 if (result
== ISC_R_SUCCESS
)
394 cpval
= isc_mem_strdup(mctx
, cfg_obj_asstring(obj
));
396 cpval
= default_dbtype
;
399 return(ISC_R_NOMEMORY
);
401 result
= strtoargv(mctx
, cpval
, &dbargc
, &dbargv
);
402 if (result
!= ISC_R_SUCCESS
&& cpval
!= default_dbtype
) {
403 isc_mem_free(mctx
, cpval
);
408 * ANSI C is strange here. There is no logical reason why (char **)
409 * cannot be promoted automatically to (const char * const *) by the
410 * compiler w/o generating a warning.
412 result
= dns_zone_setdbtype(zone
, dbargc
, (const char * const *)dbargv
);
413 isc_mem_put(mctx
, dbargv
, dbargc
* sizeof(*dbargv
));
414 if (cpval
!= default_dbtype
)
415 isc_mem_free(mctx
, cpval
);
416 if (result
!= ISC_R_SUCCESS
)
420 result
= cfg_map_get(zoptions
, "file", &obj
);
421 if (result
== ISC_R_SUCCESS
)
422 filename
= cfg_obj_asstring(obj
);
424 masterformat
= dns_masterformat_text
;
426 result
= ns_config_get(maps
, "masterfile-format", &obj
);
427 if (result
== ISC_R_SUCCESS
) {
428 const char *masterformatstr
= cfg_obj_asstring(obj
);
430 if (strcasecmp(masterformatstr
, "text") == 0)
431 masterformat
= dns_masterformat_text
;
432 else if (strcasecmp(masterformatstr
, "raw") == 0)
433 masterformat
= dns_masterformat_raw
;
437 RETERR(dns_zone_setfile2(zone
, filename
, masterformat
));
440 result
= cfg_map_get(zoptions
, "journal", &obj
);
441 if (result
== ISC_R_SUCCESS
)
442 RETERR(dns_zone_setjournal(zone
, cfg_obj_asstring(obj
)));
444 if (ztype
== dns_zone_slave
)
445 RETERR(configure_zone_acl(zconfig
, vconfig
, config
,
446 "allow-notify", ac
, zone
,
447 dns_zone_setnotifyacl
,
448 dns_zone_clearnotifyacl
));
450 * XXXAG This probably does not make sense for stubs.
452 RETERR(configure_zone_acl(zconfig
, vconfig
, config
,
453 "allow-query", ac
, zone
,
454 dns_zone_setqueryacl
,
455 dns_zone_clearqueryacl
));
458 result
= ns_config_get(maps
, "dialup", &obj
);
459 INSIST(result
== ISC_R_SUCCESS
);
460 if (cfg_obj_isboolean(obj
)) {
461 if (cfg_obj_asboolean(obj
))
462 dialup
= dns_dialuptype_yes
;
464 dialup
= dns_dialuptype_no
;
466 const char *dialupstr
= cfg_obj_asstring(obj
);
467 if (strcasecmp(dialupstr
, "notify") == 0)
468 dialup
= dns_dialuptype_notify
;
469 else if (strcasecmp(dialupstr
, "notify-passive") == 0)
470 dialup
= dns_dialuptype_notifypassive
;
471 else if (strcasecmp(dialupstr
, "refresh") == 0)
472 dialup
= dns_dialuptype_refresh
;
473 else if (strcasecmp(dialupstr
, "passive") == 0)
474 dialup
= dns_dialuptype_passive
;
478 dns_zone_setdialup(zone
, dialup
);
481 result
= ns_config_get(maps
, "zone-statistics", &obj
);
482 INSIST(result
== ISC_R_SUCCESS
);
483 RETERR(dns_zone_setstatistics(zone
, cfg_obj_asboolean(obj
)));
486 * Configure master functionality. This applies
487 * to primary masters (type "master") and slaves
488 * acting as masters (type "slave"), but not to stubs.
490 if (ztype
!= dns_zone_stub
) {
492 result
= ns_config_get(maps
, "notify", &obj
);
493 INSIST(result
== ISC_R_SUCCESS
);
494 if (cfg_obj_isboolean(obj
)) {
495 if (cfg_obj_asboolean(obj
))
496 notifytype
= dns_notifytype_yes
;
498 notifytype
= dns_notifytype_no
;
500 const char *notifystr
= cfg_obj_asstring(obj
);
501 if (strcasecmp(notifystr
, "explicit") == 0)
502 notifytype
= dns_notifytype_explicit
;
503 else if (strcasecmp(notifystr
, "master-only") == 0)
504 notifytype
= dns_notifytype_masteronly
;
508 dns_zone_setnotifytype(zone
, notifytype
);
511 result
= ns_config_get(maps
, "also-notify", &obj
);
512 if (result
== ISC_R_SUCCESS
) {
513 isc_sockaddr_t
*addrs
= NULL
;
514 isc_uint32_t addrcount
;
515 result
= ns_config_getiplist(config
, obj
, 0, mctx
,
517 if (result
!= ISC_R_SUCCESS
)
519 result
= dns_zone_setalsonotify(zone
, addrs
,
521 ns_config_putiplist(mctx
, &addrs
, addrcount
);
522 if (result
!= ISC_R_SUCCESS
)
525 RETERR(dns_zone_setalsonotify(zone
, NULL
, 0));
528 result
= ns_config_get(maps
, "notify-source", &obj
);
529 INSIST(result
== ISC_R_SUCCESS
);
530 RETERR(dns_zone_setnotifysrc4(zone
, cfg_obj_assockaddr(obj
)));
531 ns_add_reserved_dispatch(ns_g_server
, cfg_obj_assockaddr(obj
));
534 result
= ns_config_get(maps
, "notify-source-v6", &obj
);
535 INSIST(result
== ISC_R_SUCCESS
);
536 RETERR(dns_zone_setnotifysrc6(zone
, cfg_obj_assockaddr(obj
)));
537 ns_add_reserved_dispatch(ns_g_server
, cfg_obj_assockaddr(obj
));
539 dns_zone_setisself(zone
, ns_client_isself
, NULL
);
541 RETERR(configure_zone_acl(zconfig
, vconfig
, config
,
542 "allow-transfer", ac
, zone
,
544 dns_zone_clearxfracl
));
547 result
= ns_config_get(maps
, "max-transfer-time-out", &obj
);
548 INSIST(result
== ISC_R_SUCCESS
);
549 dns_zone_setmaxxfrout(zone
, cfg_obj_asuint32(obj
) * 60);
552 result
= ns_config_get(maps
, "max-transfer-idle-out", &obj
);
553 INSIST(result
== ISC_R_SUCCESS
);
554 dns_zone_setidleout(zone
, cfg_obj_asuint32(obj
) * 60);
557 result
= ns_config_get(maps
, "max-journal-size", &obj
);
558 INSIST(result
== ISC_R_SUCCESS
);
559 dns_zone_setjournalsize(zone
, -1);
560 if (cfg_obj_isstring(obj
)) {
561 const char *str
= cfg_obj_asstring(obj
);
562 INSIST(strcasecmp(str
, "unlimited") == 0);
563 journal_size
= ISC_UINT32_MAX
/ 2;
565 isc_resourcevalue_t value
;
566 value
= cfg_obj_asuint64(obj
);
567 if (value
> ISC_UINT32_MAX
/ 2) {
568 cfg_obj_log(obj
, ns_g_lctx
,
571 "%" ISC_PRINT_QUADFORMAT
"d' "
576 journal_size
= (isc_uint32_t
)value
;
578 dns_zone_setjournalsize(zone
, journal_size
);
581 result
= ns_config_get(maps
, "ixfr-from-differences", &obj
);
582 INSIST(result
== ISC_R_SUCCESS
);
583 if (cfg_obj_isboolean(obj
))
584 ixfrdiff
= cfg_obj_asboolean(obj
);
585 else if (strcasecmp(cfg_obj_asstring(obj
), "master") &&
586 ztype
== dns_zone_master
)
588 else if (strcasecmp(cfg_obj_asstring(obj
), "slave") &&
589 ztype
== dns_zone_slave
)
592 ixfrdiff
= ISC_FALSE
;
593 dns_zone_setoption(zone
, DNS_ZONEOPT_IXFRFROMDIFFS
, ixfrdiff
);
595 checknames(ztype
, maps
, &obj
);
597 if (strcasecmp(cfg_obj_asstring(obj
), "warn") == 0) {
600 } else if (strcasecmp(cfg_obj_asstring(obj
), "fail") == 0) {
601 fail
= check
= ISC_TRUE
;
602 } else if (strcasecmp(cfg_obj_asstring(obj
), "ignore") == 0) {
603 fail
= check
= ISC_FALSE
;
606 dns_zone_setoption(zone
, DNS_ZONEOPT_CHECKNAMES
, check
);
607 dns_zone_setoption(zone
, DNS_ZONEOPT_CHECKNAMESFAIL
, fail
);
610 result
= ns_config_get(maps
, "notify-delay", &obj
);
611 INSIST(result
== ISC_R_SUCCESS
);
612 dns_zone_setnotifydelay(zone
, cfg_obj_asuint32(obj
));
615 result
= ns_config_get(maps
, "check-sibling", &obj
);
616 INSIST(result
== ISC_R_SUCCESS
);
617 dns_zone_setoption(zone
, DNS_ZONEOPT_CHECKSIBLING
,
618 cfg_obj_asboolean(obj
));
621 result
= ns_config_get(maps
, "zero-no-soa-ttl", &obj
);
622 INSIST(result
== ISC_R_SUCCESS
);
623 dns_zone_setzeronosoattl(zone
, cfg_obj_asboolean(obj
));
627 * Configure update-related options. These apply to
628 * primary masters only.
630 if (ztype
== dns_zone_master
) {
631 dns_acl_t
*updateacl
;
632 RETERR(configure_zone_acl(zconfig
, vconfig
, config
,
633 "allow-update", ac
, zone
,
634 dns_zone_setupdateacl
,
635 dns_zone_clearupdateacl
));
637 updateacl
= dns_zone_getupdateacl(zone
);
638 if (updateacl
!= NULL
&& dns_acl_isinsecure(updateacl
))
639 isc_log_write(ns_g_lctx
, DNS_LOGCATEGORY_SECURITY
,
640 NS_LOGMODULE_SERVER
, ISC_LOG_WARNING
,
641 "zone '%s' allows updates by IP "
642 "address, which is insecure",
645 RETERR(configure_zone_ssutable(zoptions
, zone
));
648 result
= ns_config_get(maps
, "sig-validity-interval", &obj
);
649 INSIST(result
== ISC_R_SUCCESS
);
650 dns_zone_setsigvalidityinterval(zone
,
651 cfg_obj_asuint32(obj
) * 86400);
654 result
= ns_config_get(maps
, "key-directory", &obj
);
655 if (result
== ISC_R_SUCCESS
) {
656 filename
= cfg_obj_asstring(obj
);
657 if (!isc_file_isabsolute(filename
)) {
658 cfg_obj_log(obj
, ns_g_lctx
, ISC_LOG_ERROR
,
659 "key-directory '%s' "
660 "is not absolute", filename
);
661 return (ISC_R_FAILURE
);
663 RETERR(dns_zone_setkeydirectory(zone
, filename
));
667 result
= ns_config_get(maps
, "check-wildcard", &obj
);
668 if (result
== ISC_R_SUCCESS
)
669 check
= cfg_obj_asboolean(obj
);
672 dns_zone_setoption(zone
, DNS_ZONEOPT_CHECKWILDCARD
, check
);
675 result
= ns_config_get(maps
, "check-mx", &obj
);
677 if (strcasecmp(cfg_obj_asstring(obj
), "warn") == 0) {
680 } else if (strcasecmp(cfg_obj_asstring(obj
), "fail") == 0) {
681 fail
= check
= ISC_TRUE
;
682 } else if (strcasecmp(cfg_obj_asstring(obj
), "ignore") == 0) {
683 fail
= check
= ISC_FALSE
;
686 dns_zone_setoption(zone
, DNS_ZONEOPT_CHECKMX
, check
);
687 dns_zone_setoption(zone
, DNS_ZONEOPT_CHECKMXFAIL
, fail
);
690 result
= ns_config_get(maps
, "check-integrity", &obj
);
692 dns_zone_setoption(zone
, DNS_ZONEOPT_CHECKINTEGRITY
,
693 cfg_obj_asboolean(obj
));
696 result
= ns_config_get(maps
, "check-mx-cname", &obj
);
698 if (strcasecmp(cfg_obj_asstring(obj
), "warn") == 0) {
701 } else if (strcasecmp(cfg_obj_asstring(obj
), "fail") == 0) {
702 warn
= ignore
= ISC_FALSE
;
703 } else if (strcasecmp(cfg_obj_asstring(obj
), "ignore") == 0) {
704 warn
= ignore
= ISC_TRUE
;
707 dns_zone_setoption(zone
, DNS_ZONEOPT_WARNMXCNAME
, warn
);
708 dns_zone_setoption(zone
, DNS_ZONEOPT_IGNOREMXCNAME
, ignore
);
711 result
= ns_config_get(maps
, "check-srv-cname", &obj
);
713 if (strcasecmp(cfg_obj_asstring(obj
), "warn") == 0) {
716 } else if (strcasecmp(cfg_obj_asstring(obj
), "fail") == 0) {
717 warn
= ignore
= ISC_FALSE
;
718 } else if (strcasecmp(cfg_obj_asstring(obj
), "ignore") == 0) {
719 warn
= ignore
= ISC_TRUE
;
722 dns_zone_setoption(zone
, DNS_ZONEOPT_WARNSRVCNAME
, warn
);
723 dns_zone_setoption(zone
, DNS_ZONEOPT_IGNORESRVCNAME
, ignore
);
726 result
= ns_config_get(maps
, "update-check-ksk", &obj
);
727 INSIST(result
== ISC_R_SUCCESS
);
728 dns_zone_setoption(zone
, DNS_ZONEOPT_UPDATECHECKKSK
,
729 cfg_obj_asboolean(obj
));
733 * Configure update-related options. These apply to
734 * primary masters only.
736 if (ztype
== dns_zone_master
) {
737 dns_acl_t
*updateacl
;
738 RETERR(configure_zone_acl(zconfig
, vconfig
, config
,
739 "allow-update", ac
, zone
,
740 dns_zone_setupdateacl
,
741 dns_zone_clearupdateacl
));
743 updateacl
= dns_zone_getupdateacl(zone
);
744 if (updateacl
!= NULL
&& dns_acl_isinsecure(updateacl
))
745 isc_log_write(ns_g_lctx
, DNS_LOGCATEGORY_SECURITY
,
746 NS_LOGMODULE_SERVER
, ISC_LOG_WARNING
,
747 "zone '%s' allows updates by IP "
748 "address, which is insecure",
751 RETERR(configure_zone_ssutable(zoptions
, zone
));
754 result
= ns_config_get(maps
, "sig-validity-interval", &obj
);
755 INSIST(result
== ISC_R_SUCCESS
);
756 dns_zone_setsigvalidityinterval(zone
,
757 cfg_obj_asuint32(obj
) * 86400);
760 result
= ns_config_get(maps
, "key-directory", &obj
);
761 if (result
== ISC_R_SUCCESS
) {
762 filename
= cfg_obj_asstring(obj
);
763 if (!isc_file_isabsolute(filename
)) {
764 cfg_obj_log(obj
, ns_g_lctx
, ISC_LOG_ERROR
,
765 "key-directory '%s' "
766 "is not absolute", filename
);
767 return (ISC_R_FAILURE
);
769 RETERR(dns_zone_setkeydirectory(zone
, filename
));
772 } else if (ztype
== dns_zone_slave
) {
773 RETERR(configure_zone_acl(zconfig
, vconfig
, config
,
774 "allow-update-forwarding", ac
, zone
,
775 dns_zone_setforwardacl
,
776 dns_zone_clearforwardacl
));
780 * Configure slave functionality.
787 result
= cfg_map_get(zoptions
, "masters", &obj
);
791 RETERR(ns_config_getipandkeylist(config
, obj
, mctx
,
794 result
= dns_zone_setmasterswithkeys(zone
, addrs
,
796 ns_config_putipandkeylist(mctx
, &addrs
, &keynames
,
799 result
= dns_zone_setmasters(zone
, NULL
, 0);
805 result
= ns_config_get(maps
, "multi-master", &obj
);
806 INSIST(result
== ISC_R_SUCCESS
);
807 multi
= cfg_obj_asboolean(obj
);
809 dns_zone_setoption(zone
, DNS_ZONEOPT_MULTIMASTER
, multi
);
812 result
= ns_config_get(maps
, "max-transfer-time-in", &obj
);
813 INSIST(result
== ISC_R_SUCCESS
);
814 dns_zone_setmaxxfrin(zone
, cfg_obj_asuint32(obj
) * 60);
817 result
= ns_config_get(maps
, "max-transfer-idle-in", &obj
);
818 INSIST(result
== ISC_R_SUCCESS
);
819 dns_zone_setidlein(zone
, cfg_obj_asuint32(obj
) * 60);
822 result
= ns_config_get(maps
, "max-refresh-time", &obj
);
823 INSIST(result
== ISC_R_SUCCESS
);
824 dns_zone_setmaxrefreshtime(zone
, cfg_obj_asuint32(obj
));
827 result
= ns_config_get(maps
, "min-refresh-time", &obj
);
828 INSIST(result
== ISC_R_SUCCESS
);
829 dns_zone_setminrefreshtime(zone
, cfg_obj_asuint32(obj
));
832 result
= ns_config_get(maps
, "max-retry-time", &obj
);
833 INSIST(result
== ISC_R_SUCCESS
);
834 dns_zone_setmaxretrytime(zone
, cfg_obj_asuint32(obj
));
837 result
= ns_config_get(maps
, "min-retry-time", &obj
);
838 INSIST(result
== ISC_R_SUCCESS
);
839 dns_zone_setminretrytime(zone
, cfg_obj_asuint32(obj
));
842 result
= ns_config_get(maps
, "transfer-source", &obj
);
843 INSIST(result
== ISC_R_SUCCESS
);
844 RETERR(dns_zone_setxfrsource4(zone
, cfg_obj_assockaddr(obj
)));
845 ns_add_reserved_dispatch(ns_g_server
, cfg_obj_assockaddr(obj
));
848 result
= ns_config_get(maps
, "transfer-source-v6", &obj
);
849 INSIST(result
== ISC_R_SUCCESS
);
850 RETERR(dns_zone_setxfrsource6(zone
, cfg_obj_assockaddr(obj
)));
851 ns_add_reserved_dispatch(ns_g_server
, cfg_obj_assockaddr(obj
));
854 result
= ns_config_get(maps
, "alt-transfer-source", &obj
);
855 INSIST(result
== ISC_R_SUCCESS
);
856 RETERR(dns_zone_setaltxfrsource4(zone
, cfg_obj_assockaddr(obj
)));
859 result
= ns_config_get(maps
, "alt-transfer-source-v6", &obj
);
860 INSIST(result
== ISC_R_SUCCESS
);
861 RETERR(dns_zone_setaltxfrsource6(zone
, cfg_obj_assockaddr(obj
)));
864 (void)ns_config_get(maps
, "use-alt-transfer-source", &obj
);
867 * Default off when views are in use otherwise
868 * on for BIND 8 compatibility.
870 view
= dns_zone_getview(zone
);
871 if (view
!= NULL
&& strcmp(view
->name
, "_default") == 0)
876 alt
= cfg_obj_asboolean(obj
);
877 dns_zone_setoption(zone
, DNS_ZONEOPT_USEALTXFRSRC
, alt
);
885 return (ISC_R_SUCCESS
);
889 ns_zone_reusable(dns_zone_t
*zone
, const cfg_obj_t
*zconfig
) {
890 const cfg_obj_t
*zoptions
= NULL
;
891 const cfg_obj_t
*obj
= NULL
;
892 const char *cfilename
;
893 const char *zfilename
;
895 zoptions
= cfg_tuple_get(zconfig
, "options");
897 if (zonetype_fromconfig(zoptions
) != dns_zone_gettype(zone
))
901 (void)cfg_map_get(zoptions
, "file", &obj
);
903 cfilename
= cfg_obj_asstring(obj
);
906 zfilename
= dns_zone_getfile(zone
);
907 if (!((cfilename
== NULL
&& zfilename
== NULL
) ||
908 (cfilename
!= NULL
&& zfilename
!= NULL
&&
909 strcmp(cfilename
, zfilename
) == 0)))