server.c revision 9615df2e83a322a00e4e3537b8ddb3b04f619a26
/*
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* 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 INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM 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.
*/
/* $Id: server.c,v 1.355 2001/10/26 23:04:17 gson Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/resource.h>
#include <dns/dispatch.h>
#include <dns/keytable.h>
#include <dns/rdataclass.h>
#include <dns/rdatastruct.h>
#include <dns/resolver.h>
#include <named/interfacemgr.h>
#include <named/tkeyconf.h>
#include <named/tsigconf.h>
#include <named/zoneconf.h>
/*
* Check an operation for failure. Assumes that the function
* using it has a 'result' variable and a 'cleanup' label.
*/
} while (0)
if (result != ISC_R_SUCCESS) { \
"%s: %s", msg, \
isc_result_totext(result)); \
goto cleanup; \
} \
} while (0) \
if (result != ISC_R_SUCCESS) \
} while (0) \
static void
static void
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
/*
* Configure a single view ACL at '*aclp'. Get its configuration by
* calling 'getvcacl' (for per-view configuration) and maybe 'getscacl'
* (for a global default).
*/
static isc_result_t
{
int i = 0;
}
/*
* No value available. *aclp == NULL.
*/
return (ISC_R_SUCCESS);
return (result);
}
static isc_result_t
{
char *keystr, *keynamestr;
unsigned char keydata[4096];
unsigned char rrdata[4096];
isc_region_t r;
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);
NULL));
return (ISC_R_SUCCESS);
if (result == DST_R_NOCRYPTO) {
"ignoring trusted key for '%s': no crypto support",
} else {
"configuring trusted key for '%s': %s",
}
return (result);
}
/*
* Configure DNSSEC keys for a view. Currently used only for
* the security roots.
*
* The per-view configuration values and the server-global defaults are read
* from 'vconfig' and 'config'. The variable to be configured is '*target'.
*/
static isc_result_t
{
{
{
}
}
return (result);
}
/*
* Get a dispatch appropriate for the resolver of a given view.
*/
static isc_result_t
{
/*
* Make compiler happy.
*/
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;
}
attrmask = 0;
1000, 32768, 16411, 16433,
if (result != ISC_R_SUCCESS) {
"could not get query source dispatcher");
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
char *str;
if (result != ISC_R_SUCCESS)
return (result);
else
INSIST(0);
}
if (result != ISC_R_SUCCESS)
goto cleanup;
}
return (ISC_R_SUCCESS);
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
{
int i;
char *str;
i = 0;
}
maps[i++] = ns_g_defaults;
i = 0;
/*
* Set the view's port number for outgoing queries.
*/
/*
* Configure the zones.
*/
else
{
actx));
}
/*
* Configure the view's cache. Try to reuse an existing
* cache if possible, otherwise create a new cache.
* Note that the ADB is not preserved in either case.
*
* XXX Determining when it is safe to reuse 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. As more view attributes become
* configurable, we will have to add code here to check
* whether they have changed in ways that could
* invalidate the cache.
*/
&pview);
goto cleanup;
"reusing existing cache");
} else {
}
/*
* cache-file cannot be inherited if views are present, but this
* should be caught by the configuration checking stage.
*/
if (result == ISC_R_SUCCESS) {
if (!reused_cache)
}
if (cfg_obj_isstring(obj)) {
} else {
if (value > ISC_UINT32_MAX) {
"'max-cache-size "
value);
goto cleanup;
}
}
/*
* Resolver.
*
* XXXRTH Hardwired number of tasks.
*/
0, ns_g_dispatchmgr,
/*
* Set ADB cache size
*/
if (cfg_obj_isstring(obj)) {
} else {
if (value > ISC_UINT32_MAX) {
"'max-adb-size "
value);
goto cleanup;
}
if (max_adb_size == 0 && max_cache_size != 0) {
if (max_adb_size == 0)
}
}
/*
* Set resolver's lame-ttl.
*/
if (lame_ttl > 1800)
lame_ttl = 1800;
/*
* A global or view "forwarders" option, if present,
* creates an entry for "." in the forwarding table.
*/
forwardtype = NULL;
forwarders = NULL;
if (forwarders != 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.
*/
} else {
"no root hints for view '%s'",
}
}
/*
* Configure the view's TSIG keys.
*/
/*
* Configure the view's peer list.
*/
{
{
}
}
/*
* 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'");
}
/*
* For now, there is only one kind of trusted keys, the
* "security roots".
*/
return (result);
}
/*
* Create the special view that handles queries under "bind. CH".
*/
static isc_result_t
/* Transfer ownership. */
return (result);
}
/*
* Create the zone that handles queries for "version.bind. CH". The
* version string is returned either from the "version" configuration
* option or the global defaults.
*/
static isc_result_t
char *versiontext;
unsigned char buf[256];
isc_region_t r;
static unsigned char origindata[] = "\007version\004bind";
r.base = origindata;
r.length = sizeof(origindata);
dns_name_fromregion(&origin, &r);
if (cfg_obj_isvoid(obj))
return (ISC_R_SUCCESS);
if (len > 255)
dns_db_detach(&db);
return (result);
}
/*
* Create the zone that handles queries for "hostname.bind. CH". The
* hostname string is returned either from the "hostname" configuration
* option or the the result of gethostbyname().
*/
static isc_result_t
char *hostnametext;
unsigned char buf[256];
isc_region_t r;
static unsigned char origindata[] = "\010hostname\004bind";
r.base = origindata;
r.length = sizeof(origindata);
dns_name_fromregion(&origin, &r);
if (result == ISC_R_SUCCESS) {
if (cfg_obj_isvoid(obj))
return (ISC_R_SUCCESS);
if (len > 255)
} else {
if (result != ISC_R_SUCCESS)
return (ISC_R_SUCCESS); /* Silent failure */
}
dns_db_detach(&db);
return (result);
}
/*
* Create the special zone that handles queries for "authors.bind. CH".
* The strings returned list the BIND 9 authors.
*/
static isc_result_t
{
static const char origindata[] = "\007authors\004bind";
int i;
static const char *authors[] = {
"\014Mark Andrews",
"\015James Brister",
"\014Ben Cottrell",
"\015Michael Graff",
"\022Andreas Gustafsson",
"\012Bob Halley",
"\016David Lawrence",
"\013Danny Mayer",
"\013Damien Neil",
"\013Matt Nelson",
"\016Michael Sawyer",
"\020Brian Wellington",
NULL,
};
/*
* If a version string is specified, disable the authors.bind zone.
*/
return (ISC_R_SUCCESS);
r.base = origindata;
r.length = sizeof(origindata);
}
dns_db_detach(&db);
return (result);
}
static isc_result_t
if (result == ISC_R_SUCCESS) {
dns_db_detach(&db);
}
return (result);
}
static isc_result_t
{
/*
* 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);
}
}
}
faddresses = NULL;
if (forwarders != NULL)
{
goto cleanup;
}
if (isc_sockaddr_getport(sa) == 0)
}
if (ISC_LIST_EMPTY(addresses)) {
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(addresses)) {
}
return (result);
}
/*
* 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
const char *viewname;
&viewclass);
} else {
viewname = "_default";
}
if (result == ISC_R_SUCCESS)
return (ISC_R_EXISTS);
if (result != ISC_R_NOTFOUND)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
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;
}
"zone '%s' 'type' not specified", zname);
return (ISC_R_FAILURE);
}
/*
* "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,
} 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;
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;
}
/*
* 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)
*/
&pview);
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 the zone contains a 'forwarders' statement, configure
* selective forwarding.
*/
forwarders = NULL;
{
forwardtype = NULL;
forwardtype));
}
/*
* Configure the zone.
*/
/*
* Add the zone to its view in the new view list.
*/
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
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
/*
* Update the "localhost" and "localnets" ACLs to match the
* current set of network interfaces.
*/
}
/*
* This event callback is invoked to do periodic network
* interface scanning.
*/
static void
/*
* XXX should scan interfaces unlocked and get exclusive access
* only to replace ACLs.
*/
}
static void
}
}
static isc_result_t
char *p;
if (p == NULL)
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
}
static isc_result_t
char *p;
if (p == NULL)
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
}
static void
{
char *resource;
return;
if (cfg_obj_isstring(obj)) {
else {
}
} else
result == ISC_R_SUCCESS ?
}
static void
}
static isc_result_t
{
int i;
/* Ensure exclusive access to configuration data. */
/*
* Parse the global default pseudo-config file.
*/
if (first_time) {
&ns_g_defaults) ==
}
/*
* 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);
&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'",
&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;
/*
* Set process limits, which (usually) needs to be done as root.
*/
/*
* Configure various server options.
*/
&server->recursionquota);
/*
* Configure the zone manager.
*/
/*
* Determine which port to use for listening for incoming connections.
*/
if (ns_g_port != 0)
else
/*
* 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.
*/
&listenon);
} else if (!ns_g_lwresdonly) {
/*
* Not specified, use default.
*/
}
listenon);
}
}
/*
* Ditto for IPv6.
*/
{
&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) {
}
/*
* Configure the dialup heartbeat timer.
*/
if (heartbeat_interval == 0) {
}
/*
* 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.
*/
{
ns_g_mctx, &aclconfctx));
}
/*
* Make sure we have a default view if and only if there
* were no explicit views.
*/
/*
* No explicit views; there ought to be a default view.
* There may already be one created as a side effect
* of zone statements, or we may have to create one.
* In either case, we need to configure and freeze it.
*/
&aclconfctx));
}
/*
* Create (or recreate) the internal _bind view.
*/
/*
* Swap our new view 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).
*/
&aclconfctx),
"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",
}
}
/*
* Relinquish root privileges.
*/
if (first_time)
/*
* 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) {
"ignoring config file logging "
"statement due to -g option");
} else {
"creating new logging configuration");
"configuring logging");
} else {
"setting up default logging channels");
"setting up default 'category unmatched'");
"setting up default 'category default'");
}
if (result != ISC_R_SUCCESS) {
}
"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) {
if (categories != NULL) {
{
char *str;
}
}
}
if (cfg_obj_isvoid(obj))
else
else if (ns_g_lwresdonly)
else
else
}
/*
* This cleans up either the old production view list
* or our temporary list depending on whether they
* were swapped above or not.
*/
}
if (dispatchv4 != NULL)
if (dispatchv6 != NULL)
/* Relinquish exclusive access to configuration data. */
return (result);
}
static isc_result_t
/*
* Load zone data from disk.
*/
{
}
/*
* 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.
*/
return (result);
}
static isc_result_t
/*
* Load zone data from disk.
*/
{
}
return (result);
}
static void
"creating dispatch manager");
&server->interfacemgr),
"creating interface manager");
"creating interface timer");
"creating heartbeat timer");
"creating default configuration parser");
if (ns_g_lwresdonly)
ISC_TRUE),
"loading configuration");
else
"loading configuration");
"loading zones");
ISC_LOG_INFO, "running");
}
void
}
static void
ISC_LOG_INFO, "shutting down%s",
if (flush)
else
}
}
void
/* Initialize configuration data with default values. */
/* Initialize server data structures. */
&server->in_roothints),
"setting up root hints");
"initializing reload event lock");
sizeof(isc_event_t));
"allocating reload event");
"initializing DST");
"creating TKEY context");
/*
* Setup the server task, which is responsible for coordinating
* startup and shutdown of the server.
*/
"creating server task");
"isc_task_onshutdown");
"isc_app_onrun");
server->interface_interval = 0;
server->heartbeat_interval = 0;
"dns_zonemgr_create");
"isc_mem_strdup");
"dns_stats_alloccounters");
"isc_mem_strdup");
"ns_controls_create");
}
void
}
static void
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
exit(1);
}
static isc_result_t
if (result != ISC_R_SUCCESS)
"reloading configuration failed: %s",
return (result);
}
static void
if (result != ISC_R_SUCCESS) {
"reloading zones failed: %s",
}
cleanup: ;
}
static void
if (result != ISC_R_SUCCESS) {
"loading new zones failed: %s",
}
cleanup: ;
}
/*
* Handle a reload event (from SIGHUP).
*/
static void
}
void
}
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.
*/
static isc_result_t
const char *zonetxt;
char *classtxt;
/* 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. */
}
if (result != ISC_R_SUCCESS)
goto fail1;
if (result != ISC_R_SUCCESS)
goto fail1;
} else {
}
viewtxt = "_default";
if (result != ISC_R_SUCCESS)
goto fail1;
if (result != ISC_R_SUCCESS)
goto fail2;
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);
} else {
else
}
return (ISC_R_SUCCESS);
}
/*
* Act on a "reconfig" command from the command channel.
*/
return (ISC_R_SUCCESS);
}
/*
* Act on a "refresh" command from the command channel.
*/
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_SUCCESS);
}
"query logging is now %s",
return (ISC_R_SUCCESS);
}
static isc_result_t
{
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 (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS) {
return (result);
}
return (ISC_R_SUCCESS);
}
int i;
int ncounters;
"could not open statistics dump file");
for (i = 0; i < ncounters; i++)
server->querystats[i]);
result == ISC_R_SUCCESS;
{
char zonename[DNS_NAME_FORMATSIZE];
char *viewname;
for (i = 0; i < ncounters; i++) {
"d %s",
zonestats[i],
zonename);
}
}
}
if (result == ISC_R_NOMORE)
(void)isc_stdio_close(fp);
return (result);
}
"could not open dump file");
{
"could not dump view databases");
}
(void)isc_stdio_close(fp);
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;
}
return (ISC_R_SUCCESS);
}
/* Skip the command name. */
return (ISC_R_UNEXPECTEDEND);
/* Look for the view name. */
{
continue;
if (result != ISC_R_SUCCESS)
goto out;
}
if (flushed)
else
out:
return (result);
}
int n;
"number of zones: %d\n"
"debug level: %d\n"
"xfers running: %d\n"
"xfers deferred: %d\n"
"soa queries in progress: %d\n"
"query logging is %s\n"
"server is up and running",
if (n < 0)
return (ISC_R_NOSPACE);
isc_buffer_add(text, n);
return (ISC_R_SUCCESS);
}