88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews/*
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * Copyright (C) 2002 Nuno M. Rodrigues.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews *
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * Permission to use, copy, modify, and distribute this software for any
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * purpose with or without fee is hereby granted, provided that the above
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * copyright notice and this permission notice appear in all copies.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews *
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND NUNO M. RODRIGUES
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt/* $Id: bdb.c,v 1.2 2011/10/11 00:09:02 each Exp $ */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews/*
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * BIND 9.1.x simple database driver
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * implementation, using Berkeley DB.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <errno.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <stdio.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <string.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <stdlib.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/file.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/log.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/lib.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/mem.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/msgs.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/msgcat.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/region.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/result.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/types.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <isc/util.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <dns/sdb.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <dns/log.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <dns/lib.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <dns/ttl.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <named/bdb.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <named/globals.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <named/config.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#include <db.h>
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews#define DRIVERNAME "bdb"
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsstatic dns_sdbimplementation_t *bdb_imp;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsstatic isc_result_t
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_create(const char *zone, int argc, char **argv,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews void *unused, void **dbdata)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews{
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews int ret;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews UNUSED(zone);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews UNUSED(unused);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (argc < 1)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE; /* database path must be given */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (db_create((DB **)dbdata, NULL, 0) != 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews /*
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * XXX Should use dns_msgcat et al
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews * but seems to be unavailable.
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_CRITICAL, isc_msgcat,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_MSGSET_GENERAL, ISC_MSG_FATALERROR,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews "db_create");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (isc_file_exists(*argv) != ISC_TRUE) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_CRITICAL, isc_msgcat,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_MSGSET_GENERAL, ISC_MSG_FATALERROR,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews "isc_file_exists: %s", *argv);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if ((ret = (*(DB **)dbdata)->open(*(DB **)dbdata, *argv, NULL, DB_HASH,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DB_RDONLY, 0)) != 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_CRITICAL,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_msgcat, ISC_MSGSET_GENERAL,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_MSG_FATALERROR, "DB->open: %s",
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews db_strerror(ret));
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_SUCCESS;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews}
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsstatic isc_result_t
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#ifdef DNS_CLIENTINFO_VERSION
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntbdb_lookup(const char *zone, const char *name, void *dbdata,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_sdblookup_t *l, dns_clientinfomethods_t *methods,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfo_t *clientinfo)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#else
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_lookup(const char *zone, const char *name, void *dbdata,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_sdblookup_t *l)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews{
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews int ret;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews char *type, *rdata;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_ttl_t ttl;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_consttextregion_t ttltext;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DBC *c;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DBT key, data;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews UNUSED(zone);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#ifdef DNS_CLIENTINFO_VERSION
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt UNUSED(methods);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt UNUSED(clientinfo);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if ((ret = ((DB *)dbdata)->cursor((DB *)dbdata, NULL, &c, 0)) != 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_msgcat, ISC_MSGSET_GENERAL,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_MSG_FAILED, "DB->cursor: %s",
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews db_strerror(ret));
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews memset(&key, 0, sizeof(DBT));
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews memset(&data, 0, sizeof(DBT));
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews (const char *)key.data = name;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews key.size = strlen(name);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ret = c->c_get(c, &key, &data, DB_SET);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews while (ret == 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ((char *)key.data)[key.size] = 0;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ((char *)data.data)[data.size] = 0;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ttltext.base = strtok((char *)data.data, " ");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ttltext.length = strlen(ttltext.base);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews type = strtok(NULL, " ");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews rdata = type + strlen(type) + 1;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (dns_sdb_putrr(l, type, ttl, rdata) != ISC_R_SUCCESS) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_msgcat, ISC_MSGSET_GENERAL,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_MSG_FAILED, "dns_sdb_putrr");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ret = c->c_get(c, &key, &data, DB_NEXT_DUP);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews c->c_close(c);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_SUCCESS;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews}
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsstatic isc_result_t
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t *n)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews{
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews int ret;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews char *type, *rdata;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_ttl_t ttl;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_consttextregion_t ttltext;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DBC *c;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DBT key, data;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews UNUSED(zone);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if ((ret = ((DB *)dbdata)->cursor((DB *)dbdata, NULL, &c, 0)) != 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx, DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_msgcat, ISC_MSGSET_GENERAL,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_MSG_FAILED, "DB->cursor: %s",
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews db_strerror(ret));
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews memset(&key, 0, sizeof(DBT));
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews memset(&data, 0, sizeof(DBT));
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews while (c->c_get(c, &key, &data, DB_NEXT) == 0) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ((char *)key.data)[key.size] = 0;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ((char *)data.data)[data.size] = 0;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ttltext.base = strtok((char *)data.data, " ");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ttltext.length = strlen(ttltext.base);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_ttl_fromtext((isc_textregion_t *)&ttltext, &ttl);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews type = strtok(NULL, " ");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews rdata = type + strlen(type) + 1;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (dns_sdb_putnamedrr(n, key.data, type, ttl, rdata) !=
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_R_SUCCESS) {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_log_iwrite(dns_lctx,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGCATEGORY_DATABASE,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews isc_msgcat, ISC_MSGSET_GENERAL,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews ISC_MSG_FAILED, "dns_sdb_putnamedrr");
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_FAILURE;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews }
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews c->c_close(c);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_SUCCESS;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews}
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsstatic isc_result_t
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_destroy(const char *zone, void *unused, void **dbdata)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews{
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews UNUSED(zone);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews UNUSED(unused);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews (*(DB **)dbdata)->close(*(DB **)dbdata, 0);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return ISC_R_SUCCESS;
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews}
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsisc_result_t
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_init(void)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews{
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews static dns_sdbmethods_t bdb_methods = {
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews bdb_lookup,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews NULL,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews bdb_allnodes,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews bdb_create,
58f1ac8dadf2c1f215343a0b2d1df2df954c4b19Mark Andrews bdb_destroy,
58f1ac8dadf2c1f215343a0b2d1df2df954c4b19Mark Andrews NULL /* lookup2 */
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews };
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews return dns_sdb_register(DRIVERNAME, &bdb_methods, NULL, 0, ns_g_mctx,
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews &bdb_imp);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews}
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsvoid
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrewsbdb_clear(void)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews{
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews if (bdb_imp != NULL)
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews dns_sdb_unregister(&bdb_imp);
88aa68f478c1634f5f10034fb6ea4158efa20ff4Mark Andrews}