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: f9ce7ac95985e3d133fc19384637fb804b8965e7 $
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
37/** Flags that show the type of arguments included
38 *
39 */
40typedef enum {
41 UNLANG_TMPL_ARGS_TYPE_EXEC = 1, //!< We have arguments for performing an exec.
43
44/** Arguments for evaluating different types of tmpls
45 *
46 */
47typedef struct {
48 unlang_tmpl_args_type_t type; //!< Flags field showing which argument structs
49 ///< were explicitly populated. Can help with
50 ///< setting defaults.
51
52 /** Exec specific arguments
53 *
54 */
55 struct {
56 fr_pair_list_t *env; //!< Environmental variables.
57 int *status_out; //!< Where to write the exit code or fatal signal
58 ///< that killed the process.
59 fr_time_delta_t timeout; //!< How long to wait for the process to finish.
60 bool stdout_on_error; //!< If true don't clear stdout if we get a non-zero
61 ///< status code. This allows more nuanced
62 ///< interpretation of status codes.
63 } exec;
65
66/** Create a temporary argument structure for evaluating an exec type tmpl
67 *
68 * @param[in] _env Environmental variables specified as a pair list.
69 * @param[in] _timeout How long to wait for program to complete.
70 * @param[in] _stdout_on_error If true we keep stdout even on non-zero status code.
71 * @param[out] _status_out Where to store the exit code of the program.
72 * - Will be positive if it's an exit code.
73 * - Will be negative if it's a fatal signal.
74 */
75#define TMPL_ARGS_EXEC(_env, _timeout, _stdout_on_error, _status_out) \
76 &(unlang_tmpl_args_t){ \
77 .type = UNLANG_TMPL_ARGS_TYPE_EXEC, \
78 .exec = { \
79 .env = _env, \
80 .timeout = _timeout, \
81 .stdout_on_error = _stdout_on_error, \
82 .status_out = _status_out \
83 }, \
84 }
85
86/** A callback when the request gets a fr_signal_t.
87 *
88 * A module may call unlang_yeild(), but still need to do something on FR_SIGNAL_DUP. If so, it's
89 * set here.
90 *
91 * @note The callback is automatically removed on unlang_interpret_mark_runnable().
92 *
93 * @param[in] rctx Resume ctx for the callback.
94 * @param[in] request The current request.
95 * @param[in] action which is signalling the request.
96 */
97typedef void (*fr_unlang_tmpl_signal_t)(request_t *request, void *rctx, fr_signal_t action);
98
99/** A callback for when the request is resumed.
100 *
101 * The resumed request cannot call the normal "authorize", etc. method. It needs a separate callback.
102 *
103 * @param[in] p_result the module return code.
104 * @param[in] request the current request.
105 * @param[in] rctx a local context for the callback.
106 * @return an unlang action.
107 */
108typedef unlang_action_t (*fr_unlang_tmpl_resume_t)(rlm_rcode_t *p_result, request_t *request, void *rctx);
109
110int unlang_tmpl_push(TALLOC_CTX *ctx, fr_value_box_list_t *out,
111 request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args)
112 CC_HINT(warn_unused_result);
113
114#ifdef __cplusplus
115}
116#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
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
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:48
unlang_action_t(* fr_unlang_tmpl_resume_t)(rlm_rcode_t *p_result, request_t *request, void *rctx)
A callback for when the request is resumed.
Definition tmpl.h:108
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:97
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:262
unlang_tmpl_args_type_t
Flags that show the type of arguments included.
Definition tmpl.h:40
@ UNLANG_TMPL_ARGS_TYPE_EXEC
We have arguments for performing an exec.
Definition tmpl.h:41
Arguments for evaluating different types of tmpls.
Definition tmpl.h:47
static size_t char ** out
Definition value.h:997