The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
tmpl.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 */
17
18/**
19 * $Id: 05c8de3f00602b954cf287e3d1d62fed343d103f $
20 *
21 * @file unlang/tmpl.h
22 *
23 * @brief Functions to allow tmpls to push resumption frames onto the stack
24 * and inform the interpreter about the conditions they need to be
25 * resumed under (usually an I/O event or timer event).
26 *
27 * @copyright 2016-2019 The FreeRADIUS server project
28 */
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <freeradius-devel/server/rcode.h>
34#include <freeradius-devel/server/tmpl.h>
35#include <freeradius-devel/unlang/tmpl.h>
36#include <freeradius-devel/unlang/interpret.h>
37
38/** Flags that show the type of arguments included
39 *
40 */
41typedef enum {
42 UNLANG_TMPL_ARGS_TYPE_EXEC = 1, //!< We have arguments for performing an exec.
44
45/** Arguments for evaluating different types of tmpls
46 *
47 */
48typedef struct {
49 unlang_tmpl_args_type_t type; //!< Flags field showing which argument structs
50 ///< were explicitly populated. Can help with
51 ///< setting defaults.
52
53 /** Exec specific arguments
54 *
55 */
56 struct {
57 fr_pair_list_t *env; //!< Environmental variables.
58 int *status_out; //!< Where to write the exit code or fatal signal
59 ///< that killed the process.
60 fr_time_delta_t timeout; //!< How long to wait for the process to finish.
61 bool stdout_on_error; //!< If true don't clear stdout if we get a non-zero
62 ///< status code. This allows more nuanced
63 ///< interpretation of status codes.
64 } exec;
66
67/** Create a temporary argument structure for evaluating an exec type tmpl
68 *
69 * @param[in] _env Environmental variables specified as a pair list.
70 * @param[in] _timeout How long to wait for program to complete.
71 * @param[in] _stdout_on_error If true we keep stdout even on non-zero status code.
72 * @param[out] _status_out Where to store the exit code of the program.
73 * - Will be positive if it's an exit code.
74 * - Will be negative if it's a fatal signal.
75 */
76#define TMPL_ARGS_EXEC(_env, _timeout, _stdout_on_error, _status_out) \
77 &(unlang_tmpl_args_t){ \
78 .type = UNLANG_TMPL_ARGS_TYPE_EXEC, \
79 .exec = { \
80 .env = _env, \
81 .timeout = _timeout, \
82 .stdout_on_error = _stdout_on_error, \
83 .status_out = _status_out \
84 }, \
85 }
86
87/** A callback when the request gets a fr_signal_t.
88 *
89 * A module may call unlang_yeild(), but still need to do something on FR_SIGNAL_DUP. If so, it's
90 * set here.
91 *
92 * @note The callback is automatically removed on unlang_interpret_mark_runnable().
93 *
94 * @param[in] rctx Resume ctx for the callback.
95 * @param[in] request The current request.
96 * @param[in] action which is signalling the request.
97 */
98typedef void (*fr_unlang_tmpl_signal_t)(request_t *request, void *rctx, fr_signal_t action);
99
100/** A callback for when the request is resumed.
101 *
102 * The resumed request cannot call the normal "authorize", etc. method. It needs a separate callback.
103 *
104 * @param[in] p_result the module return code.
105 * @param[in] request the current request.
106 * @param[in] rctx a local context for the callback.
107 * @return an unlang action.
108 */
109typedef unlang_action_t (*fr_unlang_tmpl_resume_t)(unlang_result_t *p_result, request_t *request, void *rctx);
110
111int unlang_tmpl_push(TALLOC_CTX *ctx, fr_value_box_list_t *out,
112 request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args)
113 CC_HINT(warn_unused_result);
114
115#ifdef __cplusplus
116}
117#endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
va_list args
Definition acutest.h:770
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
unlang_tmpl_args_type_t type
Flags field showing which argument structs were explicitly populated.
Definition tmpl.h:49
void(* fr_unlang_tmpl_signal_t)(request_t *request, void *rctx, fr_signal_t action)
A callback when the request gets a fr_signal_t.
Definition tmpl.h:98
int unlang_tmpl_push(TALLOC_CTX *ctx, fr_value_box_list_t *out, request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args)
Push a tmpl onto the stack for evaluation.
Definition tmpl.c:254
unlang_action_t(* fr_unlang_tmpl_resume_t)(unlang_result_t *p_result, request_t *request, void *rctx)
A callback for when the request is resumed.
Definition tmpl.h:109
unlang_tmpl_args_type_t
Flags that show the type of arguments included.
Definition tmpl.h:41
@ UNLANG_TMPL_ARGS_TYPE_EXEC
We have arguments for performing an exec.
Definition tmpl.h:42
Arguments for evaluating different types of tmpls.
Definition tmpl.h:48
static size_t char ** out
Definition value.h:1020