Skip to contentSkip to conversation

plugin: Improve the handling of default plug-in directory

PATCH In review David Sommerseth 2 participants 2 messages Jan 27, 2017 – Mar 19, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 plugin: Improve the handling of default plug-in directory

OpenVPN uses a default plug-in directore, set using PLUGINDIR when running ./configure. If this is set, it will use $LIBDIR/openvpn/plugin.

When using --plugin, OpenVPN will load plug-ins from this directory with the only exception if the plug-in filename is based on an absolute path. Any other relative paths are relative to the PLUGINDIR.

This patch adds a third variant, using plug-in paths starting with '.' In this case, OpenVPN will use the relative directory of where OpenVPN was started, or the directory OpenVPN have changed into due to --cd being used before the actual --plugin option.

---
 doc/openvpn.8        | 28 ++++++++++++++++++++++++++++
 src/openvpn/plugin.c | 18 +++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
doc/openvpn.8 +28 -0
index e3d603e..a8d06f3 100644
@@ -2712,6 +2712,34 @@ to the module initialization function.  Multiple
 plugin modules may be loaded into one OpenVPN
 process.
 
+The
+.B module-pathname
+argument can be just a filename or a filename with a relative
+or absolute path.  The format of the filename and path defines
+if the plug-in will be loaded from a default plug-in directory
+or outside this directory.
+
+.nf
+.ft 3
+.in +4
+.B \-\-plugin path\ \ \ \ \ \ \ \ Effective directory used
+====================================================
+ myplug.so            DEFAULT_DIR/myplug.so
+ subdir/myplug.so     DEFAULT_DIR/subdir/myplug.so
+ ./subdir/myplug.so   CWD/subdir/myplug.so
+ /usr/lib/my/plug.so  /usr/lib/my/plug.so
+.in -4
+.fi
+
+DEFAULT_DIR is replaced by the default plug-in directory,
+which is configured at the build time of OpenVPN.  CWD is the
+current directory where OpenVPN was started or the directory
+OpenVPN have swithed into via the
+.B\-\-cd
+option before the
+.B\-\-plugin
+option.
+
 For more information and examples on how to build OpenVPN
 plug-in modules, see the README file in the
 .B plugin
src/openvpn/plugin.c +17 -1
index f777027..05cbae3 100644
@@ -235,7 +235,23 @@ plugin_init_item(struct plugin *p, const struct plugin_option *o)
 
     p->handle = NULL;
 
-    if (!absolute_pathname(p->so_pathname))
+    /* If the plug-in filename is not an absolute path,
+     * or beginning with '.', it should use the PLUGIN_LIBDIR
+     * as the base directory for loading the plug-in.
+     *
+     * This means the following scenarios are loaded from these places:
+     *    --plugin fancyplug.so              -> $PLUGIN_LIBDIR/fancyplug.so
+     *    --plugin my/fancyplug.so           -> $PLUGIN_LIBDIR/my/fancyplug.so
+     *    --plugin ./fancyplug.so            -> $CWD/fancyplug.so
+     *    --plugin /usr/lib/my/fancyplug.so  -> /usr/lib/my/fancyplug.so
+     *
+     * Please note that $CWD means the directory OpenVPN is either started from
+     * or the directory OpenVPN have changed into using --cd before --plugin
+     * was parsed.
+     *
+     */
+    if (!absolute_pathname(p->so_pathname)
+        && p->so_pathname[0] != '.')
     {
         char full[PATH_MAX];
 
Signature · 1 line
2.11.0
#1 lore raw

ACK. The code change is straightforward enough :-) and makes sense.

(And it brings LOTS of documentation, which is always welcome).

As a side note: the behaviour on Windows is different from the behaviour on Unix now (actually, since the introduction of PLUGIN_LIBDIR), so this might warrant revisiting.

Your patch has been applied to the master and release/2.4 branch.

commit f9609f1df9d8c070245b7c008dc54ac9ccdbe231 (master) commit d21bed998bca21ab44e769896b0e9a8b4bfc0be1 (release/2.4)

Author: David Sommerseth
Date:   Fri Jan 27 15:21:20 2017 +0100
     plugin: Improve the handling of default plug-in directory

     Signed-off-by: David Sommerseth <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg13970.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering