Skip to contentSkip to conversation

Add demo plugin that excercises "CLIENT_CONNECT" and "CLIENT_CONNECT_V2" paths

PATCH Superseded Gert Doering 2 participants 10 messages Jul 17, 2020 – Sep 18, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add demo plugin that excercises "CLIENT_CONNECT" and "CLIENT_CONNECT_V2" paths

This is a new "samples" plugin which does not do many useful things, besides
- show how a plugin is programmed
- how the various messages get dispatched
- how to pass back information from a client-connect/v2 plugin
- how to do async-cc plugins [not yet implemented]

the operation of the plugin is controlled by UV_WANT_* environment variables controlled by the client ("--setenv UV_WANT_CC_FAIL 1 --push-peer-info"), to "fail CLIENT_CONNECT" or "use async-cc for CLIENT_CONNECT_V2" or "send 'disable' back from ...") - which is useful for automated testing of server success/defer/fail code paths for the CLIENT_CONNECT_* functions.

See samples/sample-plugins/client-connect/README for details how to do this.

---
 sample/sample-plugins/client-connect/README   |  33 ++
 sample/sample-plugins/client-connect/build    |  15 +
 .../client-connect/sample-client-connect.c    | 375 ++++++++++++++++++
 3 files changed, 423 insertions(+)
 create mode 100644 sample/sample-plugins/client-connect/README
 create mode 100755 sample/sample-plugins/client-connect/build
 create mode 100644 sample/sample-plugins/client-connect/sample-client-connect.c
sample/sample-plugins/client-connect/README new file +33 -0
new file mode 100644
index 00000000..2dd10dc3
@@ -0,0 +1,33 @@
+OpenVPN plugin examples.
+
+Examples provided:
+
+sample-client-connect.c
+
+  - hook to all plugin hooks that openvpn offers
+  - log which hook got called
+  - on CLIENT_CONNECT or CLIENT_CONNECT_V2 set some config variables
+    (push "route 192.0.2.x" and other easy recognizeable things)
+
+  - if the environment variable UV_WANT_CC_FAIL is set, fail
+  - if the environment variable UV_WANT_CC_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC_ASYNC is set, go to 
+    asynchronous/deferred mode on CLIENT_CONNECT, and sleep for 
+    ${UV_WANT_CC_ASYNC} seconds
+
+  - if the environment variable UV_WANT_CC2_FAIL is set, fail CC2
+  - if the environment variable UV_WANT_CC2_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC2_ASYNC is set, go to 
+    asynchronous/deferred mode on CLIENT_CONNECT_V2, and sleep for 
+    ${UV_WANT_CC2_ASYNC} seconds
+
+    (this can be client-controlled with --setenv UV_WANT_CC_ASYNC nnn
+     etc. --> for easy testing server code paths)
+
+To build:
+
+  ./build sample-client-connect (Linux/BSD/etc.)
+
+To use in OpenVPN, add to config file:
+
+  plugin sample-client-connect.so (Linux/BSD/etc.)
sample/sample-plugins/client-connect/build new file +15 -0
new file mode 100755
index 00000000..3f93aa4f
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+#
+# Build an OpenVPN plugin module on *nix.  The argument should
+# be the base name of the C source file (without the .c).
+#
+
+# This directory is where we will look for openvpn-plugin.h
+CPPFLAGS="${CPPFLAGS:--I../../../include}"
+
+CC="${CC:-gcc}"
+CFLAGS="${CFLAGS:--O2 -Wall -Wno-unused-variable -g}"
+
+$CC $CPPFLAGS $CFLAGS -fPIC -c $1.c && \
+$CC $CFLAGS -fPIC -shared $LDFLAGS -Wl,-soname,$1.so -o $1.so $1.o -lc
sample/sample-plugins/client-connect/sample-client-connect.c new file +375 -0

375 lines not on this page · raw message

Signature · 1 line
2.26.2
#1 lore raw

Hi,

Quoted 7 lines · Gert Doering

