The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
tmpl_escape.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 of the License, or
6 * (at your option) 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
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 8f12ebc363f1b46d3f554abfda21360715cb169c $
20 *
21 * @file lib/server/escape.h
22 * @brief Structures and prototypes for escaping the result of tmpl evaluation
23 */
24#include <freeradius-devel/util/value.h>
25#include <freeradius-devel/server/request.h>
26
27/** Different modes for creating a user context for escaping
28 *
29 */
30typedef enum {
31 TMPL_ESCAPE_UCTX_STATIC = 0, //!< A static (to us) is provided by whatever is initialising
32 ///< the tmpl_escape_t. This is the default.
33 TMPL_ESCAPE_UCTX_ALLOC, //!< A new uctx of the specified size and type is allocated
34 ///< and freed when escaping is complete.
35 TMPL_ESCAPE_UCTX_ALLOC_FUNC, //!< A new uctx of the specified size and type is allocated
36 ///< and pre-populated by memcpying uctx.size bytes
37 ///< from uctx.ptr.
39
40/** Function to allocate a user context for escaping
41 *
42 * @param[in] request Request that the tmpl is being evaluated for.
43 * @param[in] uctx The user context that was passed via the tmpl_escape_t.
44 * @return
45 * - A pointer to the allocated user context on success.
46 * - NULL on failure.
47 */
48typedef void *(*tmpl_escape_uctx_alloc_t)(request_t *request, void const *uctx);
49
50/** Free a previously allocated used ctx
51 *
52 * @param[in] uctx to free.
53 */
54typedef void(*tmpl_escape_uctx_free_t)(void *uctx);
55
56/** When to apply escaping
57 */
58typedef enum {
59 TMPL_ESCAPE_NONE = 0, //!< No escaping is performed.
60
61 TMPL_ESCAPE_PRE_CONCAT, //!< Pre-concatenation escaping is useful for
62 ///< DSLs where elements of the expansion are
63 ///< static, specified by the user, and other parts
64 ///< are dynamic, which may or may not need to be
65 ///< escaped based on which "safe" flags are applied
66 ///< to the box. When using this mode, the escape
67 ///< function must be able to handle boxes of a type
68 ///< other than the cast type, possibly performing
69 ///< a cast itself if necessary.
70
71 TMPL_ESCAPE_POST_CONCAT //!< Post-concatenation escaping is useful for when
72 ///< we don't want to allow the user to bypass escaping
73 ///< for any part of the value.
74 ///< Here all boxes are guaranteed to be of the cast type.
76
77/** Escaping rules for tmpls
78 *
79 */
80typedef struct {
81 fr_value_box_escape_t func; //!< How to escape when returned from evaluation.
82 ///< Currently only used for async evaluation.
83 fr_value_box_safe_for_t safe_for; //!< Value to set on boxes which have been escaped
84 ///< by the #fr_value_box_escape_t function.
85
86 tmpl_escape_mode_t mode; //!< Whether to apply escape function after
87 ///< concatenation, i.e. to the final output
88 ///< of the tmpl. If false, then the escaping
89 ///< is performed on each value box
90 ///< individually prior to concatenation and
91 ///< prior to casting.
92 ///< If no concatenation is performed, then
93 ///< the escaping is performed on each box individually.
94
95 struct {
96 union {
97 void const *ptr; //!< User context for escape function.
98
99 struct {
100 size_t size; //!< Size of the uctx to allocate.
101 char const * talloc_type; //!< Talloc type to assign to the uctx.
102 };
103
104 struct {
105 tmpl_escape_uctx_alloc_t alloc; //!< Function to call to allocate the uctx.
106 tmpl_escape_uctx_free_t free; //!< Function to call to free the uctx.
107 void const *uctx; //!< User context to pass to allocation func.
108 } func;
109 };
110 tmpl_escape_uctx_type_t type; //!< Type of uctx to use for this escape operation.
111 ///< default is TMPL_ESCAPE_UCTX_STATIC.
112 } uctx;
114
115/** See if we should perform output escaping before concatenation
116 *
117 */
118#define tmpl_escape_pre_concat(_tmpl) ((_tmpl)->rules.escape.func && ((_tmpl)->rules.escape.mode == TMPL_ESCAPE_PRE_CONCAT))
119
120/** See if we should perform output escaping after concatenation
121 *
122 */
123#define tmpl_escape_post_concat(_tmpl) ((_tmpl)->rules.escape.func && ((_tmpl)->rules.escape.mode == TMPL_ESCAPE_POST_CONCAT))
free(array)
fr_aka_sim_id_type_t type
fr_value_box_escape_t func
How to escape when returned from evaluation.
Definition tmpl_escape.h:81
tmpl_escape_uctx_type_t
Different modes for creating a user context for escaping.
Definition tmpl_escape.h:30
@ TMPL_ESCAPE_UCTX_ALLOC
A new uctx of the specified size and type is allocated and freed when escaping is complete.
Definition tmpl_escape.h:33
@ TMPL_ESCAPE_UCTX_STATIC
A static (to us) is provided by whatever is initialising the tmpl_escape_t.
Definition tmpl_escape.h:31
@ TMPL_ESCAPE_UCTX_ALLOC_FUNC
A new uctx of the specified size and type is allocated and pre-populated by memcpying uctx....
Definition tmpl_escape.h:35
void *(* tmpl_escape_uctx_alloc_t)(request_t *request, void const *uctx)
Function to allocate a user context for escaping.
Definition tmpl_escape.h:48
tmpl_escape_mode_t
When to apply escaping.
Definition tmpl_escape.h:58
@ TMPL_ESCAPE_PRE_CONCAT
Pre-concatenation escaping is useful for DSLs where elements of the expansion are static,...
Definition tmpl_escape.h:61
@ TMPL_ESCAPE_NONE
No escaping is performed.
Definition tmpl_escape.h:59
@ TMPL_ESCAPE_POST_CONCAT
Post-concatenation escaping is useful for when we don't want to allow the user to bypass escaping for...
Definition tmpl_escape.h:71
void(* tmpl_escape_uctx_free_t)(void *uctx)
Free a previously allocated used ctx.
Definition tmpl_escape.h:54
fr_value_box_safe_for_t safe_for
Value to set on boxes which have been escaped by the fr_value_box_escape_t function.
Definition tmpl_escape.h:83
tmpl_escape_mode_t mode
Whether to apply escape function after concatenation, i.e.
Definition tmpl_escape.h:86
Escaping rules for tmpls.
Definition tmpl_escape.h:80
int(* fr_value_box_escape_t)(fr_value_box_t *vb, void *uctx)
Escape a value box.
Definition value.h:651
uintptr_t fr_value_box_safe_for_t
Escaping that's been applied to a value box.
Definition value.h:155