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.
Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20170127142120.10492-1-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg13970.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -2712,6 +2712,34 @@ to the module initialization function. Multiple |
2712 | 2712 |
plugin modules may be loaded into one OpenVPN |
2713 | 2713 |
process. |
2714 | 2714 |
|
2715 |
+The |
|
2716 |
+.B module-pathname |
|
2717 |
+argument can be just a filename or a filename with a relative |
|
2718 |
+or absolute path. The format of the filename and path defines |
|
2719 |
+if the plug-in will be loaded from a default plug-in directory |
|
2720 |
+or outside this directory. |
|
2721 |
+ |
|
2722 |
+.nf |
|
2723 |
+.ft 3 |
|
2724 |
+.in +4 |
|
2725 |
+.B \-\-plugin path\ \ \ \ \ \ \ \ Effective directory used |
|
2726 |
+==================================================== |
|
2727 |
+ myplug.so DEFAULT_DIR/myplug.so |
|
2728 |
+ subdir/myplug.so DEFAULT_DIR/subdir/myplug.so |
|
2729 |
+ ./subdir/myplug.so CWD/subdir/myplug.so |
|
2730 |
+ /usr/lib/my/plug.so /usr/lib/my/plug.so |
|
2731 |
+.in -4 |
|
2732 |
+.fi |
|
2733 |
+ |
|
2734 |
+DEFAULT_DIR is replaced by the default plug-in directory, |
|
2735 |
+which is configured at the build time of OpenVPN. CWD is the |
|
2736 |
+current directory where OpenVPN was started or the directory |
|
2737 |
+OpenVPN have swithed into via the |
|
2738 |
+.B\-\-cd |
|
2739 |
+option before the |
|
2740 |
+.B\-\-plugin |
|
2741 |
+option. |
|
2742 |
+ |
|
2715 | 2743 |
For more information and examples on how to build OpenVPN |
2716 | 2744 |
plug-in modules, see the README file in the |
2717 | 2745 |
.B plugin |
... | ... |
@@ -235,7 +235,23 @@ plugin_init_item(struct plugin *p, const struct plugin_option *o) |
235 | 235 |
|
236 | 236 |
p->handle = NULL; |
237 | 237 |
|
238 |
- if (!absolute_pathname(p->so_pathname)) |
|
238 |
+ /* If the plug-in filename is not an absolute path, |
|
239 |
+ * or beginning with '.', it should use the PLUGIN_LIBDIR |
|
240 |
+ * as the base directory for loading the plug-in. |
|
241 |
+ * |
|
242 |
+ * This means the following scenarios are loaded from these places: |
|
243 |
+ * --plugin fancyplug.so -> $PLUGIN_LIBDIR/fancyplug.so |
|
244 |
+ * --plugin my/fancyplug.so -> $PLUGIN_LIBDIR/my/fancyplug.so |
|
245 |
+ * --plugin ./fancyplug.so -> $CWD/fancyplug.so |
|
246 |
+ * --plugin /usr/lib/my/fancyplug.so -> /usr/lib/my/fancyplug.so |
|
247 |
+ * |
|
248 |
+ * Please note that $CWD means the directory OpenVPN is either started from |
|
249 |
+ * or the directory OpenVPN have changed into using --cd before --plugin |
|
250 |
+ * was parsed. |
|
251 |
+ * |
|
252 |
+ */ |
|
253 |
+ if (!absolute_pathname(p->so_pathname) |
|
254 |
+ && p->so_pathname[0] != '.') |
|
239 | 255 |
{ |
240 | 256 |
char full[PATH_MAX]; |
241 | 257 |
|