config.c revision b4914b3d69de3eb57bcf1d6cb3bb8e0b645c1081
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
4a979d35776321abc952346ba128d1a3cef730ceAutomatic Updater * Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2001-2003 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and/or distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley
ece6c39dd823d92cf89e7e37614bd458d5d42658Mark Andrews/* $Id: config.c,v 1.123 2012/01/06 23:46:41 tbox Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley/*! \file */
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#include <config.h>
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <stdlib.h>
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <isc/buffer.h>
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <isc/log.h>
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley#include <isc/mem.h>
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley#include <isc/parseint.h>
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <isc/region.h>
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <isc/result.h>
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <isc/sockaddr.h>
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer#include <isc/string.h>
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley#include <isc/util.h>
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#include <isccfg/namedconf.h>
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence#include <dns/fixedname.h>
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence#include <dns/name.h>
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence#include <dns/rdataclass.h>
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence#include <dns/rdatatype.h>
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence#include <dns/tsig.h>
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence#include <dns/zone.h>
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer#include <dst/dst.h>
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer#include <named/config.h>
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer#include <named/globals.h>
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews#include "bind.keys.h"
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer/*% default configuration */
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halleystatic char defaultconf[] = "\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halleyoptions {\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley# blackhole {none;};\n"
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley#ifndef WIN32
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews" coresize default;\n\
27809a2ee5db141b684e53bf1d94da26e9f92d3aMark Andrews datasize default;\n\
ea872078bfa9473cfe9c89b474dae2496377797bDavid Lawrence files unlimited;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley stacksize default;\n"
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson#endif
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson"# session-keyfile \"" NS_LOCALSTATEDIR "/run/named/session.key\";\n\
e76d4c91bfadf823f04dcca1c1c5bcc14c67671dAndreas Gustafsson session-keyname local-ddns;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley session-keyalg hmac-sha256;\n\
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer deallocate-on-exit true;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley# directory <none>\n\
e72c1e7e465822fc9b5067b2dd3cf047f6132214Mark Andrews dump-file \"named_dump.db\";\n\
e72c1e7e465822fc9b5067b2dd3cf047f6132214Mark Andrews fake-iquery no;\n\
e72c1e7e465822fc9b5067b2dd3cf047f6132214Mark Andrews has-old-clients false;\n\
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence heartbeat-interval 60;\n\
e72c1e7e465822fc9b5067b2dd3cf047f6132214Mark Andrews host-statistics no;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley interface-interval 60;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley listen-on {any;};\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley listen-on-v6 {any;};\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson match-mapped-addresses no;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley max-rsa-exponent-size 0; /* no limit */\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley memstatistics-file \"named.memstats\";\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley multiple-cnames no;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley# named-xfer <obsolete>;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley# pid-file \"" NS_LOCALSTATEDIR "/run/named/named.pid\"; /* or /lwresd.pid */\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley bindkeys-file \"" NS_SYSCONFDIR "/bind.keys\";\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley port 53;\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews recursing-file \"named.recursing\";\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews secroots-file \"named.secroots\";\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews"
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews#ifdef PATH_RANDOMDEV
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews"\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews random-device \"" PATH_RANDOMDEV "\";\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews"
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews#endif
e2c97aef510f4cdced2894ab2a5daf2b1d316e2aAutomatic Updater"\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews recursive-clients 1000;\n\
e2c97aef510f4cdced2894ab2a5daf2b1d316e2aAutomatic Updater resolver-query-timeout 10;\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews rrset-order { order random; };\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews serial-queries 20;\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews serial-query-rate 20;\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews server-id none;\n\
ed9ca2306508e3106e3d111d7cf39bf82f8689d0Mark Andrews statistics-file \"named.stats\";\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews statistics-interval 60;\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews tcp-clients 100;\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews tcp-listen-queue 3;\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews# tkey-dhkey <none>\n\
8343d55b3d97923fa444ea9b92aae2ec60ffd40fMark Andrews# tkey-gssapi-credential <none>\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley# tkey-domain <none>\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence transfers-per-ns 2;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley transfers-in 10;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley transfers-out 10;\n\
355cc22e32085faeb553fe6c37de69e83b9d5191Andreas Gustafsson treat-cr-as-space true;\n\
355cc22e32085faeb553fe6c37de69e83b9d5191Andreas Gustafsson use-id-pool true;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley use-ixfr true;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley edns-udp-size 4096;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley max-udp-size 4096;\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson request-nsid false;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley reserved-sockets 512;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley\n\
355cc22e32085faeb553fe6c37de69e83b9d5191Andreas Gustafsson /* DLV */\n\
355cc22e32085faeb553fe6c37de69e83b9d5191Andreas Gustafsson dnssec-lookaside . trust-anchor dlv.isc.org;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley /* view */\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley allow-notify {none;};\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley allow-update-forwarding {none;};\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley allow-query-cache { localnets; localhost; };\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence allow-query-cache-on { any; };\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence allow-recursion { localnets; localhost; };\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley allow-recursion-on { any; };\n\
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley# allow-v6-synthesis <obsolete>;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley# sortlist <none>\n\
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley# topology <none>\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley auth-nxdomain false;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley minimal-responses false;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley recursion true;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence provide-ixfr true;\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson request-ixfr true;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence fetch-glue no;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley rfc2308-type1 no;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence additional-from-auth true;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence additional-from-cache true;\n\
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence query-source address *;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence query-source-v6 address *;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence notify-source *;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence notify-source-v6 *;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence cleaning-interval 0; /* now meaningless */\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence min-roots 2;\n\
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer lame-ttl 600;\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence max-ncache-ttl 10800; /* 3 hours */\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence max-cache-ttl 604800; /* 1 week */\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence transfer-format many-answers;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence max-cache-size 0;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-names master fail;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-names slave warn;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-names response ignore;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-dup-records warn;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-mx warn;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence acache-enable no;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence acache-cleaning-interval 60;\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson max-acache-size 16M;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley dnssec-enable yes;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley dnssec-validation yes; \n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley dnssec-accept-expired no;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley clients-per-query 10;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley max-clients-per-query 100;\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence zero-no-soa-ttl-cache no;\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson nsec3-test-zone no;\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson allow-new-zones no;\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence"
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley#ifdef ALLOW_FILTER_AAAA
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley" filter-aaaa-on-v4 no;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley filter-aaaa-on-v6 no;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley filter-aaaa { any; };\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley"
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley#endif
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence" /* zone */\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence allow-query {any;};\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence allow-query-on {any;};\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence allow-transfer {any;};\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence notify yes;\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence# also-notify <none>\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence notify-delay 5;\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence notify-to-soa no;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley dialup no;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley# forward <none>\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence# forwarders <none>\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson maintain-ixfr-base no;\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson# max-ixfr-log-size <obsolete>\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence transfer-source *;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley transfer-source-v6 *;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley alt-transfer-source *;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley alt-transfer-source-v6 *;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley max-transfer-time-in 120;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley max-transfer-time-out 120;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley max-transfer-idle-in 60;\n\
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer max-transfer-idle-out 60;\n\
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence max-retry-time 1209600; /* 2 weeks */\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence min-retry-time 500;\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence max-refresh-time 2419200; /* 4 weeks */\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence min-refresh-time 300;\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence multi-master no;\n\
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence dnssec-secure-to-insecure no;\n\
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer sig-validity-interval 30; /* days */\n\
e35c1bb3ecd9a6597360b9160b397c8053af69bfDanny Mayer sig-signing-nodes 100;\n\
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley sig-signing-signatures 10;\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley sig-signing-type 65534;\n\
d3e7d196cd14fc3095ce97846a66cd49fc6fee6dDavid Lawrence inline-signing no;\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson zone-statistics terse;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence max-journal-size unlimited;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley ixfr-from-differences false;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley check-wildcard yes;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-sibling yes;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-integrity yes;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence check-mx-cname warn;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley check-srv-cname warn;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence zero-no-soa-ttl yes;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley update-check-ksk yes;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley serial-update-method increment;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley dnssec-update-mode maintain;\n\
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley dnssec-dnskey-kskonly no;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence dnssec-loadkeys-interval 60;\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence try-tcp-refresh yes; /* BIND 8 compat */\n\
d3e7d196cd14fc3095ce97846a66cd49fc6fee6dDavid Lawrence};\n\
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence"
d3e7d196cd14fc3095ce97846a66cd49fc6fee6dDavid Lawrence
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence"#\n\
d3e7d196cd14fc3095ce97846a66cd49fc6fee6dDavid Lawrence# Zones in the \"_bind\" view are NOT counted in the count of zones.\n\
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley#\n\
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrenceview \"_bind\" chaos {\n\
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews recursion no;\n\
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews notify no;\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews allow-new-zones no;\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews # Prevent use of this zone in DNS amplified reflection DoS attacks\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews rate-limit {\n\
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews responses-per-second 3;\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews slip 0;\n\
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews min-table-size 10;\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews };\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews zone \"version.bind\" chaos {\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews type master;\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews database \"_builtin version\";\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews };\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews\n\
ece6c39dd823d92cf89e7e37614bd458d5d42658Mark Andrews zone \"hostname.bind\" chaos {\n\
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews type master;\n\
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews database \"_builtin hostname\";\n\
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence };\n\
6c6ceac1bc66812f6e0097dcf5fd8b901c3fecd1Andreas Gustafsson\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews zone \"authors.bind\" chaos {\n\
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence type master;\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews database \"_builtin authors\";\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews };\n\
1d9958c6cc291916010779792f0fbdf6cd5ba368Mark Andrews\n\
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence zone \"id.server\" chaos {\n\
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson type master;\n\
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson database \"_builtin id\";\n\
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson };\n\
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson};\n\
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson"
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafsson"#\n\
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafsson# Default trusted key(s) for builtin DLV support\n\
6ebd91a0c7f4c62a501b67adce4a6800d8b7dfacAutomatic Updater# (used if \"dnssec-lookaside auto;\" is set and\n\
13f20ab1fad3f7620a1eb31937ff0d1021e5590bDanny Mayer# sysconfdir/bind.keys doesn't exist).\n\
6ebd91a0c7f4c62a501b67adce4a6800d8b7dfacAutomatic Updater#\n\
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson# BEGIN MANAGED KEYS\n"
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafsson/* Imported from bind.keys.h: */
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark AndrewsMANAGED_KEYS
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafsson"# END MANAGED KEYS\n\
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafsson";
6ebd91a0c7f4c62a501b67adce4a6800d8b7dfacAutomatic Updater
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafssonisc_result_t
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafssonns_config_parsedefaults(cfg_parser_t *parser, cfg_obj_t **conf) {
6ebd91a0c7f4c62a501b67adce4a6800d8b7dfacAutomatic Updater isc_buffer_t b;
b38ab99bdc833da490c0ca0cbd05fb9d54dff997Andreas Gustafsson
f3fcde886c32bf92c464ed13b94b4c267bab5de4Danny Mayer isc_buffer_init(&b, defaultconf, sizeof(defaultconf) - 1);
ff8cd3afa7f900d7986ccbc3638235cb8ad6f1ecAndreas Gustafsson isc_buffer_add(&b, sizeof(defaultconf) - 1);
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews return (cfg_parse_buffer(parser, &b, &cfg_type_namedconf, conf));
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews}
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrewsisc_result_t
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrewsns_config_get(cfg_obj_t const * const *maps, const char *name,
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews const cfg_obj_t **obj)
6ebd91a0c7f4c62a501b67adce4a6800d8b7dfacAutomatic Updater{
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt int i;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews for (i = 0;; i++) {
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews if (maps[i] == NULL)
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt return (ISC_R_NOTFOUND);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS)
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews return (ISC_R_SUCCESS);
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews }
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews}
6ebd91a0c7f4c62a501b67adce4a6800d8b7dfacAutomatic Updater
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrewsisc_result_t
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrewsns_checknames_get(const cfg_obj_t **maps, const char *which,
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews const cfg_obj_t **obj)
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews{
186e7f37c9fc985a7a7264cc8170e48a25bed434Mark Andrews const cfg_listelt_t *element;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt const cfg_obj_t *checknames;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt const cfg_obj_t *type;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt const cfg_obj_t *value;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt int i;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt for (i = 0;; i++) {
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt if (maps[i] == NULL)
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt return (ISC_R_NOTFOUND);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt checknames = NULL;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt if (cfg_map_get(maps[i], "check-names",
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt &checknames) == ISC_R_SUCCESS) {
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt /*
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt * Zone map entry is not a list.
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt */
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt if (checknames != NULL && !cfg_obj_islist(checknames)) {
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt *obj = checknames;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt return (ISC_R_SUCCESS);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt }
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt for (element = cfg_list_first(checknames);
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt element != NULL;
aeff7de836558fa8002ab5db35292d2bb6450da8Evan Hunt element = cfg_list_next(element)) {
value = cfg_listelt_value(element);
type = cfg_tuple_get(value, "type");
if (strcasecmp(cfg_obj_asstring(type),
which) == 0) {
*obj = cfg_tuple_get(value, "mode");
return (ISC_R_SUCCESS);
}
}
}
}
}
int
ns_config_listcount(const cfg_obj_t *list) {
const cfg_listelt_t *e;
int i = 0;
for (e = cfg_list_first(list); e != NULL; e = cfg_list_next(e))
i++;
return (i);
}
isc_result_t
ns_config_getclass(const cfg_obj_t *classobj, dns_rdataclass_t defclass,
dns_rdataclass_t *classp) {
isc_textregion_t r;
isc_result_t result;
if (!cfg_obj_isstring(classobj)) {
*classp = defclass;
return (ISC_R_SUCCESS);
}
DE_CONST(cfg_obj_asstring(classobj), r.base);
r.length = strlen(r.base);
result = dns_rdataclass_fromtext(classp, &r);
if (result != ISC_R_SUCCESS)
cfg_obj_log(classobj, ns_g_lctx, ISC_LOG_ERROR,
"unknown class '%s'", r.base);
return (result);
}
isc_result_t
ns_config_gettype(const cfg_obj_t *typeobj, dns_rdatatype_t deftype,
dns_rdatatype_t *typep) {
isc_textregion_t r;
isc_result_t result;
if (!cfg_obj_isstring(typeobj)) {
*typep = deftype;
return (ISC_R_SUCCESS);
}
DE_CONST(cfg_obj_asstring(typeobj), r.base);
r.length = strlen(r.base);
result = dns_rdatatype_fromtext(typep, &r);
if (result != ISC_R_SUCCESS)
cfg_obj_log(typeobj, ns_g_lctx, ISC_LOG_ERROR,
"unknown type '%s'", r.base);
return (result);
}
dns_zonetype_t
ns_config_getzonetype(const cfg_obj_t *zonetypeobj) {
dns_zonetype_t ztype = dns_zone_none;
const char *str;
str = cfg_obj_asstring(zonetypeobj);
if (strcasecmp(str, "master") == 0)
ztype = dns_zone_master;
else if (strcasecmp(str, "slave") == 0)
ztype = dns_zone_slave;
else if (strcasecmp(str, "stub") == 0)
ztype = dns_zone_stub;
else if (strcasecmp(str, "static-stub") == 0)
ztype = dns_zone_staticstub;
else if (strcasecmp(str, "redirect") == 0)
ztype = dns_zone_redirect;
else
INSIST(0);
return (ztype);
}
isc_result_t
ns_config_getiplist(const cfg_obj_t *config, const cfg_obj_t *list,
in_port_t defport, isc_mem_t *mctx,
isc_sockaddr_t **addrsp, isc_dscp_t **dscpsp,
isc_uint32_t *countp)
{
int count, i = 0;
const cfg_obj_t *addrlist;
const cfg_obj_t *portobj, *dscpobj;
const cfg_listelt_t *element;
isc_sockaddr_t *addrs;
in_port_t port;
isc_dscp_t dscp = -1, *dscps = NULL;
isc_result_t result;
INSIST(addrsp != NULL && *addrsp == NULL);
INSIST(dscpsp == NULL || *dscpsp == NULL);
INSIST(countp != NULL);
addrlist = cfg_tuple_get(list, "addresses");
count = ns_config_listcount(addrlist);
portobj = cfg_tuple_get(list, "port");
if (cfg_obj_isuint32(portobj)) {
isc_uint32_t val = cfg_obj_asuint32(portobj);
if (val > ISC_UINT16_MAX) {
cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
"port '%u' out of range", val);
return (ISC_R_RANGE);
}
port = (in_port_t) val;
} else if (defport != 0)
port = defport;
else {
result = ns_config_getport(config, &port);
if (result != ISC_R_SUCCESS)
return (result);
}
if (dscpsp != NULL) {
dscps = isc_mem_get(mctx, count * sizeof(isc_dscp_t));
if (dscps == NULL)
return (ISC_R_NOMEMORY);
dscpobj = cfg_tuple_get(list, "dscp");
if (dscpobj != NULL && cfg_obj_isuint32(dscpobj)) {
if (cfg_obj_asuint32(dscpobj) > 63) {
cfg_obj_log(dscpobj, ns_g_lctx, ISC_LOG_ERROR,
"dscp value '%u' is out of range",
cfg_obj_asuint32(dscpobj));
return (ISC_R_RANGE);
}
dscp = (isc_dscp_t)cfg_obj_asuint32(dscpobj);
}
}
addrs = isc_mem_get(mctx, count * sizeof(isc_sockaddr_t));
if (addrs == NULL)
return (ISC_R_NOMEMORY);
for (element = cfg_list_first(addrlist);
element != NULL;
element = cfg_list_next(element), i++)
{
const cfg_obj_t *addr;
INSIST(i < count);
addr = cfg_listelt_value(element);
addrs[i] = *cfg_obj_assockaddr(addr);
if (dscpsp != NULL) {
isc_dscp_t innerdscp;
innerdscp = cfg_obj_getdscp(addr);
if (innerdscp == -1)
innerdscp = dscp;
dscps[i] = innerdscp;
}
if (isc_sockaddr_getport(&addrs[i]) == 0)
isc_sockaddr_setport(&addrs[i], port);
}
INSIST(i == count);
*addrsp = addrs;
*countp = count;
if (dscpsp != NULL)
*dscpsp = dscps;
return (ISC_R_SUCCESS);
}
void
ns_config_putiplist(isc_mem_t *mctx, isc_sockaddr_t **addrsp,
isc_dscp_t **dscpsp, isc_uint32_t count)
{
INSIST(addrsp != NULL && *addrsp != NULL);
INSIST(dscpsp == NULL || *dscpsp != NULL);
isc_mem_put(mctx, *addrsp, count * sizeof(isc_sockaddr_t));
*addrsp = NULL;
if (dscpsp != NULL) {
isc_mem_put(mctx, *dscpsp, count * sizeof(isc_dscp_t));
*dscpsp = NULL;
}
}
static isc_result_t
get_masters_def(const cfg_obj_t *cctx, const char *name,
const cfg_obj_t **ret)
{
isc_result_t result;
const cfg_obj_t *masters = NULL;
const cfg_listelt_t *elt;
result = cfg_map_get(cctx, "masters", &masters);
if (result != ISC_R_SUCCESS)
return (result);
for (elt = cfg_list_first(masters);
elt != NULL;
elt = cfg_list_next(elt)) {
const cfg_obj_t *list;
const char *listname;
list = cfg_listelt_value(elt);
listname = cfg_obj_asstring(cfg_tuple_get(list, "name"));
if (strcasecmp(listname, name) == 0) {
*ret = list;
return (ISC_R_SUCCESS);
}
}
return (ISC_R_NOTFOUND);
}
isc_result_t
ns_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list,
isc_mem_t *mctx, isc_sockaddr_t **addrsp,
isc_dscp_t **dscpsp, dns_name_t ***keysp,
isc_uint32_t *countp)
{
isc_uint32_t addrcount = 0, dscpcount = 0, keycount = 0, i = 0;
isc_uint32_t listcount = 0, l = 0, j;
isc_uint32_t stackcount = 0, pushed = 0;
isc_result_t result;
const cfg_listelt_t *element;
const cfg_obj_t *addrlist;
const cfg_obj_t *portobj;
const cfg_obj_t *dscpobj;
in_port_t port;
isc_dscp_t dscp;
dns_fixedname_t fname;
isc_sockaddr_t *addrs = NULL;
isc_dscp_t *dscps = NULL;
dns_name_t **keys = NULL;
struct { const char *name; } *lists = NULL;
struct {
const cfg_listelt_t *element;
in_port_t port;
isc_dscp_t dscp;
} *stack = NULL;
REQUIRE(addrsp != NULL && *addrsp == NULL);
REQUIRE(dscpsp != NULL && *dscpsp == NULL);
REQUIRE(keysp != NULL && *keysp == NULL);
REQUIRE(countp != NULL);
newlist:
addrlist = cfg_tuple_get(list, "addresses");
portobj = cfg_tuple_get(list, "port");
dscpobj = cfg_tuple_get(list, "dscp");
if (cfg_obj_isuint32(portobj)) {
isc_uint32_t val = cfg_obj_asuint32(portobj);
if (val > ISC_UINT16_MAX) {
cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
"port '%u' out of range", val);
result = ISC_R_RANGE;
goto cleanup;
}
port = (in_port_t) val;
} else {
result = ns_config_getport(config, &port);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
if (dscpobj != NULL && cfg_obj_isuint32(dscpobj)) {
if (cfg_obj_asuint32(dscpobj) > 63) {
cfg_obj_log(dscpobj, ns_g_lctx, ISC_LOG_ERROR,
"dscp value '%u' is out of range",
cfg_obj_asuint32(dscpobj));
return (ISC_R_RANGE);
}
dscp = (isc_dscp_t)cfg_obj_asuint32(dscpobj);
} else {
result = ns_config_getdscp(config, &dscp);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
result = ISC_R_NOMEMORY;
element = cfg_list_first(addrlist);
resume:
for ( ;
element != NULL;
element = cfg_list_next(element))
{
const cfg_obj_t *addr;
const cfg_obj_t *key;
const char *keystr;
isc_buffer_t b;
addr = cfg_tuple_get(cfg_listelt_value(element),
"masterselement");
key = cfg_tuple_get(cfg_listelt_value(element), "key");
if (!cfg_obj_issockaddr(addr)) {
const char *listname = cfg_obj_asstring(addr);
isc_result_t tresult;
/* Grow lists? */
if (listcount == l) {
void * new;
isc_uint32_t newlen = listcount + 16;
size_t newsize, oldsize;
newsize = newlen * sizeof(*lists);
oldsize = listcount * sizeof(*lists);
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
if (listcount != 0) {
memcpy(new, lists, oldsize);
isc_mem_put(mctx, lists, oldsize);
}
lists = new;
listcount = newlen;
}
/* Seen? */
for (j = 0; j < l; j++)
if (strcasecmp(lists[j].name, listname) == 0)
break;
if (j < l)
continue;
tresult = get_masters_def(config, listname, &list);
if (tresult == ISC_R_NOTFOUND) {
cfg_obj_log(addr, ns_g_lctx, ISC_LOG_ERROR,
"masters \"%s\" not found", listname);
result = tresult;
goto cleanup;
}
if (tresult != ISC_R_SUCCESS)
goto cleanup;
lists[l++].name = listname;
/* Grow stack? */
if (stackcount == pushed) {
void * new;
isc_uint32_t newlen = stackcount + 16;
size_t newsize, oldsize;
newsize = newlen * sizeof(*stack);
oldsize = stackcount * sizeof(*stack);
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
if (stackcount != 0) {
memcpy(new, stack, oldsize);
isc_mem_put(mctx, stack, oldsize);
}
stack = new;
stackcount = newlen;
}
/*
* We want to resume processing this list on the
* next element.
*/
stack[pushed].element = cfg_list_next(element);
stack[pushed].port = port;
stack[pushed].dscp = dscp;
pushed++;
goto newlist;
}
if (i == addrcount) {
void * new;
isc_uint32_t newlen = addrcount + 16;
size_t newsize, oldsize;
newsize = newlen * sizeof(isc_sockaddr_t);
oldsize = addrcount * sizeof(isc_sockaddr_t);
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
if (addrcount != 0) {
memcpy(new, addrs, oldsize);
isc_mem_put(mctx, addrs, oldsize);
}
addrs = new;
addrcount = newlen;
newsize = newlen * sizeof(isc_dscp_t);
oldsize = dscpcount * sizeof(isc_dscp_t);
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
if (dscpcount != 0) {
memcpy(new, dscps, oldsize);
isc_mem_put(mctx, dscps, oldsize);
}
dscps = new;
dscpcount = newlen;
newsize = newlen * sizeof(dns_name_t *);
oldsize = keycount * sizeof(dns_name_t *);
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
if (keycount != 0) {
memcpy(new, keys, oldsize);
isc_mem_put(mctx, keys, oldsize);
}
keys = new;
keycount = newlen;
}
addrs[i] = *cfg_obj_assockaddr(addr);
if (isc_sockaddr_getport(&addrs[i]) == 0)
isc_sockaddr_setport(&addrs[i], port);
dscps[i] = cfg_obj_getdscp(addr);
if (dscps[i] == -1)
dscps[i] = dscp;
keys[i] = NULL;
i++; /* Increment here so that cleanup on error works. */
if (!cfg_obj_isstring(key))
continue;
keys[i - 1] = isc_mem_get(mctx, sizeof(dns_name_t));
if (keys[i - 1] == NULL)
goto cleanup;
dns_name_init(keys[i - 1], NULL);
keystr = cfg_obj_asstring(key);
isc_buffer_constinit(&b, keystr, strlen(keystr));
isc_buffer_add(&b, strlen(keystr));
dns_fixedname_init(&fname);
result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
dns_rootname, 0, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = dns_name_dup(dns_fixedname_name(&fname), mctx,
keys[i - 1]);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
if (pushed != 0) {
pushed--;
element = stack[pushed].element;
port = stack[pushed].port;
dscp = stack[pushed].dscp;
goto resume;
}
if (i < addrcount) {
void * new;
size_t newsize, oldsize;
newsize = i * sizeof(isc_sockaddr_t);
oldsize = addrcount * sizeof(isc_sockaddr_t);
if (i != 0) {
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
memcpy(new, addrs, newsize);
} else
new = NULL;
isc_mem_put(mctx, addrs, oldsize);
addrs = new;
addrcount = i;
newsize = i * sizeof(isc_dscp_t);
oldsize = dscpcount * sizeof(isc_dscp_t);
if (i != 0) {
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
memcpy(new, dscps, newsize);
} else
new = NULL;
isc_mem_put(mctx, dscps, oldsize);
dscps = new;
dscpcount = i;
newsize = i * sizeof(dns_name_t *);
oldsize = keycount * sizeof(dns_name_t *);
if (i != 0) {
new = isc_mem_get(mctx, newsize);
if (new == NULL)
goto cleanup;
memcpy(new, keys, newsize);
} else
new = NULL;
isc_mem_put(mctx, keys, oldsize);
keys = new;
keycount = i;
}
if (lists != NULL)
isc_mem_put(mctx, lists, listcount * sizeof(*lists));
if (stack != NULL)
isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
INSIST(keycount == addrcount);
*addrsp = addrs;
*dscpsp = dscps;
*keysp = keys;
*countp = addrcount;
return (ISC_R_SUCCESS);
cleanup:
if (addrs != NULL)
isc_mem_put(mctx, addrs, addrcount * sizeof(isc_sockaddr_t));
if (dscps != NULL)
isc_mem_put(mctx, dscps, dscpcount * sizeof(isc_dscp_t));
if (keys != NULL) {
for (j = 0; j < i; j++) {
if (keys[j] == NULL)
continue;
if (dns_name_dynamic(keys[j]))
dns_name_free(keys[j], mctx);
isc_mem_put(mctx, keys[j], sizeof(dns_name_t));
}
isc_mem_put(mctx, keys, keycount * sizeof(dns_name_t *));
}
if (lists != NULL)
isc_mem_put(mctx, lists, listcount * sizeof(*lists));
if (stack != NULL)
isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
return (result);
}
void
ns_config_putipandkeylist(isc_mem_t *mctx, isc_sockaddr_t **addrsp,
isc_dscp_t **dscpsp, dns_name_t ***keysp,
isc_uint32_t count)
{
unsigned int i;
dns_name_t **keys;
REQUIRE(addrsp != NULL && *addrsp != NULL);
REQUIRE(dscpsp == NULL || *dscpsp != NULL);
REQUIRE(keysp != NULL && *keysp != NULL);
keys = *keysp;
isc_mem_put(mctx, *addrsp, count * sizeof(isc_sockaddr_t));
if (dscpsp != NULL)
isc_mem_put(mctx, *dscpsp, count * sizeof(isc_dscp_t));
for (i = 0; i < count; i++) {
if (keys[i] == NULL)
continue;
if (dns_name_dynamic(keys[i]))
dns_name_free(keys[i], mctx);
isc_mem_put(mctx, keys[i], sizeof(dns_name_t));
}
isc_mem_put(mctx, *keysp, count * sizeof(dns_name_t *));
*addrsp = NULL;
if (dscpsp != NULL)
*dscpsp = NULL;
*keysp = NULL;
}
isc_result_t
ns_config_getport(const cfg_obj_t *config, in_port_t *portp) {
const cfg_obj_t *maps[3];
const cfg_obj_t *options = NULL;
const cfg_obj_t *portobj = NULL;
isc_result_t result;
int i;
(void)cfg_map_get(config, "options", &options);
i = 0;
if (options != NULL)
maps[i++] = options;
maps[i++] = ns_g_defaults;
maps[i] = NULL;
result = ns_config_get(maps, "port", &portobj);
INSIST(result == ISC_R_SUCCESS);
if (cfg_obj_asuint32(portobj) >= ISC_UINT16_MAX) {
cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
"port '%u' out of range",
cfg_obj_asuint32(portobj));
return (ISC_R_RANGE);
}
*portp = (in_port_t)cfg_obj_asuint32(portobj);
return (ISC_R_SUCCESS);
}
isc_result_t
ns_config_getdscp(const cfg_obj_t *config, isc_dscp_t *dscpp) {
const cfg_obj_t *options = NULL;
const cfg_obj_t *dscpobj = NULL;
isc_result_t result;
(void)cfg_map_get(config, "options", &options);
if (options == NULL)
return (ISC_R_SUCCESS);
result = cfg_map_get(options, "dscp", &dscpobj);
if (result != ISC_R_SUCCESS || dscpobj == NULL) {
*dscpp = -1;
return (ISC_R_SUCCESS);
}
if (cfg_obj_asuint32(dscpobj) >= 64) {
cfg_obj_log(dscpobj, ns_g_lctx, ISC_LOG_ERROR,
"dscp '%u' out of range",
cfg_obj_asuint32(dscpobj));
return (ISC_R_RANGE);
}
*dscpp = (isc_dscp_t)cfg_obj_asuint32(dscpobj);
return (ISC_R_SUCCESS);
}
struct keyalgorithms {
const char *str;
enum { hmacnone, hmacmd5, hmacsha1, hmacsha224,
hmacsha256, hmacsha384, hmacsha512 } hmac;
unsigned int type;
isc_uint16_t size;
} algorithms[] = {
{ "hmac-md5", hmacmd5, DST_ALG_HMACMD5, 128 },
{ "hmac-md5.sig-alg.reg.int", hmacmd5, DST_ALG_HMACMD5, 0 },
{ "hmac-md5.sig-alg.reg.int.", hmacmd5, DST_ALG_HMACMD5, 0 },
{ "hmac-sha1", hmacsha1, DST_ALG_HMACSHA1, 160 },
{ "hmac-sha224", hmacsha224, DST_ALG_HMACSHA224, 224 },
{ "hmac-sha256", hmacsha256, DST_ALG_HMACSHA256, 256 },
{ "hmac-sha384", hmacsha384, DST_ALG_HMACSHA384, 384 },
{ "hmac-sha512", hmacsha512, DST_ALG_HMACSHA512, 512 },
{ NULL, hmacnone, DST_ALG_UNKNOWN, 0 }
};
isc_result_t
ns_config_getkeyalgorithm(const char *str, dns_name_t **name,
isc_uint16_t *digestbits)
{
return (ns_config_getkeyalgorithm2(str, name, NULL, digestbits));
}
isc_result_t
ns_config_getkeyalgorithm2(const char *str, dns_name_t **name,
unsigned int *typep, isc_uint16_t *digestbits)
{
int i;
size_t len = 0;
isc_uint16_t bits;
isc_result_t result;
for (i = 0; algorithms[i].str != NULL; i++) {
len = strlen(algorithms[i].str);
if (strncasecmp(algorithms[i].str, str, len) == 0 &&
(str[len] == '\0' ||
(algorithms[i].size != 0 && str[len] == '-')))
break;
}
if (algorithms[i].str == NULL)
return (ISC_R_NOTFOUND);
if (str[len] == '-') {
result = isc_parse_uint16(&bits, str + len + 1, 10);
if (result != ISC_R_SUCCESS)
return (result);
if (bits > algorithms[i].size)
return (ISC_R_RANGE);
} else if (algorithms[i].size == 0)
bits = 128;
else
bits = algorithms[i].size;
if (name != NULL) {
switch (algorithms[i].hmac) {
case hmacmd5: *name = dns_tsig_hmacmd5_name; break;
case hmacsha1: *name = dns_tsig_hmacsha1_name; break;
case hmacsha224: *name = dns_tsig_hmacsha224_name; break;
case hmacsha256: *name = dns_tsig_hmacsha256_name; break;
case hmacsha384: *name = dns_tsig_hmacsha384_name; break;
case hmacsha512: *name = dns_tsig_hmacsha512_name; break;
default:
INSIST(0);
}
}
if (typep != NULL)
*typep = algorithms[i].type;
if (digestbits != NULL)
*digestbits = bits;
return (ISC_R_SUCCESS);
}