1999-01-19 06:32:53 +00:00
|
|
|
/*
|
1999-03-06 03:55:54 +00:00
|
|
|
* Copyright (C) 1999 Internet Software Consortium.
|
1999-01-19 06:32:53 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
1999-10-23 00:02:23 +00:00
|
|
|
#include <stdarg.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <isc/app.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <isc/assertions.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <isc/dir.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <isc/error.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/result.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <isc/rwlock.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <isc/socket.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/thread.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <isc/timer.h>
|
1999-12-16 22:24:22 +00:00
|
|
|
#include <isc/util.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
#include <dns/aclconf.h>
|
1999-12-02 22:38:34 +00:00
|
|
|
#include <dns/cache.h>
|
1999-10-13 17:50:21 +00:00
|
|
|
#include <dns/confparser.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <dns/db.h>
|
|
|
|
#include <dns/fixedname.h>
|
|
|
|
#include <dns/journal.h>
|
1999-08-05 22:14:43 +00:00
|
|
|
#include <dns/master.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/tkey.h>
|
|
|
|
#include <dns/tsig.h>
|
|
|
|
#include <dns/types.h>
|
1999-08-05 22:14:43 +00:00
|
|
|
#include <dns/view.h>
|
1999-10-13 17:50:21 +00:00
|
|
|
#include <dns/zone.h>
|
1999-12-16 23:11:07 +00:00
|
|
|
#include <dns/zoneconf.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-18 18:09:47 +00:00
|
|
|
#include <named/client.h>
|
1999-07-24 01:16:38 +00:00
|
|
|
#include <named/globals.h>
|
2000-01-13 23:32:41 +00:00
|
|
|
#include <named/interfacemgr.h>
|
|
|
|
#include <named/listenlist.h>
|
1999-10-22 19:35:19 +00:00
|
|
|
#include <named/log.h>
|
1999-09-24 01:42:22 +00:00
|
|
|
#include <named/rootns.h>
|
1999-07-24 01:16:38 +00:00
|
|
|
#include <named/server.h>
|
2000-01-13 23:32:41 +00:00
|
|
|
#include <named/types.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
/*
|
|
|
|
* Check an operation for failure. Assumes that the function
|
|
|
|
* using it has a 'result' variable and a 'cleanup' label.
|
|
|
|
*/
|
|
|
|
#define CHECK(op) \
|
|
|
|
do { result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) goto cleanup; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CHECKM(op, msg) \
|
|
|
|
do { result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) { \
|
|
|
|
isc_log_write(ns_g_lctx, \
|
|
|
|
NS_LOGCATEGORY_GENERAL, \
|
|
|
|
NS_LOGMODULE_SERVER, \
|
|
|
|
ISC_LOG_ERROR, \
|
|
|
|
"%s: %s", msg, \
|
|
|
|
isc_result_totext(result)); \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
} while (0) \
|
|
|
|
|
|
|
|
#define CHECKFATAL(op, msg) \
|
|
|
|
do { result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
fatal(msg, result); \
|
|
|
|
} while (0) \
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
typedef struct {
|
|
|
|
isc_mem_t * mctx;
|
|
|
|
dns_viewlist_t viewlist;
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclconfctx_t *aclconf;
|
1999-10-15 01:51:48 +00:00
|
|
|
} ns_load_t;
|
1999-10-13 17:50:21 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
static void fatal(char *msg, isc_result_t result);
|
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Configure 'view' according to 'cctx'.
|
|
|
|
*
|
|
|
|
* XXX reconfiguration should preserve cache contents.
|
|
|
|
*/
|
1999-10-15 01:51:48 +00:00
|
|
|
static isc_result_t
|
2000-01-21 19:24:01 +00:00
|
|
|
configure_view(dns_view_t *view, dns_c_ctx_t *cctx, isc_mem_t *mctx)
|
1999-10-15 01:51:48 +00:00
|
|
|
{
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_cache_t *cache;
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
1999-12-17 01:02:49 +00:00
|
|
|
isc_int32_t cleaning_interval;
|
2000-01-21 20:24:49 +00:00
|
|
|
dns_tsig_keyring_t *ring;
|
1999-10-15 01:51:48 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Cache.
|
|
|
|
*/
|
1999-12-02 22:38:34 +00:00
|
|
|
cache = NULL;
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_cache_create(mctx, ns_g_taskmgr, ns_g_timermgr,
|
|
|
|
view->rdclass, "rbt", 0, NULL, &cache));
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_view_setcache(view, cache);
|
1999-12-17 01:02:49 +00:00
|
|
|
cleaning_interval = 3600; /* Default is 1 hour. */
|
|
|
|
(void) dns_c_ctx_getcleaninterval(cctx, &cleaning_interval);
|
|
|
|
dns_cache_setcleaninginterval(cache, cleaning_interval);
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_cache_detach(&cache);
|
1999-05-03 19:56:23 +00:00
|
|
|
|
1999-10-25 18:59:20 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH Temporary support for loading cache contents.
|
|
|
|
*/
|
|
|
|
if (ns_g_cachefile != NULL) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_DEBUG(1), "loading cache '%s'",
|
|
|
|
ns_g_cachefile);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_db_load(view->cachedb, ns_g_cachefile));
|
1999-10-25 18:59:20 +00:00
|
|
|
}
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Resolver.
|
|
|
|
*
|
|
|
|
* XXXRTH hardwired number of tasks. Also, we'll need to
|
|
|
|
* see if we are dealing with a shared dispatcher in this view.
|
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_createresolver(view, ns_g_taskmgr, 31,
|
|
|
|
ns_g_socketmgr, ns_g_timermgr,
|
|
|
|
NULL));
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* We have default hints for class IN.
|
|
|
|
*/
|
2000-01-21 19:24:01 +00:00
|
|
|
if (view->rdclass == dns_rdataclass_in)
|
2000-01-18 23:38:42 +00:00
|
|
|
dns_view_sethints(view, ns_g_server->roothints);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-21 20:24:49 +00:00
|
|
|
/*
|
2000-01-21 23:55:12 +00:00
|
|
|
* Configure the view's TSIG keys.
|
2000-01-21 20:24:49 +00:00
|
|
|
*/
|
|
|
|
ring = NULL;
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_tsig_init(cctx, view->mctx, &ring));
|
2000-01-21 20:24:49 +00:00
|
|
|
dns_view_setkeyring(view, ring);
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
cleanup:
|
1999-08-05 22:14:43 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-12-08 21:27:08 +00:00
|
|
|
/*
|
|
|
|
* Create the special view that handles queries for
|
|
|
|
* "version.bind. CH". The version string returned is that
|
|
|
|
* configured in 'configctx', or a compiled-in default if
|
|
|
|
* there is no "version" configuration option.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
create_version_view(dns_c_ctx_t *configctx, dns_view_t **viewp) {
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result;
|
1999-12-08 21:27:08 +00:00
|
|
|
dns_db_t *db = NULL;
|
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
dns_dbversion_t *dbver = NULL;
|
|
|
|
dns_difftuple_t *tuple = NULL;
|
|
|
|
dns_diff_t diff;
|
|
|
|
dns_view_t *view = NULL;
|
|
|
|
char *versiontext;
|
2000-01-19 21:25:24 +00:00
|
|
|
unsigned char buf[256];
|
1999-12-08 21:27:08 +00:00
|
|
|
isc_region_t r;
|
|
|
|
size_t len;
|
|
|
|
dns_rdata_t rdata;
|
2000-01-21 19:24:01 +00:00
|
|
|
static unsigned char origindata[] = "\007version\004bind";
|
|
|
|
dns_name_t origin;
|
1999-12-08 21:27:08 +00:00
|
|
|
|
|
|
|
REQUIRE(viewp != NULL && *viewp == NULL);
|
|
|
|
|
|
|
|
dns_diff_init(ns_g_mctx, &diff);
|
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
dns_name_init(&origin, NULL);
|
|
|
|
r.base = origindata;
|
|
|
|
r.length = sizeof(origindata);
|
|
|
|
dns_name_fromregion(&origin, &r);
|
|
|
|
|
1999-12-08 21:27:08 +00:00
|
|
|
(void) dns_c_ctx_getversion(configctx, &versiontext);
|
|
|
|
if (versiontext == NULL)
|
|
|
|
versiontext = ns_g_version;
|
|
|
|
len = strlen(versiontext);
|
|
|
|
if (len > 255)
|
|
|
|
len = 255; /* Silently truncate. */
|
|
|
|
buf[0] = len;
|
|
|
|
memcpy(buf + 1, versiontext, len);
|
|
|
|
|
|
|
|
r.base = buf;
|
|
|
|
r.length = 1 + len;
|
|
|
|
dns_rdata_fromregion(&rdata, dns_rdataclass_ch, dns_rdatatype_txt, &r);
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_zone_create(&zone, ns_g_mctx));
|
|
|
|
CHECK(dns_zone_setorigin(zone, &origin));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_db_create(ns_g_mctx, "rbt", &origin, ISC_FALSE,
|
|
|
|
dns_rdataclass_ch, 0, NULL, &db));
|
|
|
|
|
|
|
|
CHECK(dns_db_newversion(db, &dbver));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_difftuple_create(ns_g_mctx, DNS_DIFFOP_ADD, &origin,
|
|
|
|
0, &rdata, &tuple));
|
1999-12-08 21:27:08 +00:00
|
|
|
dns_diff_append(&diff, &tuple);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_diff_apply(&diff, db, dbver));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
|
|
|
dns_db_closeversion(db, &dbver, ISC_TRUE);
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_create(ns_g_mctx, dns_rdataclass_ch, "_version",
|
|
|
|
&view));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_zone_replacedb(zone, db, ISC_FALSE));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_addzone(view, zone));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
|
|
|
dns_view_freeze(view);
|
|
|
|
|
|
|
|
/* Transfer ownership. */
|
|
|
|
*viewp = view;
|
|
|
|
view = NULL;
|
|
|
|
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (view != NULL)
|
|
|
|
dns_view_detach(&view);
|
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
if (dbver != NULL)
|
|
|
|
dns_db_closeversion(db, &dbver, ISC_FALSE);
|
|
|
|
if (db != NULL)
|
|
|
|
dns_db_detach(&db);
|
|
|
|
dns_diff_clear(&diff);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Configure or reconfigure a zone. This callback function
|
|
|
|
* is called after parsing each "zone" statement in named.conf.
|
|
|
|
*/
|
1999-08-05 22:14:43 +00:00
|
|
|
static isc_result_t
|
2000-01-21 19:24:01 +00:00
|
|
|
load_zone(dns_c_ctx_t *cctx, dns_c_zone_t *czone, dns_c_view_t *cview,
|
1999-10-15 01:51:48 +00:00
|
|
|
void *uap)
|
|
|
|
{
|
2000-01-21 19:24:01 +00:00
|
|
|
ns_load_t *lctx = (ns_load_t *) uap;
|
|
|
|
dns_view_t *view = NULL; /* New view */
|
|
|
|
dns_view_t *pview = NULL; /* Production view */
|
|
|
|
dns_zone_t *zone = NULL; /* New or reused zone */
|
|
|
|
dns_zone_t *tzone = NULL; /* Temporary zone */
|
|
|
|
char *viewname;
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
char *corigin;
|
|
|
|
isc_buffer_t buffer;
|
|
|
|
dns_fixedname_t fixorigin;
|
|
|
|
dns_name_t *origin;
|
|
|
|
|
1999-08-05 22:14:43 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* Get the zone origin as a dns_name_t.
|
1999-08-05 22:14:43 +00:00
|
|
|
*/
|
2000-01-21 19:24:01 +00:00
|
|
|
corigin = NULL;
|
|
|
|
/* XXX casting away const */
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_c_zone_getname(czone, (const char **) &corigin));
|
2000-01-21 19:24:01 +00:00
|
|
|
isc_buffer_init(&buffer, corigin, strlen(corigin), ISC_BUFFERTYPE_TEXT);
|
|
|
|
isc_buffer_add(&buffer, strlen(corigin));
|
|
|
|
dns_fixedname_init(&fixorigin);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_name_fromtext(dns_fixedname_name(&fixorigin),
|
|
|
|
&buffer, dns_rootname, ISC_FALSE, NULL));
|
2000-01-21 19:24:01 +00:00
|
|
|
origin = dns_fixedname_name(&fixorigin);
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* Find or create the view in the new view list.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
|
|
|
view = NULL;
|
2000-01-21 19:24:01 +00:00
|
|
|
if (cview != NULL)
|
|
|
|
viewname = cview->name;
|
|
|
|
else
|
|
|
|
viewname = "_default";
|
|
|
|
result = dns_viewlist_find(&lctx->viewlist, viewname,
|
|
|
|
czone->zclass, &view);
|
|
|
|
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
if (view == NULL) {
|
|
|
|
dns_view_t *tview = NULL;
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_create(ns_g_mctx, czone->zclass,
|
|
|
|
viewname, &view));
|
2000-01-21 19:24:01 +00:00
|
|
|
dns_view_attach(view, &tview);
|
|
|
|
ISC_LIST_APPEND(lctx->viewlist, tview, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for duplicates in the new zone table.
|
|
|
|
*/
|
|
|
|
result = dns_view_findzone(view, origin, &tzone);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* We already have this zone!
|
|
|
|
*/
|
|
|
|
result = ISC_R_EXISTS;
|
|
|
|
goto cleanup;
|
1999-10-15 01:51:48 +00:00
|
|
|
}
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* 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)
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
1999-12-22 18:45:56 +00:00
|
|
|
RWLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
|
2000-01-12 01:19:47 +00:00
|
|
|
result = dns_viewlist_find(&ns_g_server->viewlist,
|
|
|
|
view->name, view->rdclass,
|
1999-10-15 01:51:48 +00:00
|
|
|
&pview);
|
1999-12-22 18:45:56 +00:00
|
|
|
RWUNLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
|
1999-10-15 01:51:48 +00:00
|
|
|
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
2000-01-21 19:24:01 +00:00
|
|
|
if (pview != NULL)
|
|
|
|
result = dns_view_findzone(pview, origin, &zone);
|
|
|
|
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
if (zone != NULL) {
|
|
|
|
if (! dns_zone_reusable(zone, czone))
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
}
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* If we cannot reuse an existing zone, we will have to
|
|
|
|
* create a new one.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-01-21 19:24:01 +00:00
|
|
|
if (zone == NULL) {
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_zone_create(&zone, lctx->mctx));
|
|
|
|
CHECK(dns_zone_setorigin(zone, origin));
|
|
|
|
CHECK(dns_zonemgr_managezone(ns_g_server->zonemgr,
|
|
|
|
zone));
|
2000-01-21 19:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the zone.
|
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_zone_configure(cctx, lctx->aclconf, czone, zone));
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* XXX Why was this here?
|
|
|
|
*
|
|
|
|
* if (dns_zone_gettype(zone) == dns_zone_hint)
|
|
|
|
* INSIST(0);
|
|
|
|
*/
|
1999-05-03 19:56:23 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Add the zone to its view in the new view list.
|
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_addzone(view, zone));
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-14 01:37:00 +00:00
|
|
|
cleanup:
|
1999-10-15 01:51:48 +00:00
|
|
|
if (tzone != NULL)
|
|
|
|
dns_zone_detach(&tzone);
|
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
if (pview != NULL)
|
|
|
|
dns_view_detach(&pview);
|
|
|
|
if (view != NULL)
|
|
|
|
dns_view_detach(&view);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
|
|
|
return (result);
|
1999-05-03 19:56:23 +00:00
|
|
|
}
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
/*
|
|
|
|
* Configure a single server ACL at '*aclp'. Get its configuration by
|
|
|
|
* calling 'getacl'.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
1999-12-16 23:11:07 +00:00
|
|
|
configure_server_acl(dns_c_ctx_t *cctx, dns_aclconfctx_t *actx, isc_mem_t *mctx,
|
|
|
|
isc_result_t (*getcacl)(dns_c_ctx_t *, dns_c_ipmatchlist_t **),
|
2000-01-21 23:55:12 +00:00
|
|
|
dns_acl_t **aclp)
|
1999-12-16 23:11:07 +00:00
|
|
|
{
|
2000-01-21 23:55:12 +00:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_c_ipmatchlist_t *cacl = NULL;
|
|
|
|
if (*aclp != NULL)
|
|
|
|
dns_acl_detach(aclp);
|
|
|
|
(void) (*getcacl)(cctx, &cacl);
|
|
|
|
if (cacl != NULL) {
|
|
|
|
result = dns_acl_fromconfig(cacl, cctx, actx, mctx, aclp);
|
1999-12-21 21:51:57 +00:00
|
|
|
dns_c_ipmatchlist_detach(&cacl);
|
1999-12-16 23:11:07 +00:00
|
|
|
}
|
2000-01-21 23:55:12 +00:00
|
|
|
return (result);
|
1999-12-16 23:11:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
/*
|
|
|
|
* Configure a single server quota.
|
|
|
|
*/
|
2000-01-15 00:37:31 +00:00
|
|
|
static void
|
|
|
|
configure_server_quota(dns_c_ctx_t *cctx,
|
|
|
|
isc_result_t (*getquota)(dns_c_ctx_t *, isc_int32_t *),
|
|
|
|
isc_quota_t *quota, int defaultvalue)
|
|
|
|
{
|
|
|
|
isc_int32_t val = defaultvalue;
|
|
|
|
(void)(*getquota)(cctx, &val);
|
|
|
|
quota->max = val;
|
|
|
|
}
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
static isc_result_t
|
1999-12-16 23:11:07 +00:00
|
|
|
load_configuration(const char *filename, ns_server_t *server) {
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
|
|
|
ns_load_t lctx;
|
|
|
|
dns_c_cbks_t callbacks;
|
1999-12-17 01:02:49 +00:00
|
|
|
dns_c_ctx_t *configctx;
|
1999-10-15 01:51:48 +00:00
|
|
|
dns_view_t *view, *view_next;
|
2000-01-21 23:55:12 +00:00
|
|
|
dns_viewlist_t tmpviewlist;
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclconfctx_t aclconfctx;
|
|
|
|
|
|
|
|
dns_aclconfctx_init(&aclconfctx);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
lctx.mctx = ns_g_mctx;
|
1999-12-16 23:11:07 +00:00
|
|
|
lctx.aclconf = &aclconfctx;
|
1999-10-15 01:51:48 +00:00
|
|
|
ISC_LIST_INIT(lctx.viewlist);
|
1999-07-24 01:16:38 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
callbacks.zonecbk = load_zone;
|
|
|
|
callbacks.zonecbkuap = &lctx;
|
|
|
|
callbacks.optscbk = NULL;
|
|
|
|
callbacks.optscbkuap = NULL;
|
1999-09-24 01:42:22 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
2000-01-12 01:19:47 +00:00
|
|
|
ISC_LOG_INFO, "loading configuration from '%s'",
|
|
|
|
filename);
|
1999-07-24 01:16:38 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Parse the configuration file creating a parse tree. Any
|
|
|
|
* 'zone' statements are handled immediately by calling
|
|
|
|
* load_zone() through 'callbacks'.
|
|
|
|
*/
|
1999-10-15 01:51:48 +00:00
|
|
|
configctx = NULL;
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_c_parse_namedconf(filename, ns_g_mctx, &configctx,
|
|
|
|
&callbacks));
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
/*
|
|
|
|
* Configure various server options.
|
|
|
|
*/
|
|
|
|
(void) dns_c_ctx_getrecursion(configctx, &server->recursion);
|
1999-12-17 18:27:16 +00:00
|
|
|
(void) dns_c_ctx_getauthnxdomain(configctx, &server->auth_nxdomain);
|
1999-12-16 23:11:07 +00:00
|
|
|
(void) dns_c_ctx_gettransferformat(configctx, &server->transfer_format);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
|
|
|
|
dns_c_ctx_getqueryacl, &server->queryacl));
|
|
|
|
|
|
|
|
CHECK(configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
|
|
|
|
dns_c_ctx_getrecursionacl,
|
|
|
|
&server->recursionacl));
|
|
|
|
|
|
|
|
CHECK(configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
|
|
|
|
dns_c_ctx_gettransferacl,
|
|
|
|
&server->transferacl));
|
2000-01-15 00:37:31 +00:00
|
|
|
|
|
|
|
configure_server_quota(configctx, dns_c_ctx_gettransfersout,
|
2000-01-21 23:55:12 +00:00
|
|
|
&server->xfroutquota, 10);
|
2000-01-15 00:37:31 +00:00
|
|
|
configure_server_quota(configctx, dns_c_ctx_gettcpclients,
|
2000-01-21 23:55:12 +00:00
|
|
|
&server->tcpquota, 100);
|
2000-01-15 00:37:31 +00:00
|
|
|
configure_server_quota(configctx, dns_c_ctx_getrecursiveclients,
|
2000-01-21 23:55:12 +00:00
|
|
|
&server->recursionquota, 100);
|
2000-01-13 23:32:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the interface manager according to the "listen-on"
|
|
|
|
* statement.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
dns_c_lstnlist_t *clistenon = NULL;
|
|
|
|
ns_listenlist_t *listenon = NULL;
|
|
|
|
|
|
|
|
(void) dns_c_ctx_getlistenlist(configctx, &clistenon);
|
|
|
|
if (clistenon != NULL) {
|
|
|
|
result = ns_listenlist_fromconfig(clistenon,
|
|
|
|
configctx,
|
|
|
|
&aclconfctx,
|
|
|
|
ns_g_mctx, &listenon);
|
|
|
|
} else {
|
|
|
|
/* Not specified, use default. */
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(ns_listenlist_default(ns_g_mctx, ns_g_port,
|
|
|
|
&listenon));
|
2000-01-13 23:32:41 +00:00
|
|
|
}
|
|
|
|
ns_interfacemgr_setlistenon(server->interfacemgr, listenon);
|
|
|
|
ns_listenlist_detach(&listenon);
|
|
|
|
}
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
1999-11-02 17:21:47 +00:00
|
|
|
* If we haven't created any views, create a default view for class
|
|
|
|
* IN. (We're a caching-only server.)
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
1999-11-02 17:21:47 +00:00
|
|
|
if (ISC_LIST_EMPTY(lctx.viewlist)) {
|
|
|
|
view = NULL;
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKM(dns_view_create(ns_g_mctx, dns_rdataclass_in,
|
|
|
|
"_default", &view),
|
|
|
|
"creating default view");
|
1999-11-02 17:21:47 +00:00
|
|
|
ISC_LIST_APPEND(lctx.viewlist, view, link);
|
|
|
|
}
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* Configure and freeze the views. Their zone tables have
|
|
|
|
* already been filled in at parsing time, but other stuff
|
|
|
|
* like the resolvers are still unconfigured.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
|
|
|
for (view = ISC_LIST_HEAD(lctx.viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = ISC_LIST_NEXT(view, link))
|
2000-01-21 19:24:01 +00:00
|
|
|
{
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(configure_view(view, configctx, ns_g_mctx));
|
1999-10-15 01:51:48 +00:00
|
|
|
dns_view_freeze(view);
|
2000-01-21 19:24:01 +00:00
|
|
|
}
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* Create (or recreate) the version view.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
|
|
|
view = NULL;
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(create_version_view(configctx, &view));
|
1999-10-15 01:51:48 +00:00
|
|
|
ISC_LIST_APPEND(lctx.viewlist, view, link);
|
1999-12-08 21:27:08 +00:00
|
|
|
view = NULL;
|
1999-01-31 12:31:31 +00:00
|
|
|
|
1999-10-31 19:30:16 +00:00
|
|
|
/*
|
|
|
|
* Change directory.
|
|
|
|
*/
|
|
|
|
if (configctx->options != NULL &&
|
|
|
|
configctx->options->directory != NULL) {
|
|
|
|
result = isc_dir_chdir(configctx->options->directory);
|
2000-01-21 23:55:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_ERROR, "change directory "
|
|
|
|
"to '%s' failed: %s",
|
|
|
|
configctx->options->directory,
|
|
|
|
isc_result_totext(result));
|
|
|
|
CHECK(result);
|
|
|
|
}
|
1999-10-31 19:30:16 +00:00
|
|
|
}
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 23:55:12 +00:00
|
|
|
* Swap our new view list with the production one.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
1999-12-22 18:45:56 +00:00
|
|
|
RWLOCK(&server->viewlock, isc_rwlocktype_write);
|
2000-01-21 23:55:12 +00:00
|
|
|
tmpviewlist = server->viewlist;
|
1999-12-22 18:45:56 +00:00
|
|
|
server->viewlist = lctx.viewlist;
|
2000-01-21 23:55:12 +00:00
|
|
|
lctx.viewlist = tmpviewlist;
|
1999-12-22 18:45:56 +00:00
|
|
|
RWUNLOCK(&server->viewlock, isc_rwlocktype_write);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
|
|
|
/*
|
2000-01-21 23:55:12 +00:00
|
|
|
* Load the TKEY information from the configuration
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-01-21 20:24:49 +00:00
|
|
|
if (ns_g_tkeyctx != NULL)
|
|
|
|
dns_tkey_destroy(&ns_g_tkeyctx);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKM(dns_tkey_init(configctx, ns_g_mctx, &ns_g_tkeyctx),
|
|
|
|
"setting up TKEY");
|
2000-01-04 22:02:26 +00:00
|
|
|
/*
|
|
|
|
* Rescan the interface list to pick up changes in the
|
|
|
|
* listen-on option.
|
|
|
|
*/
|
|
|
|
ns_interfacemgr_scan(server->interfacemgr);
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclconfctx_destroy(&aclconfctx);
|
1999-12-17 00:19:29 +00:00
|
|
|
|
|
|
|
dns_c_ctx_delete(&configctx);
|
2000-01-21 23:55:12 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
cleanup:
|
2000-01-21 23:55:12 +00:00
|
|
|
/*
|
|
|
|
* This cleans up either the old production view list
|
|
|
|
* or our temporary list depending on whether they
|
|
|
|
* were swapped above or not.
|
|
|
|
*/
|
|
|
|
for (view = ISC_LIST_HEAD(lctx.viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = view_next) {
|
|
|
|
view_next = ISC_LIST_NEXT(view, link);
|
|
|
|
ISC_LIST_UNLINK(lctx.viewlist, view, link);
|
|
|
|
dns_view_detach(&view);
|
|
|
|
}
|
|
|
|
return (result);
|
1999-07-24 01:16:38 +00:00
|
|
|
}
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-22 01:36:34 +00:00
|
|
|
static isc_result_t
|
|
|
|
load_zones(ns_server_t *server, isc_boolean_t stop) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_view_t *view;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load zone data from disk.
|
|
|
|
*/
|
|
|
|
for (view = ISC_LIST_HEAD(server->viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = ISC_LIST_NEXT(view, link))
|
|
|
|
{
|
|
|
|
CHECK(dns_view_load(view, stop));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
CHECK(dns_zonemgr_forcemaint(server->zonemgr));
|
|
|
|
cleanup:
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
static void
|
|
|
|
run_server(isc_task_t *task, isc_event_t *event) {
|
2000-01-18 18:09:47 +00:00
|
|
|
isc_result_t result;
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_t *server = (ns_server_t *) event->arg;
|
1999-07-24 01:16:38 +00:00
|
|
|
(void)task;
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_event_free(&event);
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(ns_clientmgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
|
|
|
&server->clientmgr),
|
|
|
|
"creating client manager");
|
2000-01-18 18:09:47 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(ns_interfacemgr_create(ns_g_mctx, ns_g_taskmgr,
|
|
|
|
ns_g_socketmgr, server->clientmgr,
|
|
|
|
&server->interfacemgr),
|
|
|
|
"creating interface manager");
|
2000-01-18 18:09:47 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(load_configuration(ns_g_conffile, server),
|
|
|
|
"loading configuration");
|
1999-10-15 01:51:48 +00:00
|
|
|
|
2000-01-22 01:36:34 +00:00
|
|
|
CHECKFATAL(load_zones(server, ISC_TRUE),
|
|
|
|
"loading zones");
|
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
1999-10-23 00:02:23 +00:00
|
|
|
ISC_LOG_INFO, "running");
|
1999-07-24 01:16:38 +00:00
|
|
|
}
|
1999-01-28 05:52:20 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
static void
|
|
|
|
shutdown_server(isc_task_t *task, isc_event_t *event) {
|
1999-08-05 22:14:43 +00:00
|
|
|
dns_view_t *view, *view_next;
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_t *server = (ns_server_t *) event->arg;
|
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
(void)task;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
1999-10-23 00:02:23 +00:00
|
|
|
ISC_LOG_INFO, "shutting down");
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
RWLOCK(&server->viewlock, isc_rwlocktype_write);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
for (view = ISC_LIST_HEAD(server->viewlist);
|
1999-08-05 22:14:43 +00:00
|
|
|
view != NULL;
|
|
|
|
view = view_next) {
|
|
|
|
view_next = ISC_LIST_NEXT(view, link);
|
1999-12-22 18:45:56 +00:00
|
|
|
ISC_LIST_UNLINK(server->viewlist, view, link);
|
1999-08-05 22:14:43 +00:00
|
|
|
dns_view_detach(&view);
|
|
|
|
}
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
RWUNLOCK(&server->viewlock, isc_rwlocktype_write);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
2000-01-21 20:24:49 +00:00
|
|
|
dns_tkey_destroy(&ns_g_tkeyctx);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-18 18:09:47 +00:00
|
|
|
ns_clientmgr_destroy(&server->clientmgr);
|
2000-01-12 01:17:34 +00:00
|
|
|
ns_interfacemgr_shutdown(server->interfacemgr);
|
|
|
|
ns_interfacemgr_detach(&server->interfacemgr);
|
2000-01-19 22:02:18 +00:00
|
|
|
dns_zonemgr_shutdown(server->zonemgr);
|
|
|
|
|
2000-01-13 22:07:24 +00:00
|
|
|
isc_task_detach(&server->task);
|
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
}
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
void
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
|
1999-12-22 18:45:56 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_t *server = isc_mem_get(mctx, sizeof(*server));
|
|
|
|
if (server == NULL)
|
2000-01-21 23:55:12 +00:00
|
|
|
fatal("allocating server object", ISC_R_NOMEMORY);
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
server->mctx = mctx;
|
2000-01-13 22:07:24 +00:00
|
|
|
server->task = NULL;
|
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
/* Initialize configuration data with default values. */
|
1999-12-16 23:11:07 +00:00
|
|
|
server->recursion = ISC_TRUE;
|
|
|
|
server->auth_nxdomain = ISC_FALSE; /* Was true in BIND 8 */
|
|
|
|
server->transfer_format = dns_one_answer;
|
|
|
|
|
|
|
|
server->queryacl = NULL;
|
|
|
|
server->recursionacl = NULL;
|
|
|
|
server->transferacl = NULL;
|
|
|
|
|
2000-01-13 21:17:08 +00:00
|
|
|
result = isc_quota_init(&server->xfroutquota, 10);
|
2000-01-12 01:19:47 +00:00
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-01-13 21:17:08 +00:00
|
|
|
result = isc_quota_init(&server->tcpquota, 10);
|
2000-01-12 01:19:47 +00:00
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-01-13 21:17:08 +00:00
|
|
|
result = isc_quota_init(&server->recursionquota, 100);
|
2000-01-12 01:19:47 +00:00
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-01-11 21:18:22 +00:00
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
/* Initialize server data structures. */
|
2000-01-18 18:09:47 +00:00
|
|
|
server->zonemgr = NULL;
|
|
|
|
server->clientmgr = NULL;
|
|
|
|
server->interfacemgr = NULL;
|
1999-12-22 18:45:56 +00:00
|
|
|
ISC_LIST_INIT(server->viewlist);
|
2000-01-12 01:19:47 +00:00
|
|
|
result = isc_rwlock_init(&server->viewlock, 0, 0);
|
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-01-18 23:38:42 +00:00
|
|
|
server->roothints = NULL;
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(ns_rootns_create(mctx, &server->roothints),
|
|
|
|
"setting up root hints");
|
2000-01-18 23:38:42 +00:00
|
|
|
|
2000-01-13 22:07:24 +00:00
|
|
|
/*
|
|
|
|
* Setup the server task, which is responsible for coordinating
|
|
|
|
* startup and shutdown of the server.
|
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(isc_task_create(ns_g_taskmgr, ns_g_mctx, 0, &server->task),
|
|
|
|
"creating server task");
|
|
|
|
CHECKFATAL(isc_task_onshutdown(server->task, shutdown_server, server),
|
|
|
|
"isc_task_onshutdown");
|
|
|
|
CHECKFATAL(isc_app_onrun(ns_g_mctx, server->task, run_server, server),
|
|
|
|
"isc_app_onrun");
|
|
|
|
|
|
|
|
CHECKFATAL(dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
|
|
|
ns_g_socketmgr, &server->zonemgr),
|
|
|
|
"dns_zonemgr_create");
|
2000-01-19 22:02:18 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
server->magic = NS_SERVER_MAGIC;
|
|
|
|
*serverp = server;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ns_server_destroy(ns_server_t **serverp) {
|
|
|
|
ns_server_t *server = *serverp;
|
|
|
|
REQUIRE(NS_SERVER_VALID(server));
|
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
INSIST(ISC_LIST_EMPTY(server->viewlist));
|
2000-01-18 23:38:42 +00:00
|
|
|
|
2000-01-19 22:02:18 +00:00
|
|
|
dns_zonemgr_destroy(&server->zonemgr);
|
|
|
|
server->zonemgr = NULL;
|
|
|
|
|
2000-01-18 23:38:42 +00:00
|
|
|
dns_db_detach(&server->roothints);
|
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
isc_rwlock_destroy(&server->viewlock);
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
if (server->queryacl != NULL)
|
|
|
|
dns_acl_detach(&server->queryacl);
|
|
|
|
if (server->recursionacl != NULL)
|
|
|
|
dns_acl_detach(&server->recursionacl);
|
|
|
|
if (server->transferacl != NULL)
|
|
|
|
dns_acl_detach(&server->transferacl);
|
2000-01-11 21:18:22 +00:00
|
|
|
|
|
|
|
isc_quota_destroy(&server->recursionquota);
|
|
|
|
isc_quota_destroy(&server->tcpquota);
|
|
|
|
isc_quota_destroy(&server->xfroutquota);
|
1999-12-16 23:11:07 +00:00
|
|
|
|
|
|
|
server->magic = 0;
|
|
|
|
isc_mem_put(server->mctx, server, sizeof(*server));
|
|
|
|
}
|
2000-01-18 22:49:55 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
static void
|
|
|
|
fatal(char *msg, isc_result_t result)
|
1999-10-23 00:02:23 +00:00
|
|
|
{
|
2000-01-21 23:55:12 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_CRITICAL, "%s: %s", msg, isc_result_totext(result));
|
1999-10-23 00:02:23 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
|
|
|
|
exit(1);
|
|
|
|
}
|