This is a new "samples" plugin which does not do many useful things, besides
- show how a plugin is programmed
- how the various messages get dispatched
- how to pass back information from a client-connect/v2 plugin
- how to do async-cc plugins [not yet implemented]

Quoted 5 lines

the operation of the plugin is controlled by UV_WANT_* environment variables controlled by the client ("--setenv UV_WANT_CC_FAIL 1 --push-peer-info"), to "fail CLIENT_CONNECT" or "use async-cc for CLIENT_CONNECT_V2" or "send 'disable' back from ...") - which is useful for automated testing of server success/defer/fail code paths for the CLIENT_CONNECT_* functions.

This is not yet finished - all the async/deferred versions are not there yet, and I think it wants a "Makefile" to be built properly :-)

It is working nicely though and has already uncovered bugs in current master. So, out there for people that want to play with it.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#2 lore raw

PATCH v2 1/1 Add demo plugin that excercises "CLIENT_CONNECT" and "CLIENT_CONNECT_V2" paths

In reply to Gert Doering

This is a new "samples" plugin which does not do many useful things, besides
- show how a plugin is programmed
- how the various messages get dispatched
- how to pass back information from a client-connect/v2 plugin
- how to do async-cc plugins [not yet implemented]

the operation of the plugin is controlled by UV_WANT_* environment variables controlled by the client ("--setenv UV_WANT_CC_FAIL 1 --push-peer-info"), to "fail CLIENT_CONNECT" or "use async-cc for CLIENT_CONNECT_V2" or "send 'disable' back from ...") - which is useful for automated testing of server success/defer/fail code paths for the CLIENT_CONNECT_* functions.

See samples/sample-plugins/client-connect/README for details how to do this.

v2:
- implement async / deferred operation both for CLIENT_CONNECT and CLIENT_CONNECT_V2 plugin calls
- implement returning openvpn-controlled (setenv) config snippets (so the client side can verify in automated testing that the plugin operated correctly, without hard-coding something in the plugin code)

---
 sample/sample-plugins/client-connect/Makefile |  16 +
 sample/sample-plugins/client-connect/README   |  34 +
 .../client-connect/sample-client-connect.c    | 609 ++++++++++++++++++
 3 files changed, 659 insertions(+)
 create mode 100644 sample/sample-plugins/client-connect/Makefile
 create mode 100644 sample/sample-plugins/client-connect/README
 create mode 100644 sample/sample-plugins/client-connect/sample-client-connect.c
sample/sample-plugins/client-connect/Makefile new file +16 -0
new file mode 100644
index 00000000..ff187c43
@@ -0,0 +1,16 @@
+all: sample-client-connect.so
+
+
+sample-client-connect.o: sample-client-connect.c
+
+# This directory is where we will look for openvpn-plugin.h
+CPPFLAGS=-I../../../include
+
+CC=gcc
+CFLAGS=-O2 -Wall -Wno-unused-variable -g
+
+.c.o:
+	$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c $<
+
+sample-client-connect.so: sample-client-connect.o
+	$(CC) $(CFLAGS) -fPIC -shared $(LDFLAGS) -Wl,-soname,$@ -o $@ $< -lc
sample/sample-plugins/client-connect/README new file +34 -0
new file mode 100644
index 00000000..be6ef947
@@ -0,0 +1,34 @@
+OpenVPN plugin examples.
+
+Examples provided:
+
+sample-client-connect.c
+
+  - hook to all plugin hooks that openvpn offers
+  - log which hook got called
+  - on CLIENT_CONNECT or CLIENT_CONNECT_V2 set some config variables
+    (controlled by "setenv plugin_cc_config ..." and "plugin_cc2_config"
+    in openvpn's config)
+
+  - if the environment variable UV_WANT_CC_FAIL is set, fail
+  - if the environment variable UV_WANT_CC_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC_ASYNC is set, go to
+    asynchronous/deferred mode on CLIENT_CONNECT, and sleep for
+    ${UV_WANT_CC_ASYNC} seconds
+
+  - if the environment variable UV_WANT_CC2_FAIL is set, fail CC2
+  - if the environment variable UV_WANT_CC2_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC2_ASYNC is set, go to
+    asynchronous/deferred mode on CLIENT_CONNECT_V2, and sleep for
+    ${UV_WANT_CC2_ASYNC} seconds
+
+    (this can be client-controlled with --setenv UV_WANT_CC_ASYNC nnn
+     etc. --> for easy testing server code paths)
+
+To build (not very sophisticated right now, needs gcc):
+
+  .../sample-plugins/client-connect$ make (Linux/BSD/etc.)
+
+To use in OpenVPN, add to config file:
+
+  plugin sample-client-connect.so (Linux/BSD/etc.)
sample/sample-plugins/client-connect/sample-client-connect.c new file +609 -0

609 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw
Quoted 36 lines · Gert Doering

This is a new "samples" plugin which does not do many useful things, besides
- show how a plugin is programmed
- how the various messages get dispatched
- how to pass back information from a client-connect/v2 plugin
- how to do async-cc plugins [not yet implemented]

the operation of the plugin is controlled by UV_WANT_* environment variables controlled by the client ("--setenv UV_WANT_CC_FAIL 1 --push-peer-info"), to "fail CLIENT_CONNECT" or "use async-cc for CLIENT_CONNECT_V2" or "send 'disable' back from ...") - which is useful for automated testing of server success/defer/fail code paths for the CLIENT_CONNECT_* functions.

See samples/sample-plugins/client-connect/README for details how to do this.

v2:
- implement async / deferred operation both for CLIENT_CONNECT and CLIENT_CONNECT_V2 plugin calls
- implement returning openvpn-controlled (setenv) config snippets (so the client side can verify in automated testing that the plugin operated correctly, without hard-coding something in the plugin code)

---
 sample/sample-plugins/client-connect/Makefile |  16 +
 sample/sample-plugins/client-connect/README   |  34 +
 .../client-connect/sample-client-connect.c    | 609 ++++++++++++++++++
 3 files changed, 659 insertions(+)
 create mode 100644 sample/sample-plugins/client-connect/Makefile
 create mode 100644 sample/sample-plugins/client-connect/README
 create mode 100644 sample/sample-plugins/client-connect/sample-client-connect.c
sample/sample-plugins/client-connect/Makefile new file +0 -0
new file mode 100644
index 00000000..ff187c43

sample/sample-plugins/client-connect/Makefile line 9

Quoted 9 lines
sample/sample-plugins/client-connect/Makefile new file +9 -0
@@ -0,0 +1,16 @@
+all: sample-client-connect.so
+
+
+sample-client-connect.o: sample-client-connect.c
+
+# This directory is where we will look for openvpn-plugin.h
+CPPFLAGS=-I../../../include
+
+CC=gcc

If you don't set this; CC will normally be 'cc', which is normally linked to gcc on Linux systems.

sample/sample-plugins/client-connect/Makefile line 10

Quoted 1 line
sample/sample-plugins/client-connect/Makefile new file +1 -0
+CFLAGS=-O2 -Wall -Wno-unused-variable -g

I would probably skip the -Wno-unused-variable and rather not declare unused variables.

[...snip...]

Quoted 2 lines
sample/sample-plugins/client-connect/sample-client-connect.c new file +0 -0

[...snip...]

Quoted 7 lines
sample/sample-plugins/client-connect/sample-client-connect.c new file +7 -0
+/* use v3 functions so we can use openvpn's logging and base64 etc. */
+OPENVPN_EXPORT int
+openvpn_plugin_open_v3(const int v3structver,
+                       struct openvpn_plugin_args_open_in const *args,
+                       struct openvpn_plugin_args_open_return *ret)
+{
+    const char **argv = args->argv;
#4 lore raw

Hi,

thanks for the review.

Quoted 3 lines · David Sommerseth
Quoted 2 lines · Gert Doering

This is a new "samples" plugin which does not do many useful things, besides

[..]

Quoted 10 lines

sample/sample-plugins/client-connect/Makefile line 9

Quoted 6 lines
sample/sample-plugins/client-connect/Makefile new file +6 -0
+sample-client-connect.o: sample-client-connect.c
+
+# This directory is where we will look for openvpn-plugin.h
+CPPFLAGS=-I../../../include
+
+CC=gcc

If you don't set this; CC will normally be 'cc', which is normally linked to gcc on Linux systems.

Quoted 4 lines
Quoted 1 line

+CFLAGS=-O2 -Wall -Wno-unused-variable -g

I would probably skip the -Wno-unused-variable and rather not declare unused variables.

Yeah, not sure how that one slipped in. I *did* try to make it warning-free, so, next version is coming :-)

Quoted 10 lines
Quoted 1 line

+ rl->name = strdup("config");

I'm getting a lot of "warning: implicit declaration of function ???strdup???;" and
"warning: assignment to ???char *??? from ???int??? makes pointer from integer
without a cast" compiler warning on all of these strdup() calls.

We do use strdup() in the main openvpn code, but that code includes config.h, which contains #define _GNU_SOURCE 1. This removes this compiler warning.

This is on RHEL-7 with both gcc-4.8 and gcc-9.3.

Not sure what you are hitting there. According to "man strdup()", inclusion of <string.h> should be fully sufficient, without any extra declarations. But maybe it's a -std=... thing to tell GCC what C language level is desired?

I developed and tested this on a gentoo linux, with gcc-9.2.0, and it's *not* throwing strdup() warnings.

Quoted 3 lines

Otherwise, the code looks reasonable and it works. The log file does not include the pushed echo statement (can be enabled in options.c:5286). The management interface shows the pushed echo message.

Yeah, the "echo" directive is sort of weird. It's blanked out of PUSH messages as well... I do wonder what James had in mind here, or what AS/Connect are using it for :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#6 lore raw

PATCH v3 1/1 Add demo plugin that excercises "CLIENT_CONNECT" and "CLIENT_CONNECT_V2" paths

In reply to Gert Doering

This is a new "samples" plugin which does not do many useful things, besides
- show how a plugin is programmed
- how the various messages get dispatched
- how to pass back information from a client-connect/v2 plugin
- how to do async-cc plugins [not yet implemented]

the operation of the plugin is controlled by UV_WANT_* environment variables controlled by the client ("--setenv UV_WANT_CC_FAIL 1 --push-peer-info"), to "fail CLIENT_CONNECT" or "use async-cc for CLIENT_CONNECT_V2" or "send 'disable' back from ...") - which is useful for automated testing of server success/defer/fail code paths for the CLIENT_CONNECT_* functions.

See samples/sample-plugins/client-connect/README for details how to do this.

v2:
- implement async / deferred operation both for CLIENT_CONNECT and CLIENT_CONNECT_V2 plugin calls
- implement returning openvpn-controlled (setenv) config snippets (so the client side can verify in automated testing that the plugin operated correctly, without hard-coding something in the plugin code)

v3:
- remove -Wno-unused-variable from Makefile
- remove unused "char ** argv" (commented out, but kept as reference)

---
 sample/sample-plugins/client-connect/Makefile |  16 +
 sample/sample-plugins/client-connect/README   |  34 +
 .../client-connect/sample-client-connect.c    | 609 ++++++++++++++++++
 3 files changed, 659 insertions(+)
 create mode 100644 sample/sample-plugins/client-connect/Makefile
 create mode 100644 sample/sample-plugins/client-connect/README
 create mode 100644 sample/sample-plugins/client-connect/sample-client-connect.c
