[Openvpn-devel,2/2] More explicit versioning compatibility in sample-plugins/defer/simple.c

Message ID 1611778909-20630-2-git-send-email-gcox@mozilla.com
State Accepted
Headers show
Series
  • [Openvpn-devel,1/2] Update openvpn_plugin_func_v2 to _v3 in sample-plugins/defer/simple.c
Related show

Commit Message

Greg Cox Jan. 27, 2021, 8:21 p.m.
While not required, adding openvpn_plugin_min_version_required_v1 helps
by making an example for others to copy, and helps to explicitly call
attention to the difference between the API version number and the
struct version number in v3 calls.
---
 sample/sample-plugins/defer/simple.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

David Sommerseth Jan. 30, 2021, 12:05 a.m. | #1
On 27/01/2021 21:21, Greg Cox wrote:
> While not required, adding openvpn_plugin_min_version_required_v1 helps
> by making an example for others to copy, and helps to explicitly call
> attention to the difference between the API version number and the
> struct version number in v3 calls.
> ---
>   sample/sample-plugins/defer/simple.c | 21 ++++++++++++++++++---
>   1 file changed, 18 insertions(+), 3 deletions(-)
> 

Yes, this is also reasonable and aligns well with the intension of these 
version checks.  Thanks a lot!

Acked-By: David Sommerseth <davids@openvpn.net>
Gert Doering Jan. 30, 2021, 9:53 a.m. | #2
Your patch has been applied to the master, release/2.5 and release/2.4 branch.

Again, I have not tested beyond a test compile (but it looks good).

As a side note: my change to change the required v3structver to "5"
was too restrictive - there was a bit of confusion what got added when, and I 
thought this was necessary for logging.  But it isn't, "5" is "with base64", 
and "4" is "with secure_memzero()" - which we wanted for plugin-auth-pam,
and my code was copy-pasted from there...  according to openvpn-plugin.h,
logging has been there from "v3 api structver v1".

I do not think it's needed to fix that as 2.4, 2.5 and master all have "v5" 
and people really should not code new plugins on 2.3 or older openvpn 
deployments...

commit a385a3e8a28f2ce96c7ee0be8940b257765add5a (master)
commit ae5ca3ebf1cccae2f2d11a2ed6219c40be9cc4ea (release/2.5)
commit 86c674230d6334c1aa18f74acc7a9741a6c9683a (release/2.4)
Author: Greg Cox
Date:   Wed Jan 27 20:21:49 2021 +0000

     More explicit versioning compatibility in sample-plugins/defer/simple.c

     Acked-by: David Sommerseth <davids@openvpn.net>
     Message-Id: <1611778909-20630-2-git-send-email-gcox@mozilla.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21508.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/sample/sample-plugins/defer/simple.c b/sample/sample-plugins/defer/simple.c
index a2e47cfc3953ae188a5a2588a3d21e12404c75f1..05bfc4efa6d85bb1696b6811428260f4cc5e9914 100644
--- a/sample/sample-plugins/defer/simple.c
+++ b/sample/sample-plugins/defer/simple.c
@@ -66,7 +66,15 @@ 
 static plugin_log_t plugin_log = NULL;
 
 /*
- * Our context, where we keep our state.
+ * Constants indicating minimum API and struct versions by the functions
+ * in this plugin.  Consult openvpn-plugin.h, look for:
+ * OPENVPN_PLUGIN_VERSION and OPENVPN_PLUGINv3_STRUCTVER
+ */
+#define OPENVPN_PLUGIN_VERSION_MIN 3
+#define OPENVPN_PLUGIN_STRUCTVER_MIN 5
+
+/*
+* Our context, where we keep our state.
  */
 
 struct plugin_context {
@@ -136,6 +144,13 @@  atoi_null0(const char *str)
     }
 }
 
+/* Require a minimum OpenVPN Plugin API */
+OPENVPN_EXPORT int
+openvpn_plugin_min_version_required_v1()
+{
+    return OPENVPN_PLUGIN_VERSION_MIN;
+}
+
 /* use v3 functions so we can use openvpn's logging and base64 etc. */
 OPENVPN_EXPORT int
 openvpn_plugin_open_v3(const int v3structver,
@@ -146,7 +161,7 @@  openvpn_plugin_open_v3(const int v3structver,
     struct plugin_context *context;
 
     /* Check API compatibility -- struct version 5 or higher needed */
-    if (v3structver < 5)
+    if (v3structver < OPENVPN_PLUGIN_STRUCTVER_MIN)
     {
         fprintf(stderr, "%s: this plugin is incompatible with the running version of OpenVPN\n", MODULE);
         return OPENVPN_PLUGIN_FUNC_ERROR;
@@ -428,7 +443,7 @@  openvpn_plugin_func_v3(const int v3structver,
                        struct openvpn_plugin_args_func_return *ret)
 {
     /* Check API compatibility -- struct version 5 or higher needed */
-    if (v3structver < 5)
+    if (v3structver < OPENVPN_PLUGIN_STRUCTVER_MIN)
     {
         fprintf(stderr, "%s: this plugin is incompatible with the running version of OpenVPN\n", MODULE);
         return OPENVPN_PLUGIN_FUNC_ERROR;