0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2007, 2011, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
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/.
0e11ca0f0bdeb8eface941671926a9f4d2fc2685Automatic Updater/* $Id: tcldb.c,v 1.12 2011/10/11 23:46:45 tbox Exp $ */
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.
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (result != ISC_R_SUCCESS) return (result); \
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafssonstatic dns_sdbimplementation_t *tcldb = NULL;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_driver_create(isc_mem_t *mctx, tcldb_driver_t **driverp) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_driver_t *driver = isc_mem_get(mctx, sizeof(tcldb_driver_t));
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tclres = Tcl_EvalFile(driver->interp, (char *) "lookup.tcl");
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson "initializing tcldb: "
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson "loading 'lookup.tcl' failed: %s",
2fbc38f7b94704e1147137ed30638b60a37b0be1Andreas Gustafsson isc_mem_put(mctx, driver, sizeof(tcldb_driver_t));
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_driver_destroy(tcldb_driver_t **driverp) {
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_mem_put(driver->mctx, driver, sizeof(tcldb_driver_t));
89beab759407cc76083deb7a2c5215f00bf9a82eAndreas Gustafsson * Perform a lookup, by invoking the Tcl procedure "lookup".
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunttcldb_lookup(const char *zone, const char *name, void *dbdata,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_sdblookup_t *lookup, dns_clientinfomethods_t *methods,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafssontcldb_lookup(const char *zone, const char *name, void *dbdata,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#endif /* DNS_CLIENTINFO_VERSION */
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_driver_t *driver = (tcldb_driver_t *) dbdata;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson "zone '%s': tcl lookup function failed: %s",
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson if (strcmp(driver->interp->result, "NXDOMAIN") == 0) {
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington tclres = Tcl_SplitList(driver->interp, driver->interp->result,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson for (i = 0; i < rrc; i++) {
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington tclres = Tcl_SplitList(driver->interp, rrv[i],
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington tmpres = dns_sdb_putrr(lookup, fieldv[0], atoi(fieldv[1]),
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington "zone '%s': "
055934c9ddc5a7518dc3d4441fcfe00f101a267cBrian Wellington "malformed return value from tcl lookup function: %s",
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 Gustafssontcldb_create(const char *zone, int argc, char **argv,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson tcldb_driver_t *driver = (tcldb_driver_t *) driverdata;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson Tcl_SetVar2(driver->interp, (char *) "dbargs", (char *) zone, list, 0);
89beab759407cc76083deb7a2c5215f00bf9a82eAndreas Gustafsson * This driver does not support zone transfer, so allnodes() is NULL.
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson * Initialize the tcldb driver.
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson int flags = DNS_SDBFLAG_RELATIVEOWNER | DNS_SDBFLAG_RELATIVERDATA;
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson result = tcldb_driver_create(ns_g_mctx, &the_driver);
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson return (dns_sdb_register("tcl", &tcldb_methods, the_driver, flags,
22aa1c0bc258e6c2c7491e2e330e3c363daa2b80Andreas Gustafsson * Wrapper around dns_sdb_unregister().