Home | History | Annotate | Line # | Download | only in named
zoneconf.c revision 1.18
      1  1.17  christos /*	$NetBSD: zoneconf.c,v 1.18 2025/05/21 14:47:35 christos Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*
      4   1.1  christos  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5   1.1  christos  *
      6  1.12  christos  * SPDX-License-Identifier: MPL-2.0
      7  1.12  christos  *
      8   1.1  christos  * This Source Code Form is subject to the terms of the Mozilla Public
      9   1.1  christos  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10   1.9  christos  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11   1.1  christos  *
     12   1.1  christos  * See the COPYRIGHT file distributed with this work for additional
     13   1.1  christos  * information regarding copyright ownership.
     14   1.1  christos  */
     15   1.1  christos 
     16   1.3  christos #include <inttypes.h>
     17   1.3  christos #include <stdbool.h>
     18   1.3  christos 
     19   1.1  christos #include <isc/buffer.h>
     20   1.1  christos #include <isc/file.h>
     21   1.1  christos #include <isc/mem.h>
     22  1.15  christos #include <isc/result.h>
     23   1.1  christos #include <isc/stats.h>
     24  1.17  christos #include <isc/string.h>
     25   1.1  christos #include <isc/util.h>
     26   1.1  christos 
     27   1.1  christos #include <dns/acl.h>
     28   1.1  christos #include <dns/db.h>
     29   1.7  christos #include <dns/fixedname.h>
     30   1.1  christos #include <dns/ipkeylist.h>
     31   1.1  christos #include <dns/journal.h>
     32   1.7  christos #include <dns/kasp.h>
     33   1.1  christos #include <dns/log.h>
     34   1.7  christos #include <dns/masterdump.h>
     35   1.1  christos #include <dns/name.h>
     36   1.9  christos #include <dns/nsec3.h>
     37   1.1  christos #include <dns/rdata.h>
     38   1.7  christos #include <dns/rdatalist.h>
     39   1.7  christos #include <dns/rdataset.h>
     40   1.1  christos #include <dns/rdatatype.h>
     41   1.1  christos #include <dns/sdlz.h>
     42   1.1  christos #include <dns/ssu.h>
     43   1.1  christos #include <dns/stats.h>
     44   1.1  christos #include <dns/tsig.h>
     45   1.1  christos #include <dns/view.h>
     46   1.1  christos #include <dns/zone.h>
     47   1.1  christos 
     48   1.1  christos #include <ns/client.h>
     49   1.1  christos 
     50   1.1  christos #include <named/config.h>
     51   1.1  christos #include <named/globals.h>
     52   1.1  christos #include <named/log.h>
     53   1.1  christos #include <named/server.h>
     54   1.1  christos #include <named/zoneconf.h>
     55   1.1  christos 
     56   1.1  christos /* ACLs associated with zone */
     57   1.1  christos typedef enum {
     58   1.1  christos 	allow_notify,
     59   1.1  christos 	allow_query,
     60   1.1  christos 	allow_query_on,
     61   1.1  christos 	allow_transfer,
     62   1.1  christos 	allow_update,
     63   1.1  christos 	allow_update_forwarding
     64   1.1  christos } acl_type_t;
     65   1.1  christos 
     66   1.7  christos #define CHECK(x)                             \
     67   1.7  christos 	do {                                 \
     68   1.7  christos 		result = (x);                \
     69   1.7  christos 		if (result != ISC_R_SUCCESS) \
     70   1.7  christos 			goto cleanup;        \
     71  1.10    rillig 	} while (0)
     72   1.1  christos 
     73   1.1  christos /*%
     74   1.1  christos  * Convenience function for configuring a single zone ACL.
     75   1.1  christos  */
     76   1.1  christos static isc_result_t
     77   1.1  christos configure_zone_acl(const cfg_obj_t *zconfig, const cfg_obj_t *vconfig,
     78   1.1  christos 		   const cfg_obj_t *config, acl_type_t acltype,
     79   1.1  christos 		   cfg_aclconfctx_t *actx, dns_zone_t *zone,
     80   1.1  christos 		   void (*setzacl)(dns_zone_t *, dns_acl_t *),
     81   1.7  christos 		   void (*clearzacl)(dns_zone_t *)) {
     82   1.1  christos 	isc_result_t result;
     83   1.7  christos 	const cfg_obj_t *maps[5] = { NULL, NULL, NULL, NULL, NULL };
     84   1.1  christos 	const cfg_obj_t *aclobj = NULL;
     85   1.1  christos 	int i = 0;
     86   1.1  christos 	dns_acl_t **aclp = NULL, *acl = NULL;
     87   1.1  christos 	const char *aclname;
     88   1.1  christos 	dns_view_t *view;
     89   1.1  christos 
     90   1.1  christos 	view = dns_zone_getview(zone);
     91   1.1  christos 
     92   1.1  christos 	switch (acltype) {
     93   1.7  christos 	case allow_notify:
     94   1.7  christos 		if (view != NULL) {
     95   1.1  christos 			aclp = &view->notifyacl;
     96   1.7  christos 		}
     97   1.1  christos 		aclname = "allow-notify";
     98   1.1  christos 		break;
     99   1.7  christos 	case allow_query:
    100   1.7  christos 		if (view != NULL) {
    101   1.1  christos 			aclp = &view->queryacl;
    102   1.7  christos 		}
    103   1.1  christos 		aclname = "allow-query";
    104   1.1  christos 		break;
    105   1.7  christos 	case allow_query_on:
    106   1.7  christos 		if (view != NULL) {
    107   1.1  christos 			aclp = &view->queryonacl;
    108   1.7  christos 		}
    109   1.1  christos 		aclname = "allow-query-on";
    110   1.1  christos 		break;
    111   1.7  christos 	case allow_transfer:
    112   1.7  christos 		if (view != NULL) {
    113   1.1  christos 			aclp = &view->transferacl;
    114   1.7  christos 		}
    115   1.1  christos 		aclname = "allow-transfer";
    116   1.1  christos 		break;
    117   1.7  christos 	case allow_update:
    118   1.7  christos 		if (view != NULL) {
    119   1.1  christos 			aclp = &view->updateacl;
    120   1.7  christos 		}
    121   1.1  christos 		aclname = "allow-update";
    122   1.1  christos 		break;
    123   1.7  christos 	case allow_update_forwarding:
    124   1.7  christos 		if (view != NULL) {
    125   1.1  christos 			aclp = &view->upfwdacl;
    126   1.7  christos 		}
    127   1.1  christos 		aclname = "allow-update-forwarding";
    128   1.1  christos 		break;
    129   1.7  christos 	default:
    130  1.12  christos 		UNREACHABLE();
    131   1.1  christos 	}
    132   1.1  christos 
    133   1.1  christos 	/* First check to see if ACL is defined within the zone */
    134   1.1  christos 	if (zconfig != NULL) {
    135   1.1  christos 		maps[0] = cfg_tuple_get(zconfig, "options");
    136   1.1  christos 		(void)named_config_get(maps, aclname, &aclobj);
    137   1.1  christos 		if (aclobj != NULL) {
    138   1.1  christos 			aclp = NULL;
    139   1.1  christos 			goto parse_acl;
    140   1.1  christos 		}
    141   1.1  christos 	}
    142   1.1  christos 
    143   1.1  christos 	/* Failing that, see if there's a default ACL already in the view */
    144   1.1  christos 	if (aclp != NULL && *aclp != NULL) {
    145   1.1  christos 		(*setzacl)(zone, *aclp);
    146  1.17  christos 		return ISC_R_SUCCESS;
    147   1.1  christos 	}
    148   1.1  christos 
    149   1.1  christos 	/* Check for default ACLs that haven't been parsed yet */
    150   1.1  christos 	if (vconfig != NULL) {
    151   1.1  christos 		const cfg_obj_t *options = cfg_tuple_get(vconfig, "options");
    152   1.7  christos 		if (options != NULL) {
    153   1.1  christos 			maps[i++] = options;
    154   1.7  christos 		}
    155   1.1  christos 	}
    156   1.1  christos 	if (config != NULL) {
    157   1.1  christos 		const cfg_obj_t *options = NULL;
    158   1.1  christos 		(void)cfg_map_get(config, "options", &options);
    159   1.7  christos 		if (options != NULL) {
    160   1.1  christos 			maps[i++] = options;
    161   1.7  christos 		}
    162   1.1  christos 	}
    163   1.1  christos 	maps[i++] = named_g_defaults;
    164   1.1  christos 	maps[i] = NULL;
    165   1.1  christos 
    166   1.1  christos 	(void)named_config_get(maps, aclname, &aclobj);
    167   1.1  christos 	if (aclobj == NULL) {
    168   1.1  christos 		(*clearzacl)(zone);
    169  1.17  christos 		return ISC_R_SUCCESS;
    170   1.1  christos 	}
    171   1.1  christos 
    172   1.1  christos parse_acl:
    173   1.1  christos 	result = cfg_acl_fromconfig(aclobj, config, named_g_lctx, actx,
    174   1.9  christos 				    named_g_mctx, 0, &acl);
    175   1.7  christos 	if (result != ISC_R_SUCCESS) {
    176  1.17  christos 		return result;
    177   1.7  christos 	}
    178   1.1  christos 	(*setzacl)(zone, acl);
    179   1.1  christos 
    180   1.1  christos 	/* Set the view default now */
    181   1.7  christos 	if (aclp != NULL) {
    182   1.1  christos 		dns_acl_attach(acl, aclp);
    183   1.7  christos 	}
    184   1.1  christos 
    185   1.1  christos 	dns_acl_detach(&acl);
    186  1.17  christos 	return ISC_R_SUCCESS;
    187   1.1  christos }
    188   1.1  christos 
    189   1.1  christos /*%
    190   1.1  christos  * Parse the zone update-policy statement.
    191   1.1  christos  */
    192   1.1  christos static isc_result_t
    193   1.1  christos configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
    194   1.7  christos 			const char *zname) {
    195   1.1  christos 	const cfg_obj_t *updatepolicy = NULL;
    196   1.1  christos 	const cfg_listelt_t *element, *element2;
    197   1.1  christos 	dns_ssutable_t *table = NULL;
    198   1.1  christos 	isc_mem_t *mctx = dns_zone_getmctx(zone);
    199   1.3  christos 	bool autoddns = false;
    200  1.15  christos 	isc_result_t result = ISC_R_SUCCESS;
    201   1.1  christos 
    202   1.1  christos 	(void)cfg_map_get(zconfig, "update-policy", &updatepolicy);
    203   1.1  christos 
    204   1.1  christos 	if (updatepolicy == NULL) {
    205   1.1  christos 		dns_zone_setssutable(zone, NULL);
    206  1.17  christos 		return ISC_R_SUCCESS;
    207   1.1  christos 	}
    208   1.1  christos 
    209   1.1  christos 	if (cfg_obj_isstring(updatepolicy) &&
    210   1.7  christos 	    strcmp("local", cfg_obj_asstring(updatepolicy)) == 0)
    211   1.7  christos 	{
    212   1.3  christos 		autoddns = true;
    213   1.1  christos 		updatepolicy = NULL;
    214   1.1  christos 	}
    215   1.1  christos 
    216  1.15  christos 	dns_ssutable_create(mctx, &table);
    217   1.1  christos 
    218   1.7  christos 	for (element = cfg_list_first(updatepolicy); element != NULL;
    219   1.1  christos 	     element = cfg_list_next(element))
    220   1.1  christos 	{
    221   1.1  christos 		const cfg_obj_t *stmt = cfg_listelt_value(element);
    222   1.1  christos 		const cfg_obj_t *mode = cfg_tuple_get(stmt, "mode");
    223   1.1  christos 		const cfg_obj_t *identity = cfg_tuple_get(stmt, "identity");
    224   1.1  christos 		const cfg_obj_t *matchtype = cfg_tuple_get(stmt, "matchtype");
    225   1.1  christos 		const cfg_obj_t *dname = cfg_tuple_get(stmt, "name");
    226   1.1  christos 		const cfg_obj_t *typelist = cfg_tuple_get(stmt, "types");
    227   1.1  christos 		const char *str;
    228   1.3  christos 		bool grant = false;
    229   1.3  christos 		bool usezone = false;
    230   1.3  christos 		dns_ssumatchtype_t mtype = dns_ssumatchtype_name;
    231   1.1  christos 		dns_fixedname_t fname, fident;
    232   1.1  christos 		isc_buffer_t b;
    233  1.15  christos 		dns_ssuruletype_t *types;
    234   1.1  christos 		unsigned int i, n;
    235   1.1  christos 
    236   1.1  christos 		str = cfg_obj_asstring(mode);
    237   1.3  christos 		if (strcasecmp(str, "grant") == 0) {
    238   1.3  christos 			grant = true;
    239   1.3  christos 		} else if (strcasecmp(str, "deny") == 0) {
    240   1.3  christos 			grant = false;
    241   1.3  christos 		} else {
    242  1.12  christos 			UNREACHABLE();
    243   1.3  christos 		}
    244   1.1  christos 
    245   1.1  christos 		str = cfg_obj_asstring(matchtype);
    246   1.1  christos 		CHECK(dns_ssu_mtypefromstring(str, &mtype));
    247   1.9  christos 		if (mtype == dns_ssumatchtype_subdomain &&
    248  1.13  christos 		    strcasecmp(str, "zonesub") == 0)
    249  1.13  christos 		{
    250   1.3  christos 			usezone = true;
    251   1.1  christos 		}
    252   1.1  christos 
    253   1.1  christos 		dns_fixedname_init(&fident);
    254   1.1  christos 		str = cfg_obj_asstring(identity);
    255   1.1  christos 		isc_buffer_constinit(&b, str, strlen(str));
    256   1.1  christos 		isc_buffer_add(&b, strlen(str));
    257   1.1  christos 		result = dns_name_fromtext(dns_fixedname_name(&fident), &b,
    258   1.1  christos 					   dns_rootname, 0, NULL);
    259   1.1  christos 		if (result != ISC_R_SUCCESS) {
    260   1.1  christos 			cfg_obj_log(identity, named_g_lctx, ISC_LOG_ERROR,
    261   1.1  christos 				    "'%s' is not a valid name", str);
    262   1.1  christos 			goto cleanup;
    263   1.1  christos 		}
    264   1.1  christos 
    265   1.1  christos 		dns_fixedname_init(&fname);
    266   1.1  christos 		if (usezone) {
    267  1.15  christos 			dns_name_copy(dns_zone_getorigin(zone),
    268  1.15  christos 				      dns_fixedname_name(&fname));
    269   1.1  christos 		} else {
    270   1.1  christos 			str = cfg_obj_asstring(dname);
    271   1.1  christos 			isc_buffer_constinit(&b, str, strlen(str));
    272   1.1  christos 			isc_buffer_add(&b, strlen(str));
    273   1.1  christos 			result = dns_name_fromtext(dns_fixedname_name(&fname),
    274   1.1  christos 						   &b, dns_rootname, 0, NULL);
    275   1.1  christos 			if (result != ISC_R_SUCCESS) {
    276   1.1  christos 				cfg_obj_log(identity, named_g_lctx,
    277   1.1  christos 					    ISC_LOG_ERROR,
    278   1.1  christos 					    "'%s' is not a valid name", str);
    279   1.1  christos 				goto cleanup;
    280   1.1  christos 			}
    281   1.1  christos 		}
    282   1.1  christos 
    283   1.1  christos 		n = named_config_listcount(typelist);
    284   1.7  christos 		if (n == 0) {
    285   1.1  christos 			types = NULL;
    286   1.7  christos 		} else {
    287  1.17  christos 			types = isc_mem_cget(mctx, n, sizeof(*types));
    288   1.1  christos 		}
    289   1.1  christos 
    290   1.1  christos 		i = 0;
    291   1.7  christos 		for (element2 = cfg_list_first(typelist); element2 != NULL;
    292   1.1  christos 		     element2 = cfg_list_next(element2))
    293   1.1  christos 		{
    294   1.1  christos 			const cfg_obj_t *typeobj;
    295  1.15  christos 			const char *bracket;
    296   1.1  christos 			isc_textregion_t r;
    297  1.15  christos 			unsigned long max = 0;
    298   1.1  christos 
    299   1.1  christos 			INSIST(i < n);
    300   1.1  christos 
    301   1.1  christos 			typeobj = cfg_listelt_value(element2);
    302   1.1  christos 			str = cfg_obj_asstring(typeobj);
    303  1.17  christos 			r.base = UNCONST(str);
    304   1.1  christos 
    305  1.15  christos 			bracket = strchr(str, '(' /*)*/);
    306  1.15  christos 			if (bracket != NULL) {
    307  1.15  christos 				char *end = NULL;
    308  1.15  christos 				r.length = bracket - str;
    309  1.15  christos 				max = strtoul(bracket + 1, &end, 10);
    310  1.15  christos 				if (max > 0xffff || end[0] != /*(*/ ')' ||
    311  1.15  christos 				    end[1] != 0)
    312  1.15  christos 				{
    313  1.15  christos 					cfg_obj_log(identity, named_g_lctx,
    314  1.15  christos 						    ISC_LOG_ERROR,
    315  1.15  christos 						    "'%s' is not a valid count",
    316  1.15  christos 						    bracket);
    317  1.17  christos 					isc_mem_cput(mctx, types, n,
    318  1.17  christos 						     sizeof(*types));
    319  1.15  christos 					goto cleanup;
    320  1.15  christos 				}
    321  1.15  christos 			} else {
    322  1.15  christos 				r.length = strlen(str);
    323  1.15  christos 			}
    324  1.15  christos 			types[i].max = max;
    325  1.15  christos 
    326  1.15  christos 			result = dns_rdatatype_fromtext(&types[i++].type, &r);
    327   1.1  christos 			if (result != ISC_R_SUCCESS) {
    328   1.1  christos 				cfg_obj_log(identity, named_g_lctx,
    329   1.1  christos 					    ISC_LOG_ERROR,
    330  1.15  christos 					    "'%.*s' is not a valid type",
    331  1.15  christos 					    (int)r.length, str);
    332  1.17  christos 				isc_mem_cput(mctx, types, n, sizeof(*types));
    333   1.1  christos 				goto cleanup;
    334   1.1  christos 			}
    335   1.1  christos 		}
    336   1.1  christos 		INSIST(i == n);
    337   1.1  christos 
    338  1.15  christos 		dns_ssutable_addrule(table, grant, dns_fixedname_name(&fident),
    339  1.15  christos 				     mtype, dns_fixedname_name(&fname), n,
    340  1.15  christos 				     types);
    341   1.7  christos 		if (types != NULL) {
    342  1.17  christos 			isc_mem_cput(mctx, types, n, sizeof(*types));
    343   1.1  christos 		}
    344   1.1  christos 	}
    345   1.1  christos 
    346   1.1  christos 	/*
    347   1.1  christos 	 * If "update-policy local;" and a session key exists,
    348   1.1  christos 	 * then use the default policy, which is equivalent to:
    349   1.1  christos 	 * update-policy { grant <session-keyname> zonesub any; };
    350   1.1  christos 	 */
    351   1.1  christos 	if (autoddns) {
    352  1.15  christos 		dns_ssuruletype_t any = { dns_rdatatype_any, 0 };
    353   1.1  christos 
    354   1.1  christos 		if (named_g_server->session_keyname == NULL) {
    355   1.1  christos 			isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
    356   1.1  christos 				      NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
    357   1.1  christos 				      "failed to enable auto DDNS policy "
    358   1.1  christos 				      "for zone %s: session key not found",
    359   1.1  christos 				      zname);
    360   1.1  christos 			result = ISC_R_NOTFOUND;
    361   1.1  christos 			goto cleanup;
    362   1.1  christos 		}
    363   1.1  christos 
    364  1.15  christos 		dns_ssutable_addrule(table, true,
    365  1.15  christos 				     named_g_server->session_keyname,
    366  1.15  christos 				     dns_ssumatchtype_local,
    367  1.15  christos 				     dns_zone_getorigin(zone), 1, &any);
    368   1.1  christos 	}
    369   1.1  christos 
    370   1.1  christos 	dns_zone_setssutable(zone, table);
    371   1.1  christos 
    372   1.7  christos cleanup:
    373   1.1  christos 	dns_ssutable_detach(&table);
    374  1.17  christos 	return result;
    375   1.1  christos }
    376   1.1  christos 
    377   1.1  christos /*
    378   1.1  christos  * This is the TTL used for internally generated RRsets for static-stub zones.
    379   1.1  christos  * The value doesn't matter because the mapping is static, but needs to be
    380   1.1  christos  * defined for the sake of implementation.
    381   1.1  christos  */
    382   1.1  christos #define STATICSTUB_SERVER_TTL 86400
    383   1.1  christos 
    384   1.1  christos /*%
    385   1.1  christos  * Configure an apex NS with glues for a static-stub zone.
    386   1.1  christos  * For example, for the zone named "example.com", the following RRs will be
    387   1.1  christos  * added to the zone DB:
    388   1.1  christos  * example.com. NS example.com.
    389   1.1  christos  * example.com. A 192.0.2.1
    390   1.1  christos  * example.com. AAAA 2001:db8::1
    391   1.1  christos  */
    392   1.1  christos static isc_result_t
    393   1.1  christos configure_staticstub_serveraddrs(const cfg_obj_t *zconfig, dns_zone_t *zone,
    394   1.1  christos 				 dns_rdatalist_t *rdatalist_ns,
    395   1.1  christos 				 dns_rdatalist_t *rdatalist_a,
    396   1.7  christos 				 dns_rdatalist_t *rdatalist_aaaa) {
    397   1.1  christos 	const cfg_listelt_t *element;
    398   1.1  christos 	isc_mem_t *mctx = dns_zone_getmctx(zone);
    399   1.1  christos 	isc_region_t region, sregion;
    400   1.1  christos 	dns_rdata_t *rdata;
    401   1.1  christos 	isc_result_t result = ISC_R_SUCCESS;
    402   1.1  christos 
    403   1.7  christos 	for (element = cfg_list_first(zconfig); element != NULL;
    404   1.1  christos 	     element = cfg_list_next(element))
    405   1.1  christos 	{
    406   1.7  christos 		const isc_sockaddr_t *sa;
    407   1.1  christos 		isc_netaddr_t na;
    408   1.1  christos 		const cfg_obj_t *address = cfg_listelt_value(element);
    409   1.1  christos 		dns_rdatalist_t *rdatalist;
    410   1.1  christos 
    411   1.1  christos 		sa = cfg_obj_assockaddr(address);
    412   1.1  christos 		if (isc_sockaddr_getport(sa) != 0) {
    413   1.1  christos 			cfg_obj_log(zconfig, named_g_lctx, ISC_LOG_ERROR,
    414   1.1  christos 				    "port is not configurable for "
    415   1.1  christos 				    "static stub server-addresses");
    416  1.17  christos 			return ISC_R_FAILURE;
    417   1.1  christos 		}
    418   1.1  christos 		isc_netaddr_fromsockaddr(&na, sa);
    419   1.1  christos 		if (isc_netaddr_getzone(&na) != 0) {
    420   1.1  christos 			cfg_obj_log(zconfig, named_g_lctx, ISC_LOG_ERROR,
    421   1.7  christos 				    "scoped address is not allowed "
    422   1.7  christos 				    "for static stub "
    423   1.7  christos 				    "server-addresses");
    424  1.17  christos 			return ISC_R_FAILURE;
    425   1.1  christos 		}
    426   1.1  christos 
    427   1.1  christos 		switch (na.family) {
    428   1.1  christos 		case AF_INET:
    429   1.1  christos 			region.length = sizeof(na.type.in);
    430   1.1  christos 			rdatalist = rdatalist_a;
    431   1.1  christos 			break;
    432   1.1  christos 		default:
    433   1.1  christos 			INSIST(na.family == AF_INET6);
    434   1.1  christos 			region.length = sizeof(na.type.in6);
    435   1.1  christos 			rdatalist = rdatalist_aaaa;
    436   1.1  christos 			break;
    437   1.1  christos 		}
    438   1.1  christos 
    439   1.1  christos 		rdata = isc_mem_get(mctx, sizeof(*rdata) + region.length);
    440   1.1  christos 		region.base = (unsigned char *)(rdata + 1);
    441   1.1  christos 		memmove(region.base, &na.type, region.length);
    442   1.1  christos 		dns_rdata_init(rdata);
    443   1.1  christos 		dns_rdata_fromregion(rdata, dns_zone_getclass(zone),
    444   1.1  christos 				     rdatalist->type, &region);
    445   1.1  christos 		ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
    446   1.1  christos 	}
    447   1.1  christos 
    448   1.1  christos 	/*
    449   1.1  christos 	 * If no address is specified (unlikely in this context, but possible),
    450   1.1  christos 	 * there's nothing to do anymore.
    451   1.1  christos 	 */
    452   1.1  christos 	if (ISC_LIST_EMPTY(rdatalist_a->rdata) &&
    453  1.13  christos 	    ISC_LIST_EMPTY(rdatalist_aaaa->rdata))
    454  1.13  christos 	{
    455  1.17  christos 		return ISC_R_SUCCESS;
    456   1.1  christos 	}
    457   1.1  christos 
    458   1.1  christos 	/* Add to the list an apex NS with the ns name being the origin name */
    459   1.1  christos 	dns_name_toregion(dns_zone_getorigin(zone), &sregion);
    460   1.1  christos 	rdata = isc_mem_get(mctx, sizeof(*rdata) + sregion.length);
    461   1.1  christos 	region.length = sregion.length;
    462   1.1  christos 	region.base = (unsigned char *)(rdata + 1);
    463   1.1  christos 	memmove(region.base, sregion.base, region.length);
    464   1.1  christos 	dns_rdata_init(rdata);
    465   1.7  christos 	dns_rdata_fromregion(rdata, dns_zone_getclass(zone), dns_rdatatype_ns,
    466   1.7  christos 			     &region);
    467   1.1  christos 	ISC_LIST_APPEND(rdatalist_ns->rdata, rdata, link);
    468   1.1  christos 
    469  1.17  christos 	return result;
    470   1.1  christos }
    471   1.1  christos 
    472   1.1  christos /*%
    473   1.1  christos  * Configure an apex NS with an out-of-zone NS names for a static-stub zone.
    474   1.1  christos  * For example, for the zone named "example.com", something like the following
    475   1.1  christos  * RRs will be added to the zone DB:
    476   1.1  christos  * example.com. NS ns.example.net.
    477   1.1  christos  */
    478   1.1  christos static isc_result_t
    479   1.1  christos configure_staticstub_servernames(const cfg_obj_t *zconfig, dns_zone_t *zone,
    480   1.7  christos 				 dns_rdatalist_t *rdatalist,
    481   1.7  christos 				 const char *zname) {
    482   1.1  christos 	const cfg_listelt_t *element;
    483   1.1  christos 	isc_mem_t *mctx = dns_zone_getmctx(zone);
    484   1.1  christos 	dns_rdata_t *rdata;
    485   1.1  christos 	isc_region_t sregion, region;
    486   1.1  christos 	isc_result_t result = ISC_R_SUCCESS;
    487   1.1  christos 
    488   1.7  christos 	for (element = cfg_list_first(zconfig); element != NULL;
    489   1.1  christos 	     element = cfg_list_next(element))
    490   1.1  christos 	{
    491   1.1  christos 		const cfg_obj_t *obj;
    492   1.1  christos 		const char *str;
    493   1.1  christos 		dns_fixedname_t fixed_name;
    494   1.1  christos 		dns_name_t *nsname;
    495   1.1  christos 		isc_buffer_t b;
    496   1.1  christos 
    497   1.1  christos 		obj = cfg_listelt_value(element);
    498   1.1  christos 		str = cfg_obj_asstring(obj);
    499   1.1  christos 
    500   1.1  christos 		nsname = dns_fixedname_initname(&fixed_name);
    501   1.1  christos 
    502   1.1  christos 		isc_buffer_constinit(&b, str, strlen(str));
    503   1.1  christos 		isc_buffer_add(&b, strlen(str));
    504   1.1  christos 		result = dns_name_fromtext(nsname, &b, dns_rootname, 0, NULL);
    505   1.1  christos 		if (result != ISC_R_SUCCESS) {
    506   1.1  christos 			cfg_obj_log(zconfig, named_g_lctx, ISC_LOG_ERROR,
    507   1.7  christos 				    "server-name '%s' is not a valid "
    508   1.7  christos 				    "name",
    509   1.7  christos 				    str);
    510  1.17  christos 			return result;
    511   1.1  christos 		}
    512   1.1  christos 		if (dns_name_issubdomain(nsname, dns_zone_getorigin(zone))) {
    513   1.1  christos 			cfg_obj_log(zconfig, named_g_lctx, ISC_LOG_ERROR,
    514   1.1  christos 				    "server-name '%s' must not be a "
    515   1.1  christos 				    "subdomain of zone name '%s'",
    516   1.1  christos 				    str, zname);
    517  1.17  christos 			return ISC_R_FAILURE;
    518   1.1  christos 		}
    519   1.1  christos 
    520   1.1  christos 		dns_name_toregion(nsname, &sregion);
    521   1.1  christos 		rdata = isc_mem_get(mctx, sizeof(*rdata) + sregion.length);
    522   1.1  christos 		region.length = sregion.length;
    523   1.1  christos 		region.base = (unsigned char *)(rdata + 1);
    524   1.1  christos 		memmove(region.base, sregion.base, region.length);
    525   1.1  christos 		dns_rdata_init(rdata);
    526   1.1  christos 		dns_rdata_fromregion(rdata, dns_zone_getclass(zone),
    527   1.1  christos 				     dns_rdatatype_ns, &region);
    528   1.1  christos 		ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
    529   1.1  christos 	}
    530   1.1  christos 
    531  1.17  christos 	return result;
    532   1.1  christos }
    533   1.1  christos 
    534   1.1  christos /*%
    535   1.1  christos  * Configure static-stub zone.
    536   1.1  christos  */
    537   1.1  christos static isc_result_t
    538   1.1  christos configure_staticstub(const cfg_obj_t *zconfig, dns_zone_t *zone,
    539   1.7  christos 		     const char *zname, const char *dbtype) {
    540   1.1  christos 	int i = 0;
    541   1.1  christos 	const cfg_obj_t *obj;
    542   1.1  christos 	isc_mem_t *mctx = dns_zone_getmctx(zone);
    543   1.1  christos 	dns_db_t *db = NULL;
    544   1.1  christos 	dns_dbversion_t *dbversion = NULL;
    545   1.1  christos 	dns_dbnode_t *apexnode = NULL;
    546   1.1  christos 	dns_name_t apexname;
    547   1.1  christos 	isc_result_t result;
    548   1.1  christos 	dns_rdataset_t rdataset;
    549   1.1  christos 	dns_rdatalist_t rdatalist_ns, rdatalist_a, rdatalist_aaaa;
    550   1.7  christos 	dns_rdatalist_t *rdatalists[] = { &rdatalist_ns, &rdatalist_a,
    551   1.7  christos 					  &rdatalist_aaaa, NULL };
    552   1.1  christos 	dns_rdata_t *rdata;
    553   1.1  christos 	isc_region_t region;
    554   1.1  christos 
    555   1.1  christos 	/* Create the DB beforehand */
    556  1.18  christos 	result = dns_db_create(mctx, dbtype, dns_zone_getorigin(zone),
    557  1.18  christos 			       dns_dbtype_stub, dns_zone_getclass(zone), 0,
    558  1.18  christos 			       NULL, &db);
    559  1.18  christos 	if (result != ISC_R_SUCCESS) {
    560  1.18  christos 		return result;
    561  1.18  christos 	}
    562   1.5  christos 
    563   1.5  christos 	dns_rdataset_init(&rdataset);
    564   1.1  christos 
    565   1.1  christos 	dns_rdatalist_init(&rdatalist_ns);
    566   1.1  christos 	rdatalist_ns.rdclass = dns_zone_getclass(zone);
    567   1.1  christos 	rdatalist_ns.type = dns_rdatatype_ns;
    568   1.1  christos 	rdatalist_ns.ttl = STATICSTUB_SERVER_TTL;
    569   1.1  christos 
    570   1.1  christos 	dns_rdatalist_init(&rdatalist_a);
    571   1.1  christos 	rdatalist_a.rdclass = dns_zone_getclass(zone);
    572   1.1  christos 	rdatalist_a.type = dns_rdatatype_a;
    573   1.1  christos 	rdatalist_a.ttl = STATICSTUB_SERVER_TTL;
    574   1.1  christos 
    575   1.1  christos 	dns_rdatalist_init(&rdatalist_aaaa);
    576   1.1  christos 	rdatalist_aaaa.rdclass = dns_zone_getclass(zone);
    577   1.1  christos 	rdatalist_aaaa.type = dns_rdatatype_aaaa;
    578   1.1  christos 	rdatalist_aaaa.ttl = STATICSTUB_SERVER_TTL;
    579   1.1  christos 
    580   1.1  christos 	/* Prepare zone RRs from the configuration */
    581   1.1  christos 	obj = NULL;
    582   1.1  christos 	result = cfg_map_get(zconfig, "server-addresses", &obj);
    583   1.1  christos 	if (result == ISC_R_SUCCESS) {
    584   1.1  christos 		INSIST(obj != NULL);
    585   1.7  christos 		CHECK(configure_staticstub_serveraddrs(obj, zone, &rdatalist_ns,
    586   1.5  christos 						       &rdatalist_a,
    587   1.5  christos 						       &rdatalist_aaaa));
    588   1.1  christos 	}
    589   1.1  christos 
    590   1.1  christos 	obj = NULL;
    591   1.1  christos 	result = cfg_map_get(zconfig, "server-names", &obj);
    592   1.1  christos 	if (result == ISC_R_SUCCESS) {
    593   1.1  christos 		INSIST(obj != NULL);
    594   1.7  christos 		CHECK(configure_staticstub_servernames(obj, zone, &rdatalist_ns,
    595   1.5  christos 						       zname));
    596   1.1  christos 	}
    597   1.1  christos 
    598   1.1  christos 	/*
    599   1.1  christos 	 * Sanity check: there should be at least one NS RR at the zone apex
    600   1.1  christos 	 * to trigger delegation.
    601   1.1  christos 	 */
    602   1.1  christos 	if (ISC_LIST_EMPTY(rdatalist_ns.rdata)) {
    603   1.1  christos 		isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
    604   1.1  christos 			      NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
    605   1.1  christos 			      "No NS record is configured for a "
    606   1.7  christos 			      "static-stub zone '%s'",
    607   1.7  christos 			      zname);
    608   1.1  christos 		result = ISC_R_FAILURE;
    609   1.1  christos 		goto cleanup;
    610   1.1  christos 	}
    611   1.1  christos 
    612   1.1  christos 	/*
    613   1.1  christos 	 * Now add NS and glue A/AAAA RRsets to the zone DB.
    614   1.1  christos 	 * First open a new version for the add operation and get a pointer
    615   1.1  christos 	 * to the apex node (all RRs are of the apex name).
    616   1.1  christos 	 */
    617   1.5  christos 	CHECK(dns_db_newversion(db, &dbversion));
    618   1.5  christos 
    619   1.1  christos 	dns_name_init(&apexname, NULL);
    620   1.1  christos 	dns_name_clone(dns_zone_getorigin(zone), &apexname);
    621   1.5  christos 	CHECK(dns_db_findnode(db, &apexname, false, &apexnode));
    622   1.1  christos 
    623   1.1  christos 	/* Add NS RRset */
    624  1.17  christos 	dns_rdatalist_tordataset(&rdatalist_ns, &rdataset);
    625   1.7  christos 	CHECK(dns_db_addrdataset(db, apexnode, dbversion, 0, &rdataset, 0,
    626   1.7  christos 				 NULL));
    627   1.1  christos 	dns_rdataset_disassociate(&rdataset);
    628   1.1  christos 
    629   1.1  christos 	/* Add glue A RRset, if any */
    630   1.1  christos 	if (!ISC_LIST_EMPTY(rdatalist_a.rdata)) {
    631  1.17  christos 		dns_rdatalist_tordataset(&rdatalist_a, &rdataset);
    632   1.7  christos 		CHECK(dns_db_addrdataset(db, apexnode, dbversion, 0, &rdataset,
    633   1.7  christos 					 0, NULL));
    634   1.1  christos 		dns_rdataset_disassociate(&rdataset);
    635   1.1  christos 	}
    636   1.1  christos 
    637   1.1  christos 	/* Add glue AAAA RRset, if any */
    638   1.1  christos 	if (!ISC_LIST_EMPTY(rdatalist_aaaa.rdata)) {
    639  1.17  christos 		dns_rdatalist_tordataset(&rdatalist_aaaa, &rdataset);
    640   1.7  christos 		CHECK(dns_db_addrdataset(db, apexnode, dbversion, 0, &rdataset,
    641   1.7  christos 					 0, NULL));
    642   1.1  christos 		dns_rdataset_disassociate(&rdataset);
    643   1.1  christos 	}
    644   1.1  christos 
    645   1.5  christos 	dns_db_closeversion(db, &dbversion, true);
    646   1.5  christos 	dns_zone_setdb(zone, db);
    647   1.5  christos 
    648   1.1  christos 	result = ISC_R_SUCCESS;
    649   1.1  christos 
    650   1.7  christos cleanup:
    651   1.5  christos 	if (dns_rdataset_isassociated(&rdataset)) {
    652   1.5  christos 		dns_rdataset_disassociate(&rdataset);
    653   1.5  christos 	}
    654   1.5  christos 	if (apexnode != NULL) {
    655   1.1  christos 		dns_db_detachnode(db, &apexnode);
    656   1.5  christos 	}
    657   1.5  christos 	if (dbversion != NULL) {
    658   1.5  christos 		dns_db_closeversion(db, &dbversion, false);
    659   1.5  christos 	}
    660   1.5  christos 	if (db != NULL) {
    661   1.1  christos 		dns_db_detach(&db);
    662   1.5  christos 	}
    663   1.1  christos 	for (i = 0; rdatalists[i] != NULL; i++) {
    664   1.1  christos 		while ((rdata = ISC_LIST_HEAD(rdatalists[i]->rdata)) != NULL) {
    665   1.1  christos 			ISC_LIST_UNLINK(rdatalists[i]->rdata, rdata, link);
    666   1.1  christos 			dns_rdata_toregion(rdata, &region);
    667   1.1  christos 			isc_mem_put(mctx, rdata,
    668   1.1  christos 				    sizeof(*rdata) + region.length);
    669   1.1  christos 		}
    670   1.1  christos 	}
    671   1.1  christos 
    672   1.1  christos 	INSIST(dbversion == NULL);
    673   1.1  christos 
    674  1.17  christos 	return result;
    675   1.1  christos }
    676   1.1  christos 
    677   1.1  christos /*%
    678   1.1  christos  * Convert a config file zone type into a server zone type.
    679   1.1  christos  */
    680  1.12  christos static dns_zonetype_t
    681   1.1  christos zonetype_fromconfig(const cfg_obj_t *map) {
    682   1.1  christos 	const cfg_obj_t *obj = NULL;
    683   1.1  christos 	isc_result_t result;
    684   1.1  christos 
    685   1.1  christos 	result = cfg_map_get(map, "type", &obj);
    686   1.1  christos 	INSIST(result == ISC_R_SUCCESS && obj != NULL);
    687  1.17  christos 	return named_config_getzonetype(obj);
    688   1.1  christos }
    689   1.1  christos 
    690   1.1  christos /*%
    691   1.1  christos  * Helper function for strtoargv().  Pardon the gratuitous recursion.
    692   1.1  christos  */
    693   1.1  christos static isc_result_t
    694   1.7  christos strtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp,
    695   1.7  christos 	     unsigned int n) {
    696   1.1  christos 	isc_result_t result;
    697   1.1  christos 
    698   1.1  christos 	/* Discard leading whitespace. */
    699   1.7  christos 	while (*s == ' ' || *s == '\t') {
    700   1.1  christos 		s++;
    701   1.7  christos 	}
    702   1.1  christos 
    703   1.1  christos 	if (*s == '\0') {
    704   1.1  christos 		/* We have reached the end of the string. */
    705   1.1  christos 		*argcp = n;
    706  1.17  christos 		*argvp = isc_mem_cget(mctx, n, sizeof(char *));
    707   1.1  christos 	} else {
    708   1.1  christos 		char *p = s;
    709   1.7  christos 		while (*p != ' ' && *p != '\t' && *p != '\0') {
    710   1.1  christos 			p++;
    711   1.7  christos 		}
    712   1.7  christos 		if (*p != '\0') {
    713   1.1  christos 			*p++ = '\0';
    714   1.7  christos 		}
    715   1.1  christos 
    716   1.1  christos 		result = strtoargvsub(mctx, p, argcp, argvp, n + 1);
    717   1.7  christos 		if (result != ISC_R_SUCCESS) {
    718  1.17  christos 			return result;
    719   1.7  christos 		}
    720   1.1  christos 		(*argvp)[n] = s;
    721   1.1  christos 	}
    722  1.17  christos 	return ISC_R_SUCCESS;
    723   1.1  christos }
    724   1.1  christos 
    725   1.1  christos /*%
    726   1.1  christos  * Tokenize the string "s" into whitespace-separated words,
    727   1.1  christos  * return the number of words in '*argcp' and an array
    728   1.1  christos  * of pointers to the words in '*argvp'.  The caller
    729   1.1  christos  * must free the array using isc_mem_put().  The string
    730   1.1  christos  * is modified in-place.
    731   1.1  christos  */
    732   1.1  christos static isc_result_t
    733   1.1  christos strtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp) {
    734  1.17  christos 	return strtoargvsub(mctx, s, argcp, argvp, 0);
    735   1.1  christos }
    736   1.1  christos 
    737  1.12  christos static const char *const primary_synonyms[] = { "primary", "master", NULL };
    738  1.12  christos 
    739  1.12  christos static const char *const secondary_synonyms[] = { "secondary", "slave", NULL };
    740  1.12  christos 
    741   1.1  christos static void
    742   1.1  christos checknames(dns_zonetype_t ztype, const cfg_obj_t **maps,
    743   1.7  christos 	   const cfg_obj_t **objp) {
    744   1.1  christos 	isc_result_t result;
    745   1.1  christos 
    746   1.1  christos 	switch (ztype) {
    747  1.12  christos 	case dns_zone_secondary:
    748   1.3  christos 	case dns_zone_mirror:
    749  1.12  christos 		result = named_checknames_get(maps, secondary_synonyms, objp);
    750   1.3  christos 		break;
    751  1.12  christos 	case dns_zone_primary:
    752  1.12  christos 		result = named_checknames_get(maps, primary_synonyms, objp);
    753   1.3  christos 		break;
    754   1.1  christos 	default:
    755  1.12  christos 		UNREACHABLE();
    756   1.1  christos 	}
    757   1.8  christos 
    758   1.1  christos 	INSIST(result == ISC_R_SUCCESS && objp != NULL && *objp != NULL);
    759   1.1  christos }
    760   1.1  christos 
    761   1.1  christos /*
    762   1.1  christos  * Callback to see if a non-recursive query coming from 'srcaddr' to
    763   1.1  christos  * 'destaddr', with optional key 'mykey' for class 'rdclass' would be
    764   1.1  christos  * delivered to 'myview'.
    765   1.1  christos  *
    766   1.1  christos  * We run this unlocked as both the view list and the interface list
    767   1.1  christos  * are updated when the appropriate task has exclusivity.
    768   1.1  christos  */
    769   1.3  christos static bool
    770   1.7  christos isself(dns_view_t *myview, dns_tsigkey_t *mykey, const isc_sockaddr_t *srcaddr,
    771  1.17  christos        const isc_sockaddr_t *dstaddr, dns_rdataclass_t rdclass,
    772  1.17  christos        void *arg ISC_ATTR_UNUSED) {
    773  1.15  christos 	dns_aclenv_t *env = NULL;
    774  1.15  christos 	dns_view_t *view = NULL;
    775   1.1  christos 	dns_tsigkey_t *key = NULL;
    776   1.1  christos 	isc_netaddr_t netsrc;
    777   1.1  christos 	isc_netaddr_t netdst;
    778   1.1  christos 
    779  1.15  christos 	/* interfacemgr can be destroyed only in exclusive mode. */
    780  1.15  christos 	if (named_g_server->interfacemgr == NULL) {
    781  1.17  christos 		return true;
    782   1.7  christos 	}
    783   1.1  christos 
    784  1.15  christos 	if (!ns_interfacemgr_listeningon(named_g_server->interfacemgr, dstaddr))
    785  1.15  christos 	{
    786  1.17  christos 		return false;
    787   1.7  christos 	}
    788   1.1  christos 
    789   1.1  christos 	isc_netaddr_fromsockaddr(&netsrc, srcaddr);
    790   1.1  christos 	isc_netaddr_fromsockaddr(&netdst, dstaddr);
    791  1.15  christos 	env = ns_interfacemgr_getaclenv(named_g_server->interfacemgr);
    792   1.1  christos 
    793   1.7  christos 	for (view = ISC_LIST_HEAD(named_g_server->viewlist); view != NULL;
    794   1.6  christos 	     view = ISC_LIST_NEXT(view, link))
    795   1.6  christos 	{
    796   1.6  christos 		const dns_name_t *tsig = NULL;
    797   1.1  christos 
    798   1.7  christos 		if (view->matchrecursiveonly) {
    799   1.1  christos 			continue;
    800   1.7  christos 		}
    801   1.1  christos 
    802   1.7  christos 		if (rdclass != view->rdclass) {
    803   1.1  christos 			continue;
    804   1.7  christos 		}
    805   1.1  christos 
    806   1.1  christos 		if (mykey != NULL) {
    807   1.3  christos 			bool match;
    808   1.1  christos 			isc_result_t result;
    809   1.1  christos 
    810  1.17  christos 			result = dns_view_gettsig(view, mykey->name, &key);
    811   1.7  christos 			if (result != ISC_R_SUCCESS) {
    812   1.1  christos 				continue;
    813   1.7  christos 			}
    814   1.1  christos 			match = dst_key_compare(mykey->key, key->key);
    815   1.1  christos 			dns_tsigkey_detach(&key);
    816   1.7  christos 			if (!match) {
    817   1.1  christos 				continue;
    818   1.7  christos 			}
    819   1.1  christos 			tsig = dns_tsigkey_identity(mykey);
    820   1.1  christos 		}
    821   1.1  christos 
    822   1.3  christos 		if (dns_acl_allowed(&netsrc, tsig, view->matchclients, env) &&
    823   1.3  christos 		    dns_acl_allowed(&netdst, tsig, view->matchdestinations,
    824   1.3  christos 				    env))
    825   1.3  christos 		{
    826   1.1  christos 			break;
    827   1.3  christos 		}
    828   1.1  christos 	}
    829  1.17  christos 	return view == myview;
    830   1.1  christos }
    831   1.1  christos 
    832   1.3  christos /*%
    833   1.3  christos  * For mirror zones, change "notify yes;" to "notify explicit;", informing the
    834   1.3  christos  * user only if "notify" was explicitly configured rather than inherited from
    835   1.3  christos  * default configuration.
    836   1.3  christos  */
    837   1.3  christos static dns_notifytype_t
    838   1.3  christos process_notifytype(dns_notifytype_t ntype, dns_zonetype_t ztype,
    839   1.7  christos 		   const char *zname, const cfg_obj_t **maps) {
    840   1.3  christos 	const cfg_obj_t *obj = NULL;
    841   1.3  christos 
    842   1.3  christos 	/*
    843   1.3  christos 	 * Return the original setting if this is not a mirror zone or if the
    844   1.3  christos 	 * zone is configured with something else than "notify yes;".
    845   1.3  christos 	 */
    846   1.3  christos 	if (ztype != dns_zone_mirror || ntype != dns_notifytype_yes) {
    847  1.17  christos 		return ntype;
    848   1.3  christos 	}
    849   1.3  christos 
    850   1.3  christos 	/*
    851   1.3  christos 	 * Only log a message if "notify" was set in the configuration
    852   1.3  christos 	 * hierarchy supplied in 'maps'.
    853   1.3  christos 	 */
    854   1.3  christos 	if (named_config_get(maps, "notify", &obj) == ISC_R_SUCCESS) {
    855   1.3  christos 		cfg_obj_log(obj, named_g_lctx, ISC_LOG_INFO,
    856   1.3  christos 			    "'notify explicit;' will be used for mirror zone "
    857   1.7  christos 			    "'%s'",
    858   1.7  christos 			    zname);
    859   1.3  christos 	}
    860   1.3  christos 
    861  1.17  christos 	return dns_notifytype_explicit;
    862   1.3  christos }
    863   1.1  christos 
    864   1.1  christos isc_result_t
    865   1.1  christos named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
    866   1.7  christos 		     const cfg_obj_t *zconfig, cfg_aclconfctx_t *ac,
    867  1.17  christos 		     dns_kasplist_t *kasplist, dns_keystorelist_t *keystorelist,
    868  1.17  christos 		     dns_zone_t *zone, dns_zone_t *raw) {
    869   1.1  christos 	isc_result_t result;
    870   1.1  christos 	const char *zname;
    871   1.1  christos 	dns_rdataclass_t zclass;
    872   1.1  christos 	dns_rdataclass_t vclass;
    873   1.1  christos 	const cfg_obj_t *maps[5];
    874   1.1  christos 	const cfg_obj_t *nodefault[4];
    875   1.1  christos 	const cfg_obj_t *zoptions = NULL;
    876   1.1  christos 	const cfg_obj_t *options = NULL;
    877   1.1  christos 	const cfg_obj_t *obj;
    878   1.1  christos 	const char *filename = NULL;
    879   1.7  christos 	const char *kaspname = NULL;
    880   1.1  christos 	const char *dupcheck;
    881  1.17  christos 	dns_checkdstype_t checkdstype = dns_checkdstype_yes;
    882   1.1  christos 	dns_notifytype_t notifytype = dns_notifytype_yes;
    883   1.3  christos 	uint32_t count;
    884   1.1  christos 	unsigned int dbargc;
    885   1.1  christos 	char **dbargv;
    886  1.17  christos 	static char default_dbtype[] = ZONEDB_DEFAULT;
    887   1.1  christos 	static char dlz_dbtype[] = "dlz";
    888   1.1  christos 	char *cpval = default_dbtype;
    889   1.1  christos 	isc_mem_t *mctx = dns_zone_getmctx(zone);
    890   1.1  christos 	dns_dialuptype_t dialup = dns_dialuptype_no;
    891   1.1  christos 	dns_zonetype_t ztype;
    892   1.1  christos 	int i;
    893   1.3  christos 	int32_t journal_size;
    894   1.3  christos 	bool multi;
    895   1.7  christos 	dns_kasp_t *kasp = NULL;
    896   1.3  christos 	bool check = false, fail = false;
    897   1.3  christos 	bool warn = false, ignore = false;
    898   1.3  christos 	bool ixfrdiff;
    899   1.9  christos 	bool use_kasp = false;
    900   1.1  christos 	dns_masterformat_t masterformat;
    901   1.1  christos 	const dns_master_style_t *masterstyle = &dns_master_style_default;
    902   1.1  christos 	isc_stats_t *zoneqrystats;
    903   1.1  christos 	dns_stats_t *rcvquerystats;
    904   1.4  christos 	dns_stats_t *dnssecsignstats;
    905   1.3  christos 	dns_zonestat_level_t statlevel = dns_zonestat_none;
    906  1.12  christos 	dns_ttl_t maxttl = 0; /* unlimited */
    907   1.1  christos 	dns_zone_t *mayberaw = (raw != NULL) ? raw : zone;
    908  1.15  christos 	bool transferinsecs = ns_server_getoption(named_g_server->sctx,
    909  1.15  christos 						  NS_SERVER_TRANSFERINSECS);
    910   1.1  christos 
    911   1.1  christos 	i = 0;
    912   1.1  christos 	if (zconfig != NULL) {
    913   1.1  christos 		zoptions = cfg_tuple_get(zconfig, "options");
    914   1.1  christos 		nodefault[i] = maps[i] = zoptions;
    915   1.1  christos 		i++;
    916   1.1  christos 	}
    917   1.1  christos 	if (vconfig != NULL) {
    918   1.1  christos 		nodefault[i] = maps[i] = cfg_tuple_get(vconfig, "options");
    919   1.1  christos 		i++;
    920   1.1  christos 	}
    921   1.1  christos 	if (config != NULL) {
    922   1.1  christos 		(void)cfg_map_get(config, "options", &options);
    923   1.1  christos 		if (options != NULL) {
    924   1.1  christos 			nodefault[i] = maps[i] = options;
    925   1.1  christos 			i++;
    926   1.1  christos 		}
    927   1.1  christos 	}
    928   1.1  christos 	nodefault[i] = NULL;
    929   1.1  christos 	maps[i++] = named_g_defaults;
    930   1.1  christos 	maps[i] = NULL;
    931   1.1  christos 
    932   1.7  christos 	if (vconfig != NULL) {
    933  1.14  christos 		CHECK(named_config_getclass(cfg_tuple_get(vconfig, "class"),
    934  1.14  christos 					    dns_rdataclass_in, &vclass));
    935   1.7  christos 	} else {
    936   1.1  christos 		vclass = dns_rdataclass_in;
    937   1.7  christos 	}
    938   1.1  christos 
    939   1.1  christos 	/*
    940   1.1  christos 	 * Configure values common to all zone types.
    941   1.1  christos 	 */
    942   1.1  christos 
    943   1.1  christos 	zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
    944   1.1  christos 
    945  1.14  christos 	CHECK(named_config_getclass(cfg_tuple_get(zconfig, "class"), vclass,
    946  1.14  christos 				    &zclass));
    947   1.1  christos 	dns_zone_setclass(zone, zclass);
    948   1.7  christos 	if (raw != NULL) {
    949   1.1  christos 		dns_zone_setclass(raw, zclass);
    950   1.7  christos 	}
    951   1.1  christos 
    952   1.1  christos 	ztype = zonetype_fromconfig(zoptions);
    953   1.1  christos 	if (raw != NULL) {
    954   1.1  christos 		dns_zone_settype(raw, ztype);
    955  1.12  christos 		dns_zone_settype(zone, dns_zone_primary);
    956   1.7  christos 	} else {
    957   1.1  christos 		dns_zone_settype(zone, ztype);
    958   1.7  christos 	}
    959   1.1  christos 
    960   1.1  christos 	obj = NULL;
    961   1.1  christos 	result = cfg_map_get(zoptions, "database", &obj);
    962   1.7  christos 	if (result == ISC_R_SUCCESS) {
    963   1.1  christos 		cpval = isc_mem_strdup(mctx, cfg_obj_asstring(obj));
    964   1.7  christos 	}
    965   1.7  christos 	if (cpval == NULL) {
    966  1.14  christos 		CHECK(ISC_R_NOMEMORY);
    967   1.7  christos 	}
    968   1.1  christos 
    969   1.1  christos 	obj = NULL;
    970   1.1  christos 	result = cfg_map_get(zoptions, "dlz", &obj);
    971   1.1  christos 	if (result == ISC_R_SUCCESS) {
    972   1.1  christos 		const char *dlzname = cfg_obj_asstring(obj);
    973   1.1  christos 		size_t len;
    974   1.1  christos 
    975   1.1  christos 		if (cpval != default_dbtype) {
    976   1.7  christos 			isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
    977   1.7  christos 				      NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
    978   1.7  christos 				      "zone '%s': both 'database' and 'dlz' "
    979   1.7  christos 				      "specified",
    980   1.7  christos 				      zname);
    981  1.14  christos 			CHECK(ISC_R_FAILURE);
    982   1.1  christos 		}
    983   1.1  christos 
    984   1.1  christos 		len = strlen(dlzname) + 5;
    985   1.1  christos 		cpval = isc_mem_allocate(mctx, len);
    986   1.1  christos 		snprintf(cpval, len, "dlz %s", dlzname);
    987   1.1  christos 	}
    988   1.1  christos 
    989   1.1  christos 	result = strtoargv(mctx, cpval, &dbargc, &dbargv);
    990   1.1  christos 	if (result != ISC_R_SUCCESS && cpval != default_dbtype) {
    991   1.1  christos 		isc_mem_free(mctx, cpval);
    992  1.14  christos 		CHECK(result);
    993   1.1  christos 	}
    994   1.1  christos 
    995   1.1  christos 	/*
    996   1.1  christos 	 * ANSI C is strange here.  There is no logical reason why (char **)
    997   1.1  christos 	 * cannot be promoted automatically to (const char * const *) by the
    998   1.1  christos 	 * compiler w/o generating a warning.
    999   1.1  christos 	 */
   1000   1.7  christos 	dns_zone_setdbtype(zone, dbargc, (const char *const *)dbargv);
   1001  1.17  christos 	isc_mem_cput(mctx, dbargv, dbargc, sizeof(*dbargv));
   1002   1.7  christos 	if (cpval != default_dbtype && cpval != dlz_dbtype) {
   1003   1.1  christos 		isc_mem_free(mctx, cpval);
   1004   1.7  christos 	}
   1005   1.1  christos 
   1006   1.1  christos 	obj = NULL;
   1007   1.1  christos 	result = cfg_map_get(zoptions, "file", &obj);
   1008   1.7  christos 	if (result == ISC_R_SUCCESS) {
   1009   1.1  christos 		filename = cfg_obj_asstring(obj);
   1010   1.7  christos 	}
   1011   1.1  christos 
   1012   1.1  christos 	/*
   1013  1.15  christos 	 * Unless we're using some alternative database, a primary zone
   1014   1.1  christos 	 * will be needing a master file.
   1015   1.1  christos 	 */
   1016  1.12  christos 	if (ztype == dns_zone_primary && cpval == default_dbtype &&
   1017  1.13  christos 	    filename == NULL)
   1018  1.13  christos 	{
   1019   1.1  christos 		isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
   1020   1.1  christos 			      NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
   1021   1.7  christos 			      "zone '%s': 'file' not specified", zname);
   1022  1.14  christos 		CHECK(ISC_R_FAILURE);
   1023   1.1  christos 	}
   1024   1.1  christos 
   1025  1.12  christos 	if (ztype == dns_zone_secondary || ztype == dns_zone_mirror) {
   1026   1.1  christos 		masterformat = dns_masterformat_raw;
   1027   1.7  christos 	} else {
   1028   1.1  christos 		masterformat = dns_masterformat_text;
   1029   1.7  christos 	}
   1030   1.1  christos 	obj = NULL;
   1031   1.1  christos 	result = named_config_get(maps, "masterfile-format", &obj);
   1032   1.1  christos 	if (result == ISC_R_SUCCESS) {
   1033   1.1  christos 		const char *masterformatstr = cfg_obj_asstring(obj);
   1034   1.1  christos 
   1035   1.3  christos 		if (strcasecmp(masterformatstr, "text") == 0) {
   1036   1.1  christos 			masterformat = dns_masterformat_text;
   1037   1.3  christos 		} else if (strcasecmp(masterformatstr, "raw") == 0) {
   1038   1.1  christos 			masterformat = dns_masterformat_raw;
   1039   1.3  christos 		} else {
   1040  1.12  christos 			UNREACHABLE();
   1041   1.3  christos 		}
   1042   1.1  christos 	}
   1043   1.1  christos 
   1044   1.1  christos 	obj = NULL;
   1045   1.1  christos 	result = named_config_get(maps, "masterfile-style", &obj);
   1046   1.1  christos 	if (result == ISC_R_SUCCESS) {
   1047   1.1  christos 		const char *masterstylestr = cfg_obj_asstring(obj);
   1048   1.1  christos 
   1049   1.1  christos 		if (masterformat != dns_masterformat_text) {
   1050   1.1  christos 			cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR,
   1051   1.1  christos 				    "zone '%s': 'masterfile-style' "
   1052   1.1  christos 				    "can only be used with "
   1053   1.7  christos 				    "'masterfile-format text'",
   1054   1.7  christos 				    zname);
   1055  1.14  christos 			CHECK(ISC_R_FAILURE);
   1056   1.1  christos 		}
   1057   1.1  christos 
   1058   1.3  christos 		if (strcasecmp(masterstylestr, "full") == 0) {
   1059   1.1  christos 			masterstyle = &dns_master_style_full;
   1060   1.3  christos 		} else if (strcasecmp(masterstylestr, "relative") == 0) {
   1061   1.1  christos 			masterstyle = &dns_master_style_default;
   1062   1.3  christos 		} else {
   1063  1.12  christos 			UNREACHABLE();
   1064   1.7  christos 		}
   1065   1.1  christos 	}
   1066   1.1  christos 
   1067   1.1  christos 	obj = NULL;
   1068   1.1  christos 	result = named_config_get(maps, "max-records", &obj);
   1069   1.1  christos 	INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1070   1.1  christos 	dns_zone_setmaxrecords(mayberaw, cfg_obj_asuint32(obj));
   1071   1.7  christos 	if (zone != mayberaw) {
   1072   1.1  christos 		dns_zone_setmaxrecords(zone, 0);
   1073   1.7  christos 	}
   1074   1.1  christos 
   1075  1.16  christos 	obj = NULL;
   1076  1.16  christos 	result = named_config_get(maps, "max-records-per-type", &obj);
   1077  1.16  christos 	INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1078  1.16  christos 	dns_zone_setmaxrrperset(mayberaw, cfg_obj_asuint32(obj));
   1079  1.16  christos 	if (zone != mayberaw) {
   1080  1.16  christos 		dns_zone_setmaxrrperset(zone, 0);
   1081  1.16  christos 	}
   1082  1.16  christos 
   1083  1.16  christos 	obj = NULL;
   1084  1.16  christos 	result = named_config_get(maps, "max-types-per-name", &obj);
   1085  1.16  christos 	INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1086  1.16  christos 	dns_zone_setmaxtypepername(mayberaw, cfg_obj_asuint32(obj));
   1087  1.16  christos 	if (zone != mayberaw) {
   1088  1.16  christos 		dns_zone_setmaxtypepername(zone, 0);
   1089  1.16  christos 	}
   1090  1.16  christos 
   1091   1.1  christos 	if (raw != NULL && filename != NULL) {
   1092   1.1  christos #define SIGNED ".signed"
   1093   1.1  christos 		size_t signedlen = strlen(filename) + sizeof(SIGNED);
   1094   1.1  christos 		char *signedname;
   1095   1.1  christos 
   1096  1.14  christos 		CHECK(dns_zone_setfile(raw, filename, masterformat,
   1097  1.14  christos 				       masterstyle));
   1098   1.1  christos 		signedname = isc_mem_get(mctx, signedlen);
   1099   1.1  christos 
   1100   1.1  christos 		(void)snprintf(signedname, signedlen, "%s" SIGNED, filename);
   1101   1.3  christos 		result = dns_zone_setfile(zone, signedname,
   1102   1.3  christos 					  dns_masterformat_raw, NULL);
   1103   1.1  christos 		isc_mem_put(mctx, signedname, signedlen);
   1104  1.14  christos 		CHECK(result);
   1105   1.7  christos 	} else {
   1106  1.14  christos 		CHECK(dns_zone_setfile(zone, filename, masterformat,
   1107  1.14  christos 				       masterstyle));
   1108   1.7  christos 	}
   1109   1.1  christos 
   1110   1.1  christos 	obj = NULL;
   1111   1.1  christos 	result = cfg_map_get(zoptions, "journal", &obj);
   1112   1.7  christos 	if (result == ISC_R_SUCCESS) {
   1113  1.14  christos 		CHECK(dns_zone_setjournal(mayberaw, cfg_obj_asstring(obj)));
   1114   1.7  christos 	}
   1115   1.1  christos 
   1116   1.1  christos 	/*
   1117   1.1  christos 	 * Notify messages are processed by the raw zone if it exists.
   1118   1.1  christos 	 */
   1119  1.12  christos 	if (ztype == dns_zone_secondary || ztype == dns_zone_mirror) {
   1120  1.14  christos 		CHECK(configure_zone_acl(zconfig, vconfig, config, allow_notify,
   1121  1.14  christos 					 ac, mayberaw, dns_zone_setnotifyacl,
   1122  1.14  christos 					 dns_zone_clearnotifyacl));
   1123   1.7  christos 	}
   1124   1.1  christos 
   1125   1.1  christos 	/*
   1126   1.1  christos 	 * XXXAG This probably does not make sense for stubs.
   1127   1.1  christos 	 */
   1128  1.14  christos 	CHECK(configure_zone_acl(zconfig, vconfig, config, allow_query, ac,
   1129  1.14  christos 				 zone, dns_zone_setqueryacl,
   1130  1.14  christos 				 dns_zone_clearqueryacl));
   1131  1.14  christos 
   1132  1.14  christos 	CHECK(configure_zone_acl(zconfig, vconfig, config, allow_query_on, ac,
   1133  1.14  christos 				 zone, dns_zone_setqueryonacl,
   1134  1.14  christos 				 dns_zone_clearqueryonacl));
   1135   1.1  christos 
   1136   1.1  christos 	obj = NULL;
   1137   1.1  christos 	result = named_config_get(maps, "dialup", &obj);
   1138   1.1  christos 	INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1139   1.1  christos 	if (cfg_obj_isboolean(obj)) {
   1140   1.7  christos 		if (cfg_obj_asboolean(obj)) {
   1141   1.1  christos 			dialup = dns_dialuptype_yes;
   1142   1.7  christos 		} else {
   1143   1.1  christos 			dialup = dns_dialuptype_no;
   1144   1.7  christos 		}
   1145   1.1  christos 	} else {
   1146   1.1  christos 		const char *dialupstr = cfg_obj_asstring(obj);
   1147   1.3  christos 		if (strcasecmp(dialupstr, "notify") == 0) {
   1148   1.1  christos 			dialup = dns_dialuptype_notify;
   1149   1.3  christos 		} else if (strcasecmp(dialupstr, "notify-passive") == 0) {
   1150   1.1  christos 			dialup = dns_dialuptype_notifypassive;
   1151   1.3  christos 		} else if (strcasecmp(dialupstr, "refresh") == 0) {
   1152   1.1  christos 			dialup = dns_dialuptype_refresh;
   1153   1.3  christos 		} else if (strcasecmp(dialupstr, "passive") == 0) {
   1154   1.1  christos 			dialup = dns_dialuptype_passive;
   1155   1.3  christos 		} else {
   1156  1.12  christos 			UNREACHABLE();
   1157   1.3  christos 		}
   1158   1.1  christos 	}
   1159   1.7  christos 	if (raw != NULL) {
   1160   1.1  christos 		dns_zone_setdialup(raw, dialup);
   1161   1.7  christos 	}
   1162   1.1  christos 	dns_zone_setdialup(zone, dialup);
   1163   1.1  christos 
   1164   1.1  christos 	obj = NULL;
   1165   1.1  christos 	result = named_config_get(maps, "zone-statistics", &obj);
   1166   1.1  christos 	INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1167   1.1  christos 	if (cfg_obj_isboolean(obj)) {
   1168   1.7  christos 		if (cfg_obj_asboolean(obj)) {
   1169   1.1  christos 			statlevel = dns_zonestat_full;
   1170   1.7  christos 		} else {
   1171   1.1  christos 			statlevel = dns_zonestat_none;
   1172   1.7  christos 		}
   1173   1.1  christos 	} else {
   1174   1.1  christos 		const char *levelstr = cfg_obj_asstring(obj);
   1175   1.3  christos 		if (strcasecmp(levelstr, "full") == 0) {
   1176   1.1  christos 			statlevel = dns_zonestat_full;
   1177   1.3  christos 		} else if (strcasecmp(levelstr, "terse") == 0) {
   1178   1.1  christos 			statlevel = dns_zonestat_terse;
   1179   1.3  christos 		} else if (strcasecmp(levelstr, "none") == 0) {
   1180   1.1  christos 			statlevel = dns_zonestat_none;
   1181   1.3  christos 		} else {
   1182  1.12  christos 			UNREACHABLE();
   1183   1.3  christos 		}
   1184   1.1  christos 	}
   1185   1.1  christos 	dns_zone_setstatlevel(zone, statlevel);
   1186   1.1  christos 
   1187   1.7  christos 	zoneqrystats = NULL;
   1188   1.1  christos 	rcvquerystats = NULL;
   1189   1.4  christos 	dnssecsignstats = NULL;
   1190   1.1  christos 	if (statlevel == dns_zonestat_full) {
   1191  1.17  christos 		isc_stats_create(mctx, &zoneqrystats, ns_statscounter_max);
   1192  1.17  christos 		dns_rdatatypestats_create(mctx, &rcvquerystats);
   1193  1.17  christos 		dns_dnssecsignstats_create(mctx, &dnssecsignstats);
   1194   1.1  christos 	}
   1195   1.7  christos 	dns_zone_setrequeststats(zone, zoneqrystats);
   1196   1.1  christos 	dns_zone_setrcvquerystats(zone, rcvquerystats);
   1197   1.4  christos 	dns_zone_setdnssecsignstats(zone, dnssecsignstats);
   1198   1.1  christos 
   1199   1.7  christos 	if (zoneqrystats != NULL) {
   1200   1.1  christos 		isc_stats_detach(&zoneqrystats);
   1201   1.7  christos 	}
   1202   1.1  christos 
   1203   1.7  christos 	if (rcvquerystats != NULL) {
   1204   1.1  christos 		dns_stats_detach(&rcvquerystats);
   1205   1.7  christos 	}
   1206   1.1  christos 
   1207   1.7  christos 	if (dnssecsignstats != NULL) {
   1208   1.4  christos 		dns_stats_detach(&dnssecsignstats);
   1209   1.4  christos 	}
   1210   1.4  christos 
   1211   1.1  christos 	/*
   1212  1.15  christos 	 * Configure authoritative zone functionality.  This applies
   1213   1.9  christos 	 * to primary servers (type "primary") and secondaries
   1214   1.9  christos 	 * acting as primaries (type "secondary"), but not to stubs.
   1215   1.1  christos 	 */
   1216   1.1  christos 	if (ztype != dns_zone_stub && ztype != dns_zone_staticstub &&
   1217   1.7  christos 	    ztype != dns_zone_redirect)
   1218   1.7  christos 	{
   1219  1.17  christos 		/* Make a reference to the default policy. */
   1220  1.17  christos 		result = dns_kasplist_find(kasplist, "default", &kasp);
   1221  1.17  christos 		INSIST(result == ISC_R_SUCCESS && kasp != NULL);
   1222  1.17  christos 		dns_zone_setdefaultkasp(zone, kasp);
   1223  1.17  christos 		dns_kasp_detach(&kasp);
   1224  1.17  christos 
   1225   1.7  christos 		obj = NULL;
   1226   1.7  christos 		result = named_config_get(maps, "dnssec-policy", &obj);
   1227   1.7  christos 		if (result == ISC_R_SUCCESS) {
   1228   1.7  christos 			kaspname = cfg_obj_asstring(obj);
   1229  1.11  christos 			if (strcmp(kaspname, "none") != 0) {
   1230  1.11  christos 				result = dns_kasplist_find(kasplist, kaspname,
   1231  1.11  christos 							   &kasp);
   1232  1.11  christos 				if (result != ISC_R_SUCCESS) {
   1233  1.11  christos 					cfg_obj_log(
   1234  1.11  christos 						obj, named_g_lctx,
   1235  1.11  christos 						ISC_LOG_ERROR,
   1236  1.11  christos 						"dnssec-policy '%s' not found ",
   1237  1.11  christos 						kaspname);
   1238  1.14  christos 					CHECK(result);
   1239  1.11  christos 				}
   1240  1.11  christos 				dns_zone_setkasp(zone, kasp);
   1241  1.11  christos 				use_kasp = true;
   1242   1.7  christos 			}
   1243  1.11  christos 		}
   1244  1.11  christos 		if (!use_kasp) {
   1245  1.11  christos 			dns_zone_setkasp(zone, NULL);
   1246   1.7  christos 		}
   1247   1.7  christos 
   1248   1.1  christos 		obj = NULL;
   1249   1.1  christos 		result = named_config_get(maps, "notify", &obj);
   1250   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1251   1.1  christos 		if (cfg_obj_isboolean(obj)) {
   1252   1.7  christos 			if (cfg_obj_asboolean(obj)) {
   1253   1.1  christos 				notifytype = dns_notifytype_yes;
   1254   1.7  christos 			} else {
   1255   1.1  christos 				notifytype = dns_notifytype_no;
   1256   1.7  christos 			}
   1257   1.1  christos 		} else {
   1258   1.9  christos 			const char *str = cfg_obj_asstring(obj);
   1259   1.9  christos 			if (strcasecmp(str, "explicit") == 0) {
   1260   1.1  christos 				notifytype = dns_notifytype_explicit;
   1261   1.9  christos 			} else if (strcasecmp(str, "master-only") == 0 ||
   1262   1.9  christos 				   strcasecmp(str, "primary-only") == 0)
   1263   1.9  christos 			{
   1264   1.1  christos 				notifytype = dns_notifytype_masteronly;
   1265   1.3  christos 			} else {
   1266  1.12  christos 				UNREACHABLE();
   1267   1.3  christos 			}
   1268   1.1  christos 		}
   1269   1.3  christos 		notifytype = process_notifytype(notifytype, ztype, zname,
   1270   1.3  christos 						nodefault);
   1271   1.7  christos 		if (raw != NULL) {
   1272   1.1  christos 			dns_zone_setnotifytype(raw, dns_notifytype_no);
   1273   1.7  christos 		}
   1274   1.1  christos 		dns_zone_setnotifytype(zone, notifytype);
   1275   1.1  christos 
   1276   1.1  christos 		obj = NULL;
   1277   1.1  christos 		result = named_config_get(maps, "also-notify", &obj);
   1278   1.1  christos 		if (result == ISC_R_SUCCESS &&
   1279   1.1  christos 		    (notifytype == dns_notifytype_yes ||
   1280   1.1  christos 		     notifytype == dns_notifytype_explicit ||
   1281   1.1  christos 		     (notifytype == dns_notifytype_masteronly &&
   1282  1.12  christos 		      ztype == dns_zone_primary)))
   1283   1.1  christos 		{
   1284   1.1  christos 			dns_ipkeylist_t ipkl;
   1285   1.1  christos 			dns_ipkeylist_init(&ipkl);
   1286   1.1  christos 
   1287  1.18  christos 			CHECK(named_config_getipandkeylist(config, obj, mctx,
   1288  1.18  christos 							   &ipkl));
   1289  1.17  christos 			dns_zone_setalsonotify(zone, ipkl.addrs, ipkl.sources,
   1290  1.17  christos 					       ipkl.keys, ipkl.tlss,
   1291  1.17  christos 					       ipkl.count);
   1292   1.1  christos 			dns_ipkeylist_clear(mctx, &ipkl);
   1293   1.7  christos 		} else {
   1294  1.17  christos 			dns_zone_setalsonotify(zone, NULL, NULL, NULL, NULL, 0);
   1295   1.7  christos 		}
   1296   1.1  christos 
   1297   1.1  christos 		obj = NULL;
   1298  1.11  christos 		result = named_config_get(maps, "parental-source", &obj);
   1299  1.11  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1300  1.18  christos 		dns_zone_setparentalsrc4(zone, cfg_obj_assockaddr(obj));
   1301  1.11  christos 
   1302  1.11  christos 		obj = NULL;
   1303  1.11  christos 		result = named_config_get(maps, "parental-source-v6", &obj);
   1304  1.11  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1305  1.18  christos 		dns_zone_setparentalsrc6(zone, cfg_obj_assockaddr(obj));
   1306  1.11  christos 
   1307  1.11  christos 		obj = NULL;
   1308   1.1  christos 		result = named_config_get(maps, "notify-source", &obj);
   1309   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1310  1.18  christos 		dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj));
   1311   1.1  christos 
   1312   1.1  christos 		obj = NULL;
   1313   1.1  christos 		result = named_config_get(maps, "notify-source-v6", &obj);
   1314   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1315  1.18  christos 		dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj));
   1316   1.1  christos 
   1317   1.1  christos 		obj = NULL;
   1318   1.1  christos 		result = named_config_get(maps, "notify-to-soa", &obj);
   1319   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1320   1.1  christos 		dns_zone_setoption(zone, DNS_ZONEOPT_NOTIFYTOSOA,
   1321   1.1  christos 				   cfg_obj_asboolean(obj));
   1322   1.1  christos 
   1323  1.15  christos 		dns_zone_setisself(zone, isself, NULL);
   1324   1.1  christos 
   1325  1.14  christos 		CHECK(configure_zone_acl(
   1326   1.7  christos 			zconfig, vconfig, config, allow_transfer, ac, zone,
   1327   1.7  christos 			dns_zone_setxfracl, dns_zone_clearxfracl));
   1328   1.1  christos 
   1329   1.1  christos 		obj = NULL;
   1330   1.1  christos 		result = named_config_get(maps, "max-transfer-time-out", &obj);
   1331   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1332  1.15  christos 		dns_zone_setmaxxfrout(
   1333  1.15  christos 			zone, transferinsecs ? cfg_obj_asuint32(obj)
   1334  1.15  christos 					     : cfg_obj_asuint32(obj) * 60);
   1335   1.1  christos 
   1336   1.1  christos 		obj = NULL;
   1337   1.1  christos 		result = named_config_get(maps, "max-transfer-idle-out", &obj);
   1338   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1339  1.15  christos 		dns_zone_setidleout(zone, transferinsecs
   1340  1.15  christos 						  ? cfg_obj_asuint32(obj)
   1341  1.15  christos 						  : cfg_obj_asuint32(obj) * 60);
   1342   1.1  christos 
   1343   1.1  christos 		obj = NULL;
   1344   1.1  christos 		result = named_config_get(maps, "max-journal-size", &obj);
   1345   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1346   1.7  christos 		if (raw != NULL) {
   1347   1.1  christos 			dns_zone_setjournalsize(raw, -1);
   1348   1.7  christos 		}
   1349   1.1  christos 		dns_zone_setjournalsize(zone, -1);
   1350   1.1  christos 		if (cfg_obj_isstring(obj)) {
   1351   1.1  christos 			const char *str = cfg_obj_asstring(obj);
   1352   1.1  christos 			if (strcasecmp(str, "unlimited") == 0) {
   1353   1.1  christos 				journal_size = DNS_JOURNAL_SIZE_MAX;
   1354   1.1  christos 			} else {
   1355   1.1  christos 				INSIST(strcasecmp(str, "default") == 0);
   1356   1.1  christos 				journal_size = -1;
   1357   1.1  christos 			}
   1358   1.1  christos 		} else {
   1359  1.17  christos 			uint64_t value = cfg_obj_asuint64(obj);
   1360   1.1  christos 			if (value > DNS_JOURNAL_SIZE_MAX) {
   1361   1.7  christos 				cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR,
   1362   1.1  christos 					    "'max-journal-size "
   1363   1.3  christos 					    "%" PRId64 "' "
   1364   1.1  christos 					    "is too large",
   1365   1.1  christos 					    value);
   1366  1.14  christos 				CHECK(ISC_R_RANGE);
   1367   1.1  christos 			}
   1368   1.3  christos 			journal_size = (uint32_t)value;
   1369   1.1  christos 		}
   1370   1.7  christos 		if (raw != NULL) {
   1371   1.1  christos 			dns_zone_setjournalsize(raw, journal_size);
   1372   1.7  christos 		}
   1373   1.1  christos 		dns_zone_setjournalsize(zone, journal_size);
   1374   1.1  christos 
   1375   1.1  christos 		obj = NULL;
   1376   1.1  christos 		result = named_config_get(maps, "ixfr-from-differences", &obj);
   1377   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1378   1.3  christos 		if (cfg_obj_isboolean(obj)) {
   1379   1.1  christos 			ixfrdiff = cfg_obj_asboolean(obj);
   1380   1.7  christos 		} else if ((strcasecmp(cfg_obj_asstring(obj), "primary") == 0 ||
   1381   1.7  christos 			    strcasecmp(cfg_obj_asstring(obj), "master") == 0) &&
   1382  1.12  christos 			   ztype == dns_zone_primary)
   1383   1.3  christos 		{
   1384   1.3  christos 			ixfrdiff = true;
   1385   1.7  christos 		} else if ((strcasecmp(cfg_obj_asstring(obj), "secondary") ==
   1386   1.7  christos 				    0 ||
   1387   1.7  christos 			    strcasecmp(cfg_obj_asstring(obj), "slave") == 0) &&
   1388  1.12  christos 			   ztype == dns_zone_secondary)
   1389   1.3  christos 		{
   1390   1.3  christos 			ixfrdiff = true;
   1391   1.3  christos 		} else {
   1392   1.3  christos 			ixfrdiff = false;
   1393   1.3  christos 		}
   1394   1.1  christos 		if (raw != NULL) {
   1395   1.1  christos 			dns_zone_setoption(raw, DNS_ZONEOPT_IXFRFROMDIFFS,
   1396   1.3  christos 					   true);
   1397   1.1  christos 			dns_zone_setoption(zone, DNS_ZONEOPT_IXFRFROMDIFFS,
   1398   1.3  christos 					   false);
   1399   1.7  christos 		} else {
   1400   1.1  christos 			dns_zone_setoption(zone, DNS_ZONEOPT_IXFRFROMDIFFS,
   1401   1.1  christos 					   ixfrdiff);
   1402   1.7  christos 		}
   1403   1.1  christos 
   1404   1.1  christos 		obj = NULL;
   1405   1.9  christos 		result = named_config_get(maps, "max-ixfr-ratio", &obj);
   1406   1.9  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1407   1.9  christos 		if (cfg_obj_isstring(obj)) {
   1408   1.9  christos 			dns_zone_setixfrratio(zone, 0);
   1409   1.9  christos 		} else {
   1410   1.9  christos 			dns_zone_setixfrratio(zone, cfg_obj_aspercentage(obj));
   1411   1.9  christos 		}
   1412   1.9  christos 
   1413   1.9  christos 		obj = NULL;
   1414   1.1  christos 		result = named_config_get(maps, "request-expire", &obj);
   1415   1.1  christos 		INSIST(result == ISC_R_SUCCESS);
   1416   1.1  christos 		dns_zone_setrequestexpire(zone, cfg_obj_asboolean(obj));
   1417   1.1  christos 
   1418   1.1  christos 		obj = NULL;
   1419   1.1  christos 		result = named_config_get(maps, "request-ixfr", &obj);
   1420   1.1  christos 		INSIST(result == ISC_R_SUCCESS);
   1421   1.1  christos 		dns_zone_setrequestixfr(zone, cfg_obj_asboolean(obj));
   1422   1.1  christos 
   1423   1.8  christos 		obj = NULL;
   1424   1.1  christos 		checknames(ztype, maps, &obj);
   1425   1.1  christos 		INSIST(obj != NULL);
   1426   1.1  christos 		if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
   1427   1.3  christos 			fail = false;
   1428   1.3  christos 			check = true;
   1429   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
   1430   1.3  christos 			fail = check = true;
   1431   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
   1432   1.3  christos 			fail = check = false;
   1433   1.3  christos 		} else {
   1434  1.12  christos 			UNREACHABLE();
   1435   1.3  christos 		}
   1436   1.1  christos 		if (raw != NULL) {
   1437   1.7  christos 			dns_zone_setoption(raw, DNS_ZONEOPT_CHECKNAMES, check);
   1438   1.1  christos 			dns_zone_setoption(raw, DNS_ZONEOPT_CHECKNAMESFAIL,
   1439   1.1  christos 					   fail);
   1440   1.7  christos 			dns_zone_setoption(zone, DNS_ZONEOPT_CHECKNAMES, false);
   1441   1.1  christos 			dns_zone_setoption(zone, DNS_ZONEOPT_CHECKNAMESFAIL,
   1442   1.3  christos 					   false);
   1443   1.1  christos 		} else {
   1444   1.7  christos 			dns_zone_setoption(zone, DNS_ZONEOPT_CHECKNAMES, check);
   1445   1.1  christos 			dns_zone_setoption(zone, DNS_ZONEOPT_CHECKNAMESFAIL,
   1446   1.1  christos 					   fail);
   1447   1.1  christos 		}
   1448   1.1  christos 
   1449   1.1  christos 		obj = NULL;
   1450   1.1  christos 		result = named_config_get(maps, "notify-delay", &obj);
   1451   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1452   1.1  christos 		dns_zone_setnotifydelay(zone, cfg_obj_asuint32(obj));
   1453   1.1  christos 
   1454   1.1  christos 		obj = NULL;
   1455   1.1  christos 		result = named_config_get(maps, "check-sibling", &obj);
   1456   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1457   1.1  christos 		dns_zone_setoption(zone, DNS_ZONEOPT_CHECKSIBLING,
   1458   1.1  christos 				   cfg_obj_asboolean(obj));
   1459   1.1  christos 
   1460   1.1  christos 		obj = NULL;
   1461   1.1  christos 		result = named_config_get(maps, "check-spf", &obj);
   1462   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1463   1.1  christos 		if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
   1464   1.3  christos 			check = true;
   1465   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
   1466   1.3  christos 			check = false;
   1467   1.3  christos 		} else {
   1468  1.12  christos 			UNREACHABLE();
   1469   1.3  christos 		}
   1470   1.1  christos 		dns_zone_setoption(zone, DNS_ZONEOPT_CHECKSPF, check);
   1471   1.1  christos 
   1472   1.1  christos 		obj = NULL;
   1473  1.17  christos 		result = named_config_get(maps, "check-svcb", &obj);
   1474  1.17  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1475  1.17  christos 		dns_zone_setoption(zone, DNS_ZONEOPT_CHECKSVCB,
   1476  1.17  christos 				   cfg_obj_asboolean(obj));
   1477  1.17  christos 
   1478  1.17  christos 		obj = NULL;
   1479   1.1  christos 		result = named_config_get(maps, "zero-no-soa-ttl", &obj);
   1480   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1481   1.1  christos 		dns_zone_setzeronosoattl(zone, cfg_obj_asboolean(obj));
   1482   1.1  christos 
   1483   1.1  christos 		obj = NULL;
   1484   1.1  christos 		result = named_config_get(maps, "nsec3-test-zone", &obj);
   1485   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1486   1.1  christos 		dns_zone_setoption(zone, DNS_ZONEOPT_NSEC3TESTZONE,
   1487   1.1  christos 				   cfg_obj_asboolean(obj));
   1488   1.1  christos 	} else if (ztype == dns_zone_redirect) {
   1489   1.1  christos 		dns_zone_setnotifytype(zone, dns_notifytype_no);
   1490   1.1  christos 
   1491   1.1  christos 		obj = NULL;
   1492   1.1  christos 		result = named_config_get(maps, "max-journal-size", &obj);
   1493   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1494   1.1  christos 		dns_zone_setjournalsize(zone, -1);
   1495   1.1  christos 		if (cfg_obj_isstring(obj)) {
   1496   1.1  christos 			const char *str = cfg_obj_asstring(obj);
   1497   1.1  christos 			if (strcasecmp(str, "unlimited") == 0) {
   1498   1.1  christos 				journal_size = DNS_JOURNAL_SIZE_MAX;
   1499   1.1  christos 			} else {
   1500   1.1  christos 				INSIST(strcasecmp(str, "default") == 0);
   1501   1.1  christos 				journal_size = -1;
   1502   1.1  christos 			}
   1503   1.1  christos 		} else {
   1504  1.17  christos 			uint64_t value = cfg_obj_asuint64(obj);
   1505   1.1  christos 			if (value > DNS_JOURNAL_SIZE_MAX) {
   1506   1.7  christos 				cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR,
   1507   1.1  christos 					    "'max-journal-size "
   1508   1.3  christos 					    "%" PRId64 "' "
   1509   1.1  christos 					    "is too large",
   1510   1.1  christos 					    value);
   1511  1.14  christos 				CHECK(ISC_R_RANGE);
   1512   1.1  christos 			}
   1513   1.3  christos 			journal_size = (uint32_t)value;
   1514   1.1  christos 		}
   1515   1.1  christos 		dns_zone_setjournalsize(zone, journal_size);
   1516   1.1  christos 	}
   1517   1.1  christos 
   1518  1.12  christos 	if (use_kasp) {
   1519  1.15  christos 		maxttl = dns_kasp_zonemaxttl(dns_zone_getkasp(zone), false);
   1520  1.12  christos 	} else {
   1521  1.12  christos 		obj = NULL;
   1522  1.12  christos 		result = named_config_get(maps, "max-zone-ttl", &obj);
   1523  1.12  christos 		if (result == ISC_R_SUCCESS) {
   1524  1.12  christos 			if (cfg_obj_isduration(obj)) {
   1525  1.12  christos 				maxttl = cfg_obj_asduration(obj);
   1526  1.12  christos 			}
   1527  1.12  christos 		}
   1528  1.12  christos 	}
   1529  1.12  christos 	dns_zone_setmaxttl(zone, maxttl);
   1530  1.12  christos 	if (raw != NULL) {
   1531  1.12  christos 		dns_zone_setmaxttl(raw, maxttl);
   1532  1.12  christos 	}
   1533  1.12  christos 
   1534   1.1  christos 	/*
   1535   1.1  christos 	 * Configure update-related options.  These apply to
   1536   1.9  christos 	 * primary servers only.
   1537   1.1  christos 	 */
   1538  1.12  christos 	if (ztype == dns_zone_primary) {
   1539   1.1  christos 		dns_acl_t *updateacl;
   1540   1.1  christos 
   1541  1.14  christos 		CHECK(configure_zone_acl(zconfig, vconfig, config, allow_update,
   1542  1.14  christos 					 ac, mayberaw, dns_zone_setupdateacl,
   1543  1.14  christos 					 dns_zone_clearupdateacl));
   1544   1.1  christos 
   1545   1.1  christos 		updateacl = dns_zone_getupdateacl(mayberaw);
   1546   1.7  christos 		if (updateacl != NULL && dns_acl_isinsecure(updateacl)) {
   1547   1.1  christos 			isc_log_write(named_g_lctx, DNS_LOGCATEGORY_SECURITY,
   1548   1.1  christos 				      NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING,
   1549   1.1  christos 				      "zone '%s' allows unsigned updates "
   1550   1.1  christos 				      "from remote hosts, which is insecure",
   1551   1.1  christos 				      zname);
   1552   1.7  christos 		}
   1553   1.1  christos 
   1554  1.14  christos 		CHECK(configure_zone_ssutable(zoptions, mayberaw, zname));
   1555   1.1  christos 	}
   1556   1.1  christos 
   1557  1.12  christos 	/*
   1558  1.12  christos 	 * Configure DNSSEC signing. These apply to primary zones or zones that
   1559  1.12  christos 	 * use inline-signing (raw != NULL).
   1560  1.12  christos 	 */
   1561  1.12  christos 	if (ztype == dns_zone_primary || raw != NULL) {
   1562  1.17  christos 		if (use_kasp) {
   1563  1.17  christos 			int seconds;
   1564   1.3  christos 
   1565   1.9  christos 			if (dns_kasp_nsec3(kasp)) {
   1566   1.9  christos 				result = dns_zone_setnsec3param(
   1567   1.9  christos 					zone, 1, dns_kasp_nsec3flags(kasp),
   1568   1.9  christos 					dns_kasp_nsec3iter(kasp),
   1569   1.9  christos 					dns_kasp_nsec3saltlen(kasp), NULL, true,
   1570   1.9  christos 					false);
   1571   1.9  christos 			} else {
   1572   1.9  christos 				result = dns_zone_setnsec3param(
   1573   1.9  christos 					zone, 0, 0, 0, 0, NULL, true, false);
   1574   1.9  christos 			}
   1575   1.9  christos 			INSIST(result == ISC_R_SUCCESS);
   1576   1.9  christos 
   1577   1.7  christos 			seconds = (uint32_t)dns_kasp_sigvalidity_dnskey(kasp);
   1578  1.17  christos 			dns_zone_setkeyvalidityinterval(zone, seconds);
   1579   1.1  christos 
   1580   1.7  christos 			seconds = (uint32_t)dns_kasp_sigvalidity(kasp);
   1581   1.7  christos 			dns_zone_setsigvalidityinterval(zone, seconds);
   1582  1.17  christos 
   1583   1.7  christos 			seconds = (uint32_t)dns_kasp_sigrefresh(kasp);
   1584   1.7  christos 			dns_zone_setsigresigninginterval(zone, seconds);
   1585   1.1  christos 		}
   1586   1.1  christos 
   1587   1.1  christos 		obj = NULL;
   1588   1.1  christos 		result = named_config_get(maps, "key-directory", &obj);
   1589   1.1  christos 		if (result == ISC_R_SUCCESS) {
   1590   1.1  christos 			filename = cfg_obj_asstring(obj);
   1591  1.14  christos 			CHECK(dns_zone_setkeydirectory(zone, filename));
   1592   1.1  christos 		}
   1593  1.17  christos 		/* Also save a reference to the keystore list. */
   1594  1.17  christos 		dns_zone_setkeystores(zone, keystorelist);
   1595   1.1  christos 
   1596   1.1  christos 		obj = NULL;
   1597   1.1  christos 		result = named_config_get(maps, "sig-signing-signatures", &obj);
   1598   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1599   1.1  christos 		dns_zone_setsignatures(zone, cfg_obj_asuint32(obj));
   1600   1.1  christos 
   1601   1.1  christos 		obj = NULL;
   1602   1.1  christos 		result = named_config_get(maps, "sig-signing-nodes", &obj);
   1603   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1604   1.1  christos 		dns_zone_setnodes(zone, cfg_obj_asuint32(obj));
   1605   1.1  christos 
   1606   1.1  christos 		obj = NULL;
   1607   1.1  christos 		result = named_config_get(maps, "sig-signing-type", &obj);
   1608   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1609   1.1  christos 		dns_zone_setprivatetype(zone, cfg_obj_asuint32(obj));
   1610   1.1  christos 
   1611   1.1  christos 		obj = NULL;
   1612   1.1  christos 		result = named_config_get(maps, "dnssec-loadkeys-interval",
   1613   1.1  christos 					  &obj);
   1614   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1615  1.14  christos 		CHECK(dns_zone_setrefreshkeyinterval(zone,
   1616  1.14  christos 						     cfg_obj_asuint32(obj)));
   1617   1.1  christos 
   1618  1.11  christos 		if (kasp != NULL) {
   1619  1.11  christos 			bool s2i = (strcmp(dns_kasp_getname(kasp),
   1620  1.11  christos 					   "insecure") != 0);
   1621   1.7  christos 			dns_zone_setkeyopt(zone, DNS_ZONEKEY_ALLOW, true);
   1622  1.11  christos 			dns_zone_setkeyopt(zone, DNS_ZONEKEY_CREATE, !s2i);
   1623   1.7  christos 			dns_zone_setkeyopt(zone, DNS_ZONEKEY_MAINTAIN, true);
   1624   1.1  christos 		}
   1625   1.1  christos 	}
   1626   1.1  christos 
   1627  1.12  christos 	if (ztype == dns_zone_secondary || ztype == dns_zone_mirror) {
   1628  1.14  christos 		CHECK(configure_zone_acl(zconfig, vconfig, config,
   1629  1.14  christos 					 allow_update_forwarding, ac, mayberaw,
   1630  1.14  christos 					 dns_zone_setforwardacl,
   1631  1.14  christos 					 dns_zone_clearforwardacl));
   1632   1.1  christos 	}
   1633   1.1  christos 
   1634   1.1  christos 	/*%
   1635  1.11  christos 	 * Configure parental agents, applies to primary and secondary zones.
   1636  1.11  christos 	 */
   1637  1.12  christos 	if (ztype == dns_zone_primary || ztype == dns_zone_secondary) {
   1638  1.17  christos 		const cfg_obj_t *parentals = NULL;
   1639  1.17  christos 		(void)cfg_map_get(zoptions, "parental-agents", &parentals);
   1640  1.17  christos 		if (parentals != NULL) {
   1641  1.11  christos 			dns_ipkeylist_t ipkl;
   1642  1.11  christos 			dns_ipkeylist_init(&ipkl);
   1643  1.18  christos 			CHECK(named_config_getipandkeylist(config, parentals,
   1644  1.18  christos 							   mctx, &ipkl));
   1645  1.17  christos 			dns_zone_setparentals(zone, ipkl.addrs, ipkl.sources,
   1646  1.17  christos 					      ipkl.keys, ipkl.tlss, ipkl.count);
   1647  1.11  christos 			dns_ipkeylist_clear(mctx, &ipkl);
   1648  1.11  christos 		} else {
   1649  1.17  christos 			dns_zone_setparentals(zone, NULL, NULL, NULL, NULL, 0);
   1650  1.11  christos 		}
   1651  1.17  christos 
   1652  1.17  christos 		obj = NULL;
   1653  1.17  christos 		result = named_config_get(maps, "checkds", &obj);
   1654  1.17  christos 		if (result == ISC_R_SUCCESS) {
   1655  1.17  christos 			if (cfg_obj_isboolean(obj)) {
   1656  1.17  christos 				if (cfg_obj_asboolean(obj)) {
   1657  1.17  christos 					checkdstype = dns_checkdstype_yes;
   1658  1.17  christos 				} else {
   1659  1.17  christos 					checkdstype = dns_checkdstype_no;
   1660  1.17  christos 				}
   1661  1.17  christos 			} else {
   1662  1.17  christos 				const char *str = cfg_obj_asstring(obj);
   1663  1.17  christos 				if (strcasecmp(str, "explicit") == 0) {
   1664  1.17  christos 					checkdstype = dns_checkdstype_explicit;
   1665  1.17  christos 				} else {
   1666  1.17  christos 					UNREACHABLE();
   1667  1.17  christos 				}
   1668  1.17  christos 			}
   1669  1.17  christos 		} else if (parentals != NULL) {
   1670  1.17  christos 			checkdstype = dns_checkdstype_explicit;
   1671  1.17  christos 		} else {
   1672  1.17  christos 			checkdstype = dns_checkdstype_yes;
   1673  1.17  christos 		}
   1674  1.17  christos 		if (raw != NULL) {
   1675  1.17  christos 			dns_zone_setcheckdstype(raw, dns_checkdstype_no);
   1676  1.17  christos 		}
   1677  1.17  christos 		dns_zone_setcheckdstype(zone, checkdstype);
   1678  1.11  christos 	}
   1679  1.11  christos 
   1680  1.11  christos 	/*%
   1681  1.15  christos 	 * Configure primary zone functionality.
   1682   1.1  christos 	 */
   1683  1.12  christos 	if (ztype == dns_zone_primary) {
   1684   1.1  christos 		obj = NULL;
   1685   1.1  christos 		result = named_config_get(maps, "check-wildcard", &obj);
   1686   1.7  christos 		if (result == ISC_R_SUCCESS) {
   1687   1.1  christos 			check = cfg_obj_asboolean(obj);
   1688   1.7  christos 		} else {
   1689   1.3  christos 			check = false;
   1690   1.7  christos 		}
   1691   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKWILDCARD, check);
   1692   1.1  christos 
   1693   1.1  christos 		obj = NULL;
   1694  1.15  christos 		result = named_config_get(maps, "check-dup-records", &obj);
   1695  1.15  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1696  1.15  christos 		dupcheck = cfg_obj_asstring(obj);
   1697   1.1  christos 		if (strcasecmp(dupcheck, "warn") == 0) {
   1698   1.3  christos 			fail = false;
   1699   1.3  christos 			check = true;
   1700   1.1  christos 		} else if (strcasecmp(dupcheck, "fail") == 0) {
   1701   1.3  christos 			fail = check = true;
   1702   1.1  christos 		} else if (strcasecmp(dupcheck, "ignore") == 0) {
   1703   1.3  christos 			fail = check = false;
   1704   1.3  christos 		} else {
   1705  1.12  christos 			UNREACHABLE();
   1706   1.3  christos 		}
   1707   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKDUPRR, check);
   1708   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKDUPRRFAIL, fail);
   1709   1.1  christos 
   1710   1.1  christos 		obj = NULL;
   1711   1.1  christos 		result = named_config_get(maps, "check-mx", &obj);
   1712   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1713   1.1  christos 		if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
   1714   1.3  christos 			fail = false;
   1715   1.3  christos 			check = true;
   1716   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
   1717   1.3  christos 			fail = check = true;
   1718   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
   1719   1.3  christos 			fail = check = false;
   1720   1.3  christos 		} else {
   1721  1.12  christos 			UNREACHABLE();
   1722   1.3  christos 		}
   1723   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKMX, check);
   1724   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKMXFAIL, fail);
   1725   1.1  christos 
   1726   1.1  christos 		obj = NULL;
   1727  1.15  christos 		result = named_config_get(maps, "check-integrity", &obj);
   1728  1.15  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1729  1.15  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKINTEGRITY,
   1730  1.15  christos 				   cfg_obj_asboolean(obj));
   1731   1.1  christos 
   1732   1.1  christos 		obj = NULL;
   1733   1.1  christos 		result = named_config_get(maps, "check-mx-cname", &obj);
   1734   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1735   1.1  christos 		if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
   1736   1.3  christos 			warn = true;
   1737   1.3  christos 			ignore = false;
   1738   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
   1739   1.3  christos 			warn = ignore = false;
   1740   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
   1741   1.3  christos 			warn = ignore = true;
   1742   1.3  christos 		} else {
   1743  1.12  christos 			UNREACHABLE();
   1744   1.3  christos 		}
   1745   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_WARNMXCNAME, warn);
   1746   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_IGNOREMXCNAME, ignore);
   1747   1.1  christos 
   1748   1.1  christos 		obj = NULL;
   1749   1.1  christos 		result = named_config_get(maps, "check-srv-cname", &obj);
   1750   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1751   1.1  christos 		if (strcasecmp(cfg_obj_asstring(obj), "warn") == 0) {
   1752   1.3  christos 			warn = true;
   1753   1.3  christos 			ignore = false;
   1754   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "fail") == 0) {
   1755   1.3  christos 			warn = ignore = false;
   1756   1.1  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "ignore") == 0) {
   1757   1.3  christos 			warn = ignore = true;
   1758   1.3  christos 		} else {
   1759  1.12  christos 			UNREACHABLE();
   1760   1.3  christos 		}
   1761   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_WARNSRVCNAME, warn);
   1762   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_IGNORESRVCNAME,
   1763   1.1  christos 				   ignore);
   1764   1.1  christos 
   1765   1.1  christos 		obj = NULL;
   1766   1.1  christos 		result = named_config_get(maps, "serial-update-method", &obj);
   1767   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1768   1.7  christos 		if (strcasecmp(cfg_obj_asstring(obj), "unixtime") == 0) {
   1769   1.7  christos 			dns_zone_setserialupdatemethod(
   1770   1.7  christos 				zone, dns_updatemethod_unixtime);
   1771   1.7  christos 		} else if (strcasecmp(cfg_obj_asstring(obj), "date") == 0) {
   1772   1.1  christos 			dns_zone_setserialupdatemethod(zone,
   1773   1.1  christos 						       dns_updatemethod_date);
   1774   1.7  christos 		} else {
   1775   1.7  christos 			dns_zone_setserialupdatemethod(
   1776   1.7  christos 				zone, dns_updatemethod_increment);
   1777   1.7  christos 		}
   1778   1.1  christos 	}
   1779   1.1  christos 
   1780   1.1  christos 	/*
   1781  1.15  christos 	 * Configure secondary zone functionality.
   1782   1.1  christos 	 */
   1783   1.1  christos 	switch (ztype) {
   1784   1.3  christos 	case dns_zone_mirror:
   1785   1.3  christos 		/*
   1786   1.3  christos 		 * Disable outgoing zone transfers for mirror zones unless they
   1787   1.3  christos 		 * are explicitly enabled by zone configuration.
   1788   1.3  christos 		 */
   1789   1.3  christos 		obj = NULL;
   1790   1.3  christos 		(void)cfg_map_get(zoptions, "allow-transfer", &obj);
   1791   1.3  christos 		if (obj == NULL) {
   1792   1.3  christos 			dns_acl_t *none;
   1793  1.14  christos 			CHECK(dns_acl_none(mctx, &none));
   1794   1.3  christos 			dns_zone_setxfracl(zone, none);
   1795   1.3  christos 			dns_acl_detach(&none);
   1796   1.3  christos 		}
   1797  1.12  christos 		FALLTHROUGH;
   1798  1.12  christos 	case dns_zone_secondary:
   1799   1.1  christos 	case dns_zone_stub:
   1800   1.1  christos 	case dns_zone_redirect:
   1801   1.1  christos 		count = 0;
   1802   1.1  christos 		obj = NULL;
   1803   1.9  christos 		(void)cfg_map_get(zoptions, "primaries", &obj);
   1804   1.9  christos 		if (obj == NULL) {
   1805   1.9  christos 			(void)cfg_map_get(zoptions, "masters", &obj);
   1806   1.9  christos 		}
   1807   1.9  christos 
   1808   1.3  christos 		/*
   1809   1.9  christos 		 * Use the built-in primary server list if one was not
   1810   1.3  christos 		 * explicitly specified and this is a root zone mirror.
   1811   1.3  christos 		 */
   1812   1.3  christos 		if (obj == NULL && ztype == dns_zone_mirror &&
   1813   1.3  christos 		    dns_name_equal(dns_zone_getorigin(zone), dns_rootname))
   1814   1.3  christos 		{
   1815  1.11  christos 			result = named_config_getremotesdef(
   1816  1.18  christos 				named_g_config, "remote-servers",
   1817   1.9  christos 				DEFAULT_IANA_ROOT_ZONE_PRIMARIES, &obj);
   1818  1.14  christos 			CHECK(result);
   1819   1.3  christos 		}
   1820   1.1  christos 		if (obj != NULL) {
   1821   1.1  christos 			dns_ipkeylist_t ipkl;
   1822   1.1  christos 			dns_ipkeylist_init(&ipkl);
   1823   1.1  christos 
   1824  1.18  christos 			CHECK(named_config_getipandkeylist(config, obj, mctx,
   1825  1.18  christos 							   &ipkl));
   1826  1.17  christos 			dns_zone_setprimaries(mayberaw, ipkl.addrs,
   1827  1.17  christos 					      ipkl.sources, ipkl.keys,
   1828  1.15  christos 					      ipkl.tlss, ipkl.count);
   1829   1.1  christos 			count = ipkl.count;
   1830   1.1  christos 			dns_ipkeylist_clear(mctx, &ipkl);
   1831   1.7  christos 		} else {
   1832  1.17  christos 			dns_zone_setprimaries(mayberaw, NULL, NULL, NULL, NULL,
   1833  1.17  christos 					      0);
   1834   1.7  christos 		}
   1835   1.1  christos 
   1836   1.3  christos 		multi = false;
   1837   1.1  christos 		if (count > 1) {
   1838   1.1  christos 			obj = NULL;
   1839   1.1  christos 			result = named_config_get(maps, "multi-master", &obj);
   1840   1.1  christos 			INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1841   1.1  christos 			multi = cfg_obj_asboolean(obj);
   1842   1.1  christos 		}
   1843   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_MULTIMASTER, multi);
   1844   1.1  christos 
   1845   1.1  christos 		obj = NULL;
   1846  1.18  christos 		result = named_config_get(maps, "min-transfer-rate-in", &obj);
   1847  1.18  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1848  1.18  christos 		uint32_t traffic_bytes =
   1849  1.18  christos 			cfg_obj_asuint32(cfg_tuple_get(obj, "traffic_bytes"));
   1850  1.18  christos 		uint32_t time_minutes =
   1851  1.18  christos 			cfg_obj_asuint32(cfg_tuple_get(obj, "time_minutes"));
   1852  1.18  christos 		if (traffic_bytes == 0) {
   1853  1.18  christos 			cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR,
   1854  1.18  christos 				    "zone '%s': 'min-transfer-rate-in' bytes"
   1855  1.18  christos 				    "value can not be '0'",
   1856  1.18  christos 				    zname);
   1857  1.18  christos 			CHECK(ISC_R_FAILURE);
   1858  1.18  christos 		}
   1859  1.18  christos 		/* Max. 28 days (in minutes). */
   1860  1.18  christos 		const unsigned int time_minutes_max = 28 * 24 * 60;
   1861  1.18  christos 		if (time_minutes < 1 || time_minutes > time_minutes_max) {
   1862  1.18  christos 			cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR,
   1863  1.18  christos 				    "zone '%s': 'min-transfer-rate-in' minutes"
   1864  1.18  christos 				    "value is out of range (1..%u)",
   1865  1.18  christos 				    zname, time_minutes_max);
   1866  1.18  christos 			CHECK(ISC_R_FAILURE);
   1867  1.18  christos 		}
   1868  1.18  christos 		dns_zone_setminxfrratein(mayberaw, traffic_bytes,
   1869  1.18  christos 					 transferinsecs ? time_minutes
   1870  1.18  christos 							: time_minutes * 60);
   1871  1.18  christos 
   1872  1.18  christos 		obj = NULL;
   1873   1.1  christos 		result = named_config_get(maps, "max-transfer-time-in", &obj);
   1874   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1875  1.15  christos 		dns_zone_setmaxxfrin(
   1876  1.15  christos 			mayberaw, transferinsecs ? cfg_obj_asuint32(obj)
   1877  1.15  christos 						 : cfg_obj_asuint32(obj) * 60);
   1878   1.1  christos 
   1879   1.1  christos 		obj = NULL;
   1880   1.1  christos 		result = named_config_get(maps, "max-transfer-idle-in", &obj);
   1881   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1882  1.15  christos 		dns_zone_setidlein(mayberaw,
   1883  1.15  christos 				   transferinsecs ? cfg_obj_asuint32(obj)
   1884  1.15  christos 						  : cfg_obj_asuint32(obj) * 60);
   1885   1.1  christos 
   1886   1.1  christos 		obj = NULL;
   1887   1.1  christos 		result = named_config_get(maps, "max-refresh-time", &obj);
   1888   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1889   1.1  christos 		dns_zone_setmaxrefreshtime(mayberaw, cfg_obj_asuint32(obj));
   1890   1.1  christos 
   1891   1.1  christos 		obj = NULL;
   1892   1.1  christos 		result = named_config_get(maps, "min-refresh-time", &obj);
   1893   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1894   1.1  christos 		dns_zone_setminrefreshtime(mayberaw, cfg_obj_asuint32(obj));
   1895   1.1  christos 
   1896   1.1  christos 		obj = NULL;
   1897   1.1  christos 		result = named_config_get(maps, "max-retry-time", &obj);
   1898   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1899   1.1  christos 		dns_zone_setmaxretrytime(mayberaw, cfg_obj_asuint32(obj));
   1900   1.1  christos 
   1901   1.1  christos 		obj = NULL;
   1902   1.1  christos 		result = named_config_get(maps, "min-retry-time", &obj);
   1903   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1904   1.1  christos 		dns_zone_setminretrytime(mayberaw, cfg_obj_asuint32(obj));
   1905   1.1  christos 
   1906   1.1  christos 		obj = NULL;
   1907   1.1  christos 		result = named_config_get(maps, "transfer-source", &obj);
   1908   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1909  1.18  christos 		dns_zone_setxfrsource4(mayberaw, cfg_obj_assockaddr(obj));
   1910   1.1  christos 
   1911   1.1  christos 		obj = NULL;
   1912   1.1  christos 		result = named_config_get(maps, "transfer-source-v6", &obj);
   1913   1.1  christos 		INSIST(result == ISC_R_SUCCESS && obj != NULL);
   1914  1.18  christos 		dns_zone_setxfrsource6(mayberaw, cfg_obj_assockaddr(obj));
   1915   1.1  christos 
   1916   1.1  christos 		obj = NULL;
   1917   1.1  christos 		(void)named_config_get(maps, "try-tcp-refresh", &obj);
   1918   1.1  christos 		dns_zone_setoption(mayberaw, DNS_ZONEOPT_TRYTCPREFRESH,
   1919   1.1  christos 				   cfg_obj_asboolean(obj));
   1920   1.1  christos 		break;
   1921   1.1  christos 
   1922   1.1  christos 	case dns_zone_staticstub:
   1923  1.14  christos 		CHECK(configure_staticstub(zoptions, zone, zname,
   1924  1.14  christos 					   default_dbtype));
   1925   1.1  christos 		break;
   1926   1.1  christos 
   1927   1.1  christos 	default:
   1928   1.1  christos 		break;
   1929   1.1  christos 	}
   1930   1.1  christos 
   1931  1.14  christos 	result = ISC_R_SUCCESS;
   1932  1.14  christos 
   1933  1.14  christos cleanup:
   1934  1.14  christos 	if (kasp != NULL) {
   1935  1.14  christos 		dns_kasp_detach(&kasp);
   1936  1.14  christos 	}
   1937  1.17  christos 	return result;
   1938   1.1  christos }
   1939   1.1  christos 
   1940   1.1  christos /*
   1941   1.1  christos  * Set up a DLZ zone as writeable
   1942   1.1  christos  */
   1943   1.1  christos isc_result_t
   1944   1.7  christos named_zone_configure_writeable_dlz(dns_dlzdb_t *dlzdatabase, dns_zone_t *zone,
   1945   1.7  christos 				   dns_rdataclass_t rdclass, dns_name_t *name) {
   1946   1.1  christos 	dns_db_t *db = NULL;
   1947   1.1  christos 	isc_result_t result;
   1948   1.1  christos 
   1949   1.1  christos 	dns_zone_settype(zone, dns_zone_dlz);
   1950   1.1  christos 	result = dns_sdlz_setdb(dlzdatabase, rdclass, name, &db);
   1951   1.7  christos 	if (result != ISC_R_SUCCESS) {
   1952  1.17  christos 		return result;
   1953   1.7  christos 	}
   1954   1.1  christos 	result = dns_zone_dlzpostload(zone, db);
   1955   1.1  christos 	dns_db_detach(&db);
   1956  1.17  christos 	return result;
   1957   1.1  christos }
   1958   1.1  christos 
   1959   1.3  christos bool
   1960  1.17  christos named_zone_reusable(dns_zone_t *zone, const cfg_obj_t *zconfig,
   1961  1.17  christos 		    const cfg_obj_t *vconfig, const cfg_obj_t *config,
   1962  1.17  christos 		    dns_kasplist_t *kasplist) {
   1963   1.1  christos 	const cfg_obj_t *zoptions = NULL;
   1964   1.1  christos 	const cfg_obj_t *obj = NULL;
   1965   1.1  christos 	const char *cfilename;
   1966   1.1  christos 	const char *zfilename;
   1967   1.1  christos 	dns_zone_t *raw = NULL;
   1968   1.9  christos 	bool has_raw, inline_signing;
   1969   1.1  christos 	dns_zonetype_t ztype;
   1970   1.1  christos 
   1971   1.1  christos 	zoptions = cfg_tuple_get(zconfig, "options");
   1972   1.1  christos 
   1973   1.1  christos 	/*
   1974   1.1  christos 	 * We always reconfigure a static-stub zone for simplicity, assuming
   1975   1.1  christos 	 * the amount of data to be loaded is small.
   1976   1.1  christos 	 */
   1977   1.1  christos 	if (zonetype_fromconfig(zoptions) == dns_zone_staticstub) {
   1978   1.1  christos 		dns_zone_log(zone, ISC_LOG_DEBUG(1),
   1979   1.1  christos 			     "not reusable: staticstub");
   1980  1.17  christos 		return false;
   1981   1.1  christos 	}
   1982   1.1  christos 
   1983   1.1  christos 	/* If there's a raw zone, use that for filename and type comparison */
   1984   1.1  christos 	dns_zone_getraw(zone, &raw);
   1985   1.1  christos 	if (raw != NULL) {
   1986   1.1  christos 		zfilename = dns_zone_getfile(raw);
   1987   1.1  christos 		ztype = dns_zone_gettype(raw);
   1988   1.1  christos 		dns_zone_detach(&raw);
   1989   1.3  christos 		has_raw = true;
   1990   1.1  christos 	} else {
   1991   1.1  christos 		zfilename = dns_zone_getfile(zone);
   1992   1.1  christos 		ztype = dns_zone_gettype(zone);
   1993   1.3  christos 		has_raw = false;
   1994   1.1  christos 	}
   1995   1.1  christos 
   1996  1.17  christos 	inline_signing = named_zone_inlinesigning(zconfig, vconfig, config,
   1997  1.17  christos 						  kasplist);
   1998   1.9  christos 	if (!inline_signing && has_raw) {
   1999   1.1  christos 		dns_zone_log(zone, ISC_LOG_DEBUG(1),
   2000   1.1  christos 			     "not reusable: old zone was inline-signing");
   2001  1.17  christos 		return false;
   2002   1.9  christos 	} else if (inline_signing && !has_raw) {
   2003   1.1  christos 		dns_zone_log(zone, ISC_LOG_DEBUG(1),
   2004   1.1  christos 			     "not reusable: old zone was not inline-signing");
   2005  1.17  christos 		return false;
   2006   1.1  christos 	}
   2007   1.1  christos 
   2008   1.1  christos 	if (zonetype_fromconfig(zoptions) != ztype) {
   2009   1.1  christos 		dns_zone_log(zone, ISC_LOG_DEBUG(1),
   2010   1.1  christos 			     "not reusable: type mismatch");
   2011  1.17  christos 		return false;
   2012   1.1  christos 	}
   2013   1.1  christos 
   2014   1.1  christos 	obj = NULL;
   2015   1.1  christos 	(void)cfg_map_get(zoptions, "file", &obj);
   2016   1.7  christos 	if (obj != NULL) {
   2017   1.1  christos 		cfilename = cfg_obj_asstring(obj);
   2018   1.7  christos 	} else {
   2019   1.1  christos 		cfilename = NULL;
   2020   1.7  christos 	}
   2021   1.1  christos 	if (!((cfilename == NULL && zfilename == NULL) ||
   2022   1.1  christos 	      (cfilename != NULL && zfilename != NULL &&
   2023   1.1  christos 	       strcmp(cfilename, zfilename) == 0)))
   2024   1.1  christos 	{
   2025   1.1  christos 		dns_zone_log(zone, ISC_LOG_DEBUG(1),
   2026   1.1  christos 			     "not reusable: filename mismatch");
   2027  1.17  christos 		return false;
   2028   1.1  christos 	}
   2029   1.1  christos 
   2030  1.17  christos 	return true;
   2031   1.1  christos }
   2032   1.9  christos 
   2033   1.9  christos bool
   2034  1.17  christos named_zone_inlinesigning(const cfg_obj_t *zconfig, const cfg_obj_t *vconfig,
   2035  1.17  christos 			 const cfg_obj_t *config, dns_kasplist_t *kasplist) {
   2036  1.17  christos 	const cfg_obj_t *maps[4];
   2037   1.9  christos 	const cfg_obj_t *signing = NULL;
   2038  1.17  christos 	const cfg_obj_t *policy = NULL;
   2039  1.17  christos 	dns_kasp_t *kasp = NULL;
   2040  1.17  christos 	isc_result_t res;
   2041   1.9  christos 	bool inline_signing = false;
   2042  1.17  christos 	int i = 0;
   2043  1.17  christos 
   2044  1.17  christos 	maps[i++] = cfg_tuple_get(zconfig, "options");
   2045  1.17  christos 	if (vconfig != NULL) {
   2046  1.17  christos 		maps[i++] = cfg_tuple_get(vconfig, "options");
   2047  1.17  christos 	}
   2048  1.17  christos 	if (config != NULL) {
   2049  1.17  christos 		const cfg_obj_t *options = NULL;
   2050  1.17  christos 		(void)cfg_map_get(config, "options", &options);
   2051  1.17  christos 		if (options != NULL) {
   2052  1.17  christos 			maps[i++] = options;
   2053  1.17  christos 		}
   2054  1.17  christos 	}
   2055  1.17  christos 	maps[i] = NULL;
   2056  1.17  christos 
   2057  1.17  christos 	/* Check the value in dnssec-policy. */
   2058  1.17  christos 	policy = NULL;
   2059  1.17  christos 	res = named_config_get(maps, "dnssec-policy", &policy);
   2060  1.17  christos 	/* If no dnssec-policy found, then zone is not using inline-signing. */
   2061  1.17  christos 	if (res != ISC_R_SUCCESS ||
   2062  1.17  christos 	    strcmp(cfg_obj_asstring(policy), "none") == 0)
   2063  1.17  christos 	{
   2064  1.17  christos 		return false;
   2065  1.17  christos 	}
   2066   1.9  christos 
   2067  1.17  christos 	/* Lookup the policy. */
   2068  1.17  christos 	res = dns_kasplist_find(kasplist, cfg_obj_asstring(policy), &kasp);
   2069  1.17  christos 	if (res != ISC_R_SUCCESS) {
   2070  1.17  christos 		return false;
   2071  1.17  christos 	}
   2072  1.17  christos 
   2073  1.17  christos 	inline_signing = dns_kasp_inlinesigning(kasp);
   2074  1.17  christos 	dns_kasp_detach(&kasp);
   2075  1.17  christos 
   2076  1.17  christos 	/*
   2077  1.17  christos 	 * The zone option 'inline-signing' may override the value in
   2078  1.17  christos 	 * dnssec-policy. This is a zone-only option, so look in maps[0]
   2079  1.17  christos 	 * only.
   2080  1.17  christos 	 */
   2081  1.17  christos 	res = cfg_map_get(maps[0], "inline-signing", &signing);
   2082  1.17  christos 	if (res == ISC_R_SUCCESS && cfg_obj_isboolean(signing)) {
   2083  1.17  christos 		return cfg_obj_asboolean(signing);
   2084  1.17  christos 	}
   2085   1.9  christos 
   2086  1.17  christos 	return inline_signing;
   2087   1.9  christos }
   2088