server.c revision 3d066288ad6c6fe2ec2a54475f541a305a085068
/*
* Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2003 Internet Software Consortium.
*
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*! \file */
#include <config.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <ctype.h>
#include <isc/parseint.h>
#include <isc/refcount.h>
#include <isc/resource.h>
#ifdef AES_SIT
#else
#endif
#include <isccfg/namedconf.h>
#include <dns/dispatch.h>
#include <dns/keytable.h>
#include <dns/keyvalues.h>
#include <dns/masterdump.h>
#include <dns/portlist.h>
#include <dns/rdataclass.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include <dns/resolver.h>
#include <named/interfacemgr.h>
#include <named/statschannel.h>
#include <named/tkeyconf.h>
#include <named/tsigconf.h>
#include <named/zoneconf.h>
#ifdef HAVE_LIBSCF
#include <named/ns_smf_globals.h>
#include <stdlib.h>
#endif
#ifdef HAVE_GEOIP
#endif /* HAVE_GEOIP */
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#ifndef SIZE_MAX
#endif
#ifdef TUNE_LARGE
#define RESOLVER_NTASKS 523
#define UDPBUFFERS 32768
#define EXCLBUFFERS 32768
#else
#define RESOLVER_NTASKS 31
#define UDPBUFFERS 1000
#define EXCLBUFFERS 4096
#endif /* TUNE_LARGE */
/*%
* Check an operation for failure. Assumes that the function
* using it has a 'result' variable and a 'cleanup' label.
*/
} while (0)
if (tresult != ISC_R_SUCCESS) { \
isc_buffer_clear(text); \
goto cleanup; \
} \
} while (0)
if (result != ISC_R_SUCCESS) { \
"%s: %s", msg, \
isc_result_totext(result)); \
goto cleanup; \
} \
} while (0) \
if (result != ISC_R_SUCCESS) { \
isc_result_totext(result)); \
goto cleanup; \
} \
} while (0) \
if (result != ISC_R_SUCCESS) \
} while (0) \
/*%
* Maximum ADB size for views that share a cache. Use this limit to suppress
* the total of memory footprint, which should be the main reason for sharing
* a cache. Only effective when a finite max-cache-size is specified.
* This is currently defined to be 8MB.
*/
#define MAX_ADB_SIZE_FOR_CACHESHARE 8388608U
struct ns_dispatch {
unsigned int dispatchgen;
};
struct ns_cache {
};
struct dumpcontext {
struct viewlistentry *view;
struct zonelistentry *zone;
};
struct viewlistentry {
};
struct zonelistentry {
};
/*%
* Configuration context to retain for each view that allows
* new zones to be added at runtime.
*/
struct cfg_context {
};
/*%
* Holds state information for the initial zone loading process.
* Uses the isc_refcount structure to count the number of views
* with pending zone loads, dereferencing as each view finishes.
*/
typedef struct {
/*
* These zones should not leak onto the Internet.
*/
const char *empty_zones[] = {
/* RFC 1918 */
"10.IN-ADDR.ARPA",
"16.172.IN-ADDR.ARPA",
"17.172.IN-ADDR.ARPA",
"18.172.IN-ADDR.ARPA",
"19.172.IN-ADDR.ARPA",
"20.172.IN-ADDR.ARPA",
"21.172.IN-ADDR.ARPA",
"22.172.IN-ADDR.ARPA",
"23.172.IN-ADDR.ARPA",
"24.172.IN-ADDR.ARPA",
"25.172.IN-ADDR.ARPA",
"26.172.IN-ADDR.ARPA",
"27.172.IN-ADDR.ARPA",
"28.172.IN-ADDR.ARPA",
"29.172.IN-ADDR.ARPA",
"30.172.IN-ADDR.ARPA",
"31.172.IN-ADDR.ARPA",
"168.192.IN-ADDR.ARPA",
/* RFC 6598 */
"64.100.IN-ADDR.ARPA",
"65.100.IN-ADDR.ARPA",
"66.100.IN-ADDR.ARPA",
"67.100.IN-ADDR.ARPA",
"68.100.IN-ADDR.ARPA",
"69.100.IN-ADDR.ARPA",
"70.100.IN-ADDR.ARPA",
"71.100.IN-ADDR.ARPA",
"72.100.IN-ADDR.ARPA",
"73.100.IN-ADDR.ARPA",
"74.100.IN-ADDR.ARPA",
"75.100.IN-ADDR.ARPA",
"76.100.IN-ADDR.ARPA",
"77.100.IN-ADDR.ARPA",
"78.100.IN-ADDR.ARPA",
"79.100.IN-ADDR.ARPA",
"80.100.IN-ADDR.ARPA",
"81.100.IN-ADDR.ARPA",
"82.100.IN-ADDR.ARPA",
"83.100.IN-ADDR.ARPA",
"84.100.IN-ADDR.ARPA",
"85.100.IN-ADDR.ARPA",
"86.100.IN-ADDR.ARPA",
"87.100.IN-ADDR.ARPA",
"88.100.IN-ADDR.ARPA",
"89.100.IN-ADDR.ARPA",
"90.100.IN-ADDR.ARPA",
"91.100.IN-ADDR.ARPA",
"92.100.IN-ADDR.ARPA",
"93.100.IN-ADDR.ARPA",
"94.100.IN-ADDR.ARPA",
"95.100.IN-ADDR.ARPA",
"96.100.IN-ADDR.ARPA",
"97.100.IN-ADDR.ARPA",
"98.100.IN-ADDR.ARPA",
"99.100.IN-ADDR.ARPA",
"100.100.IN-ADDR.ARPA",
"101.100.IN-ADDR.ARPA",
"102.100.IN-ADDR.ARPA",
"103.100.IN-ADDR.ARPA",
"104.100.IN-ADDR.ARPA",
"105.100.IN-ADDR.ARPA",
"106.100.IN-ADDR.ARPA",
"107.100.IN-ADDR.ARPA",
"108.100.IN-ADDR.ARPA",
"109.100.IN-ADDR.ARPA",
"110.100.IN-ADDR.ARPA",
"111.100.IN-ADDR.ARPA",
"112.100.IN-ADDR.ARPA",
"113.100.IN-ADDR.ARPA",
"114.100.IN-ADDR.ARPA",
"115.100.IN-ADDR.ARPA",
"116.100.IN-ADDR.ARPA",
"117.100.IN-ADDR.ARPA",
"118.100.IN-ADDR.ARPA",
"119.100.IN-ADDR.ARPA",
"120.100.IN-ADDR.ARPA",
"121.100.IN-ADDR.ARPA",
"122.100.IN-ADDR.ARPA",
"123.100.IN-ADDR.ARPA",
"124.100.IN-ADDR.ARPA",
"125.100.IN-ADDR.ARPA",
"126.100.IN-ADDR.ARPA",
"127.100.IN-ADDR.ARPA",
/* RFC 5735 and RFC 5737 */
"0.IN-ADDR.ARPA", /* THIS NETWORK */
"127.IN-ADDR.ARPA", /* LOOPBACK */
"254.169.IN-ADDR.ARPA", /* LINK LOCAL */
"2.0.192.IN-ADDR.ARPA", /* TEST NET */
"100.51.198.IN-ADDR.ARPA", /* TEST NET 2 */
"113.0.203.IN-ADDR.ARPA", /* TEST NET 3 */
"255.255.255.255.IN-ADDR.ARPA", /* BROADCAST */
/* Local IPv6 Unicast Addresses */
"0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA",
"1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA",
/* LOCALLY ASSIGNED LOCAL ADDRESS SCOPE */
"D.F.IP6.ARPA",
"8.E.F.IP6.ARPA", /* LINK LOCAL */
"9.E.F.IP6.ARPA", /* LINK LOCAL */
"A.E.F.IP6.ARPA", /* LINK LOCAL */
"B.E.F.IP6.ARPA", /* LINK LOCAL */
/* Example Prefix, RFC 3849. */
"8.B.D.0.1.0.0.2.IP6.ARPA",
};
ISC_PLATFORM_NORETURN_PRE static void
static void
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
const cfg_obj_t *alternates);
static isc_result_t
static isc_result_t
static void
static void
newzone_cfgctx_destroy(void **cfgp);
static isc_result_t
static isc_result_t
putnull(isc_buffer_t *b);
/*%
* Configure a single view ACL at '*aclp'. Get its configuration from
* 'vconfig' (for per-view configuration) and maybe from 'config'
*/
static isc_result_t
const char *aclname, const char *acltuplename,
{
int i = 0;
}
/*
* No value available. *aclp == NULL.
*/
return (ISC_R_SUCCESS);
if (acltuplename != NULL) {
/*
* If the ACL is given in an optional tuple, retrieve it.
* The parser should have ensured that a valid object be
* returned.
*/
}
return (result);
}
/*%
* Configure a sortlist at '*aclp'. Essentially the same as
* configure_view_acl() except it calls cfg_acl_fromconfig with a
* nest_level value of 2.
*/
static isc_result_t
{
int i = 0;
}
return (ISC_R_SUCCESS);
/*
* Use a nest level of 3 for the "top level" of the sortlist;
* this means each entry in the top three levels will be stored
* as lists of separate, nested ACLs, rather than merged together
* into IP tables as is usually done with ACLs.
*/
return (result);
}
static isc_result_t
const char *confname, const char *conftuplename,
{
const cfg_listelt_t *element;
int i = 0;
isc_buffer_t b;
const char *str;
}
/*
* No value available. *rbtp == NULL.
*/
return (ISC_R_SUCCESS);
if (conftuplename != NULL) {
if (cfg_obj_isvoid(obj))
return (ISC_R_SUCCESS);
}
if (result != ISC_R_SUCCESS)
return (result);
/*
* We don't need the node data, but need to set dummy data to
* avoid a partial match with an empty node. For example, if
* we have foo.example.com and bar.example.com, we'd get a match
* for baz.example.com, which is not the expected result.
* We simply use (void *)1 as the dummy data.
*/
if (result != ISC_R_SUCCESS) {
"failed to add %s for %s: %s",
goto cleanup;
}
}
return (result);
return (result);
}
static isc_result_t
{
const char *keystr, *keynamestr;
unsigned char keydata[4096];
unsigned char rrdata[4096];
isc_region_t r;
if (managed) {
const char *initmethod;
"managed key '%s': "
"invalid initialization method '%s'",
goto cleanup;
}
}
else {
&viewclass));
}
/*
* The key data in keystruct is not dynamically allocated.
*/
if (flags > 0xffff)
if (proto > 0xff)
if (alg > 0xff)
isc_buffer_usedregion(&keydatabuf, &r);
"%s key '%s' has a weak exponent",
return (ISC_R_SUCCESS);
if (result == DST_R_NOCRYPTO) {
"ignoring %s key for '%s': no crypto support",
} else if (result == DST_R_UNSUPPORTEDALG) {
"skipping %s key for '%s': %s",
} else {
"configuring %s key for '%s': %s",
}
return (result);
}
static isc_result_t
{
if (result == DST_R_UNSUPPORTEDALG) {
continue;
}
if (result != ISC_R_SUCCESS)
goto cleanup;
/*
* If keyname was specified, we only add that key.
*/
{
continue;
}
}
}
if (result == DST_R_NOCRYPTO)
return (result);
}
/*%
* Configure DNSSEC keys for a view.
*
* The per-view configuration values and the server-global defaults are read
* from 'vconfig' and 'config'.
*/
static isc_result_t
{
const char *directory;
int i = 0;
/* We don't need trust anchors for the _bind view */
return (ISC_R_SUCCESS);
}
&view_keys);
}
}
}
}
maps[i++] = ns_g_defaults;
if (result != ISC_R_SUCCESS) {
"couldn't create keytable");
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"couldn't create NTA table");
return (ISC_R_UNEXPECTED);
}
"using built-in DLV key for view %s",
/*
* If bind.keys exists, it overrides the managed-keys
* clause hard-coded in ns_g_config.
*/
&builtin_keys);
} else {
&builtin_keys);
}
if (builtin_keys != NULL)
if (builtin_managed_keys != NULL)
}
"using built-in root key for view %s",
/*
* If bind.keys exists, it overrides the managed-keys
* clause hard-coded in ns_g_config.
*/
&builtin_keys);
} else {
&builtin_keys);
}
if (builtin_keys != NULL)
if (builtin_managed_keys != NULL)
mctx));
}
}
/*
* Add key zone for managed-keys.
*/
if (result != ISC_R_SUCCESS) {
"invalid managed-keys-directory %s: %s",
goto cleanup;
}
return (result);
}
static isc_result_t
const cfg_listelt_t *element;
const char *str;
isc_buffer_t b;
{
}
return (result);
}
/*%
* Get a dispatch appropriate for the resolver of a given view.
*/
static isc_result_t
{
unsigned int maxdispatchbuffers = UDPBUFFERS;
switch (af) {
case AF_INET:
break;
case AF_INET6:
break;
default:
INSIST(0);
}
/*
* If we don't support this address family, we're done!
*/
switch (af) {
case AF_INET:
result = isc_net_probeipv4();
break;
case AF_INET6:
result = isc_net_probeipv6();
break;
default:
INSIST(0);
}
if (result != ISC_R_SUCCESS)
return (ISC_R_SUCCESS);
/*
* Try to find a dispatcher that we can share.
*/
attrs = 0;
switch (af) {
case AF_INET:
break;
case AF_INET6:
break;
}
if (isc_sockaddr_getport(&sa) == 0) {
} else {
if (is_firstview) {
"using specific query-source port "
"suppresses port randomization and can be "
"insecure.");
}
}
attrmask = 0;
if (result != ISC_R_SUCCESS) {
char buf[ISC_SOCKADDR_FORMATSIZE];
switch (af) {
case AF_INET:
break;
case AF_INET6:
break;
}
return (ISC_R_SUCCESS);
"could not get query source dispatcher (%s)",
buf);
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int mode = 0;
const char *str;
isc_buffer_t b;
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
if (cfg_obj_isstring(obj))
else
str = "*";
dns_rootname, 0, NULL);
if (result != ISC_R_SUCCESS)
return (result);
#else
mode = 0;
#endif /* DNS_RDATASET_FIXED */
mode = 0;
else
INSIST(0);
/*
* "*" should match everything including the root (BIND 8 compat).
* As dns_name_matcheswildcard(".", "*.") returns FALSE add a
* explicit entry for "." when the name is "*".
*/
if (addroot) {
if (result != ISC_R_SUCCESS)
return (result);
}
}
static isc_result_t
const char *str;
unsigned int prefixlen;
if (result != ISC_R_SUCCESS)
return (result);
#ifdef ISC_PLATFORM_USESIT
#endif
if (udpsize < 512)
udpsize = 512;
if (udpsize > 4096)
udpsize = 4096;
}
if (udpsize < 512)
udpsize = 512;
if (udpsize > 4096)
udpsize = 4096;
}
else
INSIST(0);
}
if (result != ISC_R_SUCCESS)
goto cleanup;
}
else
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
}
else
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
}
else
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
}
return (ISC_R_SUCCESS);
return (result);
}
static isc_result_t
const cfg_obj_t *algorithms;
const cfg_listelt_t *element;
const char *str;
isc_buffer_t b;
{
if (result != ISC_R_SUCCESS) {
}
if (result != ISC_R_SUCCESS) {
"invalid algorithm");
}
}
return (result);
}
static isc_result_t
const cfg_listelt_t *element;
const char *str;
isc_buffer_t b;
{
/* disable_ds_digests handles numeric values. */
if (result != ISC_R_SUCCESS) {
"invalid algorithm");
}
}
return (result);
}
static isc_boolean_t
const cfg_listelt_t *element;
const char *str;
isc_buffer_t b;
{
0, NULL);
return (ISC_TRUE);
}
return (ISC_FALSE);
}
static isc_result_t
{
unsigned int i;
/*
* Check that all the arguments match.
*/
for (i = 0; i < dbtypec; i++)
/*
* Check that there are not extra arguments.
*/
return (result);
}
static isc_result_t
zoneqrystats = NULL;
if (level == dns_zonestat_full) {
if (result != ISC_R_SUCCESS)
return (result);
}
if (zoneqrystats != NULL)
return (ISC_R_SUCCESS);
}
static ns_cache_t *
return (nsc);
}
return (NULL);
}
static isc_boolean_t
{
return (ISC_FALSE);
}
return (ISC_TRUE);
}
static isc_boolean_t
unsigned int new_cleaning_interval,
{
/*
* If the cache cannot even reused for the same view, it cannot be
* shared with other views.
*/
return (ISC_FALSE);
/*
* Check other cache related parameters that must be consistent among
* the sharing views.
*/
return (ISC_FALSE);
}
return (ISC_TRUE);
}
/*
* Callback from DLZ configure when the driver sets up a writeable zone
*/
static isc_result_t
if (result != ISC_R_SUCCESS)
return (result);
}
static isc_result_t
const char *contact)
{
char *cp;
const char *sep = ": view ";
const unsigned char *s6;
int dns64_dbtypec = 4;
isc_buffer_t b;
sep = "";
viewname = "";
}
/*
* Construct the reverse name of the zone.
*/
while (prefixlen > 0) {
prefixlen -= 8;
cp += 4;
}
/*
* Create the actual zone.
*/
return (result);
}
static isc_result_t
{
if (result != ISC_R_SUCCESS)
return (result);
}
static isc_result_t
{
if (result != ISC_R_SUCCESS)
"invalid zone '%s'", str);
return (result);
}
static isc_result_t
{
const char *str;
"limit of %d response policy zones exceeded",
return (ISC_R_FAILURE);
}
"no memory for response policy zones");
return (ISC_R_NOMEMORY);
}
if (result != ISC_R_SUCCESS) {
return (result);
}
} else {
}
if (cfg_obj_isuint32(obj)) {
} else {
}
*old_rpz_okp = ISC_FALSE;
if (result != ISC_R_SUCCESS)
return (result);
"invalid zone name '%s'", str);
return (DNS_R_EMPTYLABEL);
}
"duplicate '%s'", str);
return (result);
}
}
*old_rpz_okp = ISC_FALSE;
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
DNS_RPZ_PASSTHRU_NAME, "name");
if (result != ISC_R_SUCCESS)
return (result);
DNS_RPZ_DROP_NAME, "name");
if (result != ISC_R_SUCCESS)
return (result);
DNS_RPZ_TCP_ONLY_NAME, "name");
if (result != ISC_R_SUCCESS)
return (result);
if (cfg_obj_isvoid(obj)) {
} else {
str, "cname");
if (result != ISC_R_SUCCESS)
return (result);
}
}
*old_rpz_okp = ISC_FALSE;
return (ISC_R_SUCCESS);
}
static isc_result_t
{
const cfg_listelt_t *zone_element;
const dns_rpz_zones_t *old;
const dns_rpz_zone_t *old_zone;
int i;
*old_rpz_okp = ISC_FALSE;
if (zone_element == NULL)
return (ISC_R_SUCCESS);
if (result != ISC_R_SUCCESS)
return (result);
if (!cfg_obj_isvoid(sub_obj) &&
else
if (!cfg_obj_isvoid(sub_obj) &&
else
if (cfg_obj_isuint32(sub_obj))
else
if (cfg_obj_isuint32(sub_obj))
else
else
if (result == ISC_R_SUCCESS) {
} else {
}
*old_rpz_okp = ISC_FALSE;
else
*old_rpz_okp = ISC_TRUE;
for (i = 0;
zone_element != NULL;
} else {
*old_rpz_okp = ISC_FALSE;
}
if (result != ISC_R_SUCCESS) {
return (result);
}
}
/*
* If this is a reloading and the parameters and list of policy
* zones are unchanged, then use the same policy data.
* Data for individual zones that must be reloaded will be merged.
*/
*old_rpz_okp = ISC_FALSE;
if (*old_rpz_okp) {
}
return (ISC_R_SUCCESS);
}
do { \
if (!(cond)) { \
result = ISC_R_RANGE; \
goto cleanup; \
} \
} while (0)
do { \
if (result == ISC_R_SUCCESS) { \
name" %d > %d", \
} else { \
} \
} while (0)
static isc_result_t
int min_entries, i, j;
/*
* Most DNS servers have few clients, but intentinally open
* recursive and authoritative servers often have many.
* So start with a small number of entries unless told otherwise
* to reduce cold-start costs.
*/
min_entries = 500;
if (result == ISC_R_SUCCESS) {
if (min_entries < 1)
min_entries = 1;
}
if (result != ISC_R_SUCCESS)
return (result);
if (result == ISC_R_SUCCESS) {
i = cfg_obj_asuint32(obj);
CHECK_RRL(i >= min_entries,
"max-table-size %d < min-table-size %d",
i, min_entries);
}
rrl->max_entries = i;
"responses-per-second");
"referrals-per-second");
"nodata-per-second");
"nxdomains-per-second");
"errors-per-second");
"all-per-second");
"slip");
i = 15;
if (result == ISC_R_SUCCESS) {
i = cfg_obj_asuint32(obj);
"window %d < 1 or > %d", i, DNS_RRL_MAX_WINDOW);
}
i = 0;
if (result == ISC_R_SUCCESS) {
i = cfg_obj_asuint32(obj);
}
i = 24;
if (result == ISC_R_SUCCESS) {
i = cfg_obj_asuint32(obj);
"invalid 'ipv4-prefix-length %d'%s", i, "");
}
rrl->ipv4_prefixlen = i;
if (i == 32)
else
i = 56;
if (result == ISC_R_SUCCESS) {
i = cfg_obj_asuint32(obj);
"ipv6-prefix-length %d < 16 or > %d",
i, DNS_RRL_MAX_PREFIX);
}
rrl->ipv6_prefixlen = i;
for (j = 0; j < 4; ++j) {
if (i <= 0) {
} else if (i < 32) {
} else {
}
i -= 32;
}
if (result == ISC_R_SUCCESS) {
"invalid %s%s", "address match list", "");
}
else
return (ISC_R_SUCCESS);
return (result);
}
static isc_result_t
{
unsigned char buf[DNS_SOA_BUFFERSIZE];
return (result);
}
static isc_result_t
{
isc_buffer_t b;
unsigned char buf[DNS_NAME_MAXWIRE];
&ns, &b));
return (result);
}
static isc_result_t
{
char namebuf[DNS_NAME_FORMATSIZE];
const cfg_listelt_t *element;
const char *sep = ": view ";
const char *str;
dns_name_t *ns;
int rbt_dbtypec = 1;
int order;
unsigned int nlabels;
/*
* Look for forward "zones" beneath this empty zone and if so
* create a custom db for the empty zone.
*/
if (namereln != dns_namereln_subdomain)
continue;
continue;
continue;
}
else
0, NULL));
0, NULL));
}
}
/*
* Is the existing zone the ok to use?
*/
unsigned int typec;
const char **dbargv;
typec = rbt_dbtypec;
dbargv = rbt_dbtype;
} else {
}
if (result != ISC_R_SUCCESS)
}
}
}
empty_dbtype));
}
else
if (view->queryonacl)
else
}
sep = "";
viewname = "";
}
ISC_LOG_INFO, "automatic empty zone%s%s: %s",
dns_db_detach(&db);
return (result);
}
/*
* Configure 'view' according to 'vconfig', taking defaults from 'config'
* where values are missing in 'vconfig'.
*
* When configuring the default view, 'vconfig' will be NULL and the
* global defaults in 'config' used exclusively.
*/
static isc_result_t
{
const cfg_obj_t *forwardtype;
const cfg_obj_t *forwarders;
const cfg_obj_t *alternates;
unsigned int dlzargc;
char **dlzargv;
const cfg_listelt_t *element;
unsigned int cleaning_interval;
int i = 0, j = 0, k = 0;
const char *str;
unsigned int resopts = 0;
unsigned int query_timeout, ndisp;
struct cfg_context *nzctx;
/*
* maps: view options, options, defaults
* cfgmaps: view options, config
* optionmaps: view options, options
*/
optionmaps[j++] = voptions;
}
optionmaps[j++] = options;
}
maps[i++] = ns_g_defaults;
optionmaps[j] = NULL;
/*
* Set the view's port number for outgoing queries.
*/
/*
* Create additional cache for this view and zones under the view
* if explicitly enabled.
* XXX950 default to on.
*/
}
if (cfg_obj_isstring(obj)) {
max_acache_size = 0;
} else {
"'max-acache-size "
"is too large for this "
"system; reducing to %lu",
}
}
}
}
/*
* Make the list of response policy zone names for a view that
* is used for real lookups and so cares about hints.
*/
}
/*
* Configure the zones.
*/
else
/*
* Load zone configuration
*/
{
}
/*
* Check that a master or slave zone was found for each
* zone named in the response policy statement.
*/
{
char namebuf[DNS_NAME_FORMATSIZE];
"'%s' is not a master or slave zone",
namebuf);
goto cleanup;
}
}
}
/*
* If we're allowing added zones, then load zone configuration
* from the newzone file for zones that were added during previous
* runs.
*/
"loading additional zones for view '%s'",
{
}
}
/*
* Create Dynamically Loadable Zone driver.
*/
else
{
if (s == NULL) {
goto cleanup;
}
if (result != ISC_R_SUCCESS) {
isc_mem_free(mctx, s);
goto cleanup;
}
&dlzdb);
isc_mem_free(mctx, s);
if (result != ISC_R_SUCCESS)
goto cleanup;
/*
* If the DLZ backend supports configuration,
* and is searchable, then call its configure
* method now. If not searchable, we'll take
* care of it when we process the zone statement.
*/
if (result != ISC_R_SUCCESS)
goto cleanup;
} else {
}
}
}
/*
* Obtain configuration parameters that affect the decision of whether
*/
if (cfg_obj_isstring(obj)) {
max_cache_size = 0;
} else {
"'max-cache-size "
"is too large for this "
"system; reducing to %lu",
}
}
/* Check-names. */
} else
INSIST(0);
const cfg_listelt_t *element;
unsigned int prefixlen;
if (result == ISC_R_SUCCESS)
else
if (result == ISC_R_SUCCESS)
else
{
unsigned int dns64options = 0;
&prefixlen);
} else
if (result != ISC_R_SUCCESS)
goto cleanup;
}
if (result != ISC_R_SUCCESS)
goto cleanup;
}
if (result != ISC_R_SUCCESS)
goto cleanup;
}
dns64options, &dns64);
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
}
}
if (cfg_obj_isboolean(obj)) {
} else {
/* If dnssec-validation is not boolean, it must be "auto" */
}
/*
* Configure the view's cache.
*
* First, check to see if there are any attach-cache options. If yes,
* attempt to lookup an existing cache at attach it to the view. If
* there is not one, then try to reuse an existing cache if possible;
* otherwise create a new cache.
*
* Note that the ADB is not preserved or shared in either case.
*
* When a matching view is found, the associated statistics are also
* retrieved and reused.
*
* XXX Determining when it is safe to reuse or share a cache is tricky.
* When the view's configuration changes, the cached data may become
* invalid because it reflects our old view of the world. We check
* some of the configuration parameters that could invalidate the cache
* or otherwise make it unsharable, but there are other configuration
* options that should be checked. For example, if a view uses a
* forwarder, changes in the forwarder configuration may invalidate
* the cache. At the moment, it's the administrator's responsibility to
*/
if (result == ISC_R_SUCCESS)
else
"views %s and %s can't share the cache "
"due to configuration parameter mismatch",
goto cleanup;
}
} else {
&pview);
goto cleanup;
zero_no_soattl)) {
ISC_LOG_DEBUG(1),
"cache cannot be reused "
"for view %s due to "
"configuration parameter "
} else {
ISC_LOG_DEBUG(3),
"reusing existing cache");
}
}
}
/*
* Create a cache with the desired name. This normally
* equals the view name, but may also be a forward
* reference to a view that share the cache with this
* view but is not yet configured. If it is not the
* view name but not a forward reference either, then it
* is simply a named cache that is not shared.
*
* We use two separate memory contexts for the
* cache, for the main cache memory and the heap
* memory.
*/
&cache));
}
goto cleanup;
}
}
/*
* cache-file cannot be inherited if views are present, but this
* should be caught by the configuration checking stage.
*/
if (!reused_cache && !shared_cache)
}
/*
* Resolver.
*
* XXXRTH Hardwired number of tasks.
*/
== NULL)));
== NULL)));
"unable to obtain neither an IPv4 nor"
" an IPv6 dispatch");
goto cleanup;
}
}
if (resquerystats == NULL)
if (dscp4 == -1)
if (dscp6 == -1)
if (dscp4 != -1)
if (dscp6 != -1)
/*
* Set the ADB cache size to 1/8th of the max-cache-size or
* MAX_ADB_SIZE_FOR_CACHESHARE when the cache is shared.
*/
max_adb_size = 0;
if (max_cache_size != 0U) {
if (max_adb_size == 0U)
if (!nsc->adbsizeadjusted) {
}
}
}
/*
* Set resolver's lame-ttl.
*/
if (lame_ttl > 1800)
lame_ttl = 1800;
/*
* Set the resolver's query timeout.
*/
/* Specify whether to use 0-TTL for negative response for SOA query */
/*
* Set the resolver's EDNS UDP size.
*/
if (udpsize < 512)
udpsize = 512;
if (udpsize > 4096)
udpsize = 4096;
/*
* Set the maximum UDP response size.
*/
if (udpsize < 512)
udpsize = 512;
if (udpsize > 4096)
udpsize = 4096;
#ifdef ISC_PLATFORM_USESIT
/*
* Set the maximum UDP when a SIT is not provided.
*/
if (udpsize < 128)
udpsize = 128;
#endif
/*
* Set the maximum rsa exponent bits.
*/
maxbits = 35;
if (maxbits > 4096)
maxbits = 4096;
/*
* Set supported DNSSEC algorithms.
*/
}
/*
*/
}
/*
* A global or view "forwarders" option, if present,
* creates an entry for "." in the forwarding table.
*/
forwardtype = NULL;
forwarders = NULL;
if (forwarders != NULL)
/*
* Dual Stack Servers.
*/
alternates = NULL;
if (alternates != NULL)
/*
* We have default hints for class IN if we need them.
*/
/*
* If we still have no hints, this is a non-IN view with no
* "hints zone" configured. Issue a warning, except if this
* is a root server. Root servers never need to consult
* their hints, so it's no point requiring users to configure
* them.
*/
}
if (need_hints)
"no root hints for view '%s'",
}
/*
* Configure the view's TSIG keys.
*/
}
/*
* See if we can re-use a dynamic key ring.
*/
goto cleanup;
} else
/*
* Configure the view's peer list.
*/
{
const cfg_listelt_t *element;
{
}
}
/*
* Configure the views rrset-order.
*/
{
const cfg_listelt_t *element;
{
}
}
/*
* Copy the aclenv object.
*/
/*
* Configure the "match-clients" and "match-destinations" ACL.
*/
/*
* Configure the "match-recursive-only" option.
*/
else
/*
* Configure other configurable data.
*/
else
INSIST(0);
/*
* targets for authoritative answers may be found.
*/
"'additional-from-auth no' is only supported "
"with 'recursion no'");
}
"'additional-from-cache no' is only supported "
"with 'recursion no'");
}
/*
* Set "allow-query-cache", "allow-query-cache-on",
* "allow-recursion", and "allow-recursion-on" acls if
* configured in named.conf.
*/
&view->recursionacl));
&view->recursiononacl));
}
/*
* "allow-query-cache" inherits from "allow-recursion" if set,
* otherwise from "allow-query" if set.
* "allow-recursion" inherits from "allow-query-cache" if set,
* otherwise from "allow-query" if set.
*/
/*
* XXXEACH: This call to configure_view_acl() is redundant. We
* are leaving it as it is because we are making a minimal change
* for a patch release. In the future this should be changed to
* dns_acl_attach(view->queryacl, &view->cacheacl).
*/
/*
* Set default "allow-recursion", "allow-recursion-on" and
* "allow-query-cache" acls.
*/
"allow-recursion", NULL,
&view->recursionacl));
"allow-recursion-on", NULL,
&view->recursiononacl));
"allow-query-cache", NULL,
else
}
/*
* Ignore case when compressing responses to the specified
* clients. This causes case not always to be preserved,
* and is needed by some broken clients.
*/
/*
* Filter setting on addresses in the answer section.
*/
"except-from", ns_g_mctx,
&view->answeracl_exclude));
/*
*/
"name", ns_g_mctx,
&view->denyanswernames));
"except-from", ns_g_mctx,
&view->answernames_exclude));
/*
* Configure sortlist, if set
*/
/*
* Configure default allow-transfer, allow-notify, allow-update
* and allow-update-forwarding ACLs, if set, so they can be
* inherited by zones.
*/
#ifdef ISC_PLATFORM_USESIT
#endif
#ifdef ALLOW_FILTER_AAAA
if (cfg_obj_isboolean(obj)) {
if (cfg_obj_asboolean(obj))
else
} else {
else
INSIST(0);
}
if (cfg_obj_isboolean(obj)) {
if (cfg_obj_asboolean(obj))
else
} else {
else
INSIST(0);
}
#endif
if (result == ISC_R_SUCCESS) {
if (cfg_obj_isvoid(eligible)) {
int i;
"prefetch", &obj);
if (cfg_obj_isuint32(eligible))
break;
}
}
}
if (result == ISC_R_SUCCESS) {
/* If set to "auto", use the version from the defaults */
const char *dom;
/* If "no", skip; if "auto", use global default */
"dnssec-lookaside", &obj);
}
}
}
if (result == ISC_R_SUCCESS) {
{
const char *str;
isc_buffer_t b;
"trust-anchor"));
}
} else
/*
* For now, there is only one kind of trusted keys, the
* "security roots".
*/
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
else
view->preferred_glue = 0;
} else
view->preferred_glue = 0;
if (result == ISC_R_SUCCESS) {
if (!cfg_obj_isvoid(obj)) {
isc_buffer_t b;
const char *str;
0, NULL));
name));
}
}
} else
/*
* Setup automatic empty zones. If recursion is off then
* they are disabled by default.
*/
else
} else {
}
if (empty_zones_enable && !lwresd_g_useresolvconf) {
const char *empty;
int empty_zone = 0;
const char *str;
const char *empty_dbtype[4] =
int empty_dbtypec = 4;
if (result == ISC_R_SUCCESS) {
NULL));
} else
if (result == ISC_R_SUCCESS) {
NULL));
} else
if (cfg_obj_isboolean(obj)) {
if (cfg_obj_asboolean(obj))
else
} else {
else
INSIST(0);
}
{
/*
* Look for zone on drop list.
*/
NULL));
if (disablelist != NULL &&
continue;
/*
* This zone already exists.
*/
continue;
}
/*
* If we would forward this name don't add a
* empty zone for it.
*/
&forwarders);
if (result == ISC_R_SUCCESS &&
continue;
/*
* See if we can re-use a existing zone.
*/
&pview);
if (result != ISC_R_NOTFOUND &&
result != ISC_R_SUCCESS)
goto cleanup;
}
statlevel));
}
}
if (result == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
goto cleanup;
}
if (resquerystats != NULL)
return (result);
}
static isc_result_t
if (result == ISC_R_SUCCESS) {
dns_db_detach(&db);
}
return (result);
}
static isc_result_t
const cfg_obj_t *alternates)
{
const cfg_listelt_t *element;
/*
* Determine which port to send requests to.
*/
if (ns_g_lwresdonly && ns_g_port != 0)
else
if (alternates != NULL) {
if (cfg_obj_isuint32(portobj)) {
if (val > ISC_UINT16_MAX) {
"port '%u' out of range", val);
return (ISC_R_RANGE);
}
}
}
if (alternates != NULL)
{
if (!cfg_obj_issockaddr(alternate)) {
alternate, "name"));
NULL));
if (cfg_obj_isuint32(portobj)) {
if (val > ISC_UINT16_MAX) {
"port '%u' out of range",
val);
return (ISC_R_RANGE);
}
}
continue;
}
if (isc_sockaddr_getport(&sa) == 0)
NULL, 0));
}
return (result);
}
static isc_result_t
{
const cfg_obj_t *faddresses;
const cfg_listelt_t *element;
/*
* Determine which port to send forwarded requests to.
*/
if (ns_g_lwresdonly && ns_g_port != 0)
else
if (forwarders != NULL) {
if (cfg_obj_isuint32(portobj)) {
if (val > ISC_UINT16_MAX) {
"port '%u' out of range", val);
return (ISC_R_RANGE);
}
}
}
/*
* DSCP value for forwarded requests.
*/
if (forwarders != NULL) {
if (cfg_obj_isuint32(dscpobj)) {
"dscp value '%u' is out of range",
return (ISC_R_RANGE);
}
}
}
faddresses = NULL;
if (forwarders != NULL)
{
goto cleanup;
}
}
if (ISC_LIST_EMPTY(fwdlist)) {
if (forwardtype != NULL)
"no forwarders seen; disabling "
"forwarding");
} else {
if (forwardtype == NULL)
else {
else
INSIST(0);
}
}
if (result != ISC_R_SUCCESS) {
char namebuf[DNS_NAME_FORMATSIZE];
"could not set up forwarding for domain '%s': %s",
goto cleanup;
}
while (!ISC_LIST_EMPTY(fwdlist)) {
}
return (result);
}
static isc_result_t
{
const char *viewname;
&viewclass);
} else {
viewname = "_default";
}
return (result);
}
/*
* Find a view based on its configuration info and attach to it.
*
* If 'vconfig' is NULL, attach to the default view.
*/
static isc_result_t
dns_view_t **viewp)
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_SUCCESS);
}
/*
* Create a new view and add it to the list.
*
* If 'vconfig' is NULL, create the default view.
*
* The view created is attached to '*viewp'.
*/
static isc_result_t
dns_view_t **viewp)
{
if (result != ISC_R_SUCCESS)
return (result);
if (result == ISC_R_SUCCESS)
return (ISC_R_EXISTS);
if (result != ISC_R_NOTFOUND)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS) {
return (result);
}
#ifdef HAVE_GEOIP
#endif
return (ISC_R_SUCCESS);
}
/*
* Configure or reconfigure a zone.
*/
static isc_result_t
{
const char *zname;
const char *ztypestr;
/*
* Get the zone origin as a dns_name_t.
*/
"name"));
else
vname = "<default view>";
"zone '%s': wrong class for view '%s'",
goto cleanup;
}
"'in-view' option is not permitted in "
"dynamically added zones");
goto cleanup;
}
&otherview);
if (result != ISC_R_SUCCESS) {
"view '%s' is not yet defined.", inview);
goto cleanup;
}
if (result != ISC_R_SUCCESS) {
"zone '%s' not defined in view '%s'",
goto cleanup;
}
/*
* If the zone contains a 'forwarders' statement, configure
* selective forwarding. Note: this is not inherited from the
* other view.
*/
forwarders = NULL;
if (result == ISC_R_SUCCESS) {
forwardtype = NULL;
}
goto cleanup;
}
"zone '%s' 'type' not specified", zname);
goto cleanup;
}
/*
* "hints zones" aren't zones. If we've got one,
* configure it and return.
*/
"zone '%s': 'file' not specified",
zname);
goto cleanup;
}
if (result != ISC_R_SUCCESS) {
"could not configure root hints "
"from '%s': %s", hintsfile,
goto cleanup;
}
/*
* Hint zones may also refer to delegation only points.
*/
&only);
} else {
"ignoring non-root hint zone '%s'",
zname);
}
/* Skip ordinary zone processing. */
goto cleanup;
}
/*
* "forward zones" aren't zones either. Translate this syntax into
* the appropriate selective forwarding configuration and return.
*/
forwardtype = NULL;
forwarders = NULL;
forwardtype));
/*
* Forward zones may also set delegation only.
*/
goto cleanup;
}
/*
* "delegation-only zones" aren't zones either.
*/
goto cleanup;
}
/*
* Redirect zones only require minimal configuration.
*/
"redirect zone already exists");
goto cleanup;
}
goto cleanup;
} else {
&zone));
zone));
}
goto cleanup;
}
/*
* Check for duplicates in the new zone table.
*/
if (result == ISC_R_SUCCESS) {
/*
* We already have this zone!
*/
"zone '%s' already exists", zname);
goto cleanup;
}
/*
* Note whether this is a response policy zone and which one if so.
*/
break;
}
break;
}
/*
* See if we can reuse an existing zone. This is
* only possible if all of these are true:
* - The zone's view exists
* - A zone with the right name exists in the view
* - The zone is compatible with the config
* options (e.g., an existing master zone cannot
* be reused if the options specify a slave zone)
* - The zone was not and is still not a response policy zone
* or the zone is a policy zone with an unchanged number
* and we are using the old policy zone summary data.
*/
goto cleanup;
goto cleanup;
/*
* We found a reusable zone. Make it use the
* new view.
*/
} else {
/*
* We cannot reuse an existing zone, we have
* to create a new one.
*/
}
if (rpz_num != DNS_RPZ_INVALID_NUM) {
if (result != ISC_R_SUCCESS) {
"zone '%s': incompatible"
" masterfile-format or database"
" for a response policy zone",
zname);
goto cleanup;
}
}
/*
* If the zone contains a 'forwarders' statement, configure
* selective forwarding.
*/
forwarders = NULL;
{
forwardtype = NULL;
forwardtype));
}
/*
* Stub and forward zones may also refer to delegation only points.
*/
{
if (cfg_obj_asboolean(only))
}
/*
* Mark whether the zone was originally added at runtime or not
*/
{
}
}
/*
* Configure the zone.
*/
/*
* Add the zone to its view in the new view list.
*/
/*
* Ensure that zone keys are reloaded on reconfig
*/
return (result);
}
/*
* Configure built-in zone for storing managed-key data.
*/
#define KEYZONE "managed-keys.bind"
#define MKEYS ".mkeys"
static isc_result_t
int n;
/* See if we can re-use an existing keydata zone. */
&pview);
if (result != ISC_R_NOTFOUND &&
result != ISC_R_SUCCESS)
return (result);
return (ISC_R_SUCCESS);
}
/* No existing keydata zone was found; create one */
goto cleanup;
}
"set up managed keys zone for view %s, file '%s'",
return (result);
}
/*
* Configure a single server quota.
*/
static void
{
}
/*
* This function is called as soon as the 'directory' statement has been
* parsed. This can be extended to support other options if necessary.
*/
static isc_result_t
const char *directory;
/*
* Change directory.
*/
if (! isc_file_ischdiridempotent(directory))
"option 'directory' contains relative path '%s'",
if (result != ISC_R_SUCCESS) {
"change directory to '%s' failed: %s",
return (result);
}
return (ISC_R_SUCCESS);
}
static void
#ifdef HAVE_GEOIP
#endif
/*
* Update the "localhost" and "localnets" ACLs to match the
* current set of network interfaces.
*/
#ifdef HAVE_GEOIP
#endif
}
static isc_result_t
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto clean;
if (result != ISC_R_SUCCESS)
goto clean;
}
return (ISC_R_SUCCESS);
return (result);
}
/*
* Make a list of xxx-source addresses and call ns_interfacemgr_adjust()
* to update the listening interfaces accordingly.
* We currently only consider IPv6, because this only affects IPv6 wildcard
* sockets.
*/
static void
if (result != ISC_R_SUCCESS)
return;
continue;
if (result != ISC_R_SUCCESS)
goto fail;
/*
* We always add non-wildcard address regardless of whether
* the port is 'any' (the fourth arg is TRUE): if the port is
* specific, we need to add it since it may conflict with a
* listening interface; if it's zero, we'll dynamically open
* query ports, and some of them may override an existing
* wildcard IPv6 port.
*/
/* XXXMPA fix dscp */
if (result != ISC_R_SUCCESS)
goto fail;
}
result == ISC_R_SUCCESS;
/*
* At this point the zone list may contain a stale zone
* just removed from the configuration. To see the validity,
* check if the corresponding view is in our current view list.
* There may also be old zones that are still in the process
* of shutting down and have detached from their old view
* (zoneview == NULL).
*/
continue;
;
continue;
if (result != ISC_R_SUCCESS)
goto fail;
if (result != ISC_R_SUCCESS)
goto fail;
}
return;
fail:
/*
* Even when we failed the procedure, most of other interfaces
* should work correctly. We therefore just warn it.
*/
"could not adjust the listen-on list; "
"some interfaces may not work");
goto clean;
}
/*
* This event callback is invoked to do periodic network interface
* scanning. It is also called by ns_server_scan_interfaces(),
* invoked by "rndc scan"
*/
static void
/*
* XXX should scan interfaces unlocked and get exclusive access
* only to replace ACLs.
*/
}
static void
}
}
static void
static unsigned int oldrequests = 0;
unsigned int requests = ns_client_requests;
/*
* Don't worry about wrapping as the overflow result will be right.
*/
}
/*
* Replace the current value of '*field', a dynamically allocated
* string or NULL, with a dynamically allocated copy of the
* null-terminated string pointed to by 'value', or NULL.
*/
static isc_result_t
char *copy;
return (ISC_R_NOMEMORY);
} else {
}
return (ISC_R_SUCCESS);
}
/*
* Replace the current value of '*field', a dynamically allocated
* string or NULL, with another dynamically allocated string
* or NULL if whether 'obj' is a string or void value, respectively.
*/
static isc_result_t
if (cfg_obj_isvoid(obj))
else
}
static void
{
const char *resource;
return;
if (cfg_obj_isstring(obj)) {
else {
}
} else
result == ISC_R_SUCCESS ?
}
static void
}
static void
{
const cfg_listelt_t *element;
if (cfg_obj_isuint32(obj)) {
if (positive)
else
} else {
if (positive)
else {
hiport);
}
}
}
}
static isc_result_t
const char *type;
return (ISC_R_SUCCESS);
switch (dns_zone_gettype(zone)) {
case dns_zone_master:
type = "master";
break;
case dns_zone_slave:
type = "slave";
break;
case dns_zone_stub:
type = "stub";
break;
case dns_zone_staticstub:
type = "static-stub";
break;
case dns_zone_redirect:
type = "redirect";
break;
default:
type = "other";
break;
}
return (ISC_R_SUCCESS);
}
static void
}
}
server->session_keybits = 0;
}
static isc_result_t
{
char key_txtsecret[256];
char key_rawsecret[64];
"generating session key for dynamic DNS");
/* generate key */
if (result != ISC_R_SUCCESS)
return (result);
/*
* Dump the key to the buffer for later use. Should be done before
* we transfer the ownership of key to tsigkey.
*/
/* Store the key in tsigkey. */
&tsigkey));
/* Dump the key to the key file. */
"could not create %s", filename);
goto cleanup;
}
"\talgorithm %s;\n"
(int) isc_buffer_usedlength(&key_txtbuffer),
(char*) isc_buffer_base(&key_txtbuffer));
dst_key_free(&key);
return (ISC_R_SUCCESS);
"failed to generate session key "
if (isc_file_exists(filename))
(void)isc_file_remove(filename);
(void)isc_stdio_close(fp);
}
dst_key_free(&key);
return (result);
}
static isc_result_t
{
unsigned int algtype;
if (result == ISC_R_SUCCESS) {
if (cfg_obj_isvoid(obj))
else
} else
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS) {
const char *s = " (keeping current key)";
"unsupported or unknown algorithm '%s'%s",
return (result);
}
/* See if we need to (re)generate a new key. */
}
if (need_deleteold) {
}
if (need_createnew) {
goto cleanup;
goto cleanup;
&server->sessionkey));
}
return (result);
return (result);
}
static isc_result_t
{
int i = 0;
if (result == ISC_R_SUCCESS)
maps[i++] = ns_g_defaults;
if (result == ISC_R_SUCCESS)
if (!allow) {
return (ISC_R_SUCCESS);
}
return (ISC_R_NOMEMORY);
}
/*
* Attempt to create a parser and parse the newzones
* file. If successful, preserve both; otherwise leave
* them NULL.
*/
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
}
}
return (ISC_R_SUCCESS);
}
static int
const cfg_listelt_t *element;
int n = 0;
n++;
return (n);
}
static isc_result_t
{
const cfg_listelt_t *element;
const cfg_obj_t *builtin_views;
int i;
int num_zones = 0;
struct cfg_context *nzctx;
unsigned int maxsocks;
/* Create the ACL configuration context */
if (ns_g_aclconfctx != NULL)
/*
* Parse the global default pseudo-config file.
*/
if (first_time) {
&ns_g_defaults) == ISC_R_SUCCESS);
}
/*
* Parse the configuration file using the new config code.
*/
/*
* Unless this is lwresd with the -C option, parse the config file.
*/
if (!(ns_g_lwresdonly && lwresd_g_useresolvconf)) {
ISC_LOG_INFO, "loading configuration from '%s'",
filename);
&cfg_type_namedconf, &config);
}
/*
* If this is lwresd with the -C option, or lwresd with no -C or -c
* option where the above parsing failed, parse resolv.conf.
*/
if (ns_g_lwresdonly &&
{
ISC_LOG_INFO, "loading configuration from '%s'",
if (conf_parser != NULL)
&config);
}
/*
* Check the validity of the configuration.
*/
/*
* Fill in the maps array, used for resolving defaults.
*/
i = 0;
if (result == ISC_R_SUCCESS)
maps[i++] = ns_g_defaults;
/*
* If bind.keys exists, load it. If "dnssec-validation auto"
* is turned on, the root key found there will be used as a
* default trust anchor, and if "dnssec-lookaside auto" is
* turned on, then the DLV key found there will too.
*/
"reading built-in trusted "
&bindkeys_parser));
}
/* Ensure exclusive access to configuration data. */
if (!exclusive) {
}
/*
* Set process limits, which (usually) needs to be done as root.
*/
/*
* Check if max number of open sockets that the system allows is
* sufficiently large. Failing this condition is not necessarily fatal,
* but may cause subsequent runtime failures for a busy recursive
* server.
*/
if (result != ISC_R_SUCCESS)
maxsocks = 0;
" is smaller than max sockets (%u)",
}
/*
* Set the number of socket reserved for TCP, stdio etc.
*/
if (maxsocks != 0) {
reserved = 0;
}
if (reserved < 128U)
reserved = 128;
"less than 128 UDP sockets available after "
"applying 'reserved-sockets' and 'maxsockets'");
}
#ifdef HAVE_GEOIP
/*
* Initialize GeoIP databases from the configured location.
* This should happen before configuring any ACLs, so that we
* know what databases are available and can reject any GeoIP
* ACLs that can't work.
*/
char *dir;
} else
#endif /* HAVE_GEOIP */
/*
* Configure various server options.
*/
&server->recursionquota);
else
&server->blackholeacl));
"configuring statistics server(s)");
/*
* Configure sets of UDP query source ports.
*/
"creating UDP port set");
"creating UDP port set");
usev4ports = NULL;
usev6ports = NULL;
avoidv4ports = NULL;
avoidv6ports = NULL;
if (usev4ports != NULL)
else {
&udpport_high),
if (udpport_low == udpport_high)
else {
}
}
if (avoidv4ports != NULL)
if (usev6ports != NULL)
else {
&udpport_high),
if (udpport_low == udpport_high)
else {
}
}
if (avoidv6ports != NULL)
/*
* Set the EDNS UDP size when we don't match a view.
*/
if (udpsize < 512)
udpsize = 512;
if (udpsize > 4096)
udpsize = 4096;
/*
* Configure the zone manager.
*/
/*
* Determine which port to use for listening for incoming connections.
*/
if (ns_g_port != 0)
else
/*
* Determing the default DSCP code point.
*/
/*
* Find the listen queue depth.
*/
ns_g_listen = 10;
/*
* Configure the interface manager according to the "listen-on"
* statement.
*/
{
/*
* Even though listen-on is present in the default
* configuration, we can't use it here, since it isn't
* used if we're in lwresd mode. This way is easier.
*/
/* check return code? */
&listenon);
} else if (!ns_g_lwresdonly) {
/*
* Not specified, use default.
*/
}
listenon);
}
}
/*
* Ditto for IPv6.
*/
{
/* check return code? */
&listenon);
} else if (!ns_g_lwresdonly) {
/*
* Not specified, use default.
*/
}
listenon);
}
}
/*
* Rescan the interface list to pick up changes in the
* listen-on option. It's important that we do this before we try
* to configure the query source, since the dispatcher we use might
* be shared with an interface.
*/
/*
* Arrange for further interface scanning to occur periodically
* as specified by the "interface-interval" option.
*/
if (interface_interval == 0) {
}
/*
* Enable automatic interface scans.
*/
/*
* Configure the dialup heartbeat timer.
*/
if (heartbeat_interval == 0) {
}
/*
* Write the PID file.
*/
if (cfg_obj_isvoid(obj))
else
else if (ns_g_lwresdonly)
else
/*
* Configure the server-wide session key. This must be done before
* configure views because zone configuration may need to know
* session-keyname.
*
* Failure of session key generation isn't fatal at this time; if it
* turns out that a session key is really needed but doesn't exist,
* we'll treat it as a fatal error then.
*/
/*
* Create the views and count all the configured zones in
* order to correctly size the zone manager's task table.
* (We only count zones for configured views; the built-in
* "bind" view can be ignored as it only adds a negligible
* number of zones.)
*
* If we're allowing new zones, we need to be able to find the
* new zone file and count those as well. So we setup the new
* zone configuration context, but otherwise view configuration
* waits until after the zone manager's task list has been sized.
*/
{
}
/*
* If there were no explicit views then we do the default
* view here.
*/
}
/*
* Zones have been counted; set the zone manager task pool size.
*/
"sizing zone task pool based on %d zones", num_zones);
/*
* Configure and freeze all explicit views. Explicit
* views that have zones were already created at parsing
* time, but views with no zones must be created here.
*/
{
}
/*
* Make sure we have a default view if and only if there
* were no explicit views.
*/
}
/*
* Create (or recreate) the built-in views.
*/
&builtin_views) == ISC_R_SUCCESS);
{
}
/* Now combine the two viewlists into one */
/* Swap our new view list with the production one. */
/* Make the view list available to each of the views */
}
/* Swap our new cache list with the production one. */
/* Load the TKEY information from the configuration. */
dns_tkeyctx_t *t = NULL;
&t),
"configuring TKEY");
}
/*
* Bind the control port(s).
*/
"binding control channel(s)");
/*
* Bind the lwresd port(s).
*/
"binding lightweight resolver ports");
/*
* Open the source of entropy.
*/
if (first_time) {
if (result != ISC_R_SUCCESS) {
"no source of entropy found");
} else {
if (result != ISC_R_SUCCESS)
"could not open entropy source "
"%s: %s",
#ifdef PATH_RANDOMDEV
if (ns_g_fallbackentropy != NULL) {
if (result != ISC_R_SUCCESS) {
"using pre-chroot entropy source "
"%s",
&ns_g_entropy);
}
}
#endif
}
}
/*
* Relinquish root privileges.
*/
if (first_time)
/*
* Check that the working directory is writable.
*/
"the working directory is not writable");
}
/*
* Configure the logging system.
*
* Do this after changing UID to make sure that any log
* files specified in named.conf get created by the
* unprivileged user, not root.
*/
if (ns_g_logstderr) {
"not using config file logging "
"statement for logging due to "
"-g option");
if (result != ISC_R_SUCCESS) {
"checking logging configuration "
"failed: %s",
goto cleanup;
}
}
} else {
"creating new logging configuration");
"configuring logging");
} else {
"setting up default logging channels");
"setting up default 'category unmatched'");
"setting up default 'category default'");
}
"installing logging configuration");
"now using logging configuration from "
"config file");
}
/*
* Set the default value of the query logging flag depending
* whether a "queries" category has been defined. This is
* a disgusting hack, but we need to do this for BIND 8
* compatibility.
*/
if (first_time) {
} else {
&categories);
if (categories != NULL) {
const cfg_listelt_t *element;
{
const char *str;
}
}
}
}
else
else if (ns_g_memstatistics)
ns_main_setmemstats("named.memstats");
else
"strdup");
"strdup");
"strdup");
"strdup");
if (result == ISC_R_SUCCESS) {
} else {
}
if (result == ISC_R_SUCCESS) {
} else {
}
/* The parser translates "hostname" to ISC_TRUE */
} else if (result == ISC_R_SUCCESS) {
/* Found a quoted string */
} else {
}
if (result == ISC_R_SUCCESS) {
} else {
}
#ifdef ISC_PLATFORM_USESIT
if (result == ISC_R_SUCCESS) {
isc_buffer_t b;
goto cleanup;
#ifdef AES_SIT
if (isc_buffer_usedlength(&b) != ISC_AES128_KEYLENGTH)
"AES sit-secret must be on 128 bits");
#endif
#ifdef HMAC_SHA1_SIT
if (isc_buffer_usedlength(&b) != ISC_SHA1_DIGESTLENGTH)
"SHA1 sit-secret must be on 160 bits");
#endif
#ifdef HMAC_SHA256_SIT
if (isc_buffer_usedlength(&b) != ISC_SHA256_DIGESTLENGTH)
"SHA256 sit-secret must be on 256 bits");
#endif
} else {
NULL,
0);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
#endif
if (conf_parser != NULL) {
}
if (bindkeys_parser != NULL) {
}
/*
* This cleans up either the old production view list
* or our temporary list depending on whether they
* were swapped above or not.
*/
if (result == ISC_R_SUCCESS &&
}
/* Same cleanup for cache list. */
}
/*
* Adjust the listening interfaces in accordance with the source
* addresses specified in views and zones.
*/
if (isc_net_probeipv6() == ISC_R_SUCCESS)
/*
* Record the time of most recent configuration
*/
if (tresult != ISC_R_SUCCESS)
ns_main_earlyfatal("isc_time_now() failed: %s",
/* Relinquish exclusive access to configuration data. */
if (exclusive)
return (result);
}
static isc_result_t
view_loaded(void *arg) {
unsigned int refs;
/*
* Force zone maintenance. Do this after loading
* so that we know when we need to force AXFR of
* slave zones whose master files are missing.
*
* We use the zoneload reference counter to let us
* know when all views are finished.
*/
if (refs != 0)
return (ISC_R_SUCCESS);
ISC_LOG_NOTICE, "all zones loaded");
"forcing zone maintenance");
ISC_LOG_NOTICE, "running");
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int refs = 0;
return (ISC_R_NOMEMORY);
/*
* Schedule zones to be loaded from disk.
*/
{
if (result != ISC_R_SUCCESS &&
result != DNS_R_UPTODATE &&
result != DNS_R_CONTINUE)
goto cleanup;
}
if (result != ISC_R_SUCCESS &&
result != DNS_R_UPTODATE &&
result != DNS_R_CONTINUE)
goto cleanup;
}
/*
* 'dns_view_asyncload' calls view_loaded if there are no
* zones.
*/
}
if (refs == 0) {
} else if (init) {
/*
* Place the task manager into privileged mode. This
* ensures that after we leave task-exclusive mode, no
* other tasks will be able to run except for the ones
* that are loading zones. (This should only be done during
* the initial server setup; it isn't necessary during
* a reload.)
*/
}
return (result);
}
static isc_result_t
/*
* Load zone data from disk.
*/
{
/* Load managed-keys data */
}
/*
* Resume zone XFRs.
*/
return (result);
}
static void
"creating dispatch manager");
"creating interface manager");
"creating interface timer");
"creating heartbeat timer");
"creating pps timer");
"creating default configuration parser");
if (ns_g_lwresdonly)
ISC_TRUE),
"loading configuration");
else
"loading configuration");
}
void
}
static void
ISC_LOG_INFO, "shutting down%s",
if (ns_g_aclconfctx != NULL)
if (flush)
else
}
}
if (ns_g_sessionkey != NULL) {
}
#ifdef HAVE_GEOIP
#endif
}
void
/* Initialize configuration data with default values. */
#ifdef HAVE_GEOIP
/* Initialize GeoIP before using ACL environment */
#endif
/* Initialize server data structures. */
/* Must be first. */
"initializing DST");
&server->in_roothints),
"setting up root hints");
"initializing reload event lock");
sizeof(isc_event_t));
"allocating reload event");
"creating TKEY context");
/*
* Setup the server task, which is responsible for coordinating
* startup and shutdown of the server, as well as all exclusive
* tasks.
*/
"creating server task");
"isc_task_onshutdown");
"isc_app_onrun");
server->interface_interval = 0;
server->heartbeat_interval = 0;
"dns_zonemgr_create");
"dns_zonemgr_setsize");
"isc_mem_strdup");
"isc_stats_create");
"isc_mem_strdup");
"isc_mem_strdup");
"isc_mem_strdup");
"isc_mem_strdup");
"dns_stats_create (server)");
&server->rcvquerystats),
"dns_stats_create (rcvquery)");
"dns_stats_create (opcode)");
"dns_stats_create (zone)");
"dns_stats_create (resolver)");
"ns_controls_create");
server->dispatchgen = 0;
server->session_keybits = 0;
}
void
}
static void
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
exit(1);
}
static void
server->dispatchgen++;
}
static void
dispatch = nextdispatch) {
continue;
}
}
void
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
return;
break;
}
return;
}
goto cleanup;
}
attrs = 0;
switch (isc_sockaddr_pf(addr)) {
case AF_INET:
break;
case AF_INET6:
break;
default:
goto cleanup;
}
attrmask = 0;
if (result != ISC_R_SUCCESS)
goto cleanup;
return;
"unable to create dispatch for reserved port %s: %s",
}
static isc_result_t
if (result == ISC_R_SUCCESS) {
"reloading configuration succeeded");
} else {
"reloading configuration failed: %s",
}
return (result);
}
static isc_result_t
if (result == ISC_R_SUCCESS)
"reloading zones succeeded");
else
"reloading zones failed: %s",
return (result);
}
static void
if (result == ISC_R_SUCCESS)
"any newly configured zones are now loaded");
else
"loading new zones failed: %s",
cleanup: ;
}
/*
* Handle a reload event (from SIGHUP).
*/
static void
"received SIGHUP signal to reload zones");
}
void
}
void
"automatic interface rescan");
}
static char *
char *res;
do {
break;
} while (*res == '\0');
return (res);
}
/*
* Find the zone specified in the control channel command 'args',
* if any. If a zone is specified, point '*zonep' at it, otherwise
* set '*zonep' to NULL.
*
* If 'zonetxt' is set, the caller has already pulled a token
* off the command line that is to be used as the zone name. (This
* is done when it's necessary to check for an optional argument
* before the zone name, as in "rndc sync [-clean] zone".)
*/
static isc_result_t
{
char *classtxt;
if (skip) {
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
}
/* Look for the zone name. */
return (ISC_R_SUCCESS);
/* Look for the optional class name. */
/* Look for the optional view name. */
}
} else
if (result == ISC_R_NOTFOUND)
"no matching zone '%s' in any view",
zonetxt);
else if (result == ISC_R_MULTIPLE)
"zone '%s' was found in multiple views",
zonetxt);
} else {
if (result != ISC_R_SUCCESS) {
"no matching view '%s'", viewtxt);
goto report;
}
if (result != ISC_R_SUCCESS)
"no matching zone '%s' in view '%s'",
}
/* Partial match? */
if (result == DNS_R_PARTIALMATCH)
if (result != ISC_R_SUCCESS) {
if (tresult == ISC_R_SUCCESS)
}
return (result);
}
/*
* Act on a "retransfer" command from the command channel.
*/
{
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_UNEXPECTEDEND);
}
else
return (result);
}
/*
* Act on a "reload" command from the command channel.
*/
if (result != ISC_R_SUCCESS)
return (result);
if (result == ISC_R_SUCCESS)
msg = "server reload successful";
} else {
msg = "zone refresh queued";
} else {
switch (result) {
case ISC_R_SUCCESS:
msg = "zone reload successful";
break;
case DNS_R_CONTINUE:
msg = "zone reload queued";
break;
case DNS_R_UPTODATE:
msg = "zone reload up-to-date";
break;
default:
/* failure message will be generated by rndc */
break;
}
}
}
return (result);
}
/*
* Act on a "reconfig" command from the command channel.
*/
return (ISC_R_SUCCESS);
}
/*
* Act on a "notify" command from the command channel.
*/
const unsigned char msg[] = "zone notify queued";
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_SUCCESS);
}
/*
* Act on a "refresh" command from the command channel.
*/
const unsigned char msg1[] = "zone refresh queued";
const unsigned char msg2[] = "not a slave or stub zone";
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_UNEXPECTEDEND);
}
return (ISC_R_SUCCESS);
}
return (ISC_R_FAILURE);
}
char *ptr;
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
else
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
"query logging is now %s",
return (ISC_R_SUCCESS);
}
static isc_result_t
{
const cfg_listelt_t *element;
if (result != ISC_R_SUCCESS)
return (result);
{
if (result != ISC_R_SUCCESS)
goto cleanup;
}
return (ISC_R_SUCCESS);
return (result);
}
/*
* Create a listen list from the corresponding configuration
* data structure.
*/
static isc_result_t
{
if (!cfg_obj_isuint32(portobj)) {
if (ns_g_port != 0) {
} else {
if (result != ISC_R_SUCCESS)
return (result);
}
} else {
"port value '%u' is out of range",
return (ISC_R_RANGE);
}
}
if (!cfg_obj_isuint32(dscpobj))
else {
"dscp value '%u' is out of range",
return (ISC_R_RANGE);
}
}
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS) {
return (result);
}
return (ISC_R_SUCCESS);
}
(void)isc_stdio_close(fp);
if (result == ISC_R_SUCCESS)
"dumpstats complete");
else
"dumpstats failed: %s",
return (result);
}
static isc_result_t
struct zonelistentry *zle;
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
}
static isc_result_t
struct viewlistentry *vle;
/*
* Prevent duplicate views.
*/
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (result);
}
static void
struct viewlistentry *vle;
struct zonelistentry *zle;
}
}
}
static void
const dns_master_style_t *style;
if (result != ISC_R_SUCCESS)
goto cleanup;
goto done;
} else
goto resume;
";\n; Cache of view '%s' is shared as '%s'\n",
{
/* start cache dump */
";\n; Cache dump of view '%s' (cache %s)\n;\n",
if (result == DNS_R_CONTINUE)
return;
if (result == ISC_R_NOTIMPLEMENTED)
else if (result != ISC_R_SUCCESS)
goto cleanup;
}
}
}
else
/* start zone dump */
if (result != ISC_R_SUCCESS) {
goto nextzone;
}
if (result == DNS_R_CONTINUE)
return;
if (result == ISC_R_NOTIMPLEMENTED) {
goto nextzone;
}
if (result != ISC_R_SUCCESS)
goto cleanup;
}
}
goto nextview;
done:
if (result == ISC_R_SUCCESS)
"dumpdb complete");
if (result != ISC_R_SUCCESS)
}
char *ptr;
const char *sep;
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_NOMEMORY);
}
{
continue;
}
goto nextview;
}
return (ISC_R_SUCCESS);
return (result);
}
char *ptr;
char tbuf[64];
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
do {
{
continue;
if (result == ISC_R_NOTFOUND) {
continue;
}
if (result != ISC_R_SUCCESS)
if (result == ISC_R_NOTFOUND) {
continue;
}
if (result != ISC_R_SUCCESS)
}
(void)isc_stdio_close(fp);
if (result == ISC_R_SUCCESS)
"dumpsecroots complete");
else
"dumpsecroots failed: %s",
return (result);
}
if (result == ISC_R_SUCCESS)
"dumprecursing complete");
else
"dumprecursing failed: %s",
return (result);
}
char *ptr;
char *levelstr;
char *endp;
long newlevel;
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
/* Look for the new level name. */
if (ns_g_debuglevel < 99)
} else {
return (ISC_R_RANGE);
ns_g_debuglevel = (unsigned int)newlevel;
}
"debug level is now %d", ns_g_debuglevel);
return (ISC_R_SUCCESS);
}
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
/* Find out what we are to do. */
return (ISC_R_UNEXPECTEDEND);
else
return (DNS_R_SYNTAX);
/* Look for the view name. */
{
continue;
if (result != ISC_R_SUCCESS)
goto out;
if (set) {
} else {
unsigned int n;
if (!first) {
"\n");
if (n >= isc_buffer_availablelength(text)) {
goto out;
}
isc_buffer_add(text, n);
}
"DNSSEC validation is %s (view %s)",
"enabled" : "disabled",
if (n >= isc_buffer_availablelength(text)) {
goto out;
}
isc_buffer_add(text, n);
}
}
if (!set)
else if (changed)
else
out:
return (result);
}
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
/* Look for the view name. */
/*
* Flushing a cache is tricky when caches are shared by multiple views.
* We first identify which caches should be flushed in the local cache
* list, flush these caches, and then update other views that refer to
* the flushed cache DB.
*/
/*
* Mark caches that need to be flushed. This is an O(#view^2)
* operation in the very worst case, but should be normally
* much more lightweight because only a few (most typically just
* one) views will match.
*/
{
continue;
break;
}
}
} else
/* Perform flush */
continue;
if (result != ISC_R_SUCCESS) {
"flushing cache in view '%s' failed: %s",
}
}
/*
* Fix up views that share a flushed cache: let the views update the
* cache DB they're referring to. This could also be an expensive
* operation, but should typically be marginal: the inner loop is only
* necessary for views that share a cache, and if there are many such
* views the number of shared cache should normally be small.
* A worst case is that we have n views and n/2 caches, each shared by
* two views. Then this will be a O(n^2/4) operation.
*/
{
if (!dns_view_iscacheshared(view))
continue;
continue;
if (result != ISC_R_SUCCESS) {
"fixing cache in view '%s' "
}
}
}
/* Cleanup the cache list. */
}
"flushing cache in view '%s' succeeded",
viewname);
else
"flushing caches in all views succeeded");
} else {
if (!found) {
"flushing cache in view '%s' failed: "
"view not found", viewname);
} else
}
return (result);
}
isc_buffer_t b;
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
/* Find the domain name to flush. */
return (ISC_R_UNEXPECTEDEND);
if (result != ISC_R_SUCCESS)
return (result);
/* Look for the view name. */
{
continue;
/*
* It's a little inefficient to try flushing name for all views
* if some of the views share a single cache. But since the
* operation is lightweight we prefer simplicity here.
*/
if (result != ISC_R_SUCCESS) {
"flushing %s '%s' in cache view '%s' "
"failed: %s",
}
}
"flushing %s '%s' in cache view '%s' "
"succeeded",
else
"flushing %s '%s' in all cache views "
"succeeded",
target);
} else {
if (!found)
"flushing %s '%s' in cache view '%s' "
"failed: view not found",
}
return (result);
}
unsigned int automatic;
unsigned int n;
if (ns_g_server->version_set) {
ob = " (";
cb = ")";
alt = "version.bind/txt/ch disabled";
else
}
sizeof(boottime));
sizeof(configtime));
"version: %s%s%s%s <id:%s>\n"
"boot time: %s\n"
"last configured: %s\n"
#ifdef ISC_PLATFORM_USETHREADS
"CPUs found: %u\n"
"worker threads: %u\n"
"UDP listeners per interface: %u\n"
#endif
"number of zones: %u (%u automatic)\n"
"debug level: %d\n"
"xfers running: %u\n"
"xfers deferred: %u\n"
"soa queries in progress: %u\n"
"query logging is %s\n"
"recursive clients: %d/%d/%d\n"
"tcp clients: %d/%d\n"
"server is up and running",
#ifdef ISC_PLATFORM_USETHREADS
#endif
if (n >= isc_buffer_availablelength(text))
return (ISC_R_NOSPACE);
isc_buffer_add(text, n);
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int *foundkeys)
{
char namestr[DNS_NAME_FORMATSIZE];
origin);
if (result == ISC_R_NOTFOUND) {
return (ISC_R_SUCCESS);
}
return (result);
}
for (;;) {
goto nextkey;
(*foundkeys)++;
goto again;
}
}
if (result == ISC_R_NOMORE)
break;
return (result);
}
}
return (ISC_R_SUCCESS);
}
unsigned int n;
unsigned int foundkeys = 0;
char *target;
char *viewname;
return (ISC_R_UNEXPECTEDEND);
&foundkeys);
if (result != ISC_R_SUCCESS) {
return (result);
}
}
}
"%d tsig keys deleted.\n", foundkeys);
if (n >= isc_buffer_availablelength(text))
return (ISC_R_NOSPACE);
isc_buffer_add(text, n);
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int *foundkeys)
{
char namestr[DNS_NAME_FORMATSIZE];
char creatorstr[DNS_NAME_FORMATSIZE];
unsigned int n;
const char *viewname;
else
viewname = "(global)";
origin);
if (result == ISC_R_NOTFOUND) {
return (ISC_R_SUCCESS);
}
return (result);
}
for (;;) {
(*foundkeys)++;
sizeof(creatorstr));
"view \"%s\"; type \"dynamic\"; key \"%s\"; creator \"%s\";\n",
} else {
"view \"%s\"; type \"static\"; key \"%s\";\n",
}
if (n >= isc_buffer_availablelength(text)) {
return (ISC_R_NOSPACE);
}
isc_buffer_add(text, n);
}
if (result == ISC_R_NOMORE)
break;
return (result);
}
}
return (ISC_R_SUCCESS);
}
unsigned int n;
unsigned int foundkeys = 0;
&foundkeys);
if (result != ISC_R_SUCCESS) {
return (result);
}
&foundkeys);
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (foundkeys == 0) {
"no tsig keys found.\n");
if (n >= isc_buffer_availablelength(text))
return (ISC_R_NOSPACE);
isc_buffer_add(text, n);
}
return (ISC_R_SUCCESS);
}
/*
* Act on a "sign" or "loadkeys" command from the command channel.
*/
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_UNEXPECTEDEND); /* XXX: or do all zones? */
if (type != dns_zone_master) {
return (DNS_R_NOTMASTER);
}
/* "rndc loadkeys" requires "auto-dnssec maintain". */
if ((keyopts & DNS_ZONEKEY_ALLOW) == 0)
else
return (result);
}
/*
* Act on a "sync" command from the command channel.
*/
static isc_result_t
char *journal;
}
if (result != ISC_R_SUCCESS)
if (cleanup) {
(void)isc_file_remove(journal);
}
return (result);
}
char zonename[DNS_NAME_FORMATSIZE];
}
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS &&
tresult == ISC_R_SUCCESS)
}
"dumping all zones%s: %s",
return (tresult);
}
{
vname = "";
sep = "";
} else {
sep = " ";
}
sizeof(classstr));
"sync: dumping zone '%s/%s'%s%s%s: %s",
return (result);
}
/*
* Act on a "freeze" or "thaw" command from the command channel.
*/
{
char zonename[DNS_NAME_FORMATSIZE];
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS &&
tresult == ISC_R_SUCCESS)
}
"%s all zones: %s",
return (tresult);
}
}
if (type != dns_zone_master) {
return (DNS_R_NOTMASTER);
}
return (DNS_R_NOTDYNAMIC);
}
if (freeze) {
if (frozen) {
msg = "WARNING: The zone was already frozen.\n"
"Someone else may be editing it or "
"it may still be re-loading.";
}
if (result == ISC_R_SUCCESS) {
if (result != ISC_R_SUCCESS)
msg = "Flushing the zone updates to "
"disk failed.";
}
if (result == ISC_R_SUCCESS)
} else {
if (frozen) {
switch (result) {
case ISC_R_SUCCESS:
case DNS_R_UPTODATE:
msg = "The zone reload and thaw was "
"successful.";
break;
case DNS_R_CONTINUE:
msg = "A zone reload and thaw was started.\n"
"Check the logs to see the result.";
break;
}
}
}
{
vname = "";
sep = "";
} else {
sep = " ";
}
sizeof(classstr));
"%s zone '%s/%s'%s%s: %s",
return (result);
}
#ifdef HAVE_LIBSCF
/*
* This function adds a message for rndc to echo if named
* is managed by smf and is also running chroot.
*/
unsigned int n;
"use svcadm(1M) to manage named");
if (n >= isc_buffer_availablelength(text))
return (ISC_R_NOSPACE);
isc_buffer_add(text, n);
return (ISC_R_SUCCESS);
}
#endif /* HAVE_LIBSCF */
/*
* Emit a comment at the top of the nzf file containing the viewname
* Expects the fp to already be open for writing
*/
#define HEADER1 "# New zone file for view: "
#define HEADER2 "\n# This file contains configuration for zones added by\n" \
"# the 'rndc addzone' command. DO NOT EDIT BY HAND.\n"
return (result);
}
/*
* Act on an "addzone" command from the command channel.
*/
const cfg_listelt_t *element;
const char *zonename;
const char *argp;
char namebuf[DNS_NAME_FORMATSIZE];
/* Try to parse the argument string */
&config));
/* Make sense of optional class argument */
/* Make sense of optional view argument */
viewname = "_default";
/* Are we accepting new zones? */
goto cleanup;
}
goto cleanup;
}
/* Zone shouldn't already exist */
if (result == ISC_R_SUCCESS) {
goto cleanup;
} else if (result == DNS_R_PARTIALMATCH) {
/* Create our sub-zone anyway */
}
else if (result != ISC_R_NOTFOUND)
goto cleanup;
/* Find the view statement */
{
const char *vname;
break;
}
/* Open save file for write configuration */
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
if (offset == 0)
/* Mark view unfrozen so that zone can be added */
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
/* Is it there yet? */
/*
* Load the zone from the master file. If this fails, we'll
* need to undo the configuration we've done already.
*/
if (result != ISC_R_SUCCESS) {
"addzone failed; reverting.");
/* If the zone loaded partially, unload it */
dns_db_detach(&dbp);
}
/* Remove the zone from the zone table */
goto cleanup;
}
/* Flag the zone as having been added at runtime */
/* Emit the zone name, quoted and escaped */
/* Classname, if not default */
NULL));
}
/* Find beginning of option block from args */
/* Add that to our file */
/* Make sure we end with a LF */
}
break;
}
}
"zone %s added to view %s via addzone",
/* Adding a zone counts as reconfiguration */
if (isc_buffer_usedlength(text) > 0)
}
return (result);
}
static isc_boolean_t
#define INUSEMSG "The following files were in use and may now be removed:\n"
{
if (first)
else
return (ISC_FALSE);
}
return (first);
}
/*
* Act on a "delzone" command from the command channel.
*/
char buf[1024];
/* Parse parameters */
}
goto cleanup;
}
/*
* Was this zone originally added at runtime?
* If not, we can't delete it now.
*/
if (!dns_zone_getadded(zone)) {
goto cleanup;
}
/* Dig out configuration for this zone */
/* No adding zones in this view */
goto cleanup;
}
/* Rewrite zone list */
size_t n;
/* Create a temporary file */
(long)getpid()));
goto cleanup;
}
/* Look for the entry for that zone */
/* Skip initial comment, if any */
continue;
if (*buf != '#')
/*
* Any other lines not starting with zone, copy
* them out and continue.
*/
continue;
}
p = buf+4;
/* This is a zone; find its name. */
while (*p &&
((*p == '"') || isspace((unsigned char)*p)))
p++;
/*
* If it's not the zone we're looking for, copy
* it out and continue
*/
continue;
}
/*
* But if it is the zone we want, skip over it
* so it will be omitted from the new file
*/
p += znamelen;
if (isspace((unsigned char)*p) ||
*p == '"' || *p == '{') {
/* This must be the entry */
found = p;
break;
}
/* Copy the rest of the buffer out and continue */
}
/* Skip over an option block (matching # of braces) */
if (found) {
for (;;) {
while (*p) {
if (*p == '{') obrace++;
if (*p == '}') cbrace++;
p++;
}
break;
break;
p = buf;
}
/* Just spool the remainder of the file out */
while (n > 0U) {
}
/* Move temporary into place */
} else {
"deleted zone %s was missing from "
"new zone file", zonename);
goto cleanup;
}
}
/* Stop answering for this zone */
dns_db_detach(&dbp);
}
/* Clean up stub / slave zone files */
if (cleanup) {
if (isc_file_exists(file))
if (isc_file_exists(file))
if (isc_file_exists(file))
if (isc_file_exists(file))
}
{
}
}
"zone %s removed via delzone", zonename);
/* Removing a zone counts as reconfiguration */
if (isc_buffer_usedlength(text) > 0)
if (exclusive)
}
return (result);
}
static void
newzone_cfgctx_destroy(void **cfgp) {
struct cfg_context *cfg;
}
}
}
static isc_result_t
int i, n;
union {
unsigned char rnd[256];
} rnd;
isc_region_t r;
if (saltlen > 256U)
return (ISC_R_RANGE);
for (i = 0; i < n; i++)
"generated salt: %s", text);
return (ISC_R_SUCCESS);
}
unsigned char salt[255];
const char *ptr;
size_t n;
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
/* Find out what we are to do. */
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_UNEXPECTEDEND);
char nbuf[512];
return (ISC_R_UNEXPECTEDEND);
hash = 0;
else {
return (ISC_R_UNEXPECTEDEND);
if (n == sizeof(nbuf))
return (ISC_R_NOSPACE);
if (n != 3U)
return (ISC_R_BADNUMBER);
return (ISC_R_RANGE);
return (ISC_R_UNEXPECTEDEND);
/* Auto-generate a random salt.
* XXXMUKS: This currently uses the
* minimum recommended length by RFC
* 5155 (64 bits). It should be made
* configurable.
*/
saltlen = 8;
}
}
} else
if (clear) {
} else if (chain) {
ISC_TRUE));
} else if (list) {
if (result == ISC_R_NOTFOUND) {
goto cleanup;
}
result == ISC_R_SUCCESS;
{
if (!first)
"%s", output);
if (n >= isc_buffer_availablelength(text))
isc_buffer_add(text, (unsigned int)n);
}
if (!first)
if (result == ISC_R_NOMORE)
}
if (dns_rdataset_isassociated(&privset))
dns_db_detach(&db);
return (result);
}
static isc_result_t
/*
* Use >= to leave space for NUL termination.
*/
if (l >= isc_buffer_availablelength(b))
return (ISC_R_NOSPACE);
isc_buffer_putmem(b, (const unsigned char *)str, l);
return (ISC_R_SUCCESS);
}
static isc_result_t
putnull(isc_buffer_t *b) {
if (isc_buffer_availablelength(b) == 0)
return (ISC_R_NOSPACE);
isc_buffer_putuint8(b, 0);
return (ISC_R_SUCCESS);
}
int nfiles = 0;
goto cleanup;
}
switch (zonetype) {
case dns_zone_master:
type = "master";
break;
case dns_zone_slave:
type = "slave";
break;
case dns_zone_stub:
type = "stub";
break;
case dns_zone_staticstub:
type = "staticstub";
break;
case dns_zone_redirect:
type = "redirect";
break;
case dns_zone_key:
type = "key";
break;
case dns_zone_dlz:
type = "dlz";
break;
default:
type = "unknown";
}
/* Inline signing? */
if (hasraw)
/* Serial number */
if (hasraw) {
}
/* Database node count */
/* Security */
DNS_ZONEKEY_MAINTAIN) != 0);
/* Master files */
/* Load time */
if (zonetype == dns_zone_slave ||
zonetype == dns_zone_stub ||
{
}
/* Key refresh time */
if (zonetype == dns_zone_master ||
{
sizeof(kbuf));
}
/* Dynamic? */
if (zonetype == dns_zone_master) {
}
/* Next resign event */
{
if (result == ISC_R_SUCCESS) {
char namebuf[DNS_NAME_FORMATSIZE];
char typebuf[DNS_RDATATYPE_FORMATSIZE];
sizeof(rtbuf));
}
}
/* Create text */
int i;
for (i = 0; i < nfiles; i++) {
}
}
if (hasraw) {
}
if (! isc_time_isepoch(&loadtime)) {
}
if (! isc_time_isepoch(&refreshtime)) {
}
if (! isc_time_isepoch(&expiretime)) {
}
if (secure) {
if (hasraw)
else
} else
if (maintain) {
if (! isc_time_isepoch(&refreshkeytime)) {
}
} else if (allow)
if (!isc_time_isepoch(&resigntime)) {
}
if (dynamic) {
if (frozen)
else
} else
/* Indicate truncated output if possible. */
if (result == ISC_R_NOSPACE)
dns_db_detach(&db);
int i;
for (i = 0; i < nfiles; i++)
}
return (result);
}
static inline isc_boolean_t
size_t l;
return (ISC_FALSE);
cmd++;
return (ISC_FALSE);
return (ISC_TRUE);
}
isc_time_t t;
char tbuf[64];
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
for (;;) {
/* Check for options */
return (ISC_R_UNEXPECTEDEND);
ntattl = 0;
continue;
msg = "No lifetime specified";
}
if (result != ISC_R_SUCCESS) {
msg = "could not parse NTA lifetime";
}
if (ntattl > 604800) {
msg = "NTA lifetime cannot exceed one week";
}
continue;
} else
break;
}
/*
* If -dump was specified, list NTA's and return
*/
if (dump) {
{
if (result == ISC_R_NOTFOUND) {
continue;
}
}
goto cleanup;
}
/* Get the NTA name. */
return (ISC_R_UNEXPECTEDEND);
else {
isc_buffer_t b;
}
/* Look for the view name. */
{
continue;
continue;
if (!ttlset)
if (result == ISC_R_NOTFOUND) {
continue;
}
"flush tree '%s' in cache view '%s': %s",
if (ntattl != 0) {
isc_time_set(&t, when, 0);
"added NTA '%s' (%d sec) in view '%s'",
} else {
"removed NTA '%s' in view %s",
}
if (isc_buffer_availablelength(text) == 0)
return (ISC_R_NOSPACE);
isc_buffer_putuint8(text, 0);
}
}
if (excl)
return (result);
}