ef491b68cd4d65839f09171df243aeaf013247bfAndreas Gustafsson/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2007, 2011, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
ef491b68cd4d65839f09171df243aeaf013247bfAndreas Gustafsson *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
ef491b68cd4d65839f09171df243aeaf013247bfAndreas Gustafsson */
ef491b68cd4d65839f09171df243aeaf013247bfAndreas Gustafsson
0e11ca0f0bdeb8eface941671926a9f4d2fc2685Automatic Updater/* $Id: tcldb.c,v 1.12 2011/10/11 23:46:45 tbox Exp $ */
740af672b43473dce3095aa3f05fd0a820d9d756Andreas Gustafsson
740af672b43473dce3095aa3f05fd0a820d9d756Andreas Gustafsson/*
740af672b43473dce3095aa3f05fd0a820d9d756Andreas Gustafsson * A simple database driver that calls a Tcl procedure to define
740af672b43473dce3095aa3f05fd0a820d9d756Andreas Gustafsson * the contents of the DNS namespace. The procedure is loaded
740af672b43473dce3095aa3f05fd0a820d9d756Andreas Gustafsson * from the file lookup.tcl; look at the comments there for
740af672b43473dce3095aa3f05fd0a820d9d756Andreas Gustafsson * more information.
740af672b43473dce3095aa3f05fd0a820d9d756Andreas Gustafsson */
ef491b68cd4d65839f09171df243aeaf013247bfAndreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <config.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <string.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <stdlib.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <unistd.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <sys/stat.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <isc/mem.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <isc/print.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <isc/result.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <isc/util.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <dns/log.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <dns/sdb.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <named/globals.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <tcl.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#include <tcldb.h>
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson#define CHECK(op) \
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson do { result = (op); \
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (result != ISC_R_SUCCESS) return (result); \
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson } while (0)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontypedef struct tcldb_driver {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_mem_t *mctx;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_Interp *interp;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson} tcldb_driver_t;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafssonstatic tcldb_driver_t *the_driver = NULL;
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafssonstatic dns_sdbimplementation_t *tcldb = NULL;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssonstatic isc_result_t
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_driver_create(isc_mem_t *mctx, tcldb_driver_t **driverp) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson int tclres;
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson isc_result_t result = ISC_R_SUCCESS;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_driver_t *driver = isc_mem_get(mctx, sizeof(tcldb_driver_t));
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (driver == NULL)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (ISC_R_NOMEMORY);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson driver->mctx = mctx;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson driver->interp = Tcl_CreateInterp();
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tclres = Tcl_EvalFile(driver->interp, (char *) "lookup.tcl");
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (tclres != TCL_OK) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson "initializing tcldb: "
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson "loading 'lookup.tcl' failed: %s",
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson driver->interp->result);
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson result = ISC_R_FAILURE;
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson goto cleanup;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson }
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson *driverp = driver;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (ISC_R_SUCCESS);
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson cleanup:
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson isc_mem_put(mctx, driver, sizeof(tcldb_driver_t));
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson return (result);
0e11ca0f0bdeb8eface941671926a9f4d2fc2685Automatic Updater
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson}
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssonstatic void
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_driver_destroy(tcldb_driver_t **driverp) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_driver_t *driver = *driverp;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_DeleteInterp(driver->interp);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_mem_put(driver->mctx, driver, sizeof(tcldb_driver_t));
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson}
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson/*
89beab759407cc76083deb7a2c5215f00bf9a82eAndreas Gustafsson * Perform a lookup, by invoking the Tcl procedure "lookup".
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#ifdef DNS_CLIENTINFO_VERSION
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntstatic isc_result_t
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunttcldb_lookup(const char *zone, const char *name, void *dbdata,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_sdblookup_t *lookup, dns_clientinfomethods_t *methods,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfo_t *clientinfo)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#else
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssonstatic isc_result_t
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_lookup(const char *zone, const char *name, void *dbdata,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson dns_sdblookup_t *lookup)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson{
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_result_t result = ISC_R_SUCCESS;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson int tclres;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson int rrc; /* RR count */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson char **rrv; /* RR vector */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson int i;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson char *cmdv[3];
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson char *cmd;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#ifdef DNS_CLIENTINFO_VERSION
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt UNUSED(methods);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt UNUSED(clientinfo);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_driver_t *driver = (tcldb_driver_t *) dbdata;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson cmdv[0] = "lookup";
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson cmdv[1] = zone;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson cmdv[2] = name;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson cmd = Tcl_Merge(3, cmdv);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tclres = Tcl_Eval(driver->interp, cmd);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_Free(cmd);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (tclres != TCL_OK) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson "zone '%s': tcl lookup function failed: %s",
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson zone, driver->interp->result);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (ISC_R_FAILURE);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson }
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (strcmp(driver->interp->result, "NXDOMAIN") == 0) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson result = ISC_R_NOTFOUND;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson goto fail;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson }
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington tclres = Tcl_SplitList(driver->interp, driver->interp->result,
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington &rrc, &rrv);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (tclres != TCL_OK)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson goto malformed;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson for (i = 0; i < rrc; i++) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_result_t tmpres;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson int fieldc; /* Field count */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson char **fieldv; /* Field vector */
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington tclres = Tcl_SplitList(driver->interp, rrv[i],
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington &fieldc, &fieldv);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (tclres != TCL_OK) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tmpres = ISC_R_FAILURE;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson goto failrr;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson }
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (fieldc != 3)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson goto malformed;
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington tmpres = dns_sdb_putrr(lookup, fieldv[0], atoi(fieldv[1]),
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington fieldv[2]);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_Free((char *) fieldv);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson failrr:
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (tmpres != ISC_R_SUCCESS)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson result = tmpres;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson }
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_Free((char *) rrv);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (result == ISC_R_SUCCESS)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (result);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson malformed:
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson DNS_LOGMODULE_SDB, ISC_LOG_ERROR,
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington "zone '%s': "
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington "malformed return value from tcl lookup function: %s",
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson zone, driver->interp->result);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson result = ISC_R_FAILURE;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson fail:
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (result);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson}
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson/*
89beab759407cc76083deb7a2c5215f00bf9a82eAndreas Gustafsson * Set up per-zone state. In our case, the database arguments of the
89beab759407cc76083deb7a2c5215f00bf9a82eAndreas Gustafsson * zone are collected into a Tcl list and assigned to an element of
89beab759407cc76083deb7a2c5215f00bf9a82eAndreas Gustafsson * the global array "dbargs".
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssonstatic isc_result_t
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_create(const char *zone, int argc, char **argv,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson void *driverdata, void **dbdata)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson{
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_driver_t *driver = (tcldb_driver_t *) driverdata;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson char *list = Tcl_Merge(argc, argv);
0e11ca0f0bdeb8eface941671926a9f4d2fc2685Automatic Updater
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_SetVar2(driver->interp, (char *) "dbargs", (char *) zone, list, 0);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_Free(list);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson *dbdata = driverdata;
0e11ca0f0bdeb8eface941671926a9f4d2fc2685Automatic Updater
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (ISC_R_SUCCESS);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson}
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson/*
89beab759407cc76083deb7a2c5215f00bf9a82eAndreas Gustafsson * This driver does not support zone transfer, so allnodes() is NULL.
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssonstatic dns_sdbmethods_t tcldb_methods = {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_lookup,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson NULL, /* authority */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson NULL, /* allnodes */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_create,
58f1ac8dadf2c1f215343a0b2d1df2df954c4b19Mark Andrews NULL, /* destroy */
58f1ac8dadf2c1f215343a0b2d1df2df954c4b19Mark Andrews NULL /* lookup2 */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson};
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson/*
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson * Initialize the tcldb driver.
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssonisc_result_t
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_init(void) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_result_t result;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson int flags = DNS_SDBFLAG_RELATIVEOWNER | DNS_SDBFLAG_RELATIVERDATA;
0e11ca0f0bdeb8eface941671926a9f4d2fc2685Automatic Updater
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson result = tcldb_driver_create(ns_g_mctx, &the_driver);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (result != ISC_R_SUCCESS)
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (result);
0e11ca0f0bdeb8eface941671926a9f4d2fc2685Automatic Updater
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (dns_sdb_register("tcl", &tcldb_methods, the_driver, flags,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson ns_g_mctx, &tcldb));
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson}
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson/*
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson * Wrapper around dns_sdb_unregister().
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssonvoid
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_clear(void) {
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson if (tcldb != NULL)
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson dns_sdb_unregister(&tcldb);
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson if (the_driver != NULL)
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson tcldb_driver_destroy(&the_driver);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson}