summaryrefslogtreecommitdiffstats
path: root/plugin.h
blob: d6ff08dff210af868049090c1864195d08a03d1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 *  OpenVPN -- An application to securely tunnel IP networks
 *             over a single TCP/UDP port, with support for SSL/TLS-based
 *             session authentication and key exchange,
 *             packet encryption, packet authentication, and
 *             packet compression.
 *
 *  Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program (see the file COPYING included with this
 *  distribution); if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * plug-in support, using dynamically loaded libraries
 */

#ifndef OPENVPN_PLUGIN_H
#define OPENVPN_PLUGIN_H

#include "openvpn-plugin.h"

#ifdef ENABLE_PLUGIN

#include "misc.h"

#define MAX_PLUGINS 16

struct plugin_option {
  const char *so_pathname;
  const char **argv;
};

struct plugin_option_list {
  int n;
  struct plugin_option plugins[MAX_PLUGINS];
};

struct plugin {
  bool initialized;
  const char *so_pathname;
  unsigned int plugin_type_mask;
  int requested_initialization_point;

#if defined(USE_LIBDL)
  void *handle;
#elif defined(USE_LOAD_LIBRARY)
  HMODULE module;
#endif

  openvpn_plugin_open_v1 open1;
  openvpn_plugin_open_v2 open2;
  openvpn_plugin_open_v3 open3;
  openvpn_plugin_func_v1 func1;
  openvpn_plugin_func_v2 func2;
  openvpn_plugin_func_v3 func3;
  openvpn_plugin_close_v1 close;
  openvpn_plugin_abort_v1 abort;
  openvpn_plugin_client_constructor_v1 client_constructor;
  openvpn_plugin_client_destructor_v1 client_destructor;
  openvpn_plugin_min_version_required_v1 min_version_required;
  openvpn_plugin_select_initialization_point_v1 initialization_point;

  openvpn_plugin_handle_t plugin_handle;
};

struct plugin_per_client
{
  void *per_client_context[MAX_PLUGINS];
};

struct plugin_common
{
  int n;
  struct plugin plugins[MAX_PLUGINS];
};

struct plugin_list
{
  struct plugin_per_client per_client;
  struct plugin_common *common;
  bool common_owned;
};

struct plugin_return
{
  int n;
  struct openvpn_plugin_string_list *list[MAX_PLUGINS];
};

struct plugin_option_list *plugin_option_list_new (struct gc_arena *gc);
bool plugin_option_list_add (struct plugin_option_list *list, char **p, struct gc_arena *gc);

#ifdef ENABLE_DEBUG
void plugin_option_list_print (const struct plugin_option_list *list, int msglevel);
#endif

struct plugin_list *plugin_list_init (const struct plugin_option_list *list);

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);

struct plugin_list *plugin_list_inherit (const struct plugin_list *src);

int plugin_call (const struct plugin_list *pl,
		 const int type,
		 const struct argv *av,
		 struct plugin_return *pr,
		 struct env_set *es,
		 int current_cert_depth,
		 X509 *current_cert);

void plugin_list_close (struct plugin_list *pl);
bool plugin_defined (const struct plugin_list *pl, const int type);

void plugin_return_get_column (const struct plugin_return *src,
			       struct plugin_return *dest,
			       const char *colname);

void plugin_return_free (struct plugin_return *pr);

#ifdef ENABLE_DEBUG
void plugin_return_print (const int msglevel, const char *prefix, const struct plugin_return *pr);
#endif

static inline int
plugin_n (const struct plugin_list *pl)
{
  if (pl && pl->common)
    return pl->common->n;
  else
    return 0;
}

static inline bool
plugin_return_defined (const struct plugin_return *pr)
{
  return pr->n >= 0;
}

static inline void
plugin_return_init (struct plugin_return *pr)
{
  pr->n = 0;
}

#else

struct plugin_list { int dummy; };
struct plugin_return { int dummy; };

static inline bool
plugin_defined (const struct plugin_list *pl, const int type)
{
  return false;
}

static inline int
plugin_call (const struct plugin_list *pl,
	     const int type,
	     const struct argv *av,
	     struct plugin_return *pr,
	     struct env_set *es,
	     int current_cert_depth,
	     X509 *current_cert)
{
  return 0;
}

#endif /* ENABLE_PLUGIN */

#endif /* OPENVPN_PLUGIN_H */