2018-08-03 14:16:41 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#if HAVE_DLFCN_H
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#elif _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
#include <isc/list.h>
|
|
|
|
#include <isc/log.h>
|
2018-08-03 14:16:41 -07:00
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/mutex.h>
|
|
|
|
#include <isc/result.h>
|
2018-09-14 12:32:36 -07:00
|
|
|
#include <isc/platform.h>
|
2018-08-03 14:16:41 -07:00
|
|
|
#include <isc/util.h>
|
2018-09-14 12:32:36 -07:00
|
|
|
#include <isc/types.h>
|
2018-08-03 14:16:41 -07:00
|
|
|
|
2018-11-02 23:28:25 -07:00
|
|
|
#include <dns/view.h>
|
|
|
|
|
2018-08-03 14:16:41 -07:00
|
|
|
#include <ns/hooks.h>
|
|
|
|
#include <ns/log.h>
|
2018-09-14 12:32:36 -07:00
|
|
|
#include <ns/query.h>
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
#define CHECK(op) \
|
2018-09-14 12:32:36 -07:00
|
|
|
do { \
|
|
|
|
result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) { \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
2018-08-03 14:16:41 -07:00
|
|
|
} while (0)
|
|
|
|
|
2018-10-31 19:02:29 -07:00
|
|
|
struct ns_module {
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
void *handle;
|
|
|
|
void *inst;
|
|
|
|
char *modpath;
|
2018-11-02 23:28:25 -07:00
|
|
|
ns_hook_check_t *check_func;
|
2018-10-31 19:02:29 -07:00
|
|
|
ns_hook_register_t *register_func;
|
|
|
|
ns_hook_destroy_t *destroy_func;
|
|
|
|
LINK(ns_module_t) link;
|
2018-08-03 14:16:41 -07:00
|
|
|
};
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
static ns_hooklist_t default_hooktable[NS_HOOKPOINTS_COUNT];
|
|
|
|
LIBNS_EXTERNAL_DATA ns_hooktable_t *ns__hook_table = &default_hooktable;
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
#if HAVE_DLFCN_H && HAVE_DLOPEN
|
|
|
|
static isc_result_t
|
2018-09-14 12:32:36 -07:00
|
|
|
load_symbol(void *handle, const char *modpath,
|
2018-08-03 14:16:41 -07:00
|
|
|
const char *symbol_name, void **symbolp)
|
|
|
|
{
|
2018-09-19 23:38:23 -07:00
|
|
|
void *symbol = NULL;
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
REQUIRE(handle != NULL);
|
|
|
|
REQUIRE(symbolp != NULL && *symbolp == NULL);
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
/*
|
|
|
|
* Clear any pre-existing error conditions before running dlsym().
|
|
|
|
* (In this case, we expect dlsym() to return non-NULL values
|
|
|
|
* and will always return an error if it returns NULL, but
|
|
|
|
* this ensures that we'll report the correct error condition
|
|
|
|
* if there is one.)
|
|
|
|
*/
|
|
|
|
dlerror();
|
2018-08-03 14:16:41 -07:00
|
|
|
symbol = dlsym(handle, symbol_name);
|
|
|
|
if (symbol == NULL) {
|
2018-09-14 12:32:36 -07:00
|
|
|
const char *errmsg = dlerror();
|
2018-08-03 14:16:41 -07:00
|
|
|
if (errmsg == NULL) {
|
|
|
|
errmsg = "returned function pointer is NULL";
|
|
|
|
}
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
2018-09-14 12:32:36 -07:00
|
|
|
"failed to look up symbol %s in "
|
2018-08-03 14:16:41 -07:00
|
|
|
"hook module '%s': %s",
|
2018-09-14 12:32:36 -07:00
|
|
|
symbol_name, modpath, errmsg);
|
2018-08-03 14:16:41 -07:00
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
*symbolp = symbol;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2018-10-31 19:02:29 -07:00
|
|
|
load_library(isc_mem_t *mctx, const char *modpath, ns_module_t **hmodp) {
|
2018-08-03 14:16:41 -07:00
|
|
|
isc_result_t result;
|
|
|
|
void *handle = NULL;
|
2018-10-31 19:02:29 -07:00
|
|
|
ns_module_t *hmod = NULL;
|
2018-11-02 23:28:25 -07:00
|
|
|
ns_hook_check_t *check_func = NULL;
|
2018-08-03 14:16:41 -07:00
|
|
|
ns_hook_register_t *register_func = NULL;
|
|
|
|
ns_hook_destroy_t *destroy_func = NULL;
|
|
|
|
ns_hook_version_t *version_func = NULL;
|
|
|
|
int version, flags;
|
|
|
|
|
|
|
|
REQUIRE(hmodp != NULL && *hmodp == NULL);
|
|
|
|
|
2018-11-02 23:28:25 -07:00
|
|
|
flags = RTLD_LAZY | RTLD_LOCAL;
|
2018-08-03 14:16:41 -07:00
|
|
|
#ifdef RTLD_DEEPBIND
|
|
|
|
flags |= RTLD_DEEPBIND;
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
handle = dlopen(modpath, flags);
|
2018-08-03 14:16:41 -07:00
|
|
|
if (handle == NULL) {
|
2018-09-14 12:32:36 -07:00
|
|
|
const char *errmsg = dlerror();
|
|
|
|
if (errmsg == NULL) {
|
|
|
|
errmsg = "unknown error";
|
|
|
|
}
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
|
|
|
"failed to dlopen() hook module '%s': %s",
|
|
|
|
modpath, errmsg);
|
|
|
|
return (ISC_R_FAILURE);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
CHECK(load_symbol(handle, modpath, "hook_version",
|
2018-08-03 14:16:41 -07:00
|
|
|
(void **)&version_func));
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
version = version_func();
|
2018-08-03 14:16:41 -07:00
|
|
|
if (version < (NS_HOOK_VERSION - NS_HOOK_AGE) ||
|
|
|
|
version > NS_HOOK_VERSION)
|
|
|
|
{
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
2018-09-14 12:32:36 -07:00
|
|
|
"hook API version mismatch: %d/%d",
|
2018-08-03 14:16:41 -07:00
|
|
|
version, NS_HOOK_VERSION);
|
|
|
|
CHECK(ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
2018-11-02 23:28:25 -07:00
|
|
|
CHECK(load_symbol(handle, modpath, "hook_check",
|
|
|
|
(void **)&check_func));
|
2018-09-14 12:32:36 -07:00
|
|
|
CHECK(load_symbol(handle, modpath, "hook_register",
|
2018-08-03 14:16:41 -07:00
|
|
|
(void **)®ister_func));
|
2018-09-14 12:32:36 -07:00
|
|
|
CHECK(load_symbol(handle, modpath, "hook_destroy",
|
2018-08-03 14:16:41 -07:00
|
|
|
(void **)&destroy_func));
|
|
|
|
|
|
|
|
hmod = isc_mem_get(mctx, sizeof(*hmod));
|
2018-11-02 23:28:25 -07:00
|
|
|
memset(hmod, 0, sizeof(*hmod));
|
2018-08-03 14:16:41 -07:00
|
|
|
isc_mem_attach(mctx, &hmod->mctx);
|
|
|
|
hmod->handle = handle;
|
2018-09-14 12:32:36 -07:00
|
|
|
hmod->modpath = isc_mem_strdup(hmod->mctx, modpath);
|
2018-11-02 23:28:25 -07:00
|
|
|
hmod->check_func = check_func;
|
2018-08-03 14:16:41 -07:00
|
|
|
hmod->register_func = register_func;
|
|
|
|
hmod->destroy_func = destroy_func;
|
|
|
|
|
|
|
|
ISC_LINK_INIT(hmod, link);
|
|
|
|
|
|
|
|
*hmodp = hmod;
|
|
|
|
hmod = NULL;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
|
|
|
"failed to dynamically load "
|
2018-09-14 12:32:36 -07:00
|
|
|
"module '%s': %s", modpath,
|
|
|
|
isc_result_totext(result));
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
if (hmod != NULL) {
|
2018-09-14 12:32:36 -07:00
|
|
|
isc_mem_putanddetach(&hmod->mctx, hmod, sizeof(*hmod));
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (handle != NULL) {
|
2018-09-14 12:32:36 -07:00
|
|
|
(void) dlclose(handle);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-10-31 19:02:29 -07:00
|
|
|
unload_library(ns_module_t **hmodp) {
|
|
|
|
ns_module_t *hmod = NULL;
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
REQUIRE(hmodp != NULL && *hmodp != NULL);
|
|
|
|
|
|
|
|
hmod = *hmodp;
|
|
|
|
*hmodp = NULL;
|
|
|
|
|
2018-10-31 19:02:29 -07:00
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
|
|
|
|
"unloading module '%s'", hmod->modpath);
|
|
|
|
|
|
|
|
if (hmod->inst != NULL) {
|
|
|
|
hmod->destroy_func(&hmod->inst);
|
|
|
|
}
|
2018-08-03 14:16:41 -07:00
|
|
|
if (hmod->handle != NULL) {
|
2018-09-14 12:32:36 -07:00
|
|
|
(void) dlclose(hmod->handle);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
2018-09-14 12:32:36 -07:00
|
|
|
if (hmod->modpath != NULL) {
|
|
|
|
isc_mem_free(hmod->mctx, hmod->modpath);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
2018-08-10 19:32:12 -07:00
|
|
|
isc_mem_putanddetach(&hmod->mctx, hmod, sizeof(*hmod));
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
#elif _WIN32
|
|
|
|
static isc_result_t
|
2018-09-14 12:32:36 -07:00
|
|
|
load_symbol(HMODULE handle, const char *modpath,
|
2018-08-03 14:16:41 -07:00
|
|
|
const char *symbol_name, void **symbolp)
|
|
|
|
{
|
2018-09-19 23:38:23 -07:00
|
|
|
void *symbol = NULL;
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
REQUIRE(handle != NULL);
|
|
|
|
REQUIRE(symbolp != NULL && *symbolp == NULL);
|
|
|
|
|
|
|
|
symbol = GetProcAddress(handle, symbol_name);
|
|
|
|
if (symbol == NULL) {
|
|
|
|
int errstatus = GetLastError();
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
|
|
|
"failed to look up symbol %s in "
|
|
|
|
"module '%s': %d",
|
2018-09-14 12:32:36 -07:00
|
|
|
symbol_name, modpath, errstatus);
|
2018-08-03 14:16:41 -07:00
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
*symbolp = symbol;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2018-10-31 19:02:29 -07:00
|
|
|
load_library(isc_mem_t *mctx, const char *modpath, ns_module_t **hmodp) {
|
2018-08-03 14:16:41 -07:00
|
|
|
isc_result_t result;
|
|
|
|
HMODULE handle;
|
2018-10-31 19:02:29 -07:00
|
|
|
ns_module_t *hmod = NULL;
|
2018-08-03 14:16:41 -07:00
|
|
|
ns_hook_register_t *register_func = NULL;
|
|
|
|
ns_hook_destroy_t *destroy_func = NULL;
|
|
|
|
ns_hook_version_t *version_func = NULL;
|
|
|
|
int version;
|
|
|
|
|
|
|
|
REQUIRE(hmodp != NULL && *hmodp == NULL);
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
handle = LoadLibraryA(modpath);
|
2018-08-03 14:16:41 -07:00
|
|
|
if (handle == NULL) {
|
|
|
|
CHECK(ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
CHECK(load_symbol(handle, modpath, "hook_version",
|
2018-08-03 14:16:41 -07:00
|
|
|
(void **)&version_func));
|
|
|
|
|
|
|
|
version = version_func(NULL);
|
|
|
|
if (version < (NS_HOOK_VERSION - NS_HOOK_AGE) ||
|
|
|
|
version > NS_HOOK_VERSION)
|
|
|
|
{
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
2018-09-14 12:32:36 -07:00
|
|
|
"hook API version mismatch: %d/%d",
|
2018-08-03 14:16:41 -07:00
|
|
|
version, NS_HOOK_VERSION);
|
|
|
|
CHECK(ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
CHECK(load_symbol(handle, modpath, "hook_register",
|
2018-08-03 14:16:41 -07:00
|
|
|
(void **)®ister_func));
|
2018-09-14 12:32:36 -07:00
|
|
|
CHECK(load_symbol(handle, modpath, "hook_destroy",
|
2018-08-03 14:16:41 -07:00
|
|
|
(void **)&destroy_func));
|
|
|
|
|
|
|
|
hmod = isc_mem_get(mctx, sizeof(*hmod));
|
2018-11-02 23:28:25 -07:00
|
|
|
memset(hmod, 0, sizeof(*hmod));
|
2018-08-03 14:16:41 -07:00
|
|
|
isc_mem_attach(mctx, &hmod->mctx);
|
|
|
|
hmod->handle = handle;
|
2018-09-14 12:32:36 -07:00
|
|
|
hmod->modpath = isc_mem_strdup(hmod->mctx, modpath);
|
2018-08-03 14:16:41 -07:00
|
|
|
hmod->register_func = register_func;
|
|
|
|
hmod->destroy_func = destroy_func;
|
|
|
|
|
|
|
|
ISC_LINK_INIT(hmod, link);
|
|
|
|
|
|
|
|
*hmodp = hmod;
|
|
|
|
hmod = NULL;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
|
|
|
"failed to dynamically load "
|
2018-09-14 12:32:36 -07:00
|
|
|
"hook module '%s': %d (%s)", modpath,
|
2018-08-03 14:16:41 -07:00
|
|
|
GetLastError(), isc_result_totext(result));
|
2018-09-14 12:32:36 -07:00
|
|
|
|
2018-08-03 14:16:41 -07:00
|
|
|
if (hmod != NULL) {
|
2018-09-14 12:32:36 -07:00
|
|
|
isc_mem_putanddetach(&hmod->mctx, hmod, sizeof(*hmod));
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (handle != NULL) {
|
|
|
|
FreeLibrary(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-10-31 19:02:29 -07:00
|
|
|
unload_library(ns_module_t **hmodp) {
|
|
|
|
ns_module_t *hmod = NULL;
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
REQUIRE(hmodp != NULL && *hmodp != NULL);
|
|
|
|
|
|
|
|
hmod = *hmodp;
|
|
|
|
*hmodp = NULL;
|
|
|
|
|
2018-10-31 19:02:29 -07:00
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
|
|
|
|
"unloading module '%s'", hmod->modpath);
|
|
|
|
|
|
|
|
if (hmod->inst != NULL) {
|
|
|
|
hmod->destroy_func(&hmod->inst);
|
|
|
|
}
|
2018-08-03 14:16:41 -07:00
|
|
|
if (hmod->handle != NULL) {
|
|
|
|
FreeLibrary(hmod->handle);
|
|
|
|
}
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
if (hmod->modpath != NULL) {
|
|
|
|
isc_mem_free(hmod->mctx, hmod->modpath);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_putanddetach(&hmod->mctx, hmod, sizeof(*hmod));
|
|
|
|
}
|
|
|
|
#else /* HAVE_DLFCN_H || _WIN32 */
|
|
|
|
static isc_result_t
|
2018-10-31 19:02:29 -07:00
|
|
|
load_library(isc_mem_t *mctx, const char *modpath, ns_module_t **hmodp) {
|
2018-08-03 14:16:41 -07:00
|
|
|
UNUSED(mctx);
|
2018-09-14 12:32:36 -07:00
|
|
|
UNUSED(modpath);
|
2018-08-03 14:16:41 -07:00
|
|
|
UNUSED(hmodp);
|
|
|
|
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
|
2018-09-14 12:32:36 -07:00
|
|
|
"hook module support is not implemented");
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-10-31 19:02:29 -07:00
|
|
|
unload_library(ns_module_t **hmodp) {
|
2018-08-03 14:16:41 -07:00
|
|
|
UNUSED(hmodp);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_DLFCN_H */
|
|
|
|
|
|
|
|
isc_result_t
|
2018-11-30 10:12:04 -08:00
|
|
|
ns_module_load(const char *modpath, const char *parameters, const void *cfg,
|
|
|
|
const char *cfg_file, unsigned long cfg_line, isc_mem_t *mctx,
|
|
|
|
isc_log_t *lctx, void *actx, dns_view_t *view)
|
2018-08-03 14:16:41 -07:00
|
|
|
{
|
|
|
|
isc_result_t result;
|
2018-10-31 19:02:29 -07:00
|
|
|
ns_module_t *hmod = NULL;
|
2018-08-03 14:16:41 -07:00
|
|
|
|
2018-11-30 10:12:04 -08:00
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(lctx != NULL);
|
|
|
|
REQUIRE(view != NULL);
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
|
2018-09-14 12:32:36 -07:00
|
|
|
"loading module '%s'", modpath);
|
2018-08-03 14:16:41 -07:00
|
|
|
|
2018-11-30 10:12:04 -08:00
|
|
|
CHECK(load_library(mctx, modpath, &hmod));
|
2018-10-31 19:02:29 -07:00
|
|
|
|
|
|
|
isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
|
|
|
|
"registering module '%s'", modpath);
|
|
|
|
|
2018-11-30 10:12:04 -08:00
|
|
|
CHECK(hmod->register_func(parameters, cfg, cfg_file, cfg_line,
|
|
|
|
mctx, lctx, actx, view->hooktable,
|
|
|
|
&hmod->inst));
|
2018-08-03 14:16:41 -07:00
|
|
|
|
2018-11-30 10:12:04 -08:00
|
|
|
ISC_LIST_APPEND(*(ns_modlist_t *)view->modlist, hmod, link);
|
2018-08-03 14:16:41 -07:00
|
|
|
|
|
|
|
cleanup:
|
2018-09-14 12:32:36 -07:00
|
|
|
if (result != ISC_R_SUCCESS && hmod != NULL) {
|
|
|
|
unload_library(&hmod);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:32:12 -07:00
|
|
|
isc_result_t
|
2018-11-02 23:28:25 -07:00
|
|
|
ns_module_check(const char *modpath, const char *parameters,
|
2018-11-30 10:12:04 -08:00
|
|
|
const void *cfg, const char *cfg_file, unsigned long cfg_line,
|
|
|
|
isc_mem_t *mctx, isc_log_t *lctx, void *actx)
|
2018-11-02 23:28:25 -07:00
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
ns_module_t *hmod = NULL;
|
|
|
|
|
|
|
|
CHECK(load_library(mctx, modpath, &hmod));
|
|
|
|
|
2018-11-30 10:12:04 -08:00
|
|
|
result = hmod->check_func(parameters, cfg, cfg_file, cfg_line,
|
|
|
|
mctx, lctx, actx);
|
2018-11-02 23:28:25 -07:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (hmod != NULL) {
|
|
|
|
unload_library(&hmod);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2018-08-03 14:16:41 -07:00
|
|
|
void
|
|
|
|
ns_hooktable_init(ns_hooktable_t *hooktable) {
|
|
|
|
int i;
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
for (i = 0; i < NS_HOOKPOINTS_COUNT; i++) {
|
2018-08-03 14:16:41 -07:00
|
|
|
ISC_LIST_INIT((*hooktable)[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-12 11:19:36 -07:00
|
|
|
isc_result_t
|
|
|
|
ns_hooktable_create(isc_mem_t *mctx, ns_hooktable_t **tablep) {
|
2018-09-19 23:38:23 -07:00
|
|
|
ns_hooktable_t *hooktable = NULL;
|
2018-08-12 11:19:36 -07:00
|
|
|
|
|
|
|
REQUIRE(tablep != NULL && *tablep == NULL);
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
hooktable = isc_mem_get(mctx, sizeof(*hooktable));
|
2018-08-12 11:19:36 -07:00
|
|
|
|
|
|
|
ns_hooktable_init(hooktable);
|
|
|
|
|
|
|
|
*tablep = hooktable;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-12 11:19:36 -07:00
|
|
|
ns_hooktable_free(isc_mem_t *mctx, void **tablep) {
|
2018-09-19 23:38:23 -07:00
|
|
|
ns_hooktable_t *table = NULL;
|
|
|
|
ns_hook_t *hook = NULL, *next = NULL;
|
|
|
|
int i = 0;
|
2018-09-14 12:32:36 -07:00
|
|
|
|
2018-08-12 11:19:36 -07:00
|
|
|
REQUIRE(tablep != NULL && *tablep != NULL);
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
table = *tablep;
|
2018-08-12 11:19:36 -07:00
|
|
|
*tablep = NULL;
|
2018-09-19 23:38:23 -07:00
|
|
|
|
|
|
|
for (i = 0; i < NS_HOOKPOINTS_COUNT; i++) {
|
|
|
|
for (hook = ISC_LIST_HEAD((*table)[i]);
|
|
|
|
hook != NULL;
|
|
|
|
hook = next)
|
|
|
|
{
|
|
|
|
next = ISC_LIST_NEXT(hook, link);
|
|
|
|
ISC_LIST_UNLINK((*table)[i], hook, link);
|
|
|
|
if (hook->mctx != NULL) {
|
|
|
|
isc_mem_putanddetach(&hook->mctx,
|
|
|
|
hook, sizeof(*hook));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-14 12:32:36 -07:00
|
|
|
isc_mem_put(mctx, table, sizeof(*table));
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-09-19 23:38:23 -07:00
|
|
|
ns_hook_add(ns_hooktable_t *hooktable, isc_mem_t *mctx,
|
|
|
|
ns_hookpoint_t hookpoint, const ns_hook_t *hook)
|
2018-08-03 14:16:41 -07:00
|
|
|
{
|
2018-09-19 23:38:23 -07:00
|
|
|
ns_hook_t *copy = NULL;
|
|
|
|
|
|
|
|
REQUIRE(hooktable != NULL);
|
|
|
|
REQUIRE(mctx != NULL);
|
2018-09-14 12:32:36 -07:00
|
|
|
REQUIRE(hookpoint < NS_HOOKPOINTS_COUNT);
|
2018-08-03 14:16:41 -07:00
|
|
|
REQUIRE(hook != NULL);
|
|
|
|
|
2018-09-19 23:38:23 -07:00
|
|
|
copy = isc_mem_get(mctx, sizeof(*copy));
|
|
|
|
memset(copy, 0, sizeof(*copy));
|
|
|
|
|
|
|
|
copy->action = hook->action;
|
|
|
|
copy->action_data = hook->action_data;
|
|
|
|
isc_mem_attach(mctx, ©->mctx);
|
2018-08-03 14:16:41 -07:00
|
|
|
|
2018-09-19 23:38:23 -07:00
|
|
|
ISC_LINK_INIT(copy, link);
|
|
|
|
ISC_LIST_APPEND((*hooktable)[hookpoint], copy, link);
|
2018-08-03 14:16:41 -07:00
|
|
|
}
|
2018-10-31 19:02:29 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
ns_modlist_create(isc_mem_t *mctx, ns_modlist_t **listp) {
|
|
|
|
ns_modlist_t *modlist = NULL;
|
|
|
|
|
|
|
|
REQUIRE(listp != NULL && *listp == NULL);
|
|
|
|
|
|
|
|
modlist = isc_mem_get(mctx, sizeof(*modlist));
|
|
|
|
memset(modlist, 0, sizeof(*modlist));
|
|
|
|
ISC_LIST_INIT(*modlist);
|
|
|
|
|
|
|
|
*listp = modlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ns_modlist_free(isc_mem_t *mctx, void **listp) {
|
|
|
|
ns_modlist_t *list = NULL;
|
|
|
|
ns_module_t *hmod = NULL, *next = NULL;
|
|
|
|
|
|
|
|
REQUIRE(listp != NULL && *listp != NULL);
|
|
|
|
|
|
|
|
list = *listp;
|
|
|
|
*listp = NULL;
|
|
|
|
|
|
|
|
for (hmod = ISC_LIST_HEAD(*list);
|
|
|
|
hmod != NULL;
|
|
|
|
hmod = next)
|
|
|
|
{
|
|
|
|
next = ISC_LIST_NEXT(hmod, link);
|
|
|
|
ISC_LIST_UNLINK(*list, hmod, link);
|
|
|
|
unload_library(&hmod);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_put(mctx, list, sizeof(*list));
|
|
|
|
}
|