From: Colin Vidal Date: Mon, 21 Jul 2025 13:06:11 +0000 (+0200) Subject: plugin expand path automatically adds extension X-Git-Tag: v9.21.11~23^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7747ac8aed685bc47179d0e929f0c34e69c90cff;p=thirdparty%2Fbind9.git 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. --- diff --git a/lib/ns/hooks.c b/lib/ns/hooks.c index d11c4c72a74..fd45b7ed03a 100644 --- a/lib/ns/hooks.c +++ b/lib/ns/hooks.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -54,9 +55,10 @@ struct ns_plugin { static ns_hooklist_t default_hooktable[NS_HOOKPOINTS_COUNT]; ns_hooktable_t *ns__hook_table = &default_hooktable; -isc_result_t -ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) { +static isc_result_t +plugin_expandpath(const char *src, char *dst, size_t dstsize, bool appendext) { int result; + const char *ext = appendext ? NAMED_PLUGINEXT : ""; /* * 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. */ - result = snprintf(dst, dstsize, "%s", src); + result = snprintf(dst, dstsize, "%s%s", src, ext); } else { /* * '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) { @@ -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 load_symbol(uv_lib_t *handle, const char *modpath, const char *symbol_name, void **symbolp) {