server.c revision 6b99e640f34b3e9b3f2b4dcb10986f78e85fe1a4
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley/*
5fec28507abad910acf4afa3efa1e634acab6d9eAutomatic Updater * Copyright (C) 1999 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * copyright notice and this permission notice appear in all copies.
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley */
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews#include <config.h>
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
e419f613d8591885df608cb73065921be07dd12eBob Halley#include <stdio.h>
e419f613d8591885df608cb73065921be07dd12eBob Halley#include <stdlib.h>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <unistd.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <string.h>
fca5f81ad69098ea8abba130c7f841c951ef91c2Bob Halley#include <stdarg.h>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
519b239fc4ef1e070e2da182a4ea559ae0152151Mark Andrews#include <isc/assertions.h>
e419f613d8591885df608cb73065921be07dd12eBob Halley#include <isc/error.h>
e419f613d8591885df608cb73065921be07dd12eBob Halley#include <isc/rwlock.h>
9695ae1c24b168996e3a267855dc754971ccb32cBob Halley#include <isc/mem.h>
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley#include <isc/task.h>
1c776a2909632bc755f3fddd3b53addd792ab4d0Brian Wellington#include <isc/thread.h>
44f175a90a855326725439b2f1178f0dcca8f67dMark Andrews#include <isc/result.h>
e419f613d8591885df608cb73065921be07dd12eBob Halley#include <isc/socket.h>
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley#include <isc/timer.h>
44f175a90a855326725439b2f1178f0dcca8f67dMark Andrews#include <isc/app.h>
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson#include <isc/dir.h>
e83cae7fa837e4757c687035d6f6c0900f152749Brian Wellington#include <isc/util.h>
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews#include <dns/aclconf.h>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <dns/cache.h>
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley#include <dns/confparser.h>
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley#include <dns/types.h>
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence#include <dns/result.h>
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington#include <dns/master.h>
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence#include <dns/name.h>
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence#include <dns/fixedname.h>
e419f613d8591885df608cb73065921be07dd12eBob Halley#include <dns/rdata.h>
e419f613d8591885df608cb73065921be07dd12eBob Halley#include <dns/rdatalist.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/rdataset.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/rdatasetiter.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/compress.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/db.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/dbtable.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/message.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/journal.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/view.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/zone.h>
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater#include <dns/zoneconf.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/tsig.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <dns/tkey.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <named/types.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <named/globals.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <named/log.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <named/rootns.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <named/server.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews#include <named/interfacemgr.h>
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewstypedef struct {
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_mem_t * mctx;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_viewlist_t viewlist;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_aclconfctx_t *aclconf;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews} ns_load_t;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
d2ef84e07b67e72a4bd9c729c6b8228067d17584Mark Andrewsstatic isc_task_t * server_task;
d2ef84e07b67e72a4bd9c729c6b8228067d17584Mark Andrews
d2ef84e07b67e72a4bd9c729c6b8228067d17584Mark Andrews/* XXX temporary kludge until TSIG/TKEY are objectified */
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewsstatic isc_boolean_t tsig_initialized = ISC_FALSE;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewsstatic isc_result_t
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewscreate_default_view(dns_c_ctx_t *cctx, isc_mem_t *mctx,
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_rdataclass_t rdclass, dns_view_t **viewp)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews{
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_view_t *view;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_cache_t *cache;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_result_t result;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_int32_t cleaning_interval;
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews REQUIRE(viewp != NULL && *viewp == NULL);
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews /*
708383382ff1d3fdd27527e5d63120a3c6c6d3b3Francis Dupont * View.
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews */
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews view = NULL;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews result = dns_view_create(mctx, rdclass, "_default", &view);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews if (result != ISC_R_SUCCESS)
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews return (result);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews /*
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews * Cache.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews cache = NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_cache_create(mctx, ns_g_taskmgr, ns_g_timermgr, rdclass,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews "rbt", 0, NULL, &cache);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews if (result != ISC_R_SUCCESS)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews goto cleanup;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_view_setcache(view, cache);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews cleaning_interval = 3600; /* Default is 1 hour. */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews (void) dns_c_ctx_getcleaninterval(cctx, &cleaning_interval);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_cache_setcleaninginterval(cache, cleaning_interval);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_cache_detach(&cache);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * XXXRTH Temporary support for loading cache contents.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (ns_g_cachefile != NULL) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews NS_LOGMODULE_SERVER,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews ISC_LOG_DEBUG(1), "loading cache '%s'",
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews ns_g_cachefile);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews result = dns_db_load(view->cachedb, ns_g_cachefile);
50105afc551903541608b11851d73278b23579a3Mark Andrews if (result != ISC_R_SUCCESS)
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews goto cleanup;
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews }
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews /*
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews * Resolver.
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews *
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley * XXXRTH hardwired number of tasks. Also, we'll need to
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews * see if we are dealing with a shared dispatcher in this view.
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley */
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt result = dns_view_createresolver(view, ns_g_taskmgr, 31,
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt ns_g_socketmgr, ns_g_timermgr,
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence NULL);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence goto cleanup;
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews /*
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence * We have default hints for class IN.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington */
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington if (rdclass == dns_rdataclass_in)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence dns_view_sethints(view, ns_g_rootns);
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews *viewp = view;
50105afc551903541608b11851d73278b23579a3Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews return (ISC_R_SUCCESS);
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews cleanup:
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence dns_view_detach(&view);
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews return (result);
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews}
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington/*
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington * Create the special view that handles queries for
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington * "version.bind. CH". The version string returned is that
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington * configured in 'configctx', or a compiled-in default if
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington * there is no "version" configuration option.
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence */
8462dfb880040cde3a60f047ec18808737fd7e85Mark Andrewsstatic isc_result_t
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssoncreate_version_view(dns_c_ctx_t *configctx, dns_view_t **viewp) {
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson isc_result_t result;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_db_t *db = NULL;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_zone_t *zone = NULL;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_dbversion_t *dbver = NULL;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_difftuple_t *tuple = NULL;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_diff_t diff;
50105afc551903541608b11851d73278b23579a3Mark Andrews dns_view_t *view = NULL;
50105afc551903541608b11851d73278b23579a3Mark Andrews dns_name_t *origin;
50105afc551903541608b11851d73278b23579a3Mark Andrews char *versiontext;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews char buf[256];
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews isc_region_t r;
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews size_t len;
6fac7ff1f9ec9c3873d3b55c5079fa79aba1f146Mark Andrews dns_rdata_t rdata;
6fac7ff1f9ec9c3873d3b55c5079fa79aba1f146Mark Andrews
6fac7ff1f9ec9c3873d3b55c5079fa79aba1f146Mark Andrews REQUIRE(viewp != NULL && *viewp == NULL);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_diff_init(ns_g_mctx, &diff);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews (void) dns_c_ctx_getversion(configctx, &versiontext);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews if (versiontext == NULL)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews versiontext = ns_g_version;
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews len = strlen(versiontext);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews if (len > 255)
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews len = 255; /* Silently truncate. */
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews buf[0] = len;
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews memcpy(buf + 1, versiontext, len);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews r.base = buf;
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews r.length = 1 + len;
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews dns_rdata_fromregion(&rdata, dns_rdataclass_ch, dns_rdatatype_txt, &r);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews result = dns_zone_create(&zone, ns_g_mctx);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews if (result != ISC_R_SUCCESS)
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews goto cleanup;
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews result = dns_zone_setorigin(zone, "version.bind.");
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews if (result != ISC_R_SUCCESS)
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews goto cleanup;
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews origin = dns_zone_getorigin(zone);
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley result = dns_db_create(ns_g_mctx, "rbt", origin, ISC_FALSE,
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley dns_rdataclass_ch, 0, NULL, &db);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley if (result != ISC_R_SUCCESS)
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley goto cleanup;
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington result = dns_db_newversion(db, &dbver);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley if (result != DNS_R_SUCCESS)
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley goto cleanup;
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley dns_difftuple_create(ns_g_mctx, DNS_DIFFOP_ADD, origin,
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley 0, &rdata, &tuple);
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington dns_diff_append(&diff, &tuple);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff result = dns_diff_apply(&diff, db, dbver);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if (result != DNS_R_SUCCESS)
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff goto cleanup;
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff dns_db_closeversion(db, &dbver, ISC_TRUE);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley result = dns_view_create(ns_g_mctx, dns_rdataclass_ch, "_version",
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley &view);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews return (result);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = dns_zone_replacedb(zone, db, ISC_FALSE);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != DNS_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews goto cleanup;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = dns_view_addzone(view, zone);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != DNS_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews goto cleanup;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_view_freeze(view);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /* Transfer ownership. */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews *viewp = view;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews view = NULL;
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews result = ISC_R_SUCCESS;
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews cleanup:
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews if (view != NULL)
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews dns_view_detach(&view);
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews if (zone != NULL)
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews dns_zone_detach(&zone);
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews if (dbver != NULL)
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews dns_db_closeversion(db, &dbver, ISC_FALSE);
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews if (db != NULL)
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews dns_db_detach(&db);
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews dns_diff_clear(&diff);
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews return (result);
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews}
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrewsstatic isc_result_t
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrewsload_zone(dns_c_ctx_t *ctx, dns_c_zone_t *czone, dns_c_view_t *cview,
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews void *uap)
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews{
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews ns_load_t *lctx;
058e44186b74531402c1f99088eb9dbe4926f8daMark Andrews dns_view_t *view, *tview, *pview;
058e44186b74531402c1f99088eb9dbe4926f8daMark Andrews dns_zone_t *zone, *tzone;
058e44186b74531402c1f99088eb9dbe4926f8daMark Andrews dns_name_t *origin;
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews isc_result_t result;
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews /*
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews * Load (or reload) a zone.
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews */
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews
72dbc7216aae3626a66e6154443be219f5edcaf0Mark Andrews lctx = uap;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews tzone = NULL;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews zone = NULL;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews pview = NULL;
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews /*
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews * Find the view.
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews */
7d211b458fed36326b9e125b9d74089f9dccc140Mark Andrews view = NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (cview != NULL) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_viewlist_find(&lctx->viewlist, cview->name,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews czone->zclass, &view);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews if (result != ISC_R_SUCCESS)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews } else {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_viewlist_find(&lctx->viewlist, "_default",
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews czone->zclass, &view);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result == ISC_R_NOTFOUND) {
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Create a default view.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews tview = NULL;
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews result = create_default_view(ctx, ns_g_mctx,
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews czone->zclass,
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews &tview);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews if (result != ISC_R_SUCCESS)
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews return (result);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews dns_view_attach(tview, &view);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews ISC_LIST_APPEND(lctx->viewlist, view, link);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews } else if (result != ISC_R_SUCCESS)
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews /*
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews * Do we already have a production version of this view?
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews */
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews RWLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews result = dns_viewlist_find(&ns_g_server->viewlist,
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews view->name, view->rdclass,
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews &pview);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews RWUNLOCK(&ns_g_server->viewlock, isc_rwlocktype_read);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews goto cleanup;
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews * Create a new zone structure and configure it.
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews */
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews result = dns_zone_create(&zone, lctx->mctx);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != ISC_R_SUCCESS)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_zone_configure(ns_g_lctx, ctx, lctx->aclconf,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews czone, zone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != ISC_R_SUCCESS)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
7d211b458fed36326b9e125b9d74089f9dccc140Mark Andrews if (dns_zone_gettype(zone) == dns_zone_hint) {
7d211b458fed36326b9e125b9d74089f9dccc140Mark Andrews INSIST(0);
7d211b458fed36326b9e125b9d74089f9dccc140Mark Andrews } else {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Check for duplicates in the new zone table.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews origin = dns_zone_getorigin(zone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_view_findzone(view, origin, &tzone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result == ISC_R_SUCCESS) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * We already have this zone!
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = ISC_R_EXISTS;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews goto cleanup;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Do we have the zone in the production view?
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (pview != NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_view_findzone(pview, origin, &tzone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews else
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = ISC_R_NOTFOUND;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result == ISC_R_SUCCESS) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Yes.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews *
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * If the production zone's configuration is
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * the same as the new zone's, we can use the
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * production zone.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (dns_zone_equal(zone, tzone))
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_view_addzone(view, tzone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews else
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_view_addzone(view, zone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews } else if (result == ISC_R_NOTFOUND) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * This is a new zone.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_view_addzone(view, zone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != DNS_R_SUCCESS)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews goto cleanup;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_zonemgr_managezone(ns_g_zonemgr, zone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (result != DNS_R_SUCCESS)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews goto cleanup;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews cleanup:
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (tzone != NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_zone_detach(&tzone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (zone != NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_zone_detach(&zone);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (pview != NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_view_detach(&pview);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (view != NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_view_detach(&view);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (result);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews}
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews/* XXX will need error recovery for reconfig */
ff380b05fec3746934c74b78bb44f641d2acb359Francis Dupontstatic void
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewsconfigure_server_acl(dns_c_ctx_t *cctx, dns_aclconfctx_t *actx, isc_mem_t *mctx,
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_result_t (*getcacl)(dns_c_ctx_t *, dns_c_ipmatchlist_t **),
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_acl_t **aclp)
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington{
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington isc_result_t result;
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington dns_c_ipmatchlist_t *cacl = NULL;
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington if (*aclp != NULL)
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington dns_acl_detach(aclp);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews (void) (*getcacl)(cctx, &cacl);
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington if (cacl != NULL) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington result = dns_acl_fromconfig(cacl, cctx, actx, mctx, aclp);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews if (result != DNS_R_SUCCESS)
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington "server ACL setup failed");
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington dns_c_ipmatchlist_detach(&cacl);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff }
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington}
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonstatic void
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonload_configuration(const char *filename, ns_server_t *server) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington isc_result_t result;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews ns_load_t lctx;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews dns_c_cbks_t callbacks;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews dns_c_ctx_t *configctx;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews dns_view_t *view, *view_next;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews dns_viewlist_t oviewlist;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews dns_aclconfctx_t aclconfctx;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington dns_aclconfctx_init(&aclconfctx);
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington lctx.mctx = ns_g_mctx;
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington lctx.aclconf = &aclconfctx;
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson ISC_LIST_INIT(lctx.viewlist);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews callbacks.zonecbk = load_zone;
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews callbacks.zonecbkuap = &lctx;
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews callbacks.optscbk = NULL;
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews callbacks.optscbkuap = NULL;
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews ISC_LOG_INFO, "loading configuration from '%s'",
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews filename);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington configctx = NULL;
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington result = dns_c_parse_namedconf(filename, ns_g_mctx, &configctx,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington &callbacks);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington if (result != ISC_R_SUCCESS) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington#ifdef notyet
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington for (view = ISC_LIST_HEAD(lctx.viewlist);
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington view != NULL;
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington view = view_next) {
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews view_next = ISC_LIST_NEXT(view, link);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews ISC_LIST_UNLINK(lctx.viewlist, view, link);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews dns_view_detach(&view);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews }
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews#endif
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews "load of '%s' failed", filename);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews }
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews /*
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews * Configure various server options.
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews */
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington (void) dns_c_ctx_getrecursion(configctx, &server->recursion);
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington (void) dns_c_ctx_getauthnxdomain(configctx, &server->auth_nxdomain);
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson (void) dns_c_ctx_gettransferformat(configctx, &server->transfer_format);
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson
18b7133679efa8f60fd4e396c628576f3f416b3eBrian Wellington configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington dns_c_ctx_getqueryacl, &server->queryacl);
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews dns_c_ctx_getrecursionacl, &server->recursionacl);
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews configure_server_acl(configctx, &aclconfctx, ns_g_mctx,
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington dns_c_ctx_gettransferacl, &server->transferacl);
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * If we haven't created any views, create a default view for class
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * IN. (We're a caching-only server.)
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington */
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington if (ISC_LIST_EMPTY(lctx.viewlist)) {
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews view = NULL;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews result = create_default_view(configctx, ns_g_mctx,
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_rdataclass_in, &view);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews if (result != ISC_R_SUCCESS)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington "could not create default view");
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ISC_LIST_APPEND(lctx.viewlist, view, link);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington }
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Freeze the views.
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington */
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington for (view = ISC_LIST_HEAD(lctx.viewlist);
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews view != NULL;
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington view = ISC_LIST_NEXT(view, link))
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington dns_view_freeze(view);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington /*
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington * Create the version view.
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington */
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington view = NULL;
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington result = create_version_view(configctx, &view);
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews if (result != ISC_R_SUCCESS)
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews "could not create version view");
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews ISC_LIST_APPEND(lctx.viewlist, view, link);
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews view = NULL;
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Change directory.
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington */
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington if (configctx->options != NULL &&
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington configctx->options->directory != NULL) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = isc_dir_chdir(configctx->options->directory);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington if (result != ISC_R_SUCCESS)
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews "change directory to '%s' failed: %s",
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews configctx->options->directory,
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews isc_result_totext(result));
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews }
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews /*
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews * Load zones.
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews */
50105afc551903541608b11851d73278b23579a3Mark Andrews for (view = ISC_LIST_HEAD(lctx.viewlist);
50105afc551903541608b11851d73278b23579a3Mark Andrews view != NULL;
50105afc551903541608b11851d73278b23579a3Mark Andrews view = view_next) {
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews view_next = ISC_LIST_NEXT(view, link);
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews dns_view_load(view);
a05f23d07e1b60a1d88119678111a47014480611Mark Andrews }
a05f23d07e1b60a1d88119678111a47014480611Mark Andrews
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Force zone maintenance. Do this after loading
a05f23d07e1b60a1d88119678111a47014480611Mark Andrews * so that we know when we need to force AXFR of
a05f23d07e1b60a1d88119678111a47014480611Mark Andrews * slave zones whose master files are missing.
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews */
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews dns_zonemgr_forcemaint(ns_g_zonemgr);
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington /*
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington * Put the configuration into production.
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
18b7133679efa8f60fd4e396c628576f3f416b3eBrian Wellington RWLOCK(&server->viewlock, isc_rwlocktype_write);
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington oviewlist = server->viewlist;
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington server->viewlist = lctx.viewlist;
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington RWUNLOCK(&server->viewlock, isc_rwlocktype_write);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington /*
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews * Cleanup old configuration.
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews for (view = ISC_LIST_HEAD(oviewlist);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews view != NULL;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews view = view_next) {
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews view_next = ISC_LIST_NEXT(view, link);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews ISC_LIST_UNLINK(oviewlist, view, link);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_view_detach(&view);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews }
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews if (tsig_initialized) {
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_tkey_destroy();
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_tsig_destroy();
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews }
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews tsig_initialized = ISC_TRUE;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Load the TSIG information from the configuration
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = dns_tsig_init(ns_g_lctx, configctx, ns_g_mctx);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews if (result != ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews "dns_tsig_init() failed: %s",
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_result_totext(result));
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Load the TKEY information from the configuration
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = dns_tkey_init(ns_g_lctx, configctx, ns_g_mctx);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ns_server_fatal(NS_LOGMODULE_SERVER, ISC_FALSE,
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington "dns_tkey_init() failed: %s",
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews isc_result_totext(result));
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews }
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews /*
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews * Rescan the interface list to pick up changes in the
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews * listen-on option.
7d116211ec7b063891130f191e3ed437b45dba70Mark Andrews */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ns_interfacemgr_scan(server->interfacemgr);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_aclconfctx_destroy(&aclconfctx);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_c_ctx_delete(&configctx);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews}
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrewsstatic void
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrewsrun_server(isc_task_t *task, isc_event_t *event) {
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews ns_server_t *server = (ns_server_t *) event->arg;
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews (void)task;
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews isc_event_free(&event);
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews load_configuration(ns_g_conffile, server);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews ISC_LOG_INFO, "running");
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews}
4b45a8fc5a47dcff7473003ceeac6f6bb3e21e79Mark Andrews
8d414d155953f89a4eff40f16878438a8c9228f3Mark Andrewsstatic void
8d414d155953f89a4eff40f16878438a8c9228f3Mark Andrewsshutdown_server(isc_task_t *task, isc_event_t *event) {
be69d484434e10d920c4d8a8bb735356eb0c2cc8Evan Hunt dns_view_t *view, *view_next;
be69d484434e10d920c4d8a8bb735356eb0c2cc8Evan Hunt ns_server_t *server = (ns_server_t *) event->arg;
8d414d155953f89a4eff40f16878438a8c9228f3Mark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews (void)task;
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews
8d414d155953f89a4eff40f16878438a8c9228f3Mark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews ISC_LOG_INFO, "shutting down");
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews RWLOCK(&server->viewlock, isc_rwlocktype_write);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
8d414d155953f89a4eff40f16878438a8c9228f3Mark Andrews for (view = ISC_LIST_HEAD(server->viewlist);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews view != NULL;
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews view = view_next) {
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews view_next = ISC_LIST_NEXT(view, link);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews ISC_LIST_UNLINK(server->viewlist, view, link);
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews dns_view_detach(&view);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews }
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews RWUNLOCK(&server->viewlock, isc_rwlocktype_write);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews dns_tkey_destroy();
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater dns_tsig_destroy();
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews ns_interfacemgr_shutdown(server->interfacemgr);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ns_interfacemgr_detach(&server->interfacemgr);
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews dns_zonemgr_destroy(&ns_g_zonemgr);
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_task_detach(&server_task);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_event_free(&event);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews}
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsisc_result_t
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_result_t result;
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ns_server_t *server = isc_mem_get(mctx, sizeof(*server));
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (server == NULL)
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews return (ISC_R_NOMEMORY);
d8fc410cf830606a82c7ca169714d2f489b19d77Mark Andrews server->mctx = mctx;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /* Initialize configuration data with default values. */
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington server->recursion = ISC_TRUE;
48ed268b3378a8b729a0037bc4ae2ed73647a96aBrian Wellington server->auth_nxdomain = ISC_FALSE; /* Was true in BIND 8 */
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews server->transfer_format = dns_one_answer;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews server->queryacl = NULL;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews server->recursionacl = NULL;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews server->transferacl = NULL;
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington /* XXX these values are for debugging only */
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington result = isc_quota_init(&server->xfroutquota, 1);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington RUNTIME_CHECK(result == ISC_R_SUCCESS);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = isc_quota_init(&server->tcpquota, 3);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington RUNTIME_CHECK(result == ISC_R_SUCCESS);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington result = isc_quota_init(&server->recursionquota, 1);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews RUNTIME_CHECK(result == ISC_R_SUCCESS);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington /* Initialize server data structures. */
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff ISC_LIST_INIT(server->viewlist);
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington result = isc_rwlock_init(&server->viewlock, 0, 0);
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington RUNTIME_CHECK(result == ISC_R_SUCCESS);
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington server->interfacemgr = NULL;
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington result = ns_interfacemgr_create(ns_g_mctx, ns_g_taskmgr,
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington ns_g_socketmgr, ns_g_clientmgr,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews &server->interfacemgr);
6f071989da905bb5ab2c6dfd01a71ee5ecea5918Brian Wellington if (result != ISC_R_SUCCESS) {
8839b6acbf816fedc15b8e9e1c71fd606a9cd8eaBrian Wellington UNEXPECTED_ERROR(__FILE__, __LINE__,
9cd6710f91bdffef5aed68ab02533e398f6134d7Brian Wellington "ns_interfacemgr_create() failed: %s",
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson isc_result_totext(result));
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington /* XXX cleanup */
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews return (ISC_R_UNEXPECTED);
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews }
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafsson server->magic = NS_SERVER_MAGIC;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews *serverp = server;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews return (ISC_R_SUCCESS);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington}
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonvoid
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellingtonns_server_destroy(ns_server_t **serverp) {
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington ns_server_t *server = *serverp;
94766449d6125cd5870891b70d46573e5deaceb4Brian Wellington REQUIRE(NS_SERVER_VALID(server));
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews INSIST(ISC_LIST_EMPTY(server->viewlist));
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews isc_rwlock_destroy(&server->viewlock);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews if (server->queryacl != NULL)
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews dns_acl_detach(&server->queryacl);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews if (server->recursionacl != NULL)
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews dns_acl_detach(&server->recursionacl);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews if (server->transferacl != NULL)
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews dns_acl_detach(&server->transferacl);
a27b3757fdd8976ce05e37f391ad9e7ac4638e5dMark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_quota_destroy(&server->recursionquota);
3676eeb6ca95c66aae1256f37af8c990d9f25eb4Brian Wellington isc_quota_destroy(&server->tcpquota);
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington isc_quota_destroy(&server->xfroutquota);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews server->magic = 0;
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews isc_mem_put(server->mctx, server, sizeof(*server));
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews}
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrewsisc_result_t
34aa7909371f13b4bc0ba6d155cfc38bfa1e3c5cAndreas Gustafssonns_server_setup(void) {
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson isc_result_t result;
18b7133679efa8f60fd4e396c628576f3f416b3eBrian Wellington
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews /*
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington * Create the server object.
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = ns_server_create(ns_g_mctx, &ns_g_server);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews return (result);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Setup default root server hints.
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews */
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews result = ns_rootns_init();
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews if (result != ISC_R_SUCCESS)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews return (result);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ns_g_socketmgr, &ns_g_zonemgr);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews return (result);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /*
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * Setup the server task, which is responsible for coordinating
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews * startup and shutdown of the server.
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews */
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = isc_task_create(ns_g_taskmgr, ns_g_mctx, 0, &server_task);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews goto cleanup_rootns;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = isc_task_onshutdown(server_task, shutdown_server, ns_g_server);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews goto cleanup_task;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews result = isc_app_onrun(ns_g_mctx, server_task, run_server, ns_g_server);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (result != ISC_R_SUCCESS)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews goto cleanup_task;
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
17a3fcecd069130a5f318685493b0db5639a77c9Brian Wellington return (ISC_R_SUCCESS);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews /* XXXRTH Add zonemgr, and version view cleanups. */
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews cleanup_task:
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews isc_task_detach(&server_task);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews cleanup_rootns:
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews ns_rootns_destroy();
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews return (result);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews}
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrewsvoid
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrewsns_server_cleanup(void)
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews{
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews ns_rootns_destroy();
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt ns_server_destroy(&ns_g_server);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews}
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrewsvoid
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrewsns_server_fatal(isc_logmodule_t *module, isc_boolean_t want_core,
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews const char *format, ...)
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews{
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews va_list args;
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews va_start(args, format);
515c7f3c43f76d7b439905b18009105364b36100Automatic Updater isc_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, module,
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews ISC_LOG_CRITICAL, format, args);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews va_end(args);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews ISC_LOG_CRITICAL, "exiting (due to fatal error)");
50105afc551903541608b11851d73278b23579a3Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if (want_core && ns_g_coreok)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews abort();
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews exit(1);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews}
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews