8664a1bd40814ed0b42eacfc5eb354b598dfd6dfTinderbox User * Copyright (C) 2015-2017 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/.
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunttypedef struct dyndb_implementation dyndb_implementation_t;
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * List of dyndb implementations. Locked by dyndb_lock.
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * These are stored here so they can be cleaned up on shutdown.
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt * (The order in which they are stored is not important.)
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Huntstatic LIST(dyndb_implementation_t) dyndb_implementations;
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt/* Locks dyndb_implementations. */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt RUNTIME_CHECK(isc_mutex_init(&dyndb_lock) == ISC_R_SUCCESS);
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt "failed to lookup symbol %s in "
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt "dyndb module '%s': %s",
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Huntload_library(isc_mem_t *mctx, const char *filename, const char *instname,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt "loading DynDB instance '%s' driver '%s'",
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt /* Clear dlerror */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt CHECK(load_symbol(handle, filename, "dyndb_version",
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt if (version < (DNS_DYNDB_VERSION - DNS_DYNDB_AGE) ||
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt "driver API version mismatch: %d/%d",
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt CHECK(load_symbol(handle, filename, "dyndb_destroy",
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt imp = isc_mem_get(mctx, sizeof(dyndb_implementation_t));
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt "failed to dynamically load instance '%s' "
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupontload_symbol(HMODULE handle, const char *filename,
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont REQUIRE(symbolp != NULL && *symbolp == NULL);
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont symbol = GetProcAddress(handle, symbol_name);
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont "failed to lookup symbol %s in "
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont "dyndb module '%s': %d",
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupontload_library(isc_mem_t *mctx, const char *filename, const char *instname,
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont "loading DynDB instance '%s' driver '%s'",
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont CHECK(load_symbol(handle, filename, "dyndb_version",
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont if (version < (DNS_DYNDB_VERSION - DNS_DYNDB_AGE) ||
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont "driver API version mismatch: %d/%d",
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont CHECK(load_symbol(handle, filename, "dyndb_init",
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont CHECK(load_symbol(handle, filename, "dyndb_destroy",
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont imp = isc_mem_get(mctx, sizeof(dyndb_implementation_t));
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont "failed to dynamically load instance '%s' "
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont if (result != ISC_R_SUCCESS && handle != NULL)
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupontunload_library(dyndb_implementation_t **impp) {
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
343aeac7176d28c4a1b9d246b1f7311b4cd5da7dFrancis Dupont#else /* HAVE_DLFCN_H || _WIN32 */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Huntload_library(isc_mem_t *mctx, const char *filename, const char *instname,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB,
dd784c18ef799e9e35c9debe34323c50d4e7f8a5Francis Dupont "dynamic database support is not implemented");
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt#endif /* HAVE_DLFCN_H */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Huntdns_dyndb_load(const char *libname, const char *name, const char *parameters,
f503aa345b451f94875a5bab637223bcbbd93b6dEvan Hunt const char *file, unsigned long line, isc_mem_t *mctx,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt /* duplicate instance names are not allowed */
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt CHECK(load_library(mctx, libname, name, &implementation));
f503aa345b451f94875a5bab637223bcbbd93b6dEvan Hunt CHECK(implementation->register_func(mctx, name, parameters, file, line,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt APPEND(dyndb_implementations, implementation, link);
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
93c211afc97e7a072c12ef346581065e4065ff15Evan Huntdns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx,
93c211afc97e7a072c12ef346581065e4065ff15Evan Hunt dns_view_t *view, dns_zonemgr_t *zmgr, isc_task_t *task,
a00f9e2f50675bd43cc6a9fe2669709162a2ccb4Evan Hunt REQUIRE(dctxp != NULL && DNS_DYNDBCTX_VALID(*dctxp));