On 11/08/2020 12:44, Gert Doering wrote: > 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 > > diff --git a/sample/sample-plugins/client-connect/Makefile > b/sample/sample-plugins/client-connect/Makefile > new file mode 100644 > index 00000000..ff187c43 > --- /dev/null > +++ b/sample/sample-plugins/client-connect/Makefile > @@ -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. > +CFLAGS=-O2 -Wall -Wno-unused-variable -g I would probably skip the -Wno-unused-variable and rather not declare unused variables. [...snip...] > --- /dev/null > +++ b/sample/sample-plugins/client-connect/sample-client-connect.c [...snip...] > +/* 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; From a code-style point of view, I think declaring unused variables should be avoided. Since this is as an example, we could just comment this line out and add a remark that we do not parse plug-in arguments in this example. [...snip...] > +int > +openvpn_plugin_client_connect_v2(struct plugin_context *context, > + struct plugin_per_client_context *pcc, > + const char **envp, > + struct openvpn_plugin_string_list > **return_list) > +{ [...snip...] > + 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. 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. -- kind regards, David Sommerseth OpenVPN Inc
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel