26 #elif defined(_MSC_VER) 29 #ifdef HAVE_CONFIG_VERSION_H 30 #include "config-version.h" 50 #define PLUGIN_SYMBOL_REQUIRED (1<<0) 59 for (i = 0; array[i]; ++i)
63 msg(msglevel,
"%s[%d] = '%s'", name, i, array[i]);
90 return "PLUGIN_ROUTE_UP";
93 return "PLUGIN_IPCHANGE";
96 return "PLUGIN_TLS_VERIFY";
99 return "PLUGIN_AUTH_USER_PASS_VERIFY";
102 return "PLUGIN_CLIENT_CONNECT";
105 return "PLUGIN_CLIENT_CONNECT";
107 case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER:
108 return "PLUGIN_CLIENT_CONNECT_DEFER";
110 case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2:
111 return "PLUGIN_CLIENT_CONNECT_DEFER_V2";
114 return "PLUGIN_CLIENT_DISCONNECT";
117 return "PLUGIN_LEARN_ADDRESS";
120 return "PLUGIN_TLS_FINAL";
123 return "PLUGIN_ROUTE_PREDOWN";
152 static inline unsigned int 193 for (i = 0; i < list->
n; ++i)
206 libdl_resolve_symbol(
void *handle,
void **dest,
const char *symbol,
const char *plugin_name,
const unsigned int flags)
208 *dest = dlsym(handle, symbol);
211 msg(
M_FATAL,
"PLUGIN: could not find required symbol '%s' in plugin shared object %s: %s", symbol, plugin_name, dlerror());
220 *dest = GetProcAddress(module, symbol);
223 msg(
M_FATAL,
"PLUGIN: could not find required symbol '%s' in plugin DLL %s", symbol, plugin_name);
263 p->handle = dlopen(full, RTLD_NOW);
272 msg(
M_ERR,
"PLUGIN_INIT: could not load plugin shared object %s: %s", p->
so_pathname, dlerror());
275 #define PLUGIN_SYM(var, name, flags) libdl_resolve_symbol(p->handle, (void *)&p->var, name, p->so_pathname, flags) 286 #define PLUGIN_SYM(var, name, flags) dll_resolve_symbol(p->module, (void *)&p->var, name, p->so_pathname, flags) 290 PLUGIN_SYM(open1,
"openvpn_plugin_open_v1", 0);
291 PLUGIN_SYM(open2,
"openvpn_plugin_open_v2", 0);
292 PLUGIN_SYM(open3,
"openvpn_plugin_open_v3", 0);
293 PLUGIN_SYM(func1,
"openvpn_plugin_func_v1", 0);
294 PLUGIN_SYM(func2,
"openvpn_plugin_func_v2", 0);
295 PLUGIN_SYM(func3,
"openvpn_plugin_func_v3", 0);
297 PLUGIN_SYM(abort,
"openvpn_plugin_abort_v1", 0);
298 PLUGIN_SYM(client_constructor,
"openvpn_plugin_client_constructor_v1", 0);
299 PLUGIN_SYM(client_destructor,
"openvpn_plugin_client_destructor_v1", 0);
300 PLUGIN_SYM(min_version_required,
"openvpn_plugin_min_version_required_v1", 0);
301 PLUGIN_SYM(initialization_point,
"openvpn_plugin_select_initialization_point_v1", 0);
321 msg(
M_FATAL,
"PLUGIN_INIT: plugin needs interface version %d, but this version of OpenVPN only supports version %d: %s",
322 plugin_needs_version,
339 msg(
M_WARN,
"WARNING: plugin '%s' specified by a relative pathname -- using an absolute pathname would be more secure", p->
so_pathname);
350 unsigned int msg_flags = 0;
357 if (!name || name[0] ==
'\0')
359 msg(
D_PLUGIN_DEBUG,
"PLUGIN: suppressed log message from plugin with unknown name");
400 x_msg_va(msg_flags, msg_fmt, arglist);
410 va_start(arglist, format);
428 #ifndef CONFIGURE_GIT_REVISION 429 #define _OPENVPN_PATCH_LEVEL OPENVPN_VERSION_PATCH 431 #define _OPENVPN_PATCH_LEVEL "git:" CONFIGURE_GIT_REVISION CONFIGURE_GIT_FLAGS 439 const int init_point)
462 (
const char **
const) o->
argv,
463 (
const char **
const)
envp,
497 msg(
D_PLUGIN,
"PLUGIN_INIT: POST %s '%s' intercepted=%s %s",
501 (retlist && *retlist) ?
"[RETLIST]" :
"");
505 msg(
M_FATAL,
"PLUGIN_INIT: plugin %s expressed interest in unsupported plugin types: [want=0x%08x, have=0x%08x]",
513 msg(
M_FATAL,
"PLUGIN_INIT: plugin initialization function failed: %s",
523 void *per_client_context,
525 const struct argv *av,
554 (
const char **
const) a.
argv,
555 (
const char **
const)
envp,
558 (current_cert ? certdepth : -1),
587 msg(
M_WARN,
"PLUGIN_CALL: plugin function %s failed with status %d: %s",
615 if (dlclose(p->handle))
619 #elif defined(_WIN32) 620 if (!FreeLibrary(p->
module))
645 const int init_point)
650 for (i = 0; i < n; ++i)
668 for (i = 0; i < n; ++i)
700 for (i = 0; i < list->
n; ++i)
707 static_plugin_common = pc;
716 const int init_point)
729 for (i = 0; i < pc->
n; ++i)
733 pr ? &pr->
list[i] : NULL,
749 static_plugin_common = NULL;
754 for (i = 0; i < pc->
n; ++i)
777 const int init_point)
786 const struct argv *av,
805 bool deferred =
false;
810 for (i = 0; i < n; ++i)
816 pr ? &pr->
list[i] : NULL,
879 static_plugin_common = NULL;
884 for (i = 0; i < pc->
n; ++i)
904 for (i = 0; i < pc->
n; ++i)
950 if (!strcmp(l->
name, name))
967 for (i = 0; i < src->
n; ++i)
978 for (i = 0; i < pr->
n; ++i)
987 plugin_return_print(
const int msglevel,
const char *prefix,
const struct plugin_return *pr)
990 msg(msglevel,
"PLUGIN_RETURN_PRINT %s", prefix);
991 for (i = 0; i < pr->
n; ++i)
996 msg(msglevel,
"PLUGIN #%d (%s)", i, prefix);
999 msg(msglevel,
"[%d] '%s' -> '%s'\n",
Arguments used to transport variables to the plug-in.
void plugin_option_list_print(const struct plugin_option_list *list, int msglevel)
static void plugin_common_close(struct plugin_common *pc)
static struct plugin_common * plugin_common_init(const struct plugin_option_list *list)
static void plugin_common_open(struct plugin_common *pc, const struct plugin_option_list *list, struct plugin_return *pr, const struct env_set *es, const int init_point)
struct plugin_option plugins[MAX_PLUGINS]
struct openvpn_plugin_string_list ** return_list
static void plugin_init_item(struct plugin *p, const struct plugin_option *o)
void plugin_return_get_column(const struct plugin_return *src, struct plugin_return *dest, const char *colname)
unsigned int plugin_type_mask
void string_clear(char *str)
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
static void plugin_return_init(struct plugin_return *pr)
static void plugin_per_client_destroy(const struct plugin_common *pc, struct plugin_per_client *cli)
static bool env_safe_to_print(const char *str)
openvpn_plugin_handle_t * handle
struct plugin plugins[MAX_PLUGINS]
struct openvpn_plugin_string_list * list[MAX_PLUGINS]
static void gc_free(struct gc_arena *a)
openvpn_plugin_open_v1 open1
static struct openvpn_plugin_callbacks callbacks
#define OPENVPN_PLUGIN_DOWN
#define OPENVPN_PLUGIN_ROUTE_UP
#define _OPENVPN_PATCH_LEVEL
#define OPENVPN_VERSION_MAJOR
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 certdepth, openvpn_x509_cert_t *current_cert)
bool buf_printf(struct buffer *buf, const char *format,...)
struct openvpn_plugin_string_list * next
openvpn_plugin_open_v2 open2
openvpn_plugin_select_initialization_point_v1 initialization_point
openvpn_plugin_abort_v1 abort
WCHAR * wide_string(const char *utf8, struct gc_arena *gc)
char * print_argv(const char **p, struct gc_arena *gc, const unsigned int flags)
static void plugin_log(openvpn_plugin_log_flags_t flags, const char *name, const char *format,...)
static int plugin_call_item(const struct plugin *p, void *per_client_context, const int type, const struct argv *av, struct openvpn_plugin_string_list **retlist, const char **envp, int certdepth, openvpn_x509_cert_t *current_cert)
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
static bool check_debug_level(unsigned int level)
#define OPENVPN_PLUGIN_FUNC_SUCCESS
#define OPENVPN_PLUGIN_LEARN_ADDRESS
openvpn_plugin_log_flags_t
Definitions needed for the plug-in callback functions.
void setenv_del(struct env_set *es, const char *name)
openvpn_plugin_close_v1 close
#define OPENVPN_PLUGIN_IPCHANGE
const char ** make_env_array(const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
bool openvpn_snprintf(char *str, size_t size, const char *format,...)
#define OPENVPN_PLUGIN_FUNC_DEFERRED
static void plugin_open_item(struct plugin *p, const struct plugin_option *o, struct openvpn_plugin_string_list **retlist, const char **envp, const int init_point)
#define PLUGIN_SYMBOL_REQUIRED
#define OPENVPN_PLUGIN_TLS_VERIFY
#define OPENVPN_PLUGIN_FUNC_ERROR
static struct plugin_common * static_plugin_common
static struct gc_arena gc_new(void)
struct plugin_per_client per_client
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)
static void plugin_show_string_array(int msglevel, const char *name, const char *array[])
openvpn_plugin_func_v2 func2
#define ALLOC_OBJ_CLEAR(dptr, type)
static void plugin_vlog(openvpn_plugin_log_flags_t flags, const char *name, const char *format, va_list arglist)
static void openvpn_plugin_string_list_free(struct openvpn_plugin_string_list *l)
static void gc_init(struct gc_arena *a)
#define OPENVPN_PLUGIN_INIT_PRE_DAEMON
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
static const char * plugin_mask_string(const unsigned int type_mask, struct gc_arena *gc)
#define OPENVPN_PLUGIN_VERSION
int openvpn_base64_decode(const char *str, void *data, int size)
Arguments used to transport variables to and from the plug-in.
static void plugin_abort_item(const struct plugin *p)
static void plugin_per_client_init(const struct plugin_common *pc, struct plugin_per_client *cli, const int init_point)
struct plugin_list * plugin_list_inherit(const struct plugin_list *src)
#define OPENVPN_PLUGIN_TLS_FINAL
openvpn_plugin_client_destructor_v1 client_destructor
const char ** make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc)
void * per_client_context[MAX_PLUGINS]
#define OPENVPN_PLUGIN_CLIENT_DISCONNECT
int openvpn_base64_encode(const void *data, int size, char **str)
static const char * plugin_type_name(const int type)
bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc)
static bool msg_test(unsigned int flags)
Return true if flags represent an enabled, not muted log level.
static void openvpn_plugin_string_list_item_free(struct openvpn_plugin_string_list *l)
static void plugin_show_args_env(int msglevel, const char *argv[], const char *envp[])
static unsigned int plugin_supported_types(void)
Arguments used to transport variables to and from the plug-in.
static void plugin_close_item(struct plugin *p)
openvpn_plugin_func_v1 func1
void plugin_return_free(struct plugin_return *pr)
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
#define OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY
bool plugin_defined(const struct plugin_list *pl, const int type)
struct plugin_option_list * plugin_option_list_new(struct gc_arena *gc)
openvpn_plugin_client_constructor_v1 client_constructor
struct plugin_list * plugin_list_init(const struct plugin_option_list *list)
Wrapper structure for dynamically allocated memory.
int requested_initialization_point
static void dll_resolve_symbol(HMODULE module, void **dest, const char *symbol, const char *plugin_name, const unsigned int flags)
struct openvpn_plugin_string_list ** return_list
void plugin_list_close(struct plugin_list *pl)
#define OPENVPN_PLUGIN_ROUTE_PREDOWN
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
openvpn_plugin_open_v3 open3
#define OPENVPN_PLUGIN_CLIENT_CONNECT
Garbage collection arena used to keep track of dynamically allocated memory.
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
#define OPENVPN_PLUGINv3_STRUCTVER
Defines version of the v3 plugin argument structs.
Arguments used to transport variables from the plug-in back to the OpenVPN process.
#define OPENVPN_PLUGIN_CLIENT_CONNECT_V2
static SERVICE_STATUS status
void * per_client_context
struct plugin_common * common
Used by the openvpn_plugin_open_v3() function to pass callback function pointers to the plug-in...
struct argv argv_insert_head(const struct argv *a, const char *head)
Inserts an argument string in front of all other argument slots.
#define OPENVPN_PLUGIN_UP
#define OPENVPN_VERSION_MINOR
#define OPENVPN_PLUGIN_MASK(x)
static int plugin_n(const struct plugin_list *pl)
static struct openvpn_plugin_string_list * openvpn_plugin_string_list_find(struct openvpn_plugin_string_list *l, const char *name)
#define PLUGIN_SYM(var, name, flags)
openvpn_plugin_func_v3 func3
openvpn_plugin_min_version_required_v1 min_version_required
openvpn_plugin_handle_t plugin_handle