server.c revision 8a23742754e4640a298acb0d6bd7ed4da0c11798
/*
* Copyright (C) 1999, 2000 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.224 2000/10/04 23:18:58 bwelling Exp $ */
#include <config.h>
#include <stdlib.h>
#include <dns/confparser.h>
#include <dns/dispatch.h>
#include <dns/keytable.h>
#include <dns/rdatastruct.h>
#include <dns/resolver.h>
#include <dns/tkeyconf.h>
#include <dns/tsigconf.h>
#include <dns/zoneconf.h>
#include <named/interfacemgr.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);
}
/*
* 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) {
{
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));
}
} 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;
/*
* Attach load manager to view.
*/
/*
* 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;
} else {
}
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;
/*
* XXXRTH Temporary support for loading cache contents.
*/
if (ns_g_cachefile != NULL) {
}
/*
* Resolver.
*
* XXXRTH Hardwired number of tasks.
*/
&dispatch4));
&dispatch6));
0, ns_g_dispatchmgr,
/*
* 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. That's an error.
*/
"no root hints for view '%s'",
goto cleanup;
}
/*
* 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));
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;
static const char *authors[] = {
"\014Mark Andrews",
"\015James Brister",
"\015Michael Graff",
"\022Andreas Gustafsson",
"\012Bob Halley",
"\016David Lawrence",
"\016Michael Sawyer",
"\020Brian Wellington",
NULL,
};
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;
}
/*
* Master zones must have 'file' set.
*/
"zone '%s': 'file' not specified",
corigin);
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.
*/
}
/*
* 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
}
/*
* This event callback is invoked to do periodic network
* interface scanning.
*/
static void
}
static isc_result_t
{
char *pidfilename;
ISC_LOG_INFO, "loading configuration from '%s'",
filename);
/*
* Parse the configuration file creating a parse tree. Any
* 'zone' statements are handled immediately by calling
* configure_zone() through 'callbacks'.
*/
/*
* Configure various server options.
*/
/* dns_loadmgr_setlimit(server->loadmgr, 20); XXXMPA */
/*
* 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) {
} else {
}
/*
* 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 size 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");
/*
* 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");
}
else if (ns_g_lwresdonly)
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");
if (ns_g_lwresdonly)
ISC_TRUE),
"loading configuration");
else
"loading configuration");
"loading zones");
ISC_LOG_INFO, "running");
}
static void
ISC_LOG_INFO, "shutting down");
}
}
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");
"dns_zonemgr_create");
"dns_loadmgr_create");
}
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 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);
}