sample/sample-plugins/client-connect/Makefile new file +16 -0
new file mode 100644
index 00000000..093bffc9
@@ -0,0 +1,16 @@
+all: sample-client-connect.so
+
+
+sample-client-connect.o: sample-client-connect.c
+
+# This directory is where we will look for openvpn-plugin.h
+CPPFLAGS=-I../../../include
+
+CC=gcc
+CFLAGS=-O2 -Wall -g
+
+.c.o:
+	$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c $<
+
+sample-client-connect.so: sample-client-connect.o
+	$(CC) $(CFLAGS) -fPIC -shared $(LDFLAGS) -Wl,-soname,$@ -o $@ $< -lc
sample/sample-plugins/client-connect/README new file +34 -0
new file mode 100644
index 00000000..be6ef947
@@ -0,0 +1,34 @@
+OpenVPN plugin examples.
+
+Examples provided:
+
+sample-client-connect.c
+
+  - hook to all plugin hooks that openvpn offers
+  - log which hook got called
+  - on CLIENT_CONNECT or CLIENT_CONNECT_V2 set some config variables
+    (controlled by "setenv plugin_cc_config ..." and "plugin_cc2_config"
+    in openvpn's config)
+
+  - if the environment variable UV_WANT_CC_FAIL is set, fail
+  - if the environment variable UV_WANT_CC_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC_ASYNC is set, go to
+    asynchronous/deferred mode on CLIENT_CONNECT, and sleep for
+    ${UV_WANT_CC_ASYNC} seconds
+
+  - if the environment variable UV_WANT_CC2_FAIL is set, fail CC2
+  - if the environment variable UV_WANT_CC2_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC2_ASYNC is set, go to
+    asynchronous/deferred mode on CLIENT_CONNECT_V2, and sleep for
+    ${UV_WANT_CC2_ASYNC} seconds
+
+    (this can be client-controlled with --setenv UV_WANT_CC_ASYNC nnn
+     etc. --> for easy testing server code paths)
+
+To build (not very sophisticated right now, needs gcc):
+
+  .../sample-plugins/client-connect$ make (Linux/BSD/etc.)
+
+To use in OpenVPN, add to config file:
+
+  plugin sample-client-connect.so (Linux/BSD/etc.)
sample/sample-plugins/client-connect/sample-client-connect.c new file +609 -0

609 lines not on this page · raw message

Signature · 1 line
2.26.2
#5 lore raw
In reply to Gert Doering

On 11/09/2020 23:39, Gert Doering wrote:
[...snip...]

Quoted 7 lines
Quoted 7 lines

I'm getting a lot of "warning: implicit declaration of function ???strdup???;" and
"warning: assignment to ???char *??? from ???int??? makes pointer from integer
without a cast" compiler warning on all of these strdup() calls.

We do use strdup() in the main openvpn code, but that code includes config.h, which contains #define _GNU_SOURCE 1. This removes this compiler warning.

Quoted 6 lines
Quoted 1 line

This is on RHEL-7 with both gcc-4.8 and gcc-9.3.

Not sure what you are hitting there. According to "man strdup()", inclusion of <string.h> should be fully sufficient, without any extra declarations. But maybe it's a -std=... thing to tell GCC what C language level is desired?

Yes, I read somewhere that -std=c99 changes the behavior. _POSIX_C_SOURCE is not defined with -std=c99 (nor c11), but is defined without -std= defined. None of the compiler standards adds _XOPEN_SOURCE - and neither _SVID_SOURCE nor _BSD_SOURCE (which is not really surprising)

Quoted 2 lines

I developed and tested this on a gentoo linux, with gcc-9.2.0, and it's *not* throwing strdup() warnings.

Without -std=c99 I get a clean compilation with GCC-9.3.1 (RHEL-7/devtoolset-9 SCL). But on stock RHEL-7 (GCC-4.8.5) this plugin does not compile without -std=c99 ...

------------------------
client-connect/sample-client-connect.c: In function ‘openvpn_plugin_client_connect’:
client-connect/sample-client-connect.c:356:9: error: ‘for’ loop initial declarations are only allowed in C99 mode

         for (int i = 0; argv[i]; i++)

------------------------

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#7 lore raw

PATCH v4 1/1 Add demo plugin that excercises "CLIENT_CONNECT" and "CLIENT_CONNECT_V2" paths

In reply to Gert Doering

This is a new "samples" plugin which does not do many useful things, besides
- show how a plugin is programmed
- how the various messages get dispatched
- how to pass back information from a client-connect/v2 plugin
- how to do async-cc plugins [not yet implemented]

the operation of the plugin is controlled by UV_WANT_* environment variables controlled by the client ("--setenv UV_WANT_CC_FAIL 1 --push-peer-info"), to "fail CLIENT_CONNECT" or "use async-cc for CLIENT_CONNECT_V2" or "send 'disable' back from ...") - which is useful for automated testing of server success/defer/fail code paths for the CLIENT_CONNECT_* functions.

