OpenVPN
Data Structures | Macros | Functions
down-root.c File Reference
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <syslog.h>
#include <errno.h>
#include <err.h>
#include <openvpn-plugin.h>
Include dependency graph for down-root.c:

Go to the source code of this file.

Data Structures

struct  down_root_context
 

Macros

#define DEBUG(verb)   ((verb) >= 7)
 
#define COMMAND_RUN_SCRIPT   1
 
#define COMMAND_EXIT   2
 
#define RESPONSE_INIT_SUCCEEDED   10
 
#define RESPONSE_INIT_FAILED   11
 
#define RESPONSE_SCRIPT_SUCCEEDED   12
 
#define RESPONSE_SCRIPT_FAILED   13
 

Functions

static void down_root_server (const int fd, char *const *argv, char *const *envp, const int verb)
 
static const char * get_env (const char *name, const char *envp[])
 
static int string_array_len (const char *array[])
 
static int recv_control (int fd)
 
static int send_control (int fd, int code)
 
static void daemonize (const char *envp[])
 
static void close_fds_except (int keep)
 
static void set_signals (void)
 
static void free_context (struct down_root_context *context)
 
static int run_script (char *const *argv, char *const *envp)
 
OPENVPN_EXPORT openvpn_plugin_handle_t openvpn_plugin_open_v1 (unsigned int *type_mask, const char *argv[], const char *envp[])
 
OPENVPN_EXPORT int openvpn_plugin_func_v1 (openvpn_plugin_handle_t handle, const int type, const char *argv[], const char *envp[])
 This function is called by OpenVPN each time the OpenVPN reaches a point where plug-in calls should happen. More...
 
OPENVPN_EXPORT void openvpn_plugin_close_v1 (openvpn_plugin_handle_t handle)
 This cleans up the last part of the plug-in, allows it to shut down cleanly and release the plug-in global context buffer. More...
 
OPENVPN_EXPORT void openvpn_plugin_abort_v1 (openvpn_plugin_handle_t handle)
 

Macro Definition Documentation

◆ COMMAND_EXIT

#define COMMAND_EXIT   2

Definition at line 52 of file down-root.c.

◆ COMMAND_RUN_SCRIPT

#define COMMAND_RUN_SCRIPT   1

Definition at line 51 of file down-root.c.

◆ DEBUG

#define DEBUG (   verb)    ((verb) >= 7)

Definition at line 48 of file down-root.c.

◆ RESPONSE_INIT_FAILED

#define RESPONSE_INIT_FAILED   11

Definition at line 56 of file down-root.c.

◆ RESPONSE_INIT_SUCCEEDED

#define RESPONSE_INIT_SUCCEEDED   10

Definition at line 55 of file down-root.c.

◆ RESPONSE_SCRIPT_FAILED

#define RESPONSE_SCRIPT_FAILED   13

Definition at line 58 of file down-root.c.

◆ RESPONSE_SCRIPT_SUCCEEDED

#define RESPONSE_SCRIPT_SUCCEEDED   12

Definition at line 57 of file down-root.c.

Function Documentation

◆ close_fds_except()

static void close_fds_except ( int  keep)
static

Definition at line 206 of file down-root.c.

Referenced by openvpn_plugin_func_v1().

◆ daemonize()

static void daemonize ( const char *  envp[])
static

Definition at line 165 of file down-root.c.

References daemon(), and get_env().

Referenced by openvpn_plugin_func_v1(), and openvpn_plugin_open_v3().

◆ down_root_server()

static void down_root_server ( const int  fd,
char *const *  argv,
char *const *  envp,
const int  verb 
)
static

◆ free_context()

static void free_context ( struct down_root_context context)
static

Definition at line 237 of file down-root.c.

Referenced by openvpn_plugin_close_v1(), and openvpn_plugin_open_v1().

◆ get_env()

static const char* get_env ( const char *  name,
const char *  envp[] 
)
static

Definition at line 87 of file down-root.c.

Referenced by daemonize(), and openvpn_plugin_open_v1().

◆ openvpn_plugin_abort_v1()

OPENVPN_EXPORT void openvpn_plugin_abort_v1 ( openvpn_plugin_handle_t  handle)

Definition at line 476 of file down-root.c.

References COMMAND_EXIT, and send_control().

◆ openvpn_plugin_close_v1()

OPENVPN_EXPORT void openvpn_plugin_close_v1 ( openvpn_plugin_handle_t  handle)

This cleans up the last part of the plug-in, allows it to shut down cleanly and release the plug-in global context buffer.

Parameters
handlePointer to the plug-in global context buffer, which need to be released by this function

Definition at line 445 of file down-root.c.

References COMMAND_EXIT, DEBUG, free_context(), and send_control().

◆ openvpn_plugin_func_v1()

OPENVPN_EXPORT int openvpn_plugin_func_v1 ( openvpn_plugin_handle_t  handle,
const int  type,
const char *  argv[],
const char *  envp[] 
)

This function is called by OpenVPN each time the OpenVPN reaches a point where plug-in calls should happen.

It only happens for those plug-in hooks enabled in openvpn_plugin_open_v3().

For the arguments, see the include/openvpn-plugin.h file for details on the function parameters

Parameters
argsPointer to a struct with details about the plug-in call from the main OpenVPN process.
returndataPointer to a struct where the plug-in can provide information back to OpenVPN to be processed
Returns
Must return OPENVPN_PLUGIN_FUNC_SUCCESS or OPENVPN_PLUGIN_FUNC_DEFERRED on success. Otherwise it should return OPENVPN_FUNC_ERROR, which will stop and reject the client session from progressing.

Definition at line 347 of file down-root.c.

References close_fds_except(), COMMAND_RUN_SCRIPT, daemonize(), down_root_server(), OPENVPN_PLUGIN_DOWN, OPENVPN_PLUGIN_FUNC_ERROR, OPENVPN_PLUGIN_FUNC_SUCCESS, OPENVPN_PLUGIN_UP, recv_control(), RESPONSE_INIT_SUCCEEDED, RESPONSE_SCRIPT_SUCCEEDED, send_control(), set_signals(), and status.

◆ openvpn_plugin_open_v1()

OPENVPN_EXPORT openvpn_plugin_handle_t openvpn_plugin_open_v1 ( unsigned int *  type_mask,
const char *  argv[],
const char *  envp[] 
)

◆ recv_control()

static int recv_control ( int  fd)
static

Definition at line 130 of file down-root.c.

References read.

Referenced by down_root_server(), and openvpn_plugin_func_v1().

◆ run_script()

static int run_script ( char *const *  argv,
char *const *  envp 
)
static

Definition at line 251 of file down-root.c.

Referenced by down_root_server().

◆ send_control()

static int send_control ( int  fd,
int  code 
)
static

◆ set_signals()

static void set_signals ( void  )
static

Definition at line 224 of file down-root.c.

Referenced by openvpn_plugin_func_v1().

◆ string_array_len()

static int string_array_len ( const char *  array[])
static

Definition at line 112 of file down-root.c.

Referenced by openvpn_plugin_open_v1().