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
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/error.h>
|
1999-08-05 22:14:43 +00:00
|
|
|
#include <isc/rwlock.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/thread.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/socket.h>
|
|
|
|
#include <isc/timer.h>
|
1999-05-27 01:51:31 +00:00
|
|
|
#include <isc/app.h>
|
1999-10-31 19:30:16 +00:00
|
|
|
#include <isc/dir.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>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <dns/types.h>
|
|
|
|
#include <dns/result.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>
|
1999-05-03 19:56:23 +00:00
|
|
|
#include <dns/fixedname.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
1999-05-03 19:56:23 +00:00
|
|
|
#include <dns/rdatasetiter.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <dns/compress.h>
|
1999-01-31 12:31:31 +00:00
|
|
|
#include <dns/db.h>
|
1999-05-03 19:56:23 +00:00
|
|
|
#include <dns/dbtable.h>
|
1999-04-30 05:42:06 +00:00
|
|
|
#include <dns/message.h>
|
1999-08-20 06:05:07 +00:00
|
|
|
#include <dns/journal.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-10-27 20:00:40 +00:00
|
|
|
#include <dns/tsig.h>
|
1999-10-26 15:41:48 +00:00
|
|
|
#include <dns/tkey.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
#include <named/types.h>
|
|
|
|
#include <named/globals.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>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
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
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
static isc_task_t * server_task;
|
1999-01-31 12:31:31 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
create_default_view(isc_mem_t *mctx, dns_rdataclass_t rdclass,
|
|
|
|
dns_view_t **viewp)
|
|
|
|
{
|
1999-08-05 22:14:43 +00:00
|
|
|
dns_view_t *view;
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_cache_t *cache;
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(viewp != NULL && *viewp == NULL);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
|
|
|
/*
|
1999-10-15 01:51:48 +00:00
|
|
|
* View.
|
1999-08-05 22:14:43 +00:00
|
|
|
*/
|
1999-10-15 01:51:48 +00:00
|
|
|
view = NULL;
|
1999-10-22 19:35:19 +00:00
|
|
|
result = dns_view_create(mctx, rdclass, "_default", &view);
|
1999-10-15 01:51:48 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
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;
|
|
|
|
result = dns_cache_create(mctx, ns_g_taskmgr, ns_g_timermgr, rdclass,
|
|
|
|
"rbt", 0, NULL, &cache);
|
1999-10-15 01:51:48 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_view_setcache(view, cache);
|
|
|
|
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);
|
|
|
|
result = dns_db_load(view->cachedb, ns_g_cachefile);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
1999-11-25 00:12:35 +00:00
|
|
|
result = dns_view_createresolver(view, ns_g_taskmgr, 31,
|
1999-10-15 01:51:48 +00:00
|
|
|
ns_g_socketmgr, ns_g_timermgr,
|
|
|
|
NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* We have default hints for class IN.
|
|
|
|
*/
|
|
|
|
if (rdclass == dns_rdataclass_in)
|
|
|
|
dns_view_sethints(view, ns_g_rootns);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
*viewp = view;
|
1999-10-14 01:37:00 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
cleanup:
|
|
|
|
dns_view_detach(&view);
|
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) {
|
|
|
|
dns_result_t result;
|
|
|
|
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;
|
|
|
|
dns_name_t *origin;
|
|
|
|
char *versiontext;
|
|
|
|
char buf[256];
|
|
|
|
isc_region_t r;
|
|
|
|
size_t len;
|
|
|
|
dns_rdata_t rdata;
|
|
|
|
|
|
|
|
REQUIRE(viewp != NULL && *viewp == NULL);
|
|
|
|
|
|
|
|
dns_diff_init(ns_g_mctx, &diff);
|
|
|
|
|
|
|
|
(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);
|
|
|
|
|
|
|
|
result = dns_zone_create(&zone, ns_g_mctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
result = dns_zone_setorigin(zone, "version.bind.");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
origin = dns_zone_getorigin(zone);
|
|
|
|
|
|
|
|
result = dns_db_create(ns_g_mctx, "rbt", origin, ISC_FALSE,
|
|
|
|
dns_rdataclass_ch, 0, NULL, &db);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = dns_db_newversion(db, &dbver);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
dns_difftuple_create(ns_g_mctx, DNS_DIFFOP_ADD, origin,
|
|
|
|
0, &rdata, &tuple);
|
|
|
|
dns_diff_append(&diff, &tuple);
|
|
|
|
result = dns_diff_apply(&diff, db, dbver);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
dns_db_closeversion(db, &dbver, ISC_TRUE);
|
|
|
|
|
|
|
|
result = dns_view_create(ns_g_mctx, dns_rdataclass_ch, "_version",
|
|
|
|
&view);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_zone_replacedb(zone, db, ISC_FALSE);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = dns_view_addzone(view, zone);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1999-08-05 22:14:43 +00:00
|
|
|
static isc_result_t
|
1999-10-15 01:51:48 +00:00
|
|
|
load_zone(dns_c_ctx_t *ctx, dns_c_zone_t *czone, dns_c_view_t *cview,
|
|
|
|
void *uap)
|
|
|
|
{
|
|
|
|
ns_load_t *lctx;
|
|
|
|
dns_view_t *view, *tview, *pview;
|
|
|
|
dns_zone_t *zone, *tzone;
|
1999-08-05 22:14:43 +00:00
|
|
|
dns_name_t *origin;
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
|
|
|
/*
|
1999-10-15 01:51:48 +00:00
|
|
|
* Load (or reload) a zone.
|
1999-08-05 22:14:43 +00:00
|
|
|
*/
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
lctx = uap;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
tzone = NULL;
|
|
|
|
zone = NULL;
|
|
|
|
pview = NULL;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Find the view.
|
|
|
|
*/
|
|
|
|
view = NULL;
|
|
|
|
if (cview != NULL) {
|
|
|
|
result = dns_viewlist_find(&lctx->viewlist, cview->name,
|
|
|
|
czone->zclass, &view);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
} else {
|
|
|
|
result = dns_viewlist_find(&lctx->viewlist, "_default",
|
|
|
|
czone->zclass, &view);
|
|
|
|
if (result == ISC_R_NOTFOUND) {
|
|
|
|
/*
|
|
|
|
* Create a default view.
|
|
|
|
*/
|
|
|
|
tview = NULL;
|
|
|
|
result = create_default_view(ctx->mem, czone->zclass,
|
|
|
|
&tview);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
dns_view_attach(tview, &view);
|
|
|
|
ISC_LIST_APPEND(lctx->viewlist, view, link);
|
|
|
|
} else if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
}
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Do we already have a production version of this view?
|
|
|
|
*/
|
|
|
|
RWLOCK(&ns_g_viewlock, isc_rwlocktype_read);
|
|
|
|
result = dns_viewlist_find(&ns_g_viewlist, view->name, view->rdclass,
|
|
|
|
&pview);
|
|
|
|
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_read);
|
|
|
|
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Create a new zone structure and configure it.
|
|
|
|
*/
|
|
|
|
result = dns_zone_create(&zone, lctx->mctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-08-05 22:14:43 +00:00
|
|
|
return (result);
|
1999-12-16 23:11:07 +00:00
|
|
|
result = dns_zone_configure(ns_g_lctx, ctx, lctx->aclconf, czone, zone);
|
1999-08-05 22:14:43 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-15 01:51:48 +00:00
|
|
|
return (result);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
if (dns_zone_gettype(zone) == dns_zone_hint) {
|
|
|
|
INSIST(0);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Check for duplicates in the new zone table.
|
|
|
|
*/
|
|
|
|
origin = dns_zone_getorigin(zone);
|
|
|
|
result = dns_view_findzone(view, origin, &tzone);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* We already have this zone!
|
|
|
|
*/
|
|
|
|
result = ISC_R_EXISTS;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
1999-05-03 19:56:23 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Do we have the zone in the production view?
|
|
|
|
*/
|
|
|
|
if (pview != NULL)
|
|
|
|
result = dns_view_findzone(pview, origin, &tzone);
|
|
|
|
else
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* Yes.
|
|
|
|
*
|
|
|
|
* If the production zone's configuration is
|
|
|
|
* the same as the new zone's, we can use the
|
|
|
|
* production zone.
|
|
|
|
*/
|
1999-10-25 16:46:15 +00:00
|
|
|
if (dns_zone_equal(zone, tzone))
|
1999-10-15 01:51:48 +00:00
|
|
|
result = dns_view_addzone(view, tzone);
|
1999-10-25 16:46:15 +00:00
|
|
|
else
|
1999-10-15 01:51:48 +00:00
|
|
|
result = dns_view_addzone(view, zone);
|
|
|
|
} else if (result == ISC_R_NOTFOUND) {
|
|
|
|
/*
|
|
|
|
* This is a new zone.
|
|
|
|
*/
|
|
|
|
result = dns_view_addzone(view, zone);
|
1999-10-29 00:46:53 +00:00
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = dns_zonemgr_managezone(ns_g_zonemgr, zone);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
goto cleanup;
|
1999-10-15 01:51:48 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
/* XXX will need error recovery for reconfig */
|
1999-10-23 00:02:23 +00:00
|
|
|
static void
|
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 **),
|
|
|
|
dns_acl_t **aclp)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
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);
|
|
|
|
if (result != DNS_R_SUCCESS)
|
|
|
|
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
|
|
|
|
"server ACL setup failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
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;
|
|
|
|
dns_c_ctx_t *configctx, *oconfigctx;
|
|
|
|
dns_view_t *view, *view_next;
|
|
|
|
dns_viewlist_t oviewlist;
|
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,
|
1999-10-23 00:02:23 +00:00
|
|
|
ISC_LOG_INFO, "loading '%s'", filename);
|
1999-07-24 01:16:38 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
configctx = NULL;
|
1999-12-06 12:40:39 +00:00
|
|
|
result = dns_c_parse_namedconf(filename, ns_g_mctx, &configctx,
|
1999-10-15 01:51:48 +00:00
|
|
|
&callbacks);
|
1999-10-25 13:44:53 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
#ifdef notyet
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#endif
|
1999-10-23 00:02:23 +00:00
|
|
|
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
|
|
|
|
"load of '%s' failed", filename);
|
1999-10-25 13:44:53 +00:00
|
|
|
}
|
1999-12-16 23:11:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure various server options.
|
|
|
|
*/
|
|
|
|
(void) dns_c_ctx_getrecursion(configctx, &server->recursion);
|
|
|
|
(void) dns_c_ctx_getauth_nx_domain(configctx, &server->auth_nxdomain);
|
|
|
|
(void) dns_c_ctx_gettransferformat(configctx, &server->transfer_format);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
|
|
|
|
dns_c_ctx_getqueryacl, &server->queryacl);
|
|
|
|
|
|
|
|
configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
|
|
|
|
dns_c_ctx_getrecursionacl, &server->recursionacl);
|
|
|
|
|
|
|
|
configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
|
|
|
|
dns_c_ctx_gettransferacl, &server->transferacl);
|
|
|
|
|
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;
|
|
|
|
result = create_default_view(ns_g_mctx, dns_rdataclass_in,
|
|
|
|
&view);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
|
|
|
|
"could not create default view");
|
|
|
|
ISC_LIST_APPEND(lctx.viewlist, view, link);
|
|
|
|
}
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Freeze the views.
|
|
|
|
*/
|
|
|
|
for (view = ISC_LIST_HEAD(lctx.viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = ISC_LIST_NEXT(view, link))
|
|
|
|
dns_view_freeze(view);
|
1999-01-29 06:18:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
1999-12-08 21:27:08 +00:00
|
|
|
* Create the version view.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
|
|
|
view = NULL;
|
1999-12-08 21:27:08 +00:00
|
|
|
result = create_version_view(configctx, &view);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
|
|
|
|
"could not create version 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);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
|
|
|
|
"change directory to '%s' failed: %s",
|
|
|
|
configctx->options->directory,
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
1999-10-25 18:59:20 +00:00
|
|
|
* Load zones.
|
1999-07-24 01:16:38 +00:00
|
|
|
*/
|
1999-10-25 13:44:53 +00:00
|
|
|
for (view = ISC_LIST_HEAD(lctx.viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = view_next) {
|
|
|
|
view_next = ISC_LIST_NEXT(view, link);
|
|
|
|
dns_view_load(view);
|
|
|
|
}
|
|
|
|
|
1999-10-29 00:46:53 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
dns_zonemgr_forcemaint(ns_g_zonemgr);
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Put the configuration into production.
|
|
|
|
*/
|
|
|
|
|
|
|
|
RWLOCK(&ns_g_viewlock, isc_rwlocktype_write);
|
|
|
|
|
|
|
|
oviewlist = ns_g_viewlist;
|
|
|
|
ns_g_viewlist = lctx.viewlist;
|
|
|
|
|
|
|
|
oconfigctx = ns_g_confctx;
|
|
|
|
ns_g_confctx = configctx;
|
|
|
|
|
|
|
|
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_write);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup old configuration.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (view = ISC_LIST_HEAD(oviewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = view_next) {
|
|
|
|
view_next = ISC_LIST_NEXT(view, link);
|
|
|
|
ISC_LIST_UNLINK(oviewlist, view, link);
|
|
|
|
dns_view_detach(&view);
|
1999-07-24 01:16:38 +00:00
|
|
|
}
|
1999-10-15 01:51:48 +00:00
|
|
|
|
|
|
|
if (oconfigctx != NULL)
|
1999-12-06 12:40:39 +00:00
|
|
|
dns_c_ctx_delete(&oconfigctx);
|
1999-10-26 15:41:48 +00:00
|
|
|
|
1999-10-27 20:00:40 +00:00
|
|
|
/*
|
|
|
|
* Load the TSIG information from the configuration
|
|
|
|
*/
|
1999-10-29 13:56:56 +00:00
|
|
|
result = dns_tsig_init(ns_g_lctx, ns_g_confctx, ns_g_mctx);
|
1999-10-27 20:00:40 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
|
|
|
|
"dns_tsig_init() failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
|
1999-10-26 15:41:48 +00:00
|
|
|
/*
|
|
|
|
* Load the TKEY information from the configuration
|
|
|
|
*/
|
|
|
|
result = dns_tkey_init(ns_g_lctx, ns_g_confctx, ns_g_mctx);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
|
1999-10-27 20:00:40 +00:00
|
|
|
"dns_tkey_init() failed: %s",
|
|
|
|
isc_result_totext(result));
|
1999-10-26 15:41:48 +00:00
|
|
|
}
|
1999-12-16 23:11:07 +00:00
|
|
|
|
|
|
|
dns_aclconfctx_destroy(&aclconfctx);
|
1999-07-24 01:16:38 +00:00
|
|
|
}
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
static void
|
|
|
|
run_server(isc_task_t *task, isc_event_t *event) {
|
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
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
load_configuration(ns_g_conffile, server);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-10-07 19:44:22 +00:00
|
|
|
ns_interfacemgr_scan(ns_g_interfacemgr);
|
1999-01-19 06:32:53 +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, "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
|
|
|
|
|
|
|
RWLOCK(&ns_g_viewlock, isc_rwlocktype_write);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-08-05 22:14:43 +00:00
|
|
|
for (view = ISC_LIST_HEAD(ns_g_viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = view_next) {
|
|
|
|
view_next = ISC_LIST_NEXT(view, link);
|
|
|
|
ISC_LIST_UNLINK(ns_g_viewlist, view, link);
|
|
|
|
dns_view_detach(&view);
|
|
|
|
}
|
1999-10-15 01:51:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXRTH Is this the right place to do this?
|
|
|
|
*/
|
1999-12-06 12:40:39 +00:00
|
|
|
dns_c_ctx_delete(&ns_g_confctx);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-11-05 20:20:18 +00:00
|
|
|
dns_tkey_destroy();
|
|
|
|
dns_tsig_destroy();
|
|
|
|
|
1999-08-05 22:14:43 +00:00
|
|
|
RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_write);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
isc_task_detach(&server_task);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-29 00:46:53 +00:00
|
|
|
dns_zonemgr_destroy(&ns_g_zonemgr);
|
|
|
|
|
1999-09-24 01:42:22 +00:00
|
|
|
ns_rootns_destroy();
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_destroy(&server);
|
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
}
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
isc_result_t
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
|
|
|
|
ns_server_t *server = isc_mem_get(mctx, sizeof(*server));
|
|
|
|
if (server == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
server->mctx = mctx;
|
|
|
|
|
|
|
|
/* Initialize. */
|
|
|
|
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;
|
|
|
|
|
|
|
|
server->magic = NS_SERVER_MAGIC;
|
|
|
|
*serverp = server;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ns_server_destroy(ns_server_t **serverp) {
|
|
|
|
ns_server_t *server = *serverp;
|
|
|
|
REQUIRE(NS_SERVER_VALID(server));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
server->magic = 0;
|
|
|
|
isc_mem_put(server->mctx, server, sizeof(*server));
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
ns_server_init() {
|
1999-07-24 01:16:38 +00:00
|
|
|
isc_result_t result;
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
/*
|
|
|
|
* Create the server object.
|
|
|
|
*/
|
|
|
|
result = ns_server_create(ns_g_mctx, &ns_g_server);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Setup default root server hints.
|
|
|
|
*/
|
1999-09-24 01:42:22 +00:00
|
|
|
result = ns_rootns_init();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
1999-10-29 00:46:53 +00:00
|
|
|
result = dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
1999-10-29 02:41:56 +00:00
|
|
|
ns_g_socketmgr, &ns_g_zonemgr);
|
1999-07-24 01:16:38 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-15 01:51:48 +00:00
|
|
|
return (result);
|
|
|
|
|
1999-10-07 19:44:22 +00:00
|
|
|
/*
|
1999-10-15 01:51:48 +00:00
|
|
|
* Setup the server task, which is responsible for coordinating
|
|
|
|
* startup and shutdown of the server.
|
1999-10-07 19:44:22 +00:00
|
|
|
*/
|
1999-07-24 01:16:38 +00:00
|
|
|
result = isc_task_create(ns_g_taskmgr, ns_g_mctx, 0, &server_task);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-15 01:51:48 +00:00
|
|
|
goto cleanup_rootns;
|
1999-12-16 23:11:07 +00:00
|
|
|
result = isc_task_onshutdown(server_task, shutdown_server, ns_g_server);
|
1999-07-24 01:16:38 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_task;
|
1999-12-16 23:11:07 +00:00
|
|
|
result = isc_app_onrun(ns_g_mctx, server_task, run_server, ns_g_server);
|
1999-07-24 01:16:38 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_task;
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-10-29 00:46:53 +00:00
|
|
|
/* XXXRTH Add zonemgr, and version view cleanups. */
|
1999-10-22 19:35:19 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
cleanup_task:
|
|
|
|
isc_task_detach(&server_task);
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
cleanup_rootns:
|
1999-09-24 01:42:22 +00:00
|
|
|
ns_rootns_destroy();
|
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
return (result);
|
1999-01-19 06:32:53 +00:00
|
|
|
}
|
1999-10-23 00:02:23 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ns_server_fatal(isc_logmodule_t *module, isc_boolean_t want_core,
|
|
|
|
const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, module,
|
|
|
|
ISC_LOG_CRITICAL, format, args);
|
|
|
|
va_end(args);
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
|
|
|
|
|
|
|
|
if (want_core && ns_g_coreok)
|
|
|
|
abort();
|
|
|
|
exit(1);
|
|
|
|
}
|