See samples/sample-plugins/client-connect/README for details how to do this.

v2:
- implement async / deferred operation both for CLIENT_CONNECT and CLIENT_CONNECT_V2 plugin calls
- implement returning openvpn-controlled (setenv) config snippets (so the client side can verify in automated testing that the plugin operated correctly, without hard-coding something in the plugin code)

v3:
- remove -Wno-unused-variable from Makefile
- remove unused "char ** argv" (commented out, but kept as reference)

v4:
- upgrade to use the build infra brought by commit 0b5141d8f946
- remove local Makefile
- include "config.h" to get what is needed to get rid of the strdup() warning

---
 sample/sample-plugins/Makefile.plugins        |   3 +-
 sample/sample-plugins/README                  |   6 +
 sample/sample-plugins/client-connect/README   |  38 ++
 .../client-connect/sample-client-connect.c    | 612 ++++++++++++++++++
 4 files changed, 658 insertions(+), 1 deletion(-)
 create mode 100644 sample/sample-plugins/client-connect/README
 create mode 100644 sample/sample-plugins/client-connect/sample-client-connect.c
sample/sample-plugins/Makefile.plugins +2 -1
index f550fc19..37559a86 100644
@@ -11,7 +11,8 @@ PLUGINS = \
 	keying-material-exporter-demo/keyingmaterialexporter \
 	log/log log/log_v3 \
 	simple/base64 \
-	simple/simple
+	simple/simple \
+	client-connect/sample-client-connect
 
 # All the plugins to build - rewritten with .so extension
 all : $(foreach var, $(PLUGINS), $(var).so)
sample/sample-plugins/README +6 -0
index 3ed60348..cf1b355e 100644
@@ -13,6 +13,12 @@ log/log_v3.c    -- A variant of log/log.c, which makes use of the
                    OpenVPN plug-in v3 API.  This will also log even more
                    information related to certificates in use.
 
+* client-connect (and logging)
+client-connect/sample-client-connect -- demonstrate how to use the
+                   CLIENT_CONNECT and CLIENT_CONNECT_V2 hooks to achieve
+                   "per client configuration / logging / ..." actions,
+                   both in synchronous and async/deferred mode
+
 * cryptography related
 simple/base64.c -- Example using the OpenVPN exported base64 encode/decode
                    functions
