zoneconf.c revision 0015ab097438e041197b19b9de2ba48f6bfd1c6c
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater * Copyright (C) 1999-2001 Internet Software Consortium.
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
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence * copyright notice and this permission notice appear in all copies.
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.
5497de6931b5ac26f65c2343b0318614f73933baMark Andrews/* $Id: zoneconf.c,v 1.84 2001/03/05 12:04:46 tale Exp $ */
64ba6e4cc3a0ccf8c8c6349fa75b937ca9bad9a6Michael Graff#include <isc/string.h> /* Required for HP/UX (and others?) */
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence * These are BIND9 server defaults, not necessarily identical to the
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence * library defaults defined in zone.c.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff#define RETERR(x) do { \
c80dde0676a7f36f65e0ad8d646bf505705fe64bDavid Lawrence * Convenience function for configuring a single zone ACL.
33950f0a0262f4d49528c4adcf8be42807fa2576David Lawrenceconfigure_zone_acl(cfg_obj_t *zconfig, cfg_obj_t *vconfig, cfg_obj_t *config,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff maps[i++] = cfg_tuple_get(zconfig, "options");
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff maps[i++] = cfg_tuple_get(vconfig, "options");
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence (void)cfg_map_get(config, "options", &options);
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence result = ns_config_get(maps, aclname, &aclobj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_acl_fromconfig(aclobj, config, actx,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Parse the zone update-policy statement.
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrenceconfigure_zone_ssutable(cfg_obj_t *zconfig, dns_zone_t *zone) {
f036af2c718147408d738081cdb0a564b981b4cdDavid Lawrence (void)cfg_map_get(zconfig, "update-policy", &updatepolicy);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff cfg_obj_t *mode = cfg_tuple_get(stmt, "mode");
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence cfg_obj_t *identity = cfg_tuple_get(stmt, "identity");
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cfg_obj_t *matchtype = cfg_tuple_get(stmt, "matchtype");
33950f0a0262f4d49528c4adcf8be42807fa2576David Lawrence cfg_obj_t *dname = cfg_tuple_get(stmt, "name");
b65f2ab14abb4b6ef906d7d02064fba158f07b1eDavid Lawrence cfg_obj_t *typelist = cfg_tuple_get(stmt, "types");
1630fce031f7a3e33f0579e477a3e17d1993e1f9Bob Halley unsigned int i, n;
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence result = dns_name_fromtext(dns_fixedname_name(&fident), &b,
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,
401fc772b1bf058a981e3c474fa6502f6ee0e2bfDavid Lawrence result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff types = isc_mem_get(mctx, n * sizeof(dns_rdatatype_t));
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence result = dns_rdatatype_fromtext(&types[i++], &r);
092b4e5359c5982a438e36ced3dbefc313f7fbfcDavid Lawrence cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,
40e7c805a8f38ad9b20dd6c688496fc09fc971c2Mark Andrews isc_mem_put(mctx, types, n * sizeof(dns_rdatatype_t));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Convert a config file zone type into a server zone type.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Helper function for strtoargv(). Pardon the gratuitous recursion.
7554feaef6057f5ea2926076900ac7634b911456Mark Andrewsstrtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff char ***argvp, unsigned int n)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff /* Discard leading whitespace. */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff if (*s == '\0') {
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff /* We have reached the end of the string. */
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff *argvp = isc_mem_get(mctx, n * sizeof(char *));
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence while (*p != ' ' && *p != '\t' && *p != '\0')
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence if (*p != '\0')
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews result = strtoargvsub(mctx, p, argcp, argvp, n + 1);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Tokenize the string "s" into whitespace-separated words,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * return the number of words in '*argcp' and an array
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * of pointers to the words in '*argvp'. The caller
73d62a89f1493865c33c689b3ee3de91c74ad58eDavid Lawrence * must free the array using isc_mem_put(). The string
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * is modified in-place.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffstrtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp) {
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff return (strtoargvsub(mctx, s, argcp, argvp, 0));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffns_zone_configure(cfg_obj_t *config, cfg_obj_t *vconfig, cfg_obj_t *zconfig,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff dns_notifytype_t notifytype = dns_notifytype_yes;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff unsigned int dbargc;
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff maps[i++] = cfg_tuple_get(vconfig, "options");
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff (void)cfg_map_get(config, "options", &options);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * Configure values common to all zone types.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(ns_config_getclass(cfg_tuple_get(zconfig, "class"), &zclass));
ec80744ad68b97f15657b1fdf5591c30b559b57dDavid Lawrence result = cfg_map_get(zoptions, "database", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(strtoargv(mctx, cpval, &dbargc, &dbargv));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * ANSI C is strange here. There is no logical reason why (char **)
ec80744ad68b97f15657b1fdf5591c30b559b57dDavid Lawrence * cannot be promoted automatically to (const char * const *) by the
ec80744ad68b97f15657b1fdf5591c30b559b57dDavid Lawrence * compiler w/o generating a warning.
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence RETERR(dns_zone_setdbtype(zone, dbargc, (const char * const *)dbargv));
f389bc2c9e9e434380e10221778b7b548612a67fDavid Lawrence isc_mem_put(mctx, dbargv, dbargc * sizeof(*dbargv));
0f5962ac3e4ef336faff68f1cb838505e64665e5David Lawrence result = cfg_map_get(zoptions, "file", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(configure_zone_acl(zconfig, vconfig, config,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * XXXAG This probably does not make sense for stubs.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(configure_zone_acl(zconfig, vconfig, config,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff else if (strcasecmp(dialupstr, "notify-passive") == 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff else if (strcasecmp(dialupstr, "refresh") == 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff else if (strcasecmp(dialupstr, "passive") == 0)
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "zone-statistics", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setstatistics(zone, cfg_obj_asboolean(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Configure master functionality. This applies
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * to primary masters (type "master") and slaves
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * acting as masters (type "slave"), but not to stubs.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "also-notify", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_getiplist(config, obj, 0, mctx,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(dns_zone_setalsonotify(zone, NULL, 0));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "notify-source", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "notify-source-v6", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(configure_zone_acl(zconfig, vconfig, config,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "max-transfer-time-out", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setmaxxfrout(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "max-transfer-idle-out", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setidleout(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Configure update-related options. These apply to
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * primary masters only.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(configure_zone_acl(zconfig, NULL, config,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff if (updateacl != NULL && dns_acl_isinsecure(updateacl))
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff isc_log_write(ns_g_lctx, DNS_LOGCATEGORY_SECURITY,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff "zone '%s' allows updates by IP "
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff "address, which is insecure",
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(configure_zone_ssutable(zoptions, zone));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "sig-validity-interval", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setsigvalidityinterval(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(configure_zone_acl(zconfig, NULL, config,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "transfer-source", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setxfrsource4(zone, cfg_obj_assockaddr(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "transfer-source-v6", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setxfrsource6(zone, cfg_obj_assockaddr(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * Configure slave functionality.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = cfg_map_get(zoptions, "masters", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff RETERR(ns_config_getipandkeylist(config, obj, mctx,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = dns_zone_setmasterswithkeys(zone, addrs,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff ns_config_putipandkeylist(mctx, &addrs, &keynames,
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "max-transfer-time-in", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setmaxxfrin(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "max-transfer-idle-in", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setidlein(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "max-refresh-time", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setmaxrefreshtime(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "min-refresh-time", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setminrefreshtime(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "max-retry-time", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setmaxretrytime(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff result = ns_config_get(maps, "min-retry-time", &obj);
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff dns_zone_setminretrytime(zone, cfg_obj_asuint32(obj));
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graffns_zone_reusable(dns_zone_t *zone, cfg_obj_t *zconfig) {