zoneconf.c revision ff4322d44f8404683b6fb6c86a38a2bc14f6c083
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
803d8426030e1f40c45d6861e95587189173f368Tinderbox User * Copyright (C) 1999-2001 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * copyright notice and this permission notice appear in all copies.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/* $Id: zoneconf.c,v 1.93 2001/09/25 23:01:15 gson Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley#include <config.h>
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley#include <isc/buffer.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <isc/mem.h>
96754ed7b400ce080279de2f92111ad868105290Bob Halley#include <isc/print.h>
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley#include <isc/string.h> /* Required for HP/UX (and others?) */
96754ed7b400ce080279de2f92111ad868105290Bob Halley#include <isc/util.h>
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/acl.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/fixedname.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/log.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <dns/name.h>
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews#include <dns/rdatatype.h>
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews#include <dns/ssu.h>
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews#include <dns/zone.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <named/config.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <named/globals.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <named/log.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <named/zoneconf.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * These are BIND9 server defaults, not necessarily identical to the
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * library defaults defined in zone.c.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#define RETERR(x) do { \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_result_t _r = (x); \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (_r != ISC_R_SUCCESS) \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (_r); \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein } while (0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Convenience function for configuring a single zone ACL.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic isc_result_t
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinconfigure_zone_acl(cfg_obj_t *zconfig, cfg_obj_t *vconfig, cfg_obj_t *config,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein const char *aclname, ns_aclconfctx_t *actx,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_zone_t *zone,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein void (*setzacl)(dns_zone_t *, dns_acl_t *),
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein void (*clearzacl)(dns_zone_t *))
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein{
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_result_t result;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *maps[4];
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *aclobj = NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein int i = 0;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_acl_t *dacl = NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (zconfig != NULL)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein maps[i++] = cfg_tuple_get(zconfig, "options");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (vconfig != NULL)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein maps[i++] = cfg_tuple_get(vconfig, "options");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (config != NULL) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *options = NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein (void)cfg_map_get(config, "options", &options);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (options != NULL)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein maps[i++] = options;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein maps[i] = NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein result = ns_config_get(maps, aclname, &aclobj);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (aclobj == NULL) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein (*clearzacl)(zone);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (ISC_R_SUCCESS);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein result = ns_acl_fromconfig(aclobj, config, actx,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_zone_getmctx(zone), &dacl);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (result != ISC_R_SUCCESS)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (result);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein (*setzacl)(zone, dacl);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_acl_detach(&dacl);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (ISC_R_SUCCESS);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein}
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Parse the zone update-policy statement.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic isc_result_t
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinconfigure_zone_ssutable(cfg_obj_t *zconfig, dns_zone_t *zone) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *updatepolicy = NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_listelt_t *element, *element2;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_ssutable_t *table = NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_mem_t *mctx = dns_zone_getmctx(zone);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_result_t result;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein (void)cfg_map_get(zconfig, "update-policy", &updatepolicy);
bfe0517fdcbe1dc62fee18e460ecf467dd491d9bEvan Hunt if (updatepolicy == NULL)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (ISC_R_SUCCESS);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein result = dns_ssutable_create(mctx, &table);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (result != ISC_R_SUCCESS)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (result);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein for (element = cfg_list_first(updatepolicy);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein element != NULL;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein element = cfg_list_next(element))
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *stmt = cfg_listelt_value(element);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *mode = cfg_tuple_get(stmt, "mode");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *identity = cfg_tuple_get(stmt, "identity");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *matchtype = cfg_tuple_get(stmt, "matchtype");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *dname = cfg_tuple_get(stmt, "name");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *typelist = cfg_tuple_get(stmt, "types");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein char *str;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_boolean_t grant = ISC_FALSE;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein unsigned int mtype = DNS_SSUMATCHTYPE_NAME;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_fixedname_t fname, fident;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_buffer_t b;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_rdatatype_t *types;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein unsigned int i, n;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein str = cfg_obj_asstring(mode);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (strcasecmp(str, "grant") == 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein grant = ISC_TRUE;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein else if (strcasecmp(str, "deny") == 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein grant = ISC_FALSE;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein else
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein INSIST(0);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein str = cfg_obj_asstring(matchtype);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (strcasecmp(str, "name") == 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein mtype = DNS_SSUMATCHTYPE_NAME;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein else if (strcasecmp(str, "subdomain") == 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein mtype = DNS_SSUMATCHTYPE_SUBDOMAIN;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein else if (strcasecmp(str, "wildcard") == 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein mtype = DNS_SSUMATCHTYPE_WILDCARD;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein else if (strcasecmp(str, "self") == 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein mtype = DNS_SSUMATCHTYPE_SELF;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein else
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein INSIST(0);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_fixedname_init(&fident);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein str = cfg_obj_asstring(identity);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_buffer_init(&b, str, strlen(str));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews isc_buffer_add(&b, strlen(str));
9b80f3a7c739a99b498a37a711a51b6a88df3a78Mark Andrews result = dns_name_fromtext(dns_fixedname_name(&fident), &b,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rootname, ISC_FALSE, NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != ISC_R_SUCCESS) {
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,
77b8f88f144928eddcca144c348d6ef53e7d5c43Evan Hunt "'%s' is not a valid name", str);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews goto cleanup;
3ad3e9c948fd8781d0343b19f0412f5bf3ea6415Evan Hunt }
3a6d62c59f73d024d1b2ba2ac94d7600530166ffMark Andrews
bad93fb90cc5f14e200f23ff67cce3127f45b705Mark Andrews dns_fixedname_init(&fname);
bad93fb90cc5f14e200f23ff67cce3127f45b705Mark Andrews str = cfg_obj_asstring(dname);
0cfb24736841b3e98bb25853229a0efabab88bddEvan Hunt isc_buffer_init(&b, str, strlen(str));
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley isc_buffer_add(&b, strlen(str));
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_rootname, ISC_FALSE, NULL);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (result != ISC_R_SUCCESS) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "'%s' is not a valid name", str);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt goto cleanup;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt n = ns_config_listcount(typelist);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (n == 0)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt types = NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt else {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt types = isc_mem_get(mctx, n * sizeof(dns_rdatatype_t));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (types == NULL) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = ISC_R_NOMEMORY;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt goto cleanup;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt i = 0;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt for (element2 = cfg_list_first(typelist);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt element2 != NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt element2 = cfg_list_next(element2))
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_t *typeobj;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_textregion_t r;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt INSIST(i < n);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt typeobj = cfg_listelt_value(element2);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt str = cfg_obj_asstring(typeobj);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt r.base = str;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt r.length = strlen(str);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = dns_rdatatype_fromtext(&types[i++], &r);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (result != ISC_R_SUCCESS) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt "'%s' is not a valid type", str);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_mem_put(mctx, types,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt n * sizeof(dns_rdatatype_t));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt goto cleanup;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt INSIST(i == n);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = dns_ssutable_addrule(table, grant,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_fixedname_name(&fident),
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt mtype,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_fixedname_name(&fname),
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt n, types);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (types != NULL)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_mem_put(mctx, types, n * sizeof(dns_rdatatype_t));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (result != ISC_R_SUCCESS) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt goto cleanup;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = ISC_R_SUCCESS;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_zone_setssutable(zone, table);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cleanup:
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_ssutable_detach(&table);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (result);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt}
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt/*
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt * Convert a config file zone type into a server zone type.
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt */
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic inline dns_zonetype_t
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntzonetype_fromconfig(cfg_obj_t *map) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_t *obj = NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_result_t result;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = cfg_map_get(map, "type", &obj);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt INSIST(result == ISC_R_SUCCESS);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (ns_config_getzonetype(obj));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt}
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt/*
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt * Helper function for strtoargv(). Pardon the gratuitous recursion.
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt */
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic isc_result_t
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstrtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt char ***argvp, unsigned int n)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt{
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_result_t result;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt /* Discard leading whitespace. */
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt while (*s == ' ' || *s == '\t')
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt s++;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (*s == '\0') {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt /* We have reached the end of the string. */
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt *argcp = n;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt *argvp = isc_mem_get(mctx, n * sizeof(char *));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (*argvp == NULL)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (ISC_R_NOMEMORY);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt } else {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt char *p = s;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt while (*p != ' ' && *p != '\t' && *p != '\0')
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt p++;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (*p != '\0')
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt *p++ = '\0';
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = strtoargvsub(mctx, p, argcp, argvp, n + 1);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (result != ISC_R_SUCCESS)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (result);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt (*argvp)[n] = s;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt return (ISC_R_SUCCESS);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt}
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt/*
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt * Tokenize the string "s" into whitespace-separated words,
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt * return the number of words in '*argcp' and an array
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt * of pointers to the words in '*argvp'. The caller
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt * must free the array using isc_mem_put(). The string
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt * is modified in-place.
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence */
9e804040a29b9c3066c8471b43835f30707039b7Evan Huntstatic isc_result_t
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstrtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (strtoargvsub(mctx, s, argcp, argvp, 0));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein}
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinisc_result_t
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinns_zone_configure(cfg_obj_t *config, cfg_obj_t *vconfig, cfg_obj_t *zconfig,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ns_aclconfctx_t *ac, dns_zone_t *zone)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein{
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_result_t result;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein char *zname;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_rdataclass_t zclass;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_rdataclass_t vclass;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_t *maps[5];
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_t *zoptions = NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_t *options = NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cfg_obj_t *obj;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein const char *filename = NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_notifytype_t notifytype = dns_notifytype_yes;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_sockaddr_t *addrs;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_name_t **keynames;
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley isc_uint32_t count;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt char *cpval;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt unsigned int dbargc;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt char **dbargv;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt static char default_dbtype[] = "rbt";
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_mem_t *mctx = dns_zone_getmctx(zone);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_dialuptype_t dialup = dns_dialuptype_no;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_zonetype_t ztype;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt int i;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt isc_int32_t journal_size;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt i = 0;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (zconfig != NULL) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt zoptions = cfg_tuple_get(zconfig, "options");
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt maps[i++] = zoptions;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt }
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (vconfig != NULL)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt maps[i++] = cfg_tuple_get(vconfig, "options");
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (config != NULL) {
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt (void)cfg_map_get(config, "options", &options);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (options != NULL)
138a6660fb74d458270511ca0ba24aa19bf375d5Bob Halley maps[i++] = options;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley }
138a6660fb74d458270511ca0ba24aa19bf375d5Bob Halley maps[i++] = ns_g_defaults;
d8dcd6ad4617cc8d7df979bd62101fa9c4bac1bcBob Halley maps[i++] = NULL;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley if (vconfig != NULL)
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RETERR(ns_config_getclass(cfg_tuple_get(vconfig, "class"),
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley dns_rdataclass_in, &vclass));
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley else
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley vclass = dns_rdataclass_in;
138a6660fb74d458270511ca0ba24aa19bf375d5Bob Halley
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley /*
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley * Configure values common to all zone types.
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley */
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RETERR(ns_config_getclass(cfg_tuple_get(zconfig, "class"),
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley vclass, &zclass));
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_zone_setclass(zone, zclass);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt ztype = zonetype_fromconfig(zoptions);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt dns_zone_settype(zone, ztype);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt obj = NULL;
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt result = cfg_map_get(zoptions, "database", &obj);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt if (result == ISC_R_SUCCESS)
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cpval = cfg_obj_asstring(obj);
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt else
9e804040a29b9c3066c8471b43835f30707039b7Evan Hunt cpval = default_dbtype;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RETERR(strtoargv(mctx, cpval, &dbargc, &dbargv));
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley /*
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley * ANSI C is strange here. There is no logical reason why (char **)
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley * cannot be promoted automatically to (const char * const *) by the
96754ed7b400ce080279de2f92111ad868105290Bob Halley * compiler w/o generating a warning.
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley */
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RETERR(dns_zone_setdbtype(zone, dbargc, (const char * const *)dbargv));
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley isc_mem_put(mctx, dbargv, dbargc * sizeof(*dbargv));
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley obj = NULL;
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley result = cfg_map_get(zoptions, "file", &obj);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley if (result == ISC_R_SUCCESS)
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley filename = cfg_obj_asstring(obj);
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RETERR(dns_zone_setfile(zone, filename));
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley if (ztype == dns_zone_slave)
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley RETERR(configure_zone_acl(zconfig, vconfig, config,
e4e071ae12aee942fefc2c0a3280e402938669deBob Halley "allow-notify", ac, zone,
c50fd34a4e0e6978f8ca5f6f3ad8545549c3cfeeBob Halley dns_zone_setnotifyacl,
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dns_zone_clearnotifyacl));
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley /*
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley * XXXAG This probably does not make sense for stubs.
711b0bed7b7f9e505c81e5810224f01df80a2ee4Bob Halley */
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley RETERR(configure_zone_acl(zconfig, vconfig, config,
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley "allow-query", ac, zone,
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dns_zone_setqueryacl,
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dns_zone_clearqueryacl));
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley obj = NULL;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley result = ns_config_get(maps, "dialup", &obj);
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley INSIST(result == ISC_R_SUCCESS);
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley if (cfg_obj_isboolean(obj)) {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley if (cfg_obj_asboolean(obj))
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dialup = dns_dialuptype_yes;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley else
542189f21b3ea9b27b0fbc047d832a34dcaf75bcAndreas Gustafsson dialup = dns_dialuptype_no;
fa756a197b059b28c44f24e332bd072178861dc6Mark Andrews } else {
542189f21b3ea9b27b0fbc047d832a34dcaf75bcAndreas Gustafsson char *dialupstr = cfg_obj_asstring(obj);
34b394b43e2207e8f8f3703f0402422121455638David Lawrence if (strcasecmp(dialupstr, "notify") == 0)
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dialup = dns_dialuptype_notify;
34b394b43e2207e8f8f3703f0402422121455638David Lawrence else if (strcasecmp(dialupstr, "notify-passive") == 0)
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dialup = dns_dialuptype_notifypassive;
34b394b43e2207e8f8f3703f0402422121455638David Lawrence else if (strcasecmp(dialupstr, "refresh") == 0)
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews dialup = dns_dialuptype_refresh;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley else if (strcasecmp(dialupstr, "passive") == 0)
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dialup = dns_dialuptype_passive;
34b394b43e2207e8f8f3703f0402422121455638David Lawrence else
34b394b43e2207e8f8f3703f0402422121455638David Lawrence INSIST(0);
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley }
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley dns_zone_setdialup(zone, dialup);
b6309ed962c4988a314d61742c4fbc4935467d68Mark Andrews
34b394b43e2207e8f8f3703f0402422121455638David Lawrence obj = NULL;
34b394b43e2207e8f8f3703f0402422121455638David Lawrence result = ns_config_get(maps, "zone-statistics", &obj);
34b394b43e2207e8f8f3703f0402422121455638David Lawrence INSIST(result == ISC_R_SUCCESS);
34b394b43e2207e8f8f3703f0402422121455638David Lawrence dns_zone_setstatistics(zone, cfg_obj_asboolean(obj));
34b394b43e2207e8f8f3703f0402422121455638David Lawrence
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
04b8111f2137a9cf9b0b71228f76b3e40ffa1173Brian Wellington * Configure master functionality. This applies
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * to primary masters (type "master") and slaves
c07c2a862e0f9d671e2961cd179c7b28d7b04f10Mark Andrews * acting as masters (type "slave"), but not to stubs.
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley */
147fd0bdf83272952521a7f343d88a421e2ff997Brian Wellington if (ztype != dns_zone_stub) {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley obj = NULL;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley result = ns_config_get(maps, "notify", &obj);
147fd0bdf83272952521a7f343d88a421e2ff997Brian Wellington INSIST(result == ISC_R_SUCCESS);
04b8111f2137a9cf9b0b71228f76b3e40ffa1173Brian Wellington if (cfg_obj_isboolean(obj)) {
95b604c5e972a5e9eb713bf45cf0b2d9b98da27eMark Andrews if (cfg_obj_asboolean(obj))
04b8111f2137a9cf9b0b71228f76b3e40ffa1173Brian Wellington notifytype = dns_notifytype_yes;
04b8111f2137a9cf9b0b71228f76b3e40ffa1173Brian Wellington else
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley notifytype = dns_notifytype_no;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley } else {
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley char *notifystr = cfg_obj_asstring(obj);
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley if (strcasecmp(notifystr, "explicit") == 0)
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley notifytype = dns_notifytype_explicit;
25e43e68b7431d5e4ff8b5427108cd7f5f9bcf3eBob Halley else
INSIST(0);
}
dns_zone_setnotifytype(zone, notifytype);
obj = NULL;
result = ns_config_get(maps, "also-notify", &obj);
if (result == ISC_R_SUCCESS) {
isc_sockaddr_t *addrs = NULL;
isc_uint32_t addrcount;
result = ns_config_getiplist(config, obj, 0, mctx,
&addrs, &addrcount);
if (result != ISC_R_SUCCESS)
return (result);
result = dns_zone_setalsonotify(zone, addrs,
addrcount);
ns_config_putiplist(mctx, &addrs, addrcount);
if (result != ISC_R_SUCCESS)
return (result);
} else
RETERR(dns_zone_setalsonotify(zone, NULL, 0));
obj = NULL;
result = ns_config_get(maps, "notify-source", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj));
obj = NULL;
result = ns_config_get(maps, "notify-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj));
RETERR(configure_zone_acl(zconfig, vconfig, config,
"allow-transfer", ac, zone,
dns_zone_setxfracl,
dns_zone_clearxfracl));
obj = NULL;
result = ns_config_get(maps, "max-transfer-time-out", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setmaxxfrout(zone, cfg_obj_asuint32(obj) * 60);
obj = NULL;
result = ns_config_get(maps, "max-transfer-idle-out", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setidleout(zone, cfg_obj_asuint32(obj) * 60);
obj = NULL;
result = ns_config_get(maps, "max-journal-size", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setjournalsize(zone, -1);
if (cfg_obj_isstring(obj)) {
const char *str = cfg_obj_asstring(obj);
INSIST(strcasecmp(str, "unlimited") == 0);
journal_size = ISC_UINT32_MAX / 2;
} else {
isc_resourcevalue_t value;
value = cfg_obj_asuint64(obj);
if (value > ISC_UINT32_MAX / 2) {
cfg_obj_log(obj, ns_g_lctx,
ISC_LOG_ERROR,
"'max-journal-size "
"%" ISC_PRINT_QUADFORMAT "d' "
"is too large",
value);
RETERR(ISC_R_RANGE);
}
journal_size = (isc_uint32_t)value;
}
dns_zone_setjournalsize(zone, journal_size);
obj = NULL;
result = ns_config_get(maps, "ixfr-from-differences", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setoption(zone, DNS_ZONEOPT_IXFRFROMDIFFS,
cfg_obj_asboolean(obj));
}
/*
* Configure update-related options. These apply to
* primary masters only.
*/
if (ztype == dns_zone_master) {
dns_acl_t *updateacl;
RETERR(configure_zone_acl(zconfig, NULL, config,
"allow-update", ac, zone,
dns_zone_setupdateacl,
dns_zone_clearupdateacl));
updateacl = dns_zone_getupdateacl(zone);
if (updateacl != NULL && dns_acl_isinsecure(updateacl))
isc_log_write(ns_g_lctx, DNS_LOGCATEGORY_SECURITY,
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
"zone '%s' allows updates by IP "
"address, which is insecure",
zname);
RETERR(configure_zone_ssutable(zoptions, zone));
obj = NULL;
result = ns_config_get(maps, "sig-validity-interval", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setsigvalidityinterval(zone,
cfg_obj_asuint32(obj) * 86400);
} else if (ztype == dns_zone_slave) {
RETERR(configure_zone_acl(zconfig, NULL, config,
"allow-update-forwarding", ac, zone,
dns_zone_setforwardacl,
dns_zone_clearforwardacl));
}
obj = NULL;
result = ns_config_get(maps, "transfer-source", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setxfrsource4(zone, cfg_obj_assockaddr(obj));
obj = NULL;
result = ns_config_get(maps, "transfer-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setxfrsource6(zone, cfg_obj_assockaddr(obj));
/*
* Configure slave functionality.
*/
switch (ztype) {
case dns_zone_slave:
case dns_zone_stub:
obj = NULL;
result = cfg_map_get(zoptions, "masters", &obj);
if (obj != NULL) {
addrs = NULL;
keynames = NULL;
RETERR(ns_config_getipandkeylist(config, obj, mctx,
&addrs, &keynames,
&count));
result = dns_zone_setmasterswithkeys(zone, addrs,
keynames, count);
ns_config_putipandkeylist(mctx, &addrs, &keynames,
count);
} else
result = dns_zone_setmasters(zone, NULL, 0);
RETERR(result);
obj = NULL;
result = ns_config_get(maps, "max-transfer-time-in", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setmaxxfrin(zone, cfg_obj_asuint32(obj) * 60);
obj = NULL;
result = ns_config_get(maps, "max-transfer-idle-in", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setidlein(zone, cfg_obj_asuint32(obj) * 60);
obj = NULL;
result = ns_config_get(maps, "max-refresh-time", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setmaxrefreshtime(zone, cfg_obj_asuint32(obj));
obj = NULL;
result = ns_config_get(maps, "min-refresh-time", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setminrefreshtime(zone, cfg_obj_asuint32(obj));
obj = NULL;
result = ns_config_get(maps, "max-retry-time", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setmaxretrytime(zone, cfg_obj_asuint32(obj));
obj = NULL;
result = ns_config_get(maps, "min-retry-time", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zone_setminretrytime(zone, cfg_obj_asuint32(obj));
break;
default:
break;
}
return (ISC_R_SUCCESS);
}
isc_boolean_t
ns_zone_reusable(dns_zone_t *zone, cfg_obj_t *zconfig) {
cfg_obj_t *zoptions = NULL;
cfg_obj_t *obj = NULL;
const char *cfilename;
const char *zfilename;
zoptions = cfg_tuple_get(zconfig, "options");
if (zonetype_fromconfig(zoptions) != dns_zone_gettype(zone))
return (ISC_FALSE);
obj = NULL;
(void)cfg_map_get(zoptions, "file", &obj);
if (obj != NULL)
cfilename = cfg_obj_asstring(obj);
else
cfilename = NULL;
zfilename = dns_zone_getfile(zone);
if (!((cfilename == NULL && zfilename == NULL) ||
(cfilename != NULL && cfilename != NULL &&
strcmp(cfilename, zfilename) == 0)))
return (ISC_FALSE);
return (ISC_TRUE);
}