server.c revision 4ff3597979acd7e74d26d4dde7e43bf9dfe4fdc3
/*
* 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.290 2001/02/08 18:01:33 halley Exp $ */
#include <config.h>
#include <stdlib.h>
#include <isc/resource.h>
#include <dns/confparser.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) \
typedef struct {
} ns_load_t;
static void
static void
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
(dns_c_view_t *, dns_c_ipmatchlist_t **),
(dns_c_ctx_t *, dns_c_ipmatchlist_t **),
{
/*
* No value available. *aclp == NULL.
*/
return (ISC_R_SUCCESS);
}
return (result);
}
static isc_result_t
{
unsigned char keydata[4096];
unsigned char rrdata[4096];
isc_region_t r;
else
&viewclass));
/*
* The key data in keystruct is not
* dynamically allocated.
*/
&keydatabuf));
isc_buffer_usedregion(&keydatabuf, &r);
NULL));
return (ISC_R_SUCCESS);
"configuring trusted key for '%s': "
return (result);
}
/*
* Configure DNSSEC keys for a view. Currently used only for
* the security roots.
*
* The per-view configuration values and their server-global
* defaults are are read from 'cview' and 'cctx' using
* the function 'cgetv' and 'cgets', respectively.
* The variable to be configured is '*target'.
*/
static isc_result_t
(dns_c_view_t *, dns_c_tkeylist_t **),
(dns_c_ctx_t *, dns_c_tkeylist_t **),
{
if (result != ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
}
} else if (result != ISC_R_NOTFOUND)
goto cleanup;
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:
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
break;
case AF_INET6:
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
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);
}
/*
* Configure 'view' according to 'cview', taking defaults from 'cctx'
* where values are missing in cview.
*
* When configuring the default view, cview will be NULL and the
* global defaults in cctx used exclusively.
*/
static isc_result_t
{
/*
* Set the view's port number for outgoing queries.
*/
if (result != ISC_R_SUCCESS)
port = 53;
/*
* 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 {
}
else
goto cleanup;
if (!reused_cache)
}
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
max_cache_size = 0;
/*
* XXX remove once rbt if fixed
*/
max_cache_size = 0;
/*
* Resolver.
*
* XXXRTH Hardwired number of tasks.
*/
&dispatch4));
&dispatch6));
0, ns_g_dispatchmgr,
/*
* Set resolver's lame-ttl.
*/
else
if (result == ISC_R_NOTFOUND)
if (result == ISC_R_NOTFOUND)
lame_ttl = 600;
if (lame_ttl > 18000)
lame_ttl = 18000;
/*
* Set resolver forwarding policy.
*/
{
}
/*
* 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 requireing users to configure
* them.
*/
} else {
"no root hints for view '%s'",
}
}
/*
* Configure the view's TSIG keys.
*/
/*
* Configure the view's peer list.
*/
{
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
}
/*
* Configure the "match-clients" ACL.
*/
&view->matchclients));
/*
* Configure other configurable data.
*/
&view->transfer_format);
if (result != ISC_R_SUCCESS)
&view->transfer_format);
if (result != ISC_R_SUCCESS)
/*
* Set sources where additional data, CNAMEs, and DNAMEs may be found.
*/
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
&view->recursionacl));
&view->v6synthesisacl));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
/*
* For now, there is only one kind of trusted keys, the
* "security roots".
*/
{
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
}
{
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
}
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 returned is that
* configured in 'cctx', or a compiled-in default if
* there is no "version" configuration option.
*/
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 (result != ISC_R_SUCCESS)
/*
* Removing the const qualifier from ns_g_version is ok
* because the resulting string is not modified, only
* copied into a new buffer.
*/
if (len > 255)
dns_db_detach(&db);
return (result);
}
/*
* Create the special view 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;
char *versiontext;
static const char *authors[] = {
"\014Mark Andrews",
"\015James Brister",
"\015Michael Graff",
"\022Andreas Gustafsson",
"\012Bob Halley",
"\016David Lawrence",
"\013Damien Neil",
"\016Michael Sawyer",
"\020Brian Wellington",
NULL,
};
/*
* If a version string is specified, disable the authors.bind zone.
*/
if (result == ISC_R_SUCCESS)
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
{
unsigned int i;
/*
* Determine which port to send forwarded requests to.
*/
if (ns_g_port != 0) {
} else {
if (result != ISC_R_SUCCESS)
port = 53;
}
if (forwarders != NULL) {
for (i = 0; i < forwarders->nextidx; i++) {
goto cleanup;
}
}
}
if (ISC_LIST_EMPTY(addresses))
else
{
forward == dns_c_forw_only);
if (forward == dns_c_forw_only)
}
if (result != ISC_R_SUCCESS)
goto cleanup;
while (!ISC_LIST_EMPTY(addresses)) {
}
return (result);
}
/*
* Find an existing view matching the name and class of 'cview'
* in 'viewlist', or create a new one and add it to the list.
*
* If 'cview' is NULL, find or create the default view.
*
* The view found or created is attached to '*viewp'.
*/
static isc_result_t
dns_view_t **viewp)
{
const char *viewname;
if (result != ISC_R_SUCCESS)
return (result);
} else {
viewname = "_default";
}
if (result == ISC_R_SUCCESS) {
return (ISC_R_SUCCESS);
}
if (result != ISC_R_NOTFOUND)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_SUCCESS);
}
/*
* Configure or reconfigure a zone. This callback function
* is called after parsing each "zone" statement in named.conf.
*/
static isc_result_t
void *uap)
{
char *corigin;
/*
* Get the zone origin as a dns_name_t.
*/
/* XXX casting away const */
/*
* Find or create the view in the new view list.
*/
"zone '%s': wrong class for view '%s'",
goto cleanup;
}
/*
* "hints zones" aren't zones. If we've got one,
* configure it and return.
*/
"zone '%s': 'file' not specified",
corigin);
goto cleanup;
}
} else {
"ignoring non-root hint zone '%s'",
corigin);
}
goto cleanup;
}
/*
* "forward zones" aren't zones either. Translate this syntax into
* the appropriate selective forwarding configuration and return.
*/
goto cleanup;
}
/*
* Check for duplicates in the new zone table.
*/
if (result == ISC_R_SUCCESS) {
/*
* We already have this zone!
*/
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 'forward' or 'forwarders' statements,
* configure selective forwarding.
*/
origin, forwarders));
/*
* 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 'options' statement has been
* parsed.
*/
static isc_result_t
/*
* Change directory.
*/
if (result != ISC_R_SUCCESS) {
ISC_LOG_ERROR, "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
}
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);
}
if (resource == DNS_C_SIZE_SPEC_DEFAULT) \
else if (resource == DNS_C_SIZE_SPEC_UNLIM) \
else \
value); \
result == ISC_R_SUCCESS ? \
isc_result_totext(result)); \
}
static void
}
static isc_result_t
{
char *pidfilename;
char *statsfilename;
char *dumpfilename;
char *randomdev;
#ifdef PATH_RANDOMDEV
char path_randomdev[] = PATH_RANDOMDEV;
#endif
/*
* Parse the configuration file creating a parse tree. Any
* 'zone' statements are handled immediately by calling
* configure_zone() through 'callbacks'.
*/
else {
ISC_LOG_INFO, "loading configuration from '%s'",
filename);
&callbacks);
}
if (result == ISC_R_FILENOTFOUND &&
{
ISC_LOG_INFO, "loading configuration from '%s'",
}
/*
* Set process limits, which (usually) needs to be done as root.
*/
/*
* Configure various server options.
*/
&server->blackholeacl));
/*
* Configure the zone manager.
*/
{
}
{
}
/*
* Determine which port to use for listening for incoming connections.
*/
if (ns_g_port != 0) {
} else {
if (result != ISC_R_SUCCESS)
listen_port = 53;
}
/*
* Configure the interface manager according to the "listen-on"
* statement.
*/
{
cctx,
&listenon);
} else if (!ns_g_lwresdonly) {
/*
* Not specified, use default.
*/
}
listenon);
}
}
/*
* Ditto for IPv6.
*/
{
cctx,
&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.
*/
{
&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.
*/
ns_g_mctx, &aclconfctx));
} else {
/*
* There are explicit views. There should not be
* a default view. If there is one, complain.
*/
if (result == ISC_R_SUCCESS) {
"when using 'view' statements, "
"all zones must be in views");
goto cleanup;
}
}
/*
* 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 OMAPI port(s).
*/
"binding control channel(s)");
/*
* Bind the lwresd port(s).
*/
"binding lightweight resolver ports");
/*
* Open the source of entropy.
*/
if (first_time) {
#ifdef PATH_RANDOMDEV
#endif
"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 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) {
}
}
else if (ns_g_lwresdonly)
else
if (result == ISC_R_NOTFOUND) {
} else {
}
if (result == ISC_R_NOTFOUND) {
} 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)
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 void
"creating dispatch manager");
&server->interfacemgr),
"creating interface manager");
"creating interface timer");
"creating heartbeat timer");
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
"initializing server configuration lock");
/* 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");
}
void
}
static void
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
exit(1);
}
static void
if (ns_g_lwresdonly)
else
if (result != ISC_R_SUCCESS) {
"reloading configuration failed: %s",
}
if (result != ISC_R_SUCCESS) {
"reloading zones failed: %s",
}
}
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 "reload" command from the command channel.
*/
if (result != ISC_R_SUCCESS)
return (result);
} else {
else
}
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 (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. */
else {
return (ISC_R_RANGE);
ns_g_debuglevel = (unsigned int)newlevel;
}
return (ISC_R_SUCCESS);
}