All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
exec.c File Reference
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
#include <sys/file.h>
#include <fcntl.h>
#include <ctype.h>
+ Include dependency graph for exec.c:

Go to the source code of this file.

Macros

#define MAX_ARGV   (256)
 
#define MAX_ENVP   1024
 
#define USEC   1000000
 
#define WEXITSTATUS(stat_val)   ((unsigned)(stat_val) >> 8)
 
#define WIFEXITED(stat_val)   (((stat_val) & 255) == 0)
 

Functions

void exec_trigger (REQUEST *request, CONF_SECTION *cs, char const *name, bool quench)
 Execute a trigger - call an executable to process an event. More...
 
void exec_trigger_set_conf (CONF_SECTION *cs)
 Set the global trigger section exec_trigger will search in. More...
 
int radius_exec_program (TALLOC_CTX *ctx, char *out, size_t outlen, VALUE_PAIR **output_pairs, REQUEST *request, char const *cmd, VALUE_PAIR *input_pairs, bool exec_wait, bool shell_escape, int timeout)
 Execute a program. More...
 
int radius_readfrom_program (int fd, pid_t pid, int timeout, char *answer, int left)
 Read from the child process. More...
 
pid_t radius_start_program (char const *cmd, REQUEST *request, bool exec_wait, int *input_fd, int *output_fd, VALUE_PAIR *input_pairs, bool shell_escape)
 Start a process. More...
 
static void time_free (void *data)
 
static void tv_sub (struct timeval *end, struct timeval *start, struct timeval *elapsed)
 

Variables

static CONF_SECTIONexec_trigger_main
 
static CONF_SECTIONexec_trigger_subcs
 

Macro Definition Documentation

#define MAX_ARGV   (256)

Definition at line 46 of file exec.c.

#define MAX_ENVP   1024
#define USEC   1000000

Definition at line 50 of file exec.c.

#define WEXITSTATUS (   stat_val)    ((unsigned)(stat_val) >> 8)

Definition at line 40 of file exec.c.

#define WIFEXITED (   stat_val)    (((stat_val) & 255) == 0)

Definition at line 43 of file exec.c.

Function Documentation

void exec_trigger ( REQUEST request,
CONF_SECTION cs,
char const *  name,
bool  quench 
)

Execute a trigger - call an executable to process an event.

Parameters
requestThe current request.
csto search for triggers in. If not NULL, only the portion after the last '.' in name is used for the trigger. If cs is NULL, the entire name is used to find the trigger in the global trigger section.
namethe path relative to the global trigger section ending in the trigger name e.g. module.ldap.pool.start.
quenchwhether to rate limit triggers.

Definition at line 686 of file exec.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void exec_trigger_set_conf ( CONF_SECTION cs)

Set the global trigger section exec_trigger will search in.

Note
Triggers are used by the connection pool, which is used in the server library which may not have the mainconfig available. Additionally, utilities may want to set their own root config sections.
Parameters
csto use as global trigger section

Definition at line 670 of file exec.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int radius_exec_program ( TALLOC_CTX *  ctx,
char *  out,
size_t  outlen,
VALUE_PAIR **  output_pairs,
REQUEST request,
char const *  cmd,
VALUE_PAIR input_pairs,
bool  exec_wait,
bool  shell_escape,
int  timeout 
)

Execute a program.

Parameters
[in,out]ctxto allocate new VALUE_PAIR (s) in.
[out]outbuffer to append plaintext (non valuepair) output.
[in]outlenlength of out buffer.
[out]output_pairslist of value pairs - Data on child's stdout will be parsed and added into this list of value pairs.
[in]requestCurrent request (may be NULL).
[in]cmdCommand to execute. This is parsed into argv[] parts, then each individual argv part is xlat'ed.
[in]input_pairslist of value pairs - these will be available in the environment of the child.
[in]exec_waitset to 1 if you want to read from or write to child.
[in]shell_escapevalues before passing them as arguments.
[in]timeoutamount of time to wait, in seconds.
Returns
  • 0 if exec_wait==0.
  • exit code if exec_wait!=0.
  • -1 on failure.

Definition at line 531 of file exec.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int radius_readfrom_program ( int  fd,
pid_t  pid,
int  timeout,
char *  answer,
int  left 
)

Read from the child process.

Parameters
fdfile descriptor to read from.
pidpid of child, will be reaped if it dies.
timeoutamount of time to wait, in seconds.
answerbuffer to write into.
leftlength of buffer.
Returns
  • -1 on failure.
  • Length of output.

Definition at line 386 of file exec.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

pid_t radius_start_program ( char const *  cmd,
REQUEST request,
bool  exec_wait,
int *  input_fd,
int *  output_fd,
VALUE_PAIR input_pairs,
bool  shell_escape 
)

Start a process.

Parameters
cmdCommand to execute. This is parsed into argv[] parts, then each individual argv part is xlat'ed.
requestCurrent reuqest
exec_waitset to true to read from or write to child.
[in,out]input_fdpointer to int, receives the stdin file descriptor. Set to NULL and the child will have /dev/null on stdin.
[in,out]output_fdpinter to int, receives the stdout file descriptor. Set to NULL and child will have /dev/null on stdout.
input_pairslist of value pairs - these will be put into the environment variables of the child.
shell_escapevalues before passing them as arguments.
Returns
  • PID of the child process.
  • -1 on failure.

Definition at line 87 of file exec.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void time_free ( void *  data)
static

Definition at line 657 of file exec.c.

+ Here is the caller graph for this function:

static void tv_sub ( struct timeval *  end,
struct timeval *  start,
struct timeval *  elapsed 
)
static

Definition at line 51 of file exec.c.

+ Here is the caller graph for this function:

Variable Documentation

CONF_SECTION* exec_trigger_main
static

Definition at line 48 of file exec.c.

CONF_SECTION * exec_trigger_subcs
static

Definition at line 48 of file exec.c.