openvpn-plugin.h.in 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. #ifndef OPENVPN_PLUGIN_H_
  24. #define OPENVPN_PLUGIN_H_
  25. #define OPENVPN_PLUGIN_VERSION 3
  26. #ifdef ENABLE_CRYPTO
  27. #ifdef ENABLE_CRYPTO_MBEDTLS
  28. #include <mbedtls/x509_crt.h>
  29. #ifndef __OPENVPN_X509_CERT_T_DECLARED
  30. #define __OPENVPN_X509_CERT_T_DECLARED
  31. typedef mbedtls_x509_crt openvpn_x509_cert_t;
  32. #endif
  33. #else /* ifdef ENABLE_CRYPTO_MBEDTLS */
  34. #include <openssl/x509.h>
  35. #ifndef __OPENVPN_X509_CERT_T_DECLARED
  36. #define __OPENVPN_X509_CERT_T_DECLARED
  37. typedef X509 openvpn_x509_cert_t;
  38. #endif
  39. #endif
  40. #endif
  41. #include <stdarg.h>
  42. #include <stddef.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /* Provide some basic version information to plug-ins at OpenVPN compile time
  47. * This is will not be the complete version
  48. */
  49. #define OPENVPN_VERSION_MAJOR @OPENVPN_VERSION_MAJOR@
  50. #define OPENVPN_VERSION_MINOR @OPENVPN_VERSION_MINOR@
  51. #define OPENVPN_VERSION_PATCH "@OPENVPN_VERSION_PATCH@"
  52. /*
  53. * Plug-in types. These types correspond to the set of script callbacks
  54. * supported by OpenVPN.
  55. *
  56. * This is the general call sequence to expect when running in server mode:
  57. *
  58. * Initial Server Startup:
  59. *
  60. * FUNC: openvpn_plugin_open_v1
  61. * FUNC: openvpn_plugin_client_constructor_v1 (this is the top-level "generic"
  62. * client template)
  63. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_UP
  64. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_ROUTE_UP
  65. *
  66. * New Client Connection:
  67. *
  68. * FUNC: openvpn_plugin_client_constructor_v1
  69. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_ENABLE_PF
  70. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_TLS_VERIFY (called once for every cert
  71. * in the server chain)
  72. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY
  73. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_TLS_FINAL
  74. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_IPCHANGE
  75. *
  76. * [If OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY returned OPENVPN_PLUGIN_FUNC_DEFERRED,
  77. * we don't proceed until authentication is verified via auth_control_file]
  78. *
  79. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_CONNECT_V2
  80. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS
  81. *
  82. * [Client session ensues]
  83. *
  84. * For each "TLS soft reset", according to reneg-sec option (or similar):
  85. *
  86. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_ENABLE_PF
  87. *
  88. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_TLS_VERIFY (called once for every cert
  89. * in the server chain)
  90. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY
  91. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_TLS_FINAL
  92. *
  93. * [If OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY returned OPENVPN_PLUGIN_FUNC_DEFERRED,
  94. * we expect that authentication is verified via auth_control_file within
  95. * the number of seconds defined by the "hand-window" option. Data channel traffic
  96. * will continue to flow uninterrupted during this period.]
  97. *
  98. * [Client session continues]
  99. *
  100. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_DISCONNECT
  101. * FUNC: openvpn_plugin_client_destructor_v1
  102. *
  103. * [ some time may pass ]
  104. *
  105. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS (this coincides with a
  106. * lazy free of initial
  107. * learned addr object)
  108. * Server Shutdown:
  109. *
  110. * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_DOWN
  111. * FUNC: openvpn_plugin_client_destructor_v1 (top-level "generic" client)
  112. * FUNC: openvpn_plugin_close_v1
  113. */
  114. #define OPENVPN_PLUGIN_UP 0
  115. #define OPENVPN_PLUGIN_DOWN 1
  116. #define OPENVPN_PLUGIN_ROUTE_UP 2
  117. #define OPENVPN_PLUGIN_IPCHANGE 3
  118. #define OPENVPN_PLUGIN_TLS_VERIFY 4
  119. #define OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY 5
  120. #define OPENVPN_PLUGIN_CLIENT_CONNECT 6
  121. #define OPENVPN_PLUGIN_CLIENT_DISCONNECT 7
  122. #define OPENVPN_PLUGIN_LEARN_ADDRESS 8
  123. #define OPENVPN_PLUGIN_CLIENT_CONNECT_V2 9
  124. #define OPENVPN_PLUGIN_TLS_FINAL 10
  125. #define OPENVPN_PLUGIN_ENABLE_PF 11
  126. #define OPENVPN_PLUGIN_ROUTE_PREDOWN 12
  127. #define OPENVPN_PLUGIN_N 13
  128. /*
  129. * Build a mask out of a set of plug-in types.
  130. */
  131. #define OPENVPN_PLUGIN_MASK(x) (1<<(x))
  132. /*
  133. * A pointer to a plugin-defined object which contains
  134. * the object state.
  135. */
  136. typedef void *openvpn_plugin_handle_t;
  137. /*
  138. * Return value for openvpn_plugin_func_v1 function
  139. */
  140. #define OPENVPN_PLUGIN_FUNC_SUCCESS 0
  141. #define OPENVPN_PLUGIN_FUNC_ERROR 1
  142. #define OPENVPN_PLUGIN_FUNC_DEFERRED 2
  143. /*
  144. * For Windows (needs to be modified for MSVC)
  145. */
  146. #if defined(_WIN32) && !defined(OPENVPN_PLUGIN_H)
  147. #define OPENVPN_EXPORT __declspec(dllexport)
  148. #else
  149. #define OPENVPN_EXPORT
  150. #endif
  151. /*
  152. * If OPENVPN_PLUGIN_H is defined, we know that we are being
  153. * included in an OpenVPN compile, rather than a plugin compile.
  154. */
  155. #ifdef OPENVPN_PLUGIN_H
  156. /*
  157. * We are compiling OpenVPN.
  158. */
  159. #define OPENVPN_PLUGIN_DEF typedef
  160. #define OPENVPN_PLUGIN_FUNC(name) (*name)
  161. #else /* ifdef OPENVPN_PLUGIN_H */
  162. /*
  163. * We are compiling plugin.
  164. */
  165. #define OPENVPN_PLUGIN_DEF OPENVPN_EXPORT
  166. #define OPENVPN_PLUGIN_FUNC(name) name
  167. #endif
  168. /*
  169. * Used by openvpn_plugin_func to return structured
  170. * data. The plugin should allocate all structure
  171. * instances, name strings, and value strings with
  172. * malloc, since OpenVPN will assume that it
  173. * can free the list by calling free() over the same.
  174. */
  175. struct openvpn_plugin_string_list
  176. {
  177. struct openvpn_plugin_string_list *next;
  178. char *name;
  179. char *value;
  180. };
  181. /* openvpn_plugin_{open,func}_v3() related structs */
  182. /**
  183. * Defines version of the v3 plugin argument structs
  184. *
  185. * Whenever one or more of these structs are modified, this constant
  186. * must be updated. A changelog should be appended in this comment
  187. * as well, to make it easier to see what information is available
  188. * in the different versions.
  189. *
  190. * Version Comment
  191. * 1 Initial plugin v3 structures providing the same API as
  192. * the v2 plugin interface, X509 certificate information +
  193. * a logging API for plug-ins.
  194. *
  195. * 2 Added ssl_api member in struct openvpn_plugin_args_open_in
  196. * which identifies the SSL implementation OpenVPN is compiled
  197. * against.
  198. *
  199. * 3 Added ovpn_version, ovpn_version_major, ovpn_version_minor
  200. * and ovpn_version_patch to provide the runtime version of
  201. * OpenVPN to plug-ins.
  202. *
  203. * 4 Exported secure_memzero() as plugin_secure_memzero()
  204. *
  205. * 5 Exported openvpn_base64_encode() as plugin_base64_encode()
  206. * Exported openvpn_base64_decode() as plugin_base64_decode()
  207. */
  208. #define OPENVPN_PLUGINv3_STRUCTVER 5
  209. /**
  210. * Definitions needed for the plug-in callback functions.
  211. */
  212. typedef enum
  213. {
  214. PLOG_ERR = (1 << 0),/* Error condition message */
  215. PLOG_WARN = (1 << 1),/* General warning message */
  216. PLOG_NOTE = (1 << 2),/* Informational message */
  217. PLOG_DEBUG = (1 << 3),/* Debug message, displayed if verb >= 7 */
  218. PLOG_ERRNO = (1 << 8),/* Add error description to message */
  219. PLOG_NOMUTE = (1 << 9), /* Mute setting does not apply for message */
  220. } openvpn_plugin_log_flags_t;
  221. #ifdef __GNUC__
  222. #if __USE_MINGW_ANSI_STDIO
  223. #define _ovpn_chk_fmt(a, b) __attribute__ ((format(gnu_printf, (a), (b))))
  224. #else
  225. #define _ovpn_chk_fmt(a, b) __attribute__ ((format(__printf__, (a), (b))))
  226. #endif
  227. #else /* ifdef __GNUC__ */
  228. #define _ovpn_chk_fmt(a, b)
  229. #endif
  230. typedef void (*plugin_log_t)(openvpn_plugin_log_flags_t flags,
  231. const char *plugin_name,
  232. const char *format, ...) _ovpn_chk_fmt (3, 4);
  233. typedef void (*plugin_vlog_t)(openvpn_plugin_log_flags_t flags,
  234. const char *plugin_name,
  235. const char *format,
  236. va_list arglist) _ovpn_chk_fmt (3, 0);
  237. #undef _ovpn_chk_fmt
  238. /**
  239. * Export of secure_memzero() to be used inside plug-ins
  240. *
  241. * @param data Pointer to data to zeroise
  242. * @param len Length of data, in bytes
  243. *
  244. */
  245. typedef void (*plugin_secure_memzero_t)(void *data, size_t len);
  246. /**
  247. * Export of openvpn_base64_encode() to be used inside plug-ins
  248. *
  249. * @param data Pointer to data to BASE64 encode
  250. * @param size Length of data, in bytes
  251. * @param *str Pointer to the return buffer. This needed memory is
  252. * allocated by openvpn_base64_encode() and needs to be free()d
  253. * after use.
  254. *
  255. * @return int Returns the length of the buffer created, or -1 on error.
  256. *
  257. */
  258. typedef int (*plugin_base64_encode_t)(const void *data, int size, char **str);
  259. /**
  260. * Export of openvpn_base64_decode() to be used inside plug-ins
  261. *
  262. * @param str Pointer to the BASE64 encoded data
  263. * @param data Pointer to the buffer where save the decoded data
  264. * @param size Size of the destination buffer
  265. *
  266. * @return int Returns the length of the decoded data, or -1 on error or
  267. * if the destination buffer is too small.
  268. *
  269. */
  270. typedef int (*plugin_base64_decode_t)(const char *str, void *data, int size);
  271. /**
  272. * Used by the openvpn_plugin_open_v3() function to pass callback
  273. * function pointers to the plug-in.
  274. *
  275. * plugin_log
  276. * plugin_vlog : Use these functions to add information to the OpenVPN log file.
  277. * Messages will only be displayed if the plugin_name parameter
  278. * is set. PLOG_DEBUG messages will only be displayed with plug-in
  279. * debug log verbosity (at the time of writing that's verb >= 7).
  280. *
  281. * plugin_secure_memzero
  282. * : Use this function to securely wipe sensitive information from
  283. * memory. This function is declared in a way that the compiler
  284. * will not remove these function calls during the compiler
  285. * optimization phase.
  286. */
  287. struct openvpn_plugin_callbacks
  288. {
  289. plugin_log_t plugin_log;
  290. plugin_vlog_t plugin_vlog;
  291. plugin_secure_memzero_t plugin_secure_memzero;
  292. plugin_base64_encode_t plugin_base64_encode;
  293. plugin_base64_decode_t plugin_base64_decode;
  294. };
  295. /**
  296. * Used by the openvpn_plugin_open_v3() function to indicate to the
  297. * plug-in what kind of SSL implementation OpenVPN uses. This is
  298. * to avoid SEGV issues when OpenVPN is complied against mbed TLS
  299. * and the plug-in against OpenSSL.
  300. */
  301. typedef enum {
  302. SSLAPI_NONE,
  303. SSLAPI_OPENSSL,
  304. SSLAPI_MBEDTLS
  305. } ovpnSSLAPI;
  306. /**
  307. * Arguments used to transport variables to the plug-in.
  308. * The struct openvpn_plugin_args_open_in is only used
  309. * by the openvpn_plugin_open_v3() function.
  310. *
  311. * STRUCT MEMBERS
  312. *
  313. * type_mask : Set by OpenVPN to the logical OR of all script
  314. * types which this version of OpenVPN supports.
  315. *
  316. * argv : a NULL-terminated array of options provided to the OpenVPN
  317. * "plug-in" directive. argv[0] is the dynamic library pathname.
  318. *
  319. * envp : a NULL-terminated array of OpenVPN-set environmental
  320. * variables in "name=value" format. Note that for security reasons,
  321. * these variables are not actually written to the "official"
  322. * environmental variable store of the process.
  323. *
  324. * callbacks : a pointer to the plug-in callback function struct.
  325. *
  326. */
  327. struct openvpn_plugin_args_open_in
  328. {
  329. const int type_mask;
  330. const char **const argv;
  331. const char **const envp;
  332. struct openvpn_plugin_callbacks *callbacks;
  333. const ovpnSSLAPI ssl_api;
  334. const char *ovpn_version;
  335. const unsigned int ovpn_version_major;
  336. const unsigned int ovpn_version_minor;
  337. const char *const ovpn_version_patch;
  338. };
  339. /**
  340. * Arguments used to transport variables from the plug-in back
  341. * to the OpenVPN process. The struct openvpn_plugin_args_open_return
  342. * is only used by the openvpn_plugin_open_v3() function.
  343. *
  344. * STRUCT MEMBERS
  345. *
  346. * type_mask : The plug-in should set this value to the logical OR of all script
  347. * types which the plug-in wants to intercept. For example, if the
  348. * script wants to intercept the client-connect and client-disconnect
  349. * script types:
  350. *
  351. * type_mask = OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT)
  352. * | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT)
  353. *
  354. * handle : Pointer to a global plug-in context, created by the plug-in. This pointer
  355. * is passed on to the other plug-in calls.
  356. *
  357. * return_list : used to return data back to OpenVPN.
  358. *
  359. */
  360. struct openvpn_plugin_args_open_return
  361. {
  362. int type_mask;
  363. openvpn_plugin_handle_t handle;
  364. struct openvpn_plugin_string_list **return_list;
  365. };
  366. /**
  367. * Arguments used to transport variables to and from the
  368. * plug-in. The struct openvpn_plugin_args_func is only used
  369. * by the openvpn_plugin_func_v3() function.
  370. *
  371. * STRUCT MEMBERS:
  372. *
  373. * type : one of the PLUGIN_x types.
  374. *
  375. * argv : a NULL-terminated array of "command line" options which
  376. * would normally be passed to the script. argv[0] is the dynamic
  377. * library pathname.
  378. *
  379. * envp : a NULL-terminated array of OpenVPN-set environmental
  380. * variables in "name=value" format. Note that for security reasons,
  381. * these variables are not actually written to the "official"
  382. * environmental variable store of the process.
  383. *
  384. * handle : Pointer to a global plug-in context, created by the plug-in's openvpn_plugin_open_v3().
  385. *
  386. * per_client_context : the per-client context pointer which was returned by
  387. * openvpn_plugin_client_constructor_v1, if defined.
  388. *
  389. * current_cert_depth : Certificate depth of the certificate being passed over (only if compiled with ENABLE_CRYPTO defined)
  390. *
  391. * *current_cert : X509 Certificate object received from the client (only if compiled with ENABLE_CRYPTO defined)
  392. *
  393. */
  394. struct openvpn_plugin_args_func_in
  395. {
  396. const int type;
  397. const char **const argv;
  398. const char **const envp;
  399. openvpn_plugin_handle_t handle;
  400. void *per_client_context;
  401. #ifdef ENABLE_CRYPTO
  402. int current_cert_depth;
  403. openvpn_x509_cert_t *current_cert;
  404. #else
  405. int __current_cert_depth_disabled; /* Unused, for compatibility purposes only */
  406. void *__current_cert_disabled; /* Unused, for compatibility purposes only */
  407. #endif
  408. };
  409. /**
  410. * Arguments used to transport variables to and from the
  411. * plug-in. The struct openvpn_plugin_args_func is only used
  412. * by the openvpn_plugin_func_v3() function.
  413. *
  414. * STRUCT MEMBERS:
  415. *
  416. * return_list : used to return data back to OpenVPN for further processing/usage by
  417. * the OpenVPN executable.
  418. *
  419. */
  420. struct openvpn_plugin_args_func_return
  421. {
  422. struct openvpn_plugin_string_list **return_list;
  423. };
  424. /*
  425. * Multiple plugin modules can be cascaded, and modules can be
  426. * used in tandem with scripts. The order of operation is that
  427. * the module func() functions are called in the order that
  428. * the modules were specified in the config file. If a script
  429. * was specified as well, it will be called last. If the
  430. * return code of the module/script controls an authentication
  431. * function (such as tls-verify or auth-user-pass-verify), then
  432. * every module and script must return success (0) in order for
  433. * the connection to be authenticated.
  434. *
  435. * Notes:
  436. *
  437. * Plugins which use a privilege-separation model (by forking in
  438. * their initialization function before the main OpenVPN process
  439. * downgrades root privileges and/or executes a chroot) must
  440. * daemonize after a fork if the "daemon" environmental variable is
  441. * set. In addition, if the "daemon_log_redirect" variable is set,
  442. * the plugin should preserve stdout/stderr across the daemon()
  443. * syscall. See the daemonize() function in plugin/auth-pam/auth-pam.c
  444. * for an example.
  445. */
  446. /*
  447. * Prototypes for functions which OpenVPN plug-ins must define.
  448. */
  449. /*
  450. * FUNCTION: openvpn_plugin_open_v2
  451. *
  452. * REQUIRED: YES
  453. *
  454. * Called on initial plug-in load. OpenVPN will preserve plug-in state
  455. * across SIGUSR1 restarts but not across SIGHUP restarts. A SIGHUP reset
  456. * will cause the plugin to be closed and reopened.
  457. *
  458. * ARGUMENTS
  459. *
  460. * *type_mask : Set by OpenVPN to the logical OR of all script
  461. * types which this version of OpenVPN supports. The plug-in
  462. * should set this value to the logical OR of all script types
  463. * which the plug-in wants to intercept. For example, if the
  464. * script wants to intercept the client-connect and
  465. * client-disconnect script types:
  466. *
  467. * *type_mask = OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT)
  468. * | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT)
  469. *
  470. * argv : a NULL-terminated array of options provided to the OpenVPN
  471. * "plug-in" directive. argv[0] is the dynamic library pathname.
  472. *
  473. * envp : a NULL-terminated array of OpenVPN-set environmental
  474. * variables in "name=value" format. Note that for security reasons,
  475. * these variables are not actually written to the "official"
  476. * environmental variable store of the process.
  477. *
  478. * return_list : used to return data back to OpenVPN.
  479. *
  480. * RETURN VALUE
  481. *
  482. * An openvpn_plugin_handle_t value on success, NULL on failure
  483. */
  484. OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC(openvpn_plugin_open_v2)
  485. (unsigned int *type_mask,
  486. const char *argv[],
  487. const char *envp[],
  488. struct openvpn_plugin_string_list **return_list);
  489. /*
  490. * FUNCTION: openvpn_plugin_func_v2
  491. *
  492. * Called to perform the work of a given script type.
  493. *
  494. * REQUIRED: YES
  495. *
  496. * ARGUMENTS
  497. *
  498. * handle : the openvpn_plugin_handle_t value which was returned by
  499. * openvpn_plugin_open.
  500. *
  501. * type : one of the PLUGIN_x types
  502. *
  503. * argv : a NULL-terminated array of "command line" options which
  504. * would normally be passed to the script. argv[0] is the dynamic
  505. * library pathname.
  506. *
  507. * envp : a NULL-terminated array of OpenVPN-set environmental
  508. * variables in "name=value" format. Note that for security reasons,
  509. * these variables are not actually written to the "official"
  510. * environmental variable store of the process.
  511. *
  512. * per_client_context : the per-client context pointer which was returned by
  513. * openvpn_plugin_client_constructor_v1, if defined.
  514. *
  515. * return_list : used to return data back to OpenVPN.
  516. *
  517. * RETURN VALUE
  518. *
  519. * OPENVPN_PLUGIN_FUNC_SUCCESS on success, OPENVPN_PLUGIN_FUNC_ERROR on failure
  520. *
  521. * In addition, OPENVPN_PLUGIN_FUNC_DEFERRED may be returned by
  522. * OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY. This enables asynchronous
  523. * authentication where the plugin (or one of its agents) may indicate
  524. * authentication success/failure some number of seconds after the return
  525. * of the OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY handler by writing a single
  526. * char to the file named by auth_control_file in the environmental variable
  527. * list (envp).
  528. *
  529. * first char of auth_control_file:
  530. * '0' -- indicates auth failure
  531. * '1' -- indicates auth success
  532. *
  533. * OpenVPN will delete the auth_control_file after it goes out of scope.
  534. *
  535. * If an OPENVPN_PLUGIN_ENABLE_PF handler is defined and returns success
  536. * for a particular client instance, packet filtering will be enabled for that
  537. * instance. OpenVPN will then attempt to read the packet filter configuration
  538. * from the temporary file named by the environmental variable pf_file. This
  539. * file may be generated asynchronously and may be dynamically updated during the
  540. * client session, however the client will be blocked from sending or receiving
  541. * VPN tunnel packets until the packet filter file has been generated. OpenVPN
  542. * will periodically test the packet filter file over the life of the client
  543. * instance and reload when modified. OpenVPN will delete the packet filter file
  544. * when the client instance goes out of scope.
  545. *
  546. * Packet filter file grammar:
  547. *
  548. * [CLIENTS DROP|ACCEPT]
  549. * {+|-}common_name1
  550. * {+|-}common_name2
  551. * . . .
  552. * [SUBNETS DROP|ACCEPT]
  553. * {+|-}subnet1
  554. * {+|-}subnet2
  555. * . . .
  556. * [END]
  557. *
  558. * Subnet: IP-ADDRESS | IP-ADDRESS/NUM_NETWORK_BITS
  559. *
  560. * CLIENTS refers to the set of clients (by their common-name) which
  561. * this instance is allowed ('+') to connect to, or is excluded ('-')
  562. * from connecting to. Note that in the case of client-to-client
  563. * connections, such communication must be allowed by the packet filter
  564. * configuration files of both clients.
  565. *
  566. * SUBNETS refers to IP addresses or IP address subnets which this
  567. * instance may connect to ('+') or is excluded ('-') from connecting
  568. * to.
  569. *
  570. * DROP or ACCEPT defines default policy when there is no explicit match
  571. * for a common-name or subnet. The [END] tag must exist. A special
  572. * purpose tag called [KILL] will immediately kill the client instance.
  573. * A given client or subnet rule applies to both incoming and outgoing
  574. * packets.
  575. *
  576. * See plugin/defer/simple.c for an example on using asynchronous
  577. * authentication and client-specific packet filtering.
  578. */
  579. OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_func_v2)
  580. (openvpn_plugin_handle_t handle,
  581. const int type,
  582. const char *argv[],
  583. const char *envp[],
  584. void *per_client_context,
  585. struct openvpn_plugin_string_list **return_list);
  586. /*
  587. * FUNCTION: openvpn_plugin_open_v3
  588. *
  589. * REQUIRED: YES
  590. *
  591. * Called on initial plug-in load. OpenVPN will preserve plug-in state
  592. * across SIGUSR1 restarts but not across SIGHUP restarts. A SIGHUP reset
  593. * will cause the plugin to be closed and reopened.
  594. *
  595. * ARGUMENTS
  596. *
  597. * version : fixed value, defines the API version of the OpenVPN plug-in API. The plug-in
  598. * should validate that this value is matching the OPENVPN_PLUGINv3_STRUCTVER
  599. * value.
  600. *
  601. * arguments : Structure with all arguments available to the plug-in.
  602. *
  603. * retptr : used to return data back to OpenVPN.
  604. *
  605. * RETURN VALUE
  606. *
  607. * OPENVPN_PLUGIN_FUNC_SUCCESS on success, OPENVPN_PLUGIN_FUNC_ERROR on failure
  608. */
  609. OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_open_v3)
  610. (const int version,
  611. struct openvpn_plugin_args_open_in const *arguments,
  612. struct openvpn_plugin_args_open_return *retptr);
  613. /*
  614. * FUNCTION: openvpn_plugin_func_v3
  615. *
  616. * Called to perform the work of a given script type.
  617. *
  618. * REQUIRED: YES
  619. *
  620. * ARGUMENTS
  621. *
  622. * version : fixed value, defines the API version of the OpenVPN plug-in API. The plug-in
  623. * should validate that this value is matching the OPENVPN_PLUGIN_VERSION value.
  624. *
  625. * handle : the openvpn_plugin_handle_t value which was returned by
  626. * openvpn_plugin_open.
  627. *
  628. * return_list : used to return data back to OpenVPN.
  629. *
  630. * RETURN VALUE
  631. *
  632. * OPENVPN_PLUGIN_FUNC_SUCCESS on success, OPENVPN_PLUGIN_FUNC_ERROR on failure
  633. *
  634. * In addition, OPENVPN_PLUGIN_FUNC_DEFERRED may be returned by
  635. * OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY. This enables asynchronous
  636. * authentication where the plugin (or one of its agents) may indicate
  637. * authentication success/failure some number of seconds after the return
  638. * of the OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY handler by writing a single
  639. * char to the file named by auth_control_file in the environmental variable
  640. * list (envp).
  641. *
  642. * first char of auth_control_file:
  643. * '0' -- indicates auth failure
  644. * '1' -- indicates auth success
  645. *
  646. * OpenVPN will delete the auth_control_file after it goes out of scope.
  647. *
  648. * If an OPENVPN_PLUGIN_ENABLE_PF handler is defined and returns success
  649. * for a particular client instance, packet filtering will be enabled for that
  650. * instance. OpenVPN will then attempt to read the packet filter configuration
  651. * from the temporary file named by the environmental variable pf_file. This
  652. * file may be generated asynchronously and may be dynamically updated during the
  653. * client session, however the client will be blocked from sending or receiving
  654. * VPN tunnel packets until the packet filter file has been generated. OpenVPN
  655. * will periodically test the packet filter file over the life of the client
  656. * instance and reload when modified. OpenVPN will delete the packet filter file
  657. * when the client instance goes out of scope.
  658. *
  659. * Packet filter file grammar:
  660. *
  661. * [CLIENTS DROP|ACCEPT]
  662. * {+|-}common_name1
  663. * {+|-}common_name2
  664. * . . .
  665. * [SUBNETS DROP|ACCEPT]
  666. * {+|-}subnet1
  667. * {+|-}subnet2
  668. * . . .
  669. * [END]
  670. *
  671. * Subnet: IP-ADDRESS | IP-ADDRESS/NUM_NETWORK_BITS
  672. *
  673. * CLIENTS refers to the set of clients (by their common-name) which
  674. * this instance is allowed ('+') to connect to, or is excluded ('-')
  675. * from connecting to. Note that in the case of client-to-client
  676. * connections, such communication must be allowed by the packet filter
  677. * configuration files of both clients.
  678. *
  679. * SUBNETS refers to IP addresses or IP address subnets which this
  680. * instance may connect to ('+') or is excluded ('-') from connecting
  681. * to.
  682. *
  683. * DROP or ACCEPT defines default policy when there is no explicit match
  684. * for a common-name or subnet. The [END] tag must exist. A special
  685. * purpose tag called [KILL] will immediately kill the client instance.
  686. * A given client or subnet rule applies to both incoming and outgoing
  687. * packets.
  688. *
  689. * See plugin/defer/simple.c for an example on using asynchronous
  690. * authentication and client-specific packet filtering.
  691. */
  692. OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_func_v3)
  693. (const int version,
  694. struct openvpn_plugin_args_func_in const *arguments,
  695. struct openvpn_plugin_args_func_return *retptr);
  696. /*
  697. * FUNCTION: openvpn_plugin_close_v1
  698. *
  699. * REQUIRED: YES
  700. *
  701. * ARGUMENTS
  702. *
  703. * handle : the openvpn_plugin_handle_t value which was returned by
  704. * openvpn_plugin_open.
  705. *
  706. * Called immediately prior to plug-in unload.
  707. */
  708. OPENVPN_PLUGIN_DEF void OPENVPN_PLUGIN_FUNC(openvpn_plugin_close_v1)
  709. (openvpn_plugin_handle_t handle);
  710. /*
  711. * FUNCTION: openvpn_plugin_abort_v1
  712. *
  713. * REQUIRED: NO
  714. *
  715. * ARGUMENTS
  716. *
  717. * handle : the openvpn_plugin_handle_t value which was returned by
  718. * openvpn_plugin_open.
  719. *
  720. * Called when OpenVPN is in the process of aborting due to a fatal error.
  721. * Will only be called on an open context returned by a prior successful
  722. * openvpn_plugin_open callback.
  723. */
  724. OPENVPN_PLUGIN_DEF void OPENVPN_PLUGIN_FUNC(openvpn_plugin_abort_v1)
  725. (openvpn_plugin_handle_t handle);
  726. /*
  727. * FUNCTION: openvpn_plugin_client_constructor_v1
  728. *
  729. * Called to allocate a per-client memory region, which
  730. * is then passed to the openvpn_plugin_func_v2 function.
  731. * This function is called every time the OpenVPN server
  732. * constructs a client instance object, which normally
  733. * occurs when a session-initiating packet is received
  734. * by a new client, even before the client has authenticated.
  735. *
  736. * This function should allocate the private memory needed
  737. * by the plugin to track individual OpenVPN clients, and
  738. * return a void * to this memory region.
  739. *
  740. * REQUIRED: NO
  741. *
  742. * ARGUMENTS
  743. *
  744. * handle : the openvpn_plugin_handle_t value which was returned by
  745. * openvpn_plugin_open.
  746. *
  747. * RETURN VALUE
  748. *
  749. * void * pointer to plugin's private per-client memory region, or NULL
  750. * if no memory region is required.
  751. */
  752. OPENVPN_PLUGIN_DEF void *OPENVPN_PLUGIN_FUNC(openvpn_plugin_client_constructor_v1)
  753. (openvpn_plugin_handle_t handle);
  754. /*
  755. * FUNCTION: openvpn_plugin_client_destructor_v1
  756. *
  757. * This function is called on client instance object destruction.
  758. *
  759. * REQUIRED: NO
  760. *
  761. * ARGUMENTS
  762. *
  763. * handle : the openvpn_plugin_handle_t value which was returned by
  764. * openvpn_plugin_open.
  765. *
  766. * per_client_context : the per-client context pointer which was returned by
  767. * openvpn_plugin_client_constructor_v1, if defined.
  768. */
  769. OPENVPN_PLUGIN_DEF void OPENVPN_PLUGIN_FUNC(openvpn_plugin_client_destructor_v1)
  770. (openvpn_plugin_handle_t handle, void *per_client_context);
  771. /*
  772. * FUNCTION: openvpn_plugin_select_initialization_point_v1
  773. *
  774. * Several different points exist in OpenVPN's initialization sequence where
  775. * the openvpn_plugin_open function can be called. While the default is
  776. * OPENVPN_PLUGIN_INIT_PRE_DAEMON, this function can be used to select a
  777. * different initialization point. For example, if your plugin needs to
  778. * return configuration parameters to OpenVPN, use
  779. * OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE.
  780. *
  781. * REQUIRED: NO
  782. *
  783. * RETURN VALUE:
  784. *
  785. * An OPENVPN_PLUGIN_INIT_x value.
  786. */
  787. #define OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE 1
  788. #define OPENVPN_PLUGIN_INIT_PRE_DAEMON 2 /* default */
  789. #define OPENVPN_PLUGIN_INIT_POST_DAEMON 3
  790. #define OPENVPN_PLUGIN_INIT_POST_UID_CHANGE 4
  791. OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_select_initialization_point_v1)
  792. (void);
  793. /*
  794. * FUNCTION: openvpn_plugin_min_version_required_v1
  795. *
  796. * This function is called by OpenVPN to query the minimum
  797. * plugin interface version number required by the plugin.
  798. *
  799. * REQUIRED: NO
  800. *
  801. * RETURN VALUE
  802. *
  803. * The minimum OpenVPN plugin interface version number necessary to support
  804. * this plugin.
  805. */
  806. OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_min_version_required_v1)
  807. (void);
  808. /*
  809. * Deprecated functions which are still supported for backward compatibility.
  810. */
  811. OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC(openvpn_plugin_open_v1)
  812. (unsigned int *type_mask,
  813. const char *argv[],
  814. const char *envp[]);
  815. OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_func_v1)
  816. (openvpn_plugin_handle_t handle, const int type, const char *argv[], const char *envp[]);
  817. #ifdef __cplusplus
  818. }
  819. #endif
  820. #endif /* OPENVPN_PLUGIN_H_ */