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
8
* Copyright (C) 2002-2008 Telethra, Inc. <sales@openvpn.net>
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.
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.
19
* You should have received a copy of the GNU General Public License
20
* along with this program (see the file COPYING included with this
21
* distribution); if not, write to the Free Software Foundation, Inc.,
22
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
* This plugin is similar to simple.c, except it also logs extra information
27
* to stdout for every plugin method called by OpenVPN.
29
* See the README file for build instructions.
36
#include "openvpn-plugin.h"
39
* Our context, where we keep our state.
41
struct plugin_context {
47
* Given an environmental variable name, search
48
* the envp array for its value, returning it
49
* if found or NULL otherwise.
52
get_env (const char *name, const char *envp[])
57
const int namelen = strlen (name);
58
for (i = 0; envp[i]; ++i)
60
if (!strncmp (envp[i], name, namelen))
62
const char *cp = envp[i] + namelen;
71
OPENVPN_EXPORT openvpn_plugin_handle_t
72
openvpn_plugin_open_v1 (unsigned int *type_mask, const char *argv[], const char *envp[])
74
struct plugin_context *context;
77
* Allocate our context
79
context = (struct plugin_context *) calloc (1, sizeof (struct plugin_context));
82
* Set the username/password we will require.
84
context->username = "foo";
85
context->password = "bar";
88
* Which callbacks to intercept.
91
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_UP) |
92
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_DOWN) |
93
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_ROUTE_UP) |
94
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_IPCHANGE) |
95
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_TLS_VERIFY) |
96
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) |
97
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_CLIENT_CONNECT_V2) |
98
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_CLIENT_DISCONNECT) |
99
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_LEARN_ADDRESS) |
100
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_TLS_FINAL);
102
return (openvpn_plugin_handle_t) context;
106
show (const int type, const char *argv[], const char *envp[])
111
case OPENVPN_PLUGIN_UP:
112
printf ("OPENVPN_PLUGIN_UP\n");
114
case OPENVPN_PLUGIN_DOWN:
115
printf ("OPENVPN_PLUGIN_DOWN\n");
117
case OPENVPN_PLUGIN_ROUTE_UP:
118
printf ("OPENVPN_PLUGIN_ROUTE_UP\n");
120
case OPENVPN_PLUGIN_IPCHANGE:
121
printf ("OPENVPN_PLUGIN_IPCHANGE\n");
123
case OPENVPN_PLUGIN_TLS_VERIFY:
124
printf ("OPENVPN_PLUGIN_TLS_VERIFY\n");
126
case OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY:
127
printf ("OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY\n");
129
case OPENVPN_PLUGIN_CLIENT_CONNECT_V2:
130
printf ("OPENVPN_PLUGIN_CLIENT_CONNECT_V2\n");
132
case OPENVPN_PLUGIN_CLIENT_DISCONNECT:
133
printf ("OPENVPN_PLUGIN_CLIENT_DISCONNECT\n");
135
case OPENVPN_PLUGIN_LEARN_ADDRESS:
136
printf ("OPENVPN_PLUGIN_LEARN_ADDRESS\n");
138
case OPENVPN_PLUGIN_TLS_FINAL:
139
printf ("OPENVPN_PLUGIN_TLS_FINAL\n");
142
printf ("OPENVPN_PLUGIN_?\n");
147
for (i = 0; argv[i] != NULL; ++i)
148
printf ("%d '%s'\n", (int)i, argv[i]);
151
for (i = 0; envp[i] != NULL; ++i)
152
printf ("%d '%s'\n", (int)i, envp[i]);
156
openvpn_plugin_func_v1 (openvpn_plugin_handle_t handle, const int type, const char *argv[], const char *envp[])
158
struct plugin_context *context = (struct plugin_context *) handle;
160
show (type, argv, envp);
162
/* check entered username/password against what we require */
163
if (type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY)
165
/* get username/password from envp string array */
166
const char *username = get_env ("username", envp);
167
const char *password = get_env ("password", envp);
169
if (username && !strcmp (username, context->username)
170
&& password && !strcmp (password, context->password))
171
return OPENVPN_PLUGIN_FUNC_SUCCESS;
173
return OPENVPN_PLUGIN_FUNC_ERROR;
176
return OPENVPN_PLUGIN_FUNC_SUCCESS;
180
openvpn_plugin_close_v1 (openvpn_plugin_handle_t handle)
182
struct plugin_context *context = (struct plugin_context *) handle;