Skip to contentSkip to conversation

Update openvpn_plugin_func_v2 to _v3 in sample-plugins/defer/simple.c

PATCH In review Greg Cox 3 participants 6 messages Jan 27, 2021 – Jan 30, 2021

lore
Share & tools
lore

Greg Cox

author
#0 lore raw

PATCH 1/2 Update openvpn_plugin_func_v2 to _v3 in sample-plugins/defer/simple.c

This isn't strictly required, but it modernizes the functions used. This change makes _open the same parameter form as _func (for better parallelism in function writing) and includes a check for the correct struct version, as recommended by openvpn-plugin.h

---
 sample/sample-plugins/defer/simple.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
sample/sample-plugins/defer/simple.c +14 -9
index 22bc22765d6773d3ea2344a328faf5008b0c5d89..a2e47cfc3953ae188a5a2588a3d21e12404c75f1 100644
@@ -423,16 +423,21 @@ tls_final(struct plugin_context *context, struct plugin_per_client_context *pcc,
 }
 
 OPENVPN_EXPORT int
-openvpn_plugin_func_v2(openvpn_plugin_handle_t handle,
-                       const int type,
-                       const char *argv[],
-                       const char *envp[],
-                       void *per_client_context,
-                       struct openvpn_plugin_string_list **return_list)
+openvpn_plugin_func_v3(const int v3structver,
+                       struct openvpn_plugin_args_func_in const *args,
+                       struct openvpn_plugin_args_func_return *ret)
 {
-    struct plugin_context *context = (struct plugin_context *) handle;
-    struct plugin_per_client_context *pcc = (struct plugin_per_client_context *) per_client_context;
-    switch (type)
+    /* Check API compatibility -- struct version 5 or higher needed */
+    if (v3structver < 5)
+    {
+        fprintf(stderr, "%s: this plugin is incompatible with the running version of OpenVPN\n", MODULE);
+        return OPENVPN_PLUGIN_FUNC_ERROR;
+    }
+    const char **argv = args->argv;
+    const char **envp = args->envp;
+    struct plugin_context *context = (struct plugin_context *) args->handle;
+    struct plugin_per_client_context *pcc = (struct plugin_per_client_context *) args->per_client_context;
+    switch (args->type)
     {
         case OPENVPN_PLUGIN_UP:
             plugin_log(PLOG_NOTE, MODULE, "OPENVPN_PLUGIN_UP");
Signature · 1 line
2.7.6
author
#1 lore raw

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

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(-)
sample/sample-plugins/defer/simple.c +18 -3
index a2e47cfc3953ae188a5a2588a3d21e12404c75f1..05bfc4efa6d85bb1696b6811428260f4cc5e9914 100644
@@ -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;
Signature · 1 line
2.7.6
Acked-by on v1 2/2
#2 lore raw

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

Quoted 8 lines · Greg Cox

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!

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#3 lore raw

[Openvpn-devel] [PATCH applied] Re: More explicit versioning compatibility in sample-plugins/defer/simple.c

In reply to Greg Cox

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 <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg21508.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 1/2
#4 lore raw
In reply to Greg Cox
Quoted 8 lines · Greg Cox

This isn't strictly required, but it modernizes the functions used. This change makes _open the same parameter form as _func (for better parallelism in function writing) and includes a check for the correct struct version, as recommended by openvpn-plugin.h

---
  sample/sample-plugins/defer/simple.c | 23 ++++++++++++++---------
  1 file changed, 14 insertions(+), 9 deletions(-)

Thanks a lot! This makes a lot of sense and works as expected.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#5 lore raw
In reply to Greg Cox

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

I have not tested anything beyond "it still compiles", but this looks reasonable and has David's ACK.

commit 7d1361c18f38d6301b4d558578c73e74f6597927 (master) commit 11aa1288ffc95877cd5686e19137b9abd6c374bb (release/2.5) commit 5e7e41dc56d71cb7e414d53059149d9490f14a67 (release/2.4)

Author: Greg Cox
Date:   Wed Jan 27 20:21:48 2021 +0000
     Update openvpn_plugin_func_v2 to _v3 in sample-plugins/defer/simple.c

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

--
kind regards,

Gert Doering