OpenVPN
plugin.h
Go to the documentation of this file.
1 /*
2  * OpenVPN -- An application to securely tunnel IP networks
3  * over a single TCP/UDP port, with support for SSL/TLS-based
4  * session authentication and key exchange,
5  * packet encryption, packet authentication, and
6  * packet compression.
7  *
8  * Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 /*
25  * plug-in support, using dynamically loaded libraries
26  */
27 
28 #ifndef OPENVPN_PLUGIN_H
29 #define OPENVPN_PLUGIN_H
30 
31 #ifdef ENABLE_CRYPTO_OPENSSL
32 #include "ssl_verify_openssl.h"
33 #endif
34 #ifdef ENABLE_CRYPTO_MBEDTLS
35 #include "ssl_verify_mbedtls.h"
36 #endif
37 #include "openvpn-plugin.h"
38 
39 #ifdef ENABLE_PLUGIN
40 
41 #include "misc.h"
42 
43 #define MAX_PLUGINS 16
44 
45 struct plugin_option {
46  const char *so_pathname;
47  const char **argv;
48 };
49 
51  int n;
52  struct plugin_option plugins[MAX_PLUGINS];
53 };
54 
55 struct plugin {
57  const char *so_pathname;
58  unsigned int plugin_type_mask;
60 
61 #ifndef _WIN32
62  void *handle;
63 #else
64  HMODULE module;
65 #endif
66 
79 
81 };
82 
84 {
85  void *per_client_context[MAX_PLUGINS];
86 };
87 
89 {
90  int n;
91  struct plugin plugins[MAX_PLUGINS];
92 };
93 
95 {
96  struct plugin_per_client per_client;
99 };
100 
102 {
103  int n;
105 };
106 
108 
109 bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc);
110 
111 #ifndef ENABLE_SMALL
112 void plugin_option_list_print(const struct plugin_option_list *list, int msglevel);
113 
114 #endif
115 
116 struct plugin_list *plugin_list_init(const struct plugin_option_list *list);
117 
118 void plugin_list_open(struct plugin_list *pl,
119  const struct plugin_option_list *list,
120  struct plugin_return *pr,
121  const struct env_set *es,
122  const int init_point);
123 
124 struct plugin_list *plugin_list_inherit(const struct plugin_list *src);
125 
126 int plugin_call_ssl(const struct plugin_list *pl,
127  const int type,
128  const struct argv *av,
129  struct plugin_return *pr,
130  struct env_set *es,
131  int current_cert_depth,
132  openvpn_x509_cert_t *current_cert
133  );
134 
135 void plugin_list_close(struct plugin_list *pl);
136 
137 bool plugin_defined(const struct plugin_list *pl, const int type);
138 
139 void plugin_return_get_column(const struct plugin_return *src,
140  struct plugin_return *dest,
141  const char *colname);
142 
143 void plugin_return_free(struct plugin_return *pr);
144 
145 #ifdef ENABLE_DEBUG
146 void plugin_return_print(const int msglevel, const char *prefix, const struct plugin_return *pr);
147 
148 #endif
149 
150 static inline int
151 plugin_n(const struct plugin_list *pl)
152 {
153  if (pl && pl->common)
154  {
155  return pl->common->n;
156  }
157  else
158  {
159  return 0;
160  }
161 }
162 
163 static inline bool
165 {
166  return pr->n >= 0;
167 }
168 
169 static inline void
171 {
172  pr->n = 0;
173 }
174 
175 #else /* ifdef ENABLE_PLUGIN */
176 struct plugin_list { int dummy; };
177 struct plugin_return { int dummy; };
178 
179 static inline bool
180 plugin_defined(const struct plugin_list *pl, const int type)
181 {
182  return false;
183 }
184 
185 static inline int
186 plugin_call_ssl(const struct plugin_list *pl,
187  const int type,
188  const struct argv *av,
189  struct plugin_return *pr,
190  struct env_set *es,
191  int current_cert_depth,
192  openvpn_x509_cert_t *current_cert
193  )
194 {
195  return 0;
196 }
197 
198 #endif /* ENABLE_PLUGIN */
199 
200 static inline int
201 plugin_call(const struct plugin_list *pl,
202  const int type,
203  const struct argv *av,
204  struct plugin_return *pr,
205  struct env_set *es)
206 {
207  return plugin_call_ssl(pl, type, av, pr, es, -1, NULL);
208 }
209 
210 void plugin_abort(void);
211 
212 #endif /* OPENVPN_PLUGIN_H */
void plugin_list_open(struct plugin_list *pl, const struct plugin_option_list *list, struct plugin_return *pr, const struct env_set *es, const int init_point)
Definition: plugin.c:770
OPENVPN_PLUGIN_DEF void OPENVPN_PLUGIN_FUNC() openvpn_plugin_close_v1(openvpn_plugin_handle_t handle)
This cleans up the last part of the plug-in, allows it to shut down cleanly and release the plug-in g...
Definition: simple.c:334
OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC() openvpn_plugin_func_v3(const int version, struct openvpn_plugin_args_func_in const *arguments, struct openvpn_plugin_args_func_return *retptr)
unsigned int plugin_type_mask
Definition: plugin.h:58
static void plugin_return_init(struct plugin_return *pr)
Definition: plugin.h:170
struct plugin_list * plugin_list_inherit(const struct plugin_list *src)
Definition: plugin.c:679
void plugin_abort(void)
Definition: plugin.c:879
OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC() openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, const char *argv[], const char *envp[])
This function is called by OpenVPN each time the OpenVPN reaches a point where plug-in calls should h...
Definition: log.c:167
static int plugin_call(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es)
Definition: plugin.h:201
openvpn_plugin_open_v1 open1
Definition: plugin.h:67
struct plugin_list * plugin_list_init(const struct plugin_option_list *list)
Definition: plugin.c:760
X509 openvpn_x509_cert_t
openvpn_plugin_open_v2 open2
Definition: plugin.h:68
openvpn_plugin_select_initialization_point_v1 initialization_point
Definition: plugin.h:78
OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC() openvpn_plugin_open_v2(unsigned int *type_mask, const char *argv[], const char *envp[], struct openvpn_plugin_string_list **return_list)
openvpn_plugin_abort_v1 abort
Definition: plugin.h:74
static void dummy(void)
Definition: comp-lz4.c:319
OPENVPN_PLUGIN_DEF void OPENVPN_PLUGIN_FUNC() openvpn_plugin_abort_v1(openvpn_plugin_handle_t handle)
Definition: auth-pam.c:579
OPENVPN_PLUGIN_DEF void OPENVPN_PLUGIN_FUNC() openvpn_plugin_client_destructor_v1(openvpn_plugin_handle_t handle, void *per_client_context)
Definition: simple.c:327
const char * so_pathname
Definition: plugin.h:46
openvpn_plugin_close_v1 close
Definition: plugin.h:73
const char ** argv
Definition: plugin.h:47
openvpn_plugin_func_v2 func2
Definition: plugin.h:71
OPENVPN_PLUGIN_DEF void *OPENVPN_PLUGIN_FUNC() openvpn_plugin_client_constructor_v1(openvpn_plugin_handle_t handle)
Definition: simple.c:320
void plugin_return_get_column(const struct plugin_return *src, struct plugin_return *dest, const char *colname)
Definition: plugin.c:963
void plugin_return_free(struct plugin_return *pr)
Definition: plugin.c:978
bool plugin_defined(const struct plugin_list *pl, const int type)
Definition: plugin.c:895
struct plugin_option_list * plugin_option_list_new(struct gc_arena *gc)
Definition: plugin.c:156
openvpn_plugin_client_destructor_v1 client_destructor
Definition: plugin.h:76
OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC() openvpn_plugin_min_version_required_v1(void)
void plugin_list_close(struct plugin_list *pl)
Definition: plugin.c:860
OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC() openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const char *envp[])
Definition: simple.c:134
void * openvpn_plugin_handle_t
HMODULE module
Definition: plugin.h:64
const char * so_pathname
Definition: plugin.h:57
bool initialized
Definition: plugin.h:56
openvpn_plugin_func_v1 func1
Definition: plugin.h:70
openvpn_plugin_client_constructor_v1 client_constructor
Definition: plugin.h:75
int requested_initialization_point
Definition: plugin.h:59
void plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
Definition: plugin.c:184
OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC() openvpn_plugin_open_v3(const int version, struct openvpn_plugin_args_open_in const *arguments, struct openvpn_plugin_args_open_return *retptr)
This function is called when OpenVPN loads the plug-in.
OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC() 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)
Definition: simple.c:251
openvpn_plugin_open_v3 open3
Definition: plugin.h:69
bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc)
Definition: plugin.c:164
static bool plugin_return_defined(const struct plugin_return *pr)
Definition: plugin.h:164
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
#define MAX_PLUGINS
Definition: plugin.h:43
Definition: argv.h:35
char * dest
Definition: compat-lz4.h:431
OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC() openvpn_plugin_select_initialization_point_v1(void)
struct plugin_common * common
Definition: plugin.h:97
static int plugin_n(const struct plugin_list *pl)
Definition: plugin.h:151
bool common_owned
Definition: plugin.h:98
int plugin_call_ssl(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es, int current_cert_depth, openvpn_x509_cert_t *current_cert)
Definition: plugin.c:781
openvpn_plugin_func_v3 func3
Definition: plugin.h:72
openvpn_plugin_min_version_required_v1 min_version_required
Definition: plugin.h:77
openvpn_plugin_handle_t plugin_handle
Definition: plugin.h:80