db.c revision b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81
5cd4555ad444fd391002ae32450572054369fd42Rob Austein/*
5cd4555ad444fd391002ae32450572054369fd42Rob Austein * Copyright (C) 1999 Internet Software Consortium.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
938440694b33cd752e9e4b71a526368b4811c177Tinderbox User * purpose with or without fee is hereby granted, provided that the above
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews * copyright notice and this permission notice appear in all copies.
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson * 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.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews */
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews/***
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson *** Imports
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews ***/
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson#include <config.h>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
1753d3c4d74241a847794f7e7cfd94cc79be6600Evan Hunt#include <stddef.h>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#include <string.h>
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#include <isc/assertions.h>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#include <dns/db.h>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#include <dns/master.h>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#include <dns/rdataset.h>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/***
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *** Private Types
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ***/
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeintypedef struct {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein char * name;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dns_result_t (*create)(isc_mem_t *mctx, dns_name_t *name,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein isc_boolean_t cache,
c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85Mark Andrews dns_rdataclass_t rdclass,
938440694b33cd752e9e4b71a526368b4811c177Tinderbox User unsigned int argc, char *argv[],
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dns_db_t **dbp);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein} impinfo_t;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/***
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *** Supported DB Implementations Registry
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews ***/
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Supported database implementations must be registered here.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * It might be nice to generate this automatically some day.
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson */
4b01d45a49f1c2cc4bddc9a1b4c78232867de134Andreas Gustafsson
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#include "rbtdb.h"
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein#include "rbtdb64.h"
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinimpinfo_t implementations[] = {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein { "rbt", dns_rbtdb_create },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein { "rbt64", dns_rbtdb64_create },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein { NULL, NULL }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein};
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/***
821350367e2c7313c02eb275e8e05d5193b47cfdJeremy C. Reed *** Basic DB Methods
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ***/
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_result_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein isc_boolean_t cache, dns_rdataclass_t rdclass,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein unsigned int argc, char *argv[], dns_db_t **dbp)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein{
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein impinfo_t *impinfo;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Create a new database using implementation 'db_type'.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(dbp != NULL && *dbp == NULL);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(dns_name_isabsolute(origin));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein for (impinfo = implementations; impinfo->name != NULL; impinfo++)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (strcasecmp(db_type, impinfo->name) == 0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return ((impinfo->create)(mctx, origin, cache, rdclass,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein argc, argv, dbp));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (DNS_R_NOTFOUND);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinvoid
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_attach(dns_db_t *source, dns_db_t **targetp) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Attach *targetp to source.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(source));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(targetp != NULL);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein (source->methods->attach)(source, targetp);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ENSURE(*targetp == source);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinvoid
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_detach(dns_db_t **dbp) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Detach *dbp from its database.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(dbp != NULL);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(*dbp));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ((*dbp)->methods->detach)(dbp);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ENSURE(*dbp == NULL);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinisc_boolean_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_iscache(dns_db_t *db) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Does 'db' have cache semantics?
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if ((db->attributes & DNS_DBATTR_CACHE) != 0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (ISC_TRUE);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (ISC_FALSE);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinisc_boolean_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_iszone(dns_db_t *db) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Does 'db' have zone semantics?
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if ((db->attributes & DNS_DBATTR_CACHE) == 0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (ISC_TRUE);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (ISC_FALSE);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinisc_boolean_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_issecure(dns_db_t *db) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Is 'db' secure?
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return ((db->methods->issecure)(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_name_t *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_origin(dns_db_t *db) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * The origin of the database.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (&db->origin);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_rdataclass_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_class(dns_db_t *db) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * The class of the database.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (db->rdclass);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_result_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dns_dbload_t **dbloadp) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Begin loading 'db'.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(addp != NULL && *addp == NULL);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(dbloadp != NULL && *dbloadp == NULL);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return ((db->methods->beginload)(db, addp, dbloadp));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_result_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Finish loading 'db'.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(dbloadp != NULL && *dbloadp != NULL);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return ((db->methods->endload)(db, dbloadp));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_result_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_load(dns_db_t *db, char *filename) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dns_result_t result, eresult;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein int soacount, nscount;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dns_rdatacallbacks_t callbacks;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein isc_boolean_t age_ttl = ISC_FALSE;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Load master file 'filename' into 'db'.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if ((db->attributes & DNS_DBATTR_CACHE) != 0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein age_ttl = ISC_TRUE;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dns_rdatacallbacks_init(&callbacks);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein result = dns_db_beginload(db, &callbacks.add, &callbacks.add_private);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (result != DNS_R_SUCCESS)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (result);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein result = dns_master_loadfile(filename, &db->origin, &db->origin,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein db->rdclass, age_ttl, &soacount, &nscount,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein &callbacks, db->mctx);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein eresult = dns_db_endload(db, &callbacks.add_private);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * We always call dns_db_endload(), but we only want to return its
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * result if dns_master_loadfile() succeeded. If dns_master_loadfile()
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * failed, we want to return the result code it gave us.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (result == ISC_R_SUCCESS)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein result = eresult;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return (result);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_result_t
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_dump(dns_db_t *db, dns_dbversion_t *version, char *filename) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Dump 'db' into master file 'filename'.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein REQUIRE(DNS_DB_VALID(db));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return ((db->methods->dump)(db, version, filename));
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/***
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *** Version Methods
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ***/
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinvoid
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeindns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /*
* Open the current version for reading.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(versionp != NULL && *versionp == NULL);
(db->methods->currentversion)(db, versionp);
}
dns_result_t
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
/*
* Open a new version for reading and writing.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(versionp != NULL && *versionp == NULL);
return ((db->methods->newversion)(db, versionp));
}
void
dns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
dns_dbversion_t **targetp)
{
/*
* Attach '*targetp' to 'source'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(source != NULL);
REQUIRE(targetp != NULL && *targetp != NULL);
(db->methods->attachversion)(db, source, targetp);
ENSURE(*targetp != NULL);
}
void
dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
isc_boolean_t commit)
{
/*
* Close version '*versionp'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(versionp != NULL && *versionp != NULL);
(db->methods->closeversion)(db, versionp, commit);
ENSURE(*versionp == NULL);
}
/***
*** Node Methods
***/
dns_result_t
dns_db_findnode(dns_db_t *db, dns_name_t *name,
isc_boolean_t create, dns_dbnode_t **nodep)
{
/*
* Find the node with name 'name'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(dns_name_issubdomain(name, &db->origin));
REQUIRE(nodep != NULL && *nodep == NULL);
return ((db->methods->findnode)(db, name, create, nodep));
}
dns_result_t
dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
dns_dbnode_t **nodep, dns_name_t *foundname,
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
{
/*
* Find the best match for 'name' and 'type' in version 'version'
* of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(type != dns_rdatatype_sig);
REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
REQUIRE(dns_name_hasbuffer(foundname));
REQUIRE(rdataset == NULL ||
(DNS_RDATASET_VALID(rdataset) && rdataset->methods == NULL));
REQUIRE(sigrdataset == NULL ||
(DNS_RDATASET_VALID(sigrdataset) &&
sigrdataset->methods == NULL));
return ((db->methods->find)(db, name, version, type, options, now,
nodep, foundname, rdataset, sigrdataset));
}
void
dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
/*
* Attach *targetp to source.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(source != NULL);
REQUIRE(targetp != NULL && *targetp == NULL);
(db->methods->attachnode)(db, source, targetp);
}
void
dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep) {
/*
* Detach *nodep from its node.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(nodep != NULL && *nodep != NULL);
(db->methods->detachnode)(db, nodep);
ENSURE(*nodep == NULL);
}
dns_result_t
dns_db_expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) {
/*
* Mark as stale all records at 'node' which expire at or before 'now'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
REQUIRE(node != NULL);
return ((db->methods->expirenode)(db, node, now));
}
void
dns_db_printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) {
/*
* Print a textual representation of the contents of the node to
* 'out'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
(db->methods->printnode)(db, node, out);
}
/***
*** DB Iterator Creation
***/
dns_result_t
dns_db_createiterator(dns_db_t *db, isc_boolean_t relative_names,
dns_dbiterator_t **iteratorp)
{
/*
* Create an iterator for version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(iteratorp != NULL && *iteratorp == NULL);
return (db->methods->createiterator(db, relative_names, iteratorp));
}
/***
*** Rdataset Methods
***/
dns_result_t
dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
dns_rdatatype_t type, dns_rdatatype_t covers,
isc_stdtime_t now, dns_rdataset_t *rdataset)
{
/*
* Search for an rdataset of type 'type' at 'node' that are in version
* 'version' of 'db'. If found, make 'rdataset' refer to it.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(rdataset->methods == NULL);
REQUIRE(covers == 0 || type == dns_rdatatype_sig);
REQUIRE(type != dns_rdatatype_any);
return ((db->methods->findrdataset)(db, node, version, type, covers,
now, rdataset));
}
dns_result_t
dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
isc_stdtime_t now, dns_rdatasetiter_t **iteratorp)
{
/*
* Make '*iteratorp' an rdataset iteratator for all rdatasets at
* 'node' in version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(iteratorp != NULL && *iteratorp == NULL);
return ((db->methods->allrdatasets)(db, node, version, now,
iteratorp));
}
dns_result_t
dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
isc_stdtime_t now, dns_rdataset_t *rdataset,
isc_boolean_t merge, dns_rdataset_t *addedrdataset)
{
/*
* Add 'rdataset' to 'node' in version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL)||
((db->attributes & DNS_DBATTR_CACHE) != 0 &&
version == NULL && !merge));
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(rdataset->methods != NULL);
REQUIRE(rdataset->rdclass == db->rdclass);
REQUIRE(addedrdataset == NULL ||
(DNS_RDATASET_VALID(addedrdataset) &&
addedrdataset->methods == NULL));
return ((db->methods->addrdataset)(db, node, version, now, rdataset,
merge, addedrdataset));
}
dns_result_t
dns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version, dns_rdataset_t *rdataset,
dns_rdataset_t *newrdataset)
{
/*
* Remove any rdata in 'rdataset' from 'node' in version 'version' of
* 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(rdataset->methods != NULL);
REQUIRE(rdataset->rdclass == db->rdclass);
REQUIRE(newrdataset == NULL ||
(DNS_RDATASET_VALID(newrdataset) &&
newrdataset->methods == NULL));
return ((db->methods->subtractrdataset)(db, node, version, rdataset,
newrdataset));
}
dns_result_t
dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version, dns_rdatatype_t type)
{
/*
* Make it so that no rdataset of type 'type' exists at 'node' in
* version version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL)||
((db->attributes & DNS_DBATTR_CACHE) != 0 && version == NULL));
return ((db->methods->deleterdataset)(db, node, version, type));
}