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: 5022ce252186cebc4dc1e3db58e76f8a04045b14 $
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 box_escape; //!< How to escape when returned from evaluation.
82 ///< Currently only used for async evaluation.
83 tmpl_escape_mode_t mode; //!< Whether to apply escape function after
84 ///< concatenation, i.e. to the final output
85 ///< of the tmpl. If false, then the escaping
86 ///< is performed on each value box
87 ///< individually prior to concatenation and
88 ///< prior to casting.
89 ///< If no concatenation is performed, then
90 ///< the escaping is performed on each box individually.
91
92 struct {
93 union {
94 void const *ptr; //!< User context for escape function.
95
96 struct {
97 size_t size; //!< Size of the uctx to allocate.
98 char const * talloc_type; //!< Talloc type to assign to the uctx.
99 };
100
101 struct {
102 tmpl_escape_uctx_alloc_t alloc; //!< Function to call to allocate the uctx.
103 tmpl_escape_uctx_free_t free; //!< Function to call to free the uctx.
104 void const *uctx; //!< User context to pass to allocation func.
105 } func;
106 };
107 tmpl_escape_uctx_type_t type; //!< Type of uctx to use for this escape operation.
108 ///< default is TMPL_ESCAPE_UCTX_STATIC.
109 } uctx;
111
112/** See if we should perform output escaping before concatenation
113 *
114 */
115#define tmpl_escape_pre_concat(_tmpl) ((_tmpl)->rules.escape.box_escape.func && ((_tmpl)->rules.escape.mode == TMPL_ESCAPE_PRE_CONCAT))
116
117/** See if we should perform output escaping after concatenation
118 *
119 */
120#define tmpl_escape_post_concat(_tmpl) ((_tmpl)->rules.escape.box_escape.func && ((_tmpl)->rules.escape.mode == TMPL_ESCAPE_POST_CONCAT))
free(array)
fr_aka_sim_id_type_t type
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
fr_value_box_escape_t box_escape
How to escape when returned from evaluation.
Definition tmpl_escape.h:81
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
tmpl_escape_mode_t mode
Whether to apply escape function after concatenation, i.e.
Definition tmpl_escape.h:83
Escaping rules for tmpls.
Definition tmpl_escape.h:80