]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
plugin expand path automatically adds extension
authorColin Vidal <colin@isc.org>
Mon, 21 Jul 2025 13:06:11 +0000 (15:06 +0200)
committerColin Vidal <colin@isc.org>
Mon, 28 Jul 2025 21:08:04 +0000 (23:08 +0200)
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.

lib/ns/hooks.c

index d11c4c72a749de1fd7977e3b85a439362e3d00b4..fd45b7ed03abc92fba9c2201310852a6cc197e5f 100644 (file)
@@ -18,6 +18,7 @@
 #include <string.h>
 
 #include <isc/errno.h>
+#include <isc/file.h>
 #include <isc/list.h>
 #include <isc/log.h>
 #include <isc/mem.h>
@@ -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) {