1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License as published by 4 * the Free Software Foundation; either version 2 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 15 */ 16 #ifndef MAP_H 17 #define MAP_H 18 /** 19 * $Id: 584c76b4d100104087071d843904ab86b42bf7f7 $ 20 * 21 * @file map.h 22 * @brief Structures and prototypes for maps 23 * 24 * @copyright 2015 The FreeRADIUS server project 25 * @copyright 2015 Arran Cudbard-bell <a.cudbardb@freeradius.org> 26 */ 27 28 RCSIDH(map_h, "$Id: 584c76b4d100104087071d843904ab86b42bf7f7 $") 29 30 #include <freeradius-devel/conffile.h> 31 #include <freeradius-devel/tmpl.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /** Value pair map 38 * 39 * Value pair maps contain a pair of templates, that describe a src attribute 40 * or value, and a destination attribute. 41 * 42 * Neither src or dst need to be an FR attribute, and their type can be inferred 43 * from whether map->da is NULL (not FR). 44 * 45 * @see vp_tmpl_t 46 */ 47 typedef struct vp_map { 48 vp_tmpl_t *lhs; //!< Typically describes the attribute to add, modify or compare. 49 vp_tmpl_t *rhs; //!< Typically describes a literal value or a src attribute to copy or compare. 50 51 FR_TOKEN op; //!< The operator that controls insertion of the dst attribute. 52 53 CONF_ITEM *ci; //!< Config item that the map was created from. Mainly used for 54 //!< logging validation errors. 55 56 struct vp_map *next; //!< The next valuepair map. 57 } vp_map_t; 58 59 #ifndef WITH_VERIFY_PTR 60 # define VERIFY_MAP(_x) rad_assert((_x)->lhs) 61 #else 62 # define VERIFY_MAP(_x) do { \ 63 VERIFY_TMPL((_x)->lhs); \ 64 if ((_x)->rhs) VERIFY_TMPL((_x)->rhs); \ 65 } while (0) 66 #endif 67 68 typedef int (*map_validate_t)(vp_map_t *map, void *ctx); 69 typedef int (*radius_map_getvalue_t)(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, 70 vp_map_t const *map, void *uctx); 71 72 int map_afrom_cp(TALLOC_CTX *ctx, vp_map_t **out, CONF_PAIR *cp, 73 request_refs_t dst_request_def, pair_lists_t dst_list_def, 74 request_refs_t src_request_def, pair_lists_t src_list_def); 75 76 int map_afrom_fields(TALLOC_CTX *ctx, vp_map_t **out, char const *lhs, FR_TOKEN lhs_type, 77 FR_TOKEN op, char const *rhs, FR_TOKEN rhs_type, 78 request_refs_t dst_request_def, pair_lists_t dst_list_def, 79 request_refs_t src_request_def, pair_lists_t src_list_def); 80 81 int map_afrom_cs(vp_map_t **out, CONF_SECTION *cs, 82 pair_lists_t dst_list_def, pair_lists_t src_list_def, 83 map_validate_t validate, void *ctx, unsigned int max) CC_HINT(nonnull(1, 2)); 84 85 int map_afrom_attr_str(TALLOC_CTX *ctx, vp_map_t **out, char const *raw, 86 request_refs_t dst_request_def, pair_lists_t dst_list_def, 87 request_refs_t src_request_def, pair_lists_t src_list_def); 88 89 int8_t map_cmp_by_lhs_attr(void const *a, void const *b); 90 91 void map_sort(vp_map_t **maps, fr_cmp_t cmp); 92 93 int map_to_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, 94 vp_map_t const *map, void *uctx) CC_HINT(nonnull (2,3,4)); 95 96 int map_to_request(REQUEST *request, vp_map_t const *map, 97 radius_map_getvalue_t func, void *ctx); 98 99 bool map_dst_valid(REQUEST *request, vp_map_t const *map); 100 101 size_t map_prints(char *buffer, size_t bufsize, vp_map_t const *map); 102 103 void map_debug_log(REQUEST *request, vp_map_t const *map, 104 VALUE_PAIR const *vp) CC_HINT(nonnull(1, 2)); 105 106 bool map_cast_from_hex(vp_map_t *map, FR_TOKEN rhs_type, char const *rhs); 107 #ifdef __cplusplus 108 } 109 #endif 110 111 #endif /* MAP_H */ 112