2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-04 16:45:24 +00:00

plugin expand path automatically adds extension

If a plugin is configured without the extension,
`ns_plugin_expandpath()` automatically take cares of appending the
suffix to the path. The way it works is by checking if a file exists at
the expanded path. If it doesn't, it assumes the plugin path (or name)
doesn't have the extension and append the extension (which is
platform-specific) to the actual path.
This commit is contained in:
Colin Vidal
2025-07-21 15:06:11 +02:00
parent be03ed6520
commit 7747ac8aed

View File

@@ -18,6 +18,7 @@
#include <string.h> #include <string.h>
#include <isc/errno.h> #include <isc/errno.h>
#include <isc/file.h>
#include <isc/list.h> #include <isc/list.h>
#include <isc/log.h> #include <isc/log.h>
#include <isc/mem.h> #include <isc/mem.h>
@@ -54,9 +55,10 @@ struct ns_plugin {
static ns_hooklist_t default_hooktable[NS_HOOKPOINTS_COUNT]; static ns_hooklist_t default_hooktable[NS_HOOKPOINTS_COUNT];
ns_hooktable_t *ns__hook_table = &default_hooktable; ns_hooktable_t *ns__hook_table = &default_hooktable;
isc_result_t static isc_result_t
ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) { plugin_expandpath(const char *src, char *dst, size_t dstsize, bool appendext) {
int result; int result;
const char *ext = appendext ? NAMED_PLUGINEXT : "";
/* /*
* On Unix systems, differentiate between paths and filenames. * On Unix systems, differentiate between paths and filenames.
@@ -65,12 +67,13 @@ ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) {
/* /*
* 'src' is an absolute or relative path. Copy it verbatim. * 'src' is an absolute or relative path. Copy it verbatim.
*/ */
result = snprintf(dst, dstsize, "%s", src); result = snprintf(dst, dstsize, "%s%s", src, ext);
} else { } else {
/* /*
* 'src' is a filename. Prepend default plugin directory path. * 'src' is a filename. Prepend default plugin directory path.
*/ */
result = snprintf(dst, dstsize, "%s/%s", NAMED_PLUGINDIR, src); result = snprintf(dst, dstsize, "%s/%s%s", NAMED_PLUGINDIR, src,
ext);
} }
if (result < 0) { if (result < 0) {
@@ -82,6 +85,22 @@ ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) {
} }
} }
isc_result_t
ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) {
isc_result_t result;
result = plugin_expandpath(src, dst, dstsize, false);
if (result != ISC_R_SUCCESS) {
return result;
}
if (isc_file_exists(dst) == false) {
result = plugin_expandpath(src, dst, dstsize, true);
}
return result;
}
static isc_result_t static isc_result_t
load_symbol(uv_lib_t *handle, const char *modpath, const char *symbol_name, load_symbol(uv_lib_t *handle, const char *modpath, const char *symbol_name,
void **symbolp) { void **symbolp) {