sample/sample-plugins/client-connect/README new file +38 -0
new file mode 100644
index 00000000..cb3e0f3c
@@ -0,0 +1,38 @@
+OpenVPN plugin examples.
+
+Examples provided:
+
+sample-client-connect.c
+
+  - hook to all plugin hooks that openvpn offers
+  - log which hook got called
+  - on CLIENT_CONNECT or CLIENT_CONNECT_V2 set some config variables
+    (controlled by "setenv plugin_cc_config ..." and "plugin_cc2_config"
+    in openvpn's config)
+
+  - if the environment variable UV_WANT_CC_FAIL is set, fail
+  - if the environment variable UV_WANT_CC_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC_ASYNC is set, go to
+    asynchronous/deferred mode on CLIENT_CONNECT, and sleep for
+    ${UV_WANT_CC_ASYNC} seconds
+
+  - if the environment variable UV_WANT_CC2_FAIL is set, fail CC2
+  - if the environment variable UV_WANT_CC2_DISABLE is set, reject ("disable")
+  - if the environment variable UV_WANT_CC2_ASYNC is set, go to
+    asynchronous/deferred mode on CLIENT_CONNECT_V2, and sleep for
+    ${UV_WANT_CC2_ASYNC} seconds
+
+    (this can be client-controlled with --setenv UV_WANT_CC_ASYNC nnn
+     etc. --> for easy testing server code paths)
+
+To build for unixy platforms (not very sophisticated right now, needs gmake):
+
+  .../sample-plugins$ gmake client-connect/sample-client-connect.so
+
+(This plugin has not been tested on Windows, and might not even work due
+to its use of fork() and wait().  Let us know if it does or needs patches)
+
+
+To use in OpenVPN, add to config file:
+
+  plugin sample-client-connect.so (Linux/BSD/etc.)
sample/sample-plugins/client-connect/sample-client-connect.c new file +612 -0

612 lines not on this page · raw message

Signature · 1 line
2.26.2
Acked-by on v4 1/1
#8 lore raw
Quoted 31 lines · Gert Doering

This is a new "samples" plugin which does not do many useful things, besides
- show how a plugin is programmed
- how the various messages get dispatched
- how to pass back information from a client-connect/v2 plugin
- how to do async-cc plugins [not yet implemented]

the operation of the plugin is controlled by UV_WANT_* environment variables controlled by the client ("--setenv UV_WANT_CC_FAIL 1 --push-peer-info"), to "fail CLIENT_CONNECT" or "use async-cc for CLIENT_CONNECT_V2" or "send 'disable' back from ...") - which is useful for automated testing of server success/defer/fail code paths for the CLIENT_CONNECT_* functions.

See samples/sample-plugins/client-connect/README for details how to do this.

v2:
- implement async / deferred operation both for CLIENT_CONNECT and CLIENT_CONNECT_V2 plugin calls
- implement returning openvpn-controlled (setenv) config snippets (so the client side can verify in automated testing that the plugin operated correctly, without hard-coding something in the plugin code)

v3:
- remove -Wno-unused-variable from Makefile
- remove unused "char ** argv" (commented out, but kept as reference)

v4:
- upgrade to use the build infra brought by commit 0b5141d8f946
- remove local Makefile
- include "config.h" to get what is needed to get rid of the strdup() warning

Quoted 9 lines
---
 sample/sample-plugins/Makefile.plugins        |   3 +-
 sample/sample-plugins/README                  |   6 +
 sample/sample-plugins/client-connect/README   |  38 ++
 .../client-connect/sample-client-connect.c    | 612 ++++++++++++++++++
 4 files changed, 658 insertions(+), 1 deletion(-)
 create mode 100644 sample/sample-plugins/client-connect/README
 create mode 100644 sample/sample-plugins/client-connect/sample-client-connect.c

I've only glared at important code pieces, diffed against the v2 of this patch and compiled it on RHEL-7 (gcc-4.8.5 and gcc-9.3.1/devtoolset-9). Since everything is as expected now (no compiler complaints, diff is good) and prior review testing worked as expected ...

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#9 lore raw

[Openvpn-devel] [PATCH applied] Re: Add demo plugin that excercises CLIENT_CONNECT and CLIENT_CONNECT_V2 paths

In reply to Gert Doering

Patch has been applied to the master and release/2.5 branch.

commit 94cebf8261d20a55b0260cce61ad892a98bc24d8 (master) commit 44e9f3933e27988193e4a0346559f53e5b876bde (release/2.5)

Author: Gert Doering
Date:   Thu Sep 17 18:19:09 2020 +0200
     Add demo plugin that excercises CLIENT_CONNECT and CLIENT_CONNECT_V2 paths

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

--
kind regards,

Gert Doering