The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
trigger.c
Go to the documentation of this file.
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
17/*
18 * $Id: dd23349964f0d0b495300cb989b90b7356a09a63 $
19 *
20 * @file trigger.c
21 * @brief Execute scripts when a server event occurs.
22 *
23 * @copyright 2015 The FreeRADIUS server project
24 */
25RCSID("$Id: dd23349964f0d0b495300cb989b90b7356a09a63 $")
26
27#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
28#include <freeradius-devel/server/cf_file.h>
29#include <freeradius-devel/server/cf_parse.h>
30#include <freeradius-devel/server/exec.h>
31#include <freeradius-devel/server/main_loop.h>
32#include <freeradius-devel/server/map.h>
33#include <freeradius-devel/server/pair.h>
34#include <freeradius-devel/server/request_data.h>
35#include <freeradius-devel/server/trigger.h>
36#include <freeradius-devel/unlang/function.h>
37#include <freeradius-devel/unlang/subrequest.h>
38#include <freeradius-devel/unlang/xlat.h>
39#include <freeradius-devel/unlang/tmpl.h>
40
41
42#include <sys/wait.h>
43
44/** Whether triggers are enabled globally
45 *
46 */
50
51/** Describes a rate limiting entry for a trigger
52 *
53 */
54typedef struct {
55 fr_rb_node_t node; //!< Entry in the trigger last fired tree.
56 CONF_ITEM *ci; //!< Config item this rate limit counter is associated with.
57 fr_time_t last_fired; //!< When this trigger last fired.
59
63 { .out = &dict_freeradius, .proto = "freeradius" },
65};
66
73
75{
77}
78
79/** Compares two last fired structures
80 *
81 * @param one first pointer to compare.
82 * @param two second pointer to compare.
83 * @return CMP(one, two)
84 */
85static int8_t _trigger_last_fired_cmp(void const *one, void const *two)
86{
87 trigger_last_fired_t const *a = one, *b = two;
88
89 return CMP(a->ci, b->ci);
90}
91
92/** Return whether triggers are enabled
93 *
94 */
96{
97 return (trigger_cs != NULL);
98}
99
100typedef struct {
101 fr_value_box_list_t out; //!< result of the xlap (which we ignore)
102 unlang_result_t result; //!< the result of expansion
103 tmpl_t *vpt; //!< the template to execute
104 int exec_status; //!< Result of the program (if the trigger is a tmpl)
106
107/** Execute a trigger - call an executable to process an event
108 *
109 * A trigger ties a state change (e.g. connection up) in a module to an action
110 * (e.g. send an SNMP trap) defined in triggers.conf or in the trigger
111 * section of a module. There's no setup for triggers, the triggering code
112 * just calls this function with the name of the trigger to run, and an optional
113 * interpreter if the trigger should run asynchronously.
114 *
115 * If no interpreter is passed in, the trigger runs synchronously, which is
116 * useful when the server is shutting down and we want to ensure that the
117 * trigger has completed before the server exits.
118 *
119 * If an interpreter is passed in, the trigger runs asynchronously in that
120 * interpreter, allowing the server to continue processing packets while the
121 * trigger runs.
122 *
123 * The name of each trigger is based on the module or portion of the server
124 * which runs the trigger, and is usually taken from the state when the module
125 * has a state change.
126 *
127 * Triggers are separate from logs, because log messages are generally
128 * informational, are not time sensitive, and usually require log files to be
129 * parsed and filtered in order to find relevant information.
130 *
131 * In contrast, triggers are something specific which the administrator needs
132 * to be notified about immediately and can't wait to post-process a log file.
133 *
134 * @note Calls to this function will be ignored if #trigger_init has not been called.
135 *
136 * @param[in] intp Interpreter to run the trigger with. If this is NULL the
137 * trigger will be executed synchronously.
138 * @param[in] cs to search for triggers in.
139 * If cs is not NULL, the portion after the last '.' in name is used for the trigger.
140 * If cs is NULL, the entire name is used to find the trigger in the global trigger
141 * section.
142 * @param[in,out] trigger_cp Optional pointer to a CONF_PAIR pointer. If populated and the pointer is not
143 * NULL, this CONF_PAIR will be used rather than searching.
144 * If populated, and the pointer is NULL, the search will happen and the pointer
145 * will be populated with the found CONF_PAIR.
146 * @param[in] name the path relative to the global trigger section ending in the trigger name
147 * e.g. module.ldap.pool.start.
148 * @param[in] rate_limit whether to rate limit triggers.
149 * @param[in] args to populate the trigger's request list with.
150 * @return
151 * - 0 on success.
152 * - -1 if the trigger is not defined.
153 * - -2 if the trigger was rate limited.
154 * - -3 on failure.
155 */
156int trigger(unlang_interpret_t *intp, CONF_SECTION const *cs, CONF_PAIR **trigger_cp,
157 char const *name, bool rate_limit, fr_pair_list_t *args)
158{
159 CONF_ITEM *ci;
160 CONF_PAIR *cp;
161
162 char const *attr;
163 char const *value;
164
165 request_t *request;
167 ssize_t slen;
168
170 tmpl_rules_t t_rules;
171
172 /*
173 * noop if trigger_init was never called, or if
174 * we're just checking the configuration.
175 */
176 if (!trigger_cs || check_config) return 0;
177
178 /*
179 * Do we have a cached conf pair?
180 */
181 if (trigger_cp && *trigger_cp) {
182 cp = *trigger_cp;
183 ci = cf_pair_to_item(cp);
184 goto cp_found;
185 }
186
187 /*
188 * A module can have a local "trigger" section. In which
189 * case that is used in preference to the global one.
190 *
191 * @todo - we should really allow triggers via @trigger,
192 * so that all of the triggers are in one location. And
193 * then we can have different triggers for different
194 * module instances.
195 */
196 if (cs) {
197 cs = cf_section_find(cs, "trigger", NULL);
198 if (!cs) goto use_global;
199
200 /*
201 * If a local trigger{...} section exists, then
202 * use the local part of the name, rather than
203 * the full path.
204 */
205 attr = strrchr(name, '.');
206 if (attr) {
207 attr++;
208 } else {
209 attr = name;
210 }
211 } else {
212 use_global:
213 cs = trigger_cs;
214 attr = name;
215 }
216
217 /*
218 * Find the trigger. Note that we do NOT allow searching
219 * from the root of the tree. Triggers MUST be in a
220 * trigger{...} section.
221 */
222 ci = cf_reference_item(cs, cs, attr);
223 if (!ci) {
224 if (cs != trigger_cs) goto use_global; /* not found locally, try to find globally */
225
226 DEBUG3("Failed finding trigger '%s'", attr);
227 return -1;
228 }
229
230 if (!cf_item_is_pair(ci)) {
231 ERROR("Trigger is not a configuration variable: %s", attr);
232 return -1;
233 }
234
235 cp = cf_item_to_pair(ci);
236 if (!cp) return -1;
237
238 if (trigger_cp) *trigger_cp = cp;
239
240cp_found:
241 value = cf_pair_value(cp);
242 if (!value) {
243 DEBUG3("Trigger has no value: %s", name);
244 return -1;
245 }
246
247 /*
248 * Perform periodic rate_limiting.
249 */
250 if (rate_limit) {
251 trigger_last_fired_t find, *found;
252 fr_time_t now = fr_time();
253
254 find.ci = ci;
255
256 pthread_mutex_lock(trigger_mutex);
257
258 found = fr_rb_find(trigger_last_fired_tree, &find);
259 if (!found) {
260 MEM(found = talloc(NULL, trigger_last_fired_t));
261 found->ci = ci;
262 /*
263 * Initialise last_fired to 2 seconds ago so
264 * the trigger fires on the first occurrence
265 */
266 found->last_fired = fr_time_wrap(NSEC * -2);
267
269 }
270
271 /*
272 * Send the rate_limited traps at most once per second.
273 *
274 * @todo - make this configurable for longer periods of time.
275 */
276 if (fr_time_to_sec(found->last_fired) == fr_time_to_sec(now)) {
277 pthread_mutex_unlock(trigger_mutex);
278 return -2;
279 }
280
281 found->last_fired = now;
282 pthread_mutex_unlock(trigger_mutex);
283 }
284
285 /*
286 * Allocate a request to run asynchronously in the interpreter.
287 */
288 request = request_local_alloc_internal(NULL, (&(request_init_args_t){ .detachable = true }));
289 request->name = talloc_typed_asprintf(request, "trigger-%s", name);
290
291 if (args) {
292 fr_pair_t *vp;
293
294 if (fr_pair_list_copy(request->request_ctx, &request->request_pairs, args) < 0) {
295 PERROR("Failed copying trigger arguments");
296 talloc_free(request);
297 return -3;
298 }
299
300 /*
301 * Add the trigger name to the request data
302 */
305 }
306
307 MEM(trigger = talloc_zero(request, fr_trigger_t));
308 fr_value_box_list_init(&trigger->out);
309
311 if (!el) el = main_loop_event_list();
312
313 /*
314 * During shutdown there may be no event list, so nothing much can be done.
315 */
316 if (unlikely(!el)) {
317 talloc_free(request);
318 return -3;
319 }
320
321 t_rules = (tmpl_rules_t) {
322 .attr = {
323 .dict_def = request->local_dict, /* we can use local attributes */
324 .list_def = request_attr_request,
325 },
326 .xlat = {
327 .runtime_el = el,
328 },
329 .at_runtime = true,
330 };
331
333 cf_pair_value_quote(cp), NULL, &t_rules);
334 if (slen <= 0) {
335 char *spaces, *text;
336
337 fr_canonicalize_error(trigger, &spaces, &text, slen, value);
338
339 cf_log_err(cp, "Failed parsing trigger expresion");
340 cf_log_err(cp, "%s", text);
341 cf_log_perr(cp, "%s^", spaces);
342
343 talloc_free(request);
344 return -3;
345 }
346
347 if (!tmpl_is_exec(trigger->vpt) && !tmpl_is_xlat(trigger->vpt)) {
348 /*
349 * We only support exec and xlat templates.
350 * Anything else is an error.
351 */
352 cf_log_err(cp, "Trigger must be an \"expr\" or `exec`");
353 talloc_free(request);
354 return -3;
355 }
356
357 fr_assert(trigger->vpt != NULL);
358
359 if (unlang_tmpl_push(trigger, &trigger->result, &trigger->out, request, trigger->vpt,
361 .type = UNLANG_TMPL_ARGS_TYPE_EXEC,
362 .exec = {
363 .status_out = &trigger->exec_status,
364 .timeout = fr_time_delta_from_sec(5),
365 },
366 }, UNLANG_TOP_FRAME) < 0) {
367 talloc_free(request);
368 }
369
370 /*
371 * An interpreter was passed in, we can run the expansion
372 * asynchronously in that interpreter. And then the
373 * worker cleans up the detached request.
374 */
375 if (intp) {
376 unlang_interpret_set(request, intp);
377
378 /*
379 * Don't allow the expansion to run for a long time.
380 *
381 * @todo - make the timeout configurable.
382 */
384 DEBUG("Failed setting timeout on trigger %s", value);
385 talloc_free(request);
386 return -3;
387 }
388
390 PERROR("Running trigger failed");
391 talloc_free(request);
392 return -3;
393 }
394 } else {
395 /*
396 * No interpreter, we MUST be running from the
397 * main loop. We then run the expansion
398 * synchronously. This allows the expansion /
399 * notification to finish before the server shuts
400 * down.
401 *
402 * If the expansion was async, then it may be
403 * possible for the server to exit before the
404 * expansion finishes. Arguably the worker
405 * thread should ensure that the server doesn't
406 * exit until all requests have acknowledged that
407 * they've exited.
408 *
409 * But those exits may be advisory. i.e. "please
410 * finish the request". This one here is
411 * mandatary to finish before the server exits.
412 */
413 unlang_interpret_synchronous(NULL, request);
414 talloc_free(request);
415 }
416
417 return 0;
418}
419
420/** Create trigger arguments to describe the server the pool connects to
421 *
422 * @note #trigger_init must be called before calling this function,
423 * else it will return NULL.
424 *
425 * @param[in] ctx to allocate fr_pair_t s in.
426 * @param[out] list to append Pool-Server and Pool-Port pairs to
427 * @param[in] server we're connecting to.
428 * @param[in] port on that server.
429 */
430void trigger_args_afrom_server(TALLOC_CTX *ctx, fr_pair_list_t *list, char const *server, uint16_t port)
431{
432 fr_dict_attr_t const *server_da;
433 fr_dict_attr_t const *port_da;
434 fr_pair_t *vp;
435
436 server_da = fr_dict_attr_child_by_num(fr_dict_root(fr_dict_internal()), FR_CONNECTION_POOL_SERVER);
437 if (!server_da) {
438 ERROR("Incomplete dictionary: Missing definition for \"Connection-Pool-Server\"");
439 return;
440 }
441
442 port_da = fr_dict_attr_child_by_num(fr_dict_root(fr_dict_internal()), FR_CONNECTION_POOL_PORT);
443 if (!port_da) {
444 ERROR("Incomplete dictionary: Missing definition for \"Connection-Pool-Port\"");
445 return;
446 }
447
448 MEM(vp = fr_pair_afrom_da(ctx, server_da));
449 fr_pair_value_strdup(vp, server, false);
450 fr_pair_append(list, vp);
451
452 MEM(vp = fr_pair_afrom_da(ctx, port_da));
453 vp->vp_uint16 = port;
454 fr_pair_append(list, vp);
455}
456
457/** Callback to verify that trigger_args map is valid
458 */
459static int trigger_args_validate(map_t *map, UNUSED void *uctx)
460{
461 if (map->lhs->type != TMPL_TYPE_ATTR) {
462 cf_log_err(map->ci, "%s is not an internal attribute reference", map->lhs->name);
463 return -1;
464 }
465
466 switch (map->rhs->type) {
468 if (tmpl_resolve(map->rhs, NULL) < 0) {
469 cf_log_err(map->ci, "Invalid data %s", map->rhs->name);
470 return -1;
471 }
472 break;
473 case TMPL_TYPE_DATA:
474 break;
475
476 default:
477 cf_log_err(map->ci, "Right hand side of trigger_args must be litteral, not %s", tmpl_type_to_str(map->rhs->type));
478 return -1;
479 }
480
481 return 0;
482}
483
484#define BUILD_ATTR(_name, _value) if (_value) { \
485 da = fr_dict_attr_by_name(NULL, fr_dict_root(fr_dict_internal()), _name); \
486 if (!da) { \
487 ERROR("Incomplete dictionary: Missing definition for \"" _name "\""); \
488 return -1; \
489 } \
490 MEM(vp = fr_pair_afrom_da(ctx, da)); \
491 fr_pair_value_strdup(vp, _value, false); \
492 fr_pair_append(list, vp); \
493}
494
495/** Build trigger args pair list for modules
496 *
497 * @param[in] ctx to allocate pairs in.
498 * @param[in] list to populate.
499 * @param[in] cs CONF_SECTION to search for a "trigger_args" section
500 * @param[in] args Common module data which will populate default pairs
501 */
503{
504 map_list_t *maps;
505 map_t *map = NULL;
506 fr_pair_t *vp;
507 fr_dict_attr_t const *da;
508 tmpl_rules_t t_rules = (tmpl_rules_t){
509 .attr = {
511 .list_def = request_attr_request,
512 },
513 };
514
515 /*
516 * Build the default pairs from the module data
517 */
518 BUILD_ATTR("Module-Name", args->module)
519 BUILD_ATTR("Module-Instance", args->name)
520 BUILD_ATTR("Connection-Pool-Server", args->server)
521 da = fr_dict_attr_child_by_num(fr_dict_root(fr_dict_internal()), FR_CONNECTION_POOL_PORT);
522 if (!da) {
523 ERROR("Incomplete dictionary: Missing definition for \"Connection-Pool-Port\"");
524 return -1;
525 }
526 MEM(vp = fr_pair_afrom_da(ctx, da));
527 vp->vp_uint16 = args->port;
528 fr_pair_append(list, vp);
529
530 /*
531 * If a CONF_SECTION has been passed in, look for a "trigger_args"
532 * sub section and parse that as a map to create additional pairs.
533 */
534 if (!cs) return 0;
535 cs = cf_section_find(cs, "trigger_args", NULL);
536 if (!cs) return 0;
537
538 MEM(maps = talloc(NULL, map_list_t));
539 map_list_init(maps);
540 if (map_afrom_cs(maps, maps, cs, &t_rules, &t_rules, trigger_args_validate, NULL, 256) < 0) {
541 fail:
542 talloc_free(maps);
543 return -1;
544 }
545
546 while ((map = map_list_next(maps, map))) {
548 if (fr_value_box_cast(vp, &vp->data, vp->da->type, vp->da, &map->rhs->data.literal) < 0) goto fail;
549 }
550 talloc_free(maps);
551 return 0;
552}
553
554static int _mutex_free(pthread_mutex_t *mutex)
555{
556 pthread_mutex_destroy(mutex);
557 return 0;
558}
559
560/** Free trigger resources
561 *
562 */
563static int _trigger_free(UNUSED void *uctx)
564{
566 TALLOC_FREE(trigger_last_fired_tree);
567 TALLOC_FREE(trigger_mutex);
568
569 return 0;
570}
571
572/** Set the global trigger section trigger will search in, and register xlats
573 *
574 * This function exists because triggers are used by the connection pool, which
575 * is used in the server library which may not have the mainconfig available.
576 * Additionally, utilities may want to set their own root config sections.
577 *
578 * We don't register the trigger xlat here, as we may inadvertently initialise
579 * the xlat code, which is annoying when this is called from a utility.
580 *
581 * @param[in] cs_arg to use as global trigger section.
582 * @return
583 * - 0 on success.
584 * - -1 on failure.
585 */
586static int _trigger_init(void *cs_arg)
587{
588 CONF_SECTION *cs;
589
591 PERROR("Failed loading trigger dictionaries");
592 return -1;
593 }
595 PERROR("Failed loading trigger attributes");
596 return -1;
597 }
598
599 cs = talloc_get_type_abort(cs_arg, CONF_SECTION);
600 if (!cs) {
601 ERROR("%s - Pointer to main_config was NULL", __FUNCTION__);
602 return -1;
603 }
604
605 trigger_cs = cf_section_find(cs, "trigger", NULL);
606 if (!trigger_cs) {
607 WARN("trigger { ... } subsection not found, triggers will be disabled");
608 return 0;
609 }
610
614
616 pthread_mutex_init(trigger_mutex, 0);
617 talloc_set_destructor(trigger_mutex, _mutex_free);
618
619 return 0;
620}
621
623{
624 int ret;
625
626 fr_atexit_global_once_ret(&ret, _trigger_init, _trigger_free, UNCONST(CONF_SECTION *, cs));
627
628 return ret;
629}
va_list args
Definition acutest.h:772
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:167
#define RCSID(id)
Definition build.h:487
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
Definition build.h:112
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
bool check_config
Definition cf_file.c:66
CONF_ITEM * cf_reference_item(CONF_SECTION const *parent_cs, CONF_SECTION const *outer_cs, char const *ptr)
Definition cf_file.c:3811
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:72
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
Definition cf_util.c:631
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1027
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1618
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:663
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1574
CONF_ITEM * cf_pair_to_item(CONF_PAIR const *cp)
Cast a CONF_PAIR to a CONF_ITEM.
Definition cf_util.c:721
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1558
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:288
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:295
#define MEM(x)
Definition debug.h:36
#define ERROR(fmt,...)
Definition dhcpclient.c:41
#define DEBUG(fmt,...)
Definition dhcpclient.c:39
#define fr_dict_autofree(_to_free)
Definition dict.h:917
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2672
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:294
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:307
int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
Definition dict_util.c:4402
fr_dict_t const * fr_dict_internal(void)
Definition dict_util.c:4935
#define fr_dict_autoload(_to_load)
Definition dict.h:914
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:313
fr_dict_attr_t const * fr_dict_attr_child_by_num(fr_dict_attr_t const *parent, unsigned int attr)
Check if a child attribute exists in a parent using an attribute number.
Definition dict_util.c:3600
Specifies an attribute which must be present for the module to function.
Definition dict.h:293
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:306
Test enumeration values.
Definition dict_test.h:92
talloc_free(hp)
int unlang_interpret_set_timeout(request_t *request, fr_time_delta_t timeout)
Set a timeout for a request.
Definition interpret.c:1523
void unlang_interpret_set(request_t *request, unlang_interpret_t *intp)
Set a specific interpreter for a request.
Definition interpret.c:2033
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:2052
#define UNLANG_TOP_FRAME
Definition interpret.h:36
rlm_rcode_t unlang_interpret_synchronous(fr_event_list_t *el, request_t *request)
Execute an unlang section synchronously.
#define PERROR(_fmt,...)
Definition log.h:228
#define DEBUG3(_fmt,...)
Definition log.h:266
int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into an attribute map.
Definition map.c:1134
Stores all information relating to an event list.
Definition event.c:377
void fr_canonicalize_error(TALLOC_CTX *ctx, char **sp, char **text, ssize_t slen, char const *fmt)
Canonicalize error strings, removing tabs, and generate spaces for error marker.
Definition log.c:87
fr_event_list_t * main_loop_event_list(void)
Return the main loop event list.
Definition main_loop.c:164
unsigned short uint16_t
@ FR_TYPE_STRING
String of printable characters.
long int ssize_t
int fr_pair_list_copy(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t const *from)
Duplicate a list of pairs.
Definition pair.c:2327
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
Definition pair.c:2646
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1349
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:290
fr_pair_t * fr_pair_afrom_da_nested(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *da)
Create a pair (and all intermediate parents), and append it to the list.
Definition pair.c:475
#define fr_assert(_expr)
Definition rad_assert.h:38
#define WARN(fmt,...)
static const char * spaces
Definition radict.c:178
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
Definition rb.c:577
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
Definition rb.c:626
#define fr_rb_inline_talloc_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black that verifies elements are of a specific talloc type.
Definition rb.h:246
The main red black tree structure.
Definition rb.h:73
fr_dict_attr_t const * request_attr_request
Definition request.c:43
#define request_local_alloc_internal(_ctx, _args)
Allocate a new internal request outside of the request pool.
Definition request.h:343
Optional arguments for initialising requests.
Definition request.h:287
static char const * name
#define FR_SBUFF_IN(_start, _len_or_end)
#define pair_append_request(_attr, _da)
Allocate and append a fr_pair_t to the request list.
Definition pair.h:37
static char const * tmpl_type_to_str(tmpl_type_t type)
Return a static string containing the type name.
Definition tmpl.h:638
#define tmpl_is_xlat(vpt)
Definition tmpl.h:210
int tmpl_resolve(tmpl_t *vpt, tmpl_res_rules_t const *tr_rules))
Attempt to resolve functions and attributes in xlats and attribute references.
#define tmpl_is_exec(vpt)
Definition tmpl.h:211
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
@ TMPL_TYPE_DATA_UNRESOLVED
Unparsed literal string.
Definition tmpl.h:179
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:339
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:801
struct tmpl_rules_s tmpl_rules_t
Definition tmpl.h:233
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:336
fr_pair_t * vp
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition state_test.c:8
Value pair map.
Definition map.h:77
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition map.h:79
CONF_ITEM * ci
Config item that the map was created from.
Definition map.h:85
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:273
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
int unlang_subrequest_child_push_and_detach(request_t *request)
Add a child request to the runnable queue.
Definition subrequest.c:492
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:515
void * talloc_null_ctx(void)
Retrieve the current talloc NULL ctx.
Definition talloc.c:49
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:252
static int64_t fr_time_to_sec(fr_time_t when)
Convert an fr_time_t (internal time) to number of sec since the unix epoch (wallclock time)
Definition time.h:731
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_time_wrap(_time)
Definition time.h:145
#define NSEC
Definition time.h:379
"server local" time.
Definition time.h:69
int unlang_tmpl_push(TALLOC_CTX *ctx, unlang_result_t *p_result, fr_value_box_list_t *out, request_t *request, tmpl_t const *tmpl, unlang_tmpl_args_t *args, bool top_frame)
Push a tmpl onto the stack for evaluation.
Definition tmpl.c:276
tmpl_t * vpt
the template to execute
Definition trigger.c:103
int exec_status
Result of the program (if the trigger is a tmpl)
Definition trigger.c:104
static fr_dict_attr_t const * attr_trigger_name
Definition trigger.c:67
static int _trigger_init(void *cs_arg)
Set the global trigger section trigger will search in, and register xlats.
Definition trigger.c:586
void trigger_args_afrom_server(TALLOC_CTX *ctx, fr_pair_list_t *list, char const *server, uint16_t port)
Create trigger arguments to describe the server the pool connects to.
Definition trigger.c:430
static int _mutex_free(pthread_mutex_t *mutex)
Definition trigger.c:554
static fr_dict_t const * dict_freeradius
Definition trigger.c:60
int trigger_init(CONF_SECTION const *cs)
Definition trigger.c:622
fr_dict_autoload_t trigger_dict[]
Definition trigger.c:62
fr_rb_node_t node
Entry in the trigger last fired tree.
Definition trigger.c:55
fr_value_box_list_t out
result of the xlap (which we ignore)
Definition trigger.c:101
fr_time_t last_fired
When this trigger last fired.
Definition trigger.c:57
int module_trigger_args_build(TALLOC_CTX *ctx, fr_pair_list_t *list, CONF_SECTION *cs, module_trigger_args_t *args)
Build trigger args pair list for modules.
Definition trigger.c:502
static int trigger_args_validate(map_t *map, UNUSED void *uctx)
Callback to verify that trigger_args map is valid.
Definition trigger.c:459
#define BUILD_ATTR(_name, _value)
Definition trigger.c:484
static fr_rb_tree_t * trigger_last_fired_tree
Definition trigger.c:48
unlang_result_t result
the result of expansion
Definition trigger.c:102
CONF_ITEM * ci
Config item this rate limit counter is associated with.
Definition trigger.c:56
static pthread_mutex_t * trigger_mutex
Definition trigger.c:49
static int8_t _trigger_last_fired_cmp(void const *one, void const *two)
Compares two last fired structures.
Definition trigger.c:85
static CONF_SECTION const * trigger_cs
Whether triggers are enabled globally.
Definition trigger.c:47
static void _trigger_last_fired_free(void *data)
Definition trigger.c:74
bool trigger_enabled(void)
Return whether triggers are enabled.
Definition trigger.c:95
fr_dict_attr_autoload_t trigger_dict_attr[]
Definition trigger.c:69
int trigger(unlang_interpret_t *intp, CONF_SECTION const *cs, CONF_PAIR **trigger_cp, char const *name, bool rate_limit, fr_pair_list_t *args)
Execute a trigger - call an executable to process an event.
Definition trigger.c:156
static int _trigger_free(UNUSED void *uctx)
Free trigger resources.
Definition trigger.c:563
Describes a rate limiting entry for a trigger.
Definition trigger.c:54
Common values used by modules when building trigger args.
Definition trigger.h:42
static fr_event_list_t * el
Arguments for evaluating different types of tmpls.
Definition tmpl.h:48
int fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, fr_value_box_t const *src)
Convert one type of fr_value_box_t to another.
Definition value.c:3961
static fr_slen_t data
Definition value.h:1334