openvpn-plugin.h 30 KB

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