The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
rlm_radius.c
Go to the documentation of this file.
1 /*
2  * This program is 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 (at
5  * 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: c04c443728feb3ce42241322e8fb2ea6125eee19 $
19  * @file rlm_radius.c
20  * @brief A RADIUS client library.
21  *
22  * @copyright 2016 The FreeRADIUS server project
23  * @copyright 2016 Network RADIUS SAS
24  */
25 RCSID("$Id: c04c443728feb3ce42241322e8fb2ea6125eee19 $")
26 
27 #include <freeradius-devel/io/application.h>
28 #include <freeradius-devel/server/modpriv.h>
29 #include <freeradius-devel/util/debug.h>
30 #include <freeradius-devel/util/dlist.h>
31 
32 #include "rlm_radius.h"
33 
34 static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
35 static int status_check_type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
36 static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
37 
39  { FR_CONF_OFFSET_TYPE_FLAGS("type", FR_TYPE_VOID, 0, rlm_radius_t, status_check),
40  .func = status_check_type_parse },
41 
43 };
44 
47  .name2 = CF_IDENT_ANY,
48  .func = status_check_update_parse },
49  { FR_CONF_OFFSET("num_answers_to_alive", rlm_radius_t, num_answers_to_alive), .dflt = STRINGIFY(3) },
50 
52 };
53 
54 /*
55  * Retransmission intervals for the packets we support.
56  */
58  { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt), .dflt = STRINGIFY(2) },
59  { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt), .dflt = STRINGIFY(16) },
60  { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc), .dflt = STRINGIFY(5) },
61  { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd), .dflt = STRINGIFY(30) },
63 };
64 
66  { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt), .dflt = STRINGIFY(2) },
67  { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt), .dflt = STRINGIFY(5) },
68  { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc), .dflt = STRINGIFY(1) },
69  { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd), .dflt = STRINGIFY(30) },
71 };
72 
74  { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].irt), .dflt = STRINGIFY(2) },
75  { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrt), .dflt = STRINGIFY(5) },
76  { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrc), .dflt = STRINGIFY(5) },
77  { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_STATUS_SERVER].mrd), .dflt = STRINGIFY(30) },
79 };
80 
82  { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].irt), .dflt = STRINGIFY(2) },
83  { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrt), .dflt = STRINGIFY(16) },
84  { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrc), .dflt = STRINGIFY(5) },
85  { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_COA_REQUEST].mrd), .dflt = STRINGIFY(30) },
87 };
88 
90  { FR_CONF_OFFSET("initial_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt), .dflt = STRINGIFY(2) },
91  { FR_CONF_OFFSET("max_rtx_time", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt), .dflt = STRINGIFY(16) },
92  { FR_CONF_OFFSET("max_rtx_count", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc), .dflt = STRINGIFY(5) },
93  { FR_CONF_OFFSET("max_rtx_duration", rlm_radius_t, retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd), .dflt = STRINGIFY(30) },
95 };
96 
97 
98 /*
99  * A mapping of configuration file names to internal variables.
100  */
101 static conf_parser_t const module_config[] = {
102  { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, rlm_radius_t, io_submodule),
103  .func = module_rlm_submodule_parse },
104 
106  .func = type_parse },
107 
108  { FR_CONF_OFFSET("replicate", rlm_radius_t, replicate) },
109 
110  { FR_CONF_OFFSET("synchronous", rlm_radius_t, synchronous) },
111 
112  { FR_CONF_OFFSET("originate", rlm_radius_t, originate) },
113 
114  { FR_CONF_POINTER("status_check", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_check_config },
115 
116  { FR_CONF_OFFSET("max_attributes", rlm_radius_t, max_attributes), .dflt = STRINGIFY(RADIUS_MAX_ATTRIBUTES) },
117 
118  { FR_CONF_OFFSET("response_window", rlm_radius_t, response_window), .dflt = STRINGIFY(20) },
119 
120  { FR_CONF_OFFSET("zombie_period", rlm_radius_t, zombie_period), .dflt = STRINGIFY(40) },
121 
122  { FR_CONF_OFFSET("revive_interval", rlm_radius_t, revive_interval) },
123 
124  { FR_CONF_OFFSET_SUBSECTION("pool", 0, rlm_radius_t, trunk_conf, fr_trunk_config ) },
125 
127 };
128 
130  [FR_RADIUS_CODE_ACCESS_REQUEST] = { FR_CONF_POINTER("Access-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) auth_config },
131 
132  [FR_RADIUS_CODE_ACCOUNTING_REQUEST] = { FR_CONF_POINTER("Accounting-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) acct_config },
133  [FR_RADIUS_CODE_STATUS_SERVER] = { FR_CONF_POINTER("Status-Server", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) status_config },
134  [FR_RADIUS_CODE_COA_REQUEST] = { FR_CONF_POINTER("CoA-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) coa_config },
135  [FR_RADIUS_CODE_DISCONNECT_REQUEST] = { FR_CONF_POINTER("Disconnect-Request", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) disconnect_config },
136 };
137 
138 static fr_dict_t const *dict_radius;
139 
142  { .out = &dict_radius, .proto = "radius" },
143  { NULL }
144 };
145 
150 
153  { .out = &attr_chap_challenge, .name = "CHAP-Challenge", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
154  { .out = &attr_chap_password, .name = "CHAP-Password", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
155  { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_radius },
156  { .out = &attr_proxy_state, .name = "Proxy-State", .type = FR_TYPE_OCTETS, .dict = &dict_radius},
157  { NULL }
158 };
159 
160 /** Set which types of packets we can parse
161  *
162  * @param[in] ctx to allocate data in (instance of rlm_radius).
163  * @param[out] out Where to write the parsed data.
164  * @param[in] parent Base structure address.
165  * @param[in] ci #CONF_PAIR specifying the name of the type module.
166  * @param[in] rule unused.
167  * @return
168  * - 0 on success.
169  * - -1 on failure.
170  */
171 static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
172  CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
173 {
174  char const *type_str = cf_pair_value(cf_item_to_pair(ci));
176  fr_dict_enum_value_t const *type_enum;
177  uint32_t code;
178 
179  /*
180  * Must be the RADIUS module
181  */
182  fr_assert(cs && (strcmp(cf_section_name1(cs), "radius") == 0));
183 
184  /*
185  * Allow the process module to be specified by
186  * packet type.
187  */
188  type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
189  if (!type_enum) {
190  invalid_code:
191  cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
192  return -1;
193  }
194 
195  code = type_enum->value->vb_uint32;
196 
197  /*
198  * Status-Server packets cannot be proxied.
199  */
200  if (code == FR_RADIUS_CODE_STATUS_SERVER) {
201  cf_log_err(ci, "Invalid setting of 'type = Status-Server'. Status-Server packets cannot be proxied.");
202  return -1;
203  }
204 
205  if (!code ||
206  (code >= FR_RADIUS_CODE_MAX) ||
207  (!type_interval_config[code].name1)) goto invalid_code;
208 
209  /*
210  * If we're doing async proxying, push the timers for the
211  * various packet types.
212  */
214 
215  memcpy(out, &code, sizeof(code));
216 
217  return 0;
218 }
219 
220 /** Allow for Status-Server ping checks
221  *
222  * @param[in] ctx to allocate data in (instance of proto_radius).
223  * @param[out] out Where to write our parsed data.
224  * @param[in] parent Base structure address.
225  * @param[in] ci #CONF_PAIR specifying the name of the type module.
226  * @param[in] rule unused.
227  * @return
228  * - 0 on success.
229  * - -1 on failure.
230  */
231 static int status_check_type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
232  CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
233 {
234  char const *type_str = cf_pair_value(cf_item_to_pair(ci));
236  fr_dict_enum_value_t const *type_enum;
237  uint32_t code;
238 
239  /*
240  * Allow the process module to be specified by
241  * packet type.
242  */
243  type_enum = fr_dict_enum_by_name(attr_packet_type, type_str, -1);
244  if (!type_enum) {
245  invalid_code:
246  cf_log_err(ci, "Unknown or invalid RADIUS packet type '%s'", type_str);
247  return -1;
248  }
249 
250  code = type_enum->value->vb_uint32;
251 
252  /*
253  * Cheat, and reuse the "type" array for allowed packet
254  * types.
255  */
256  if (!code ||
257  (code >= FR_RADIUS_CODE_MAX) ||
258  (!type_interval_config[code].name1)) goto invalid_code;
259 
260  /*
261  * Add irt / mrt / mrd / mrc parsing, in the parent
262  * configuration section.
263  */
265 
266  memcpy(out, &code, sizeof(code));
267 
268  /*
269  * Nothing more to do here, so we stop.
270  */
271  if (code == FR_RADIUS_CODE_STATUS_SERVER) return 0;
272 
274 
275  return 0;
276 }
277 
278 /** Allow the admin to set packet contents for Status-Server ping checks
279  *
280  * @param[in] ctx to allocate data in (instance of proto_radius).
281  * @param[out] out Where to write our parsed data
282  * @param[in] parent Base structure address.
283  * @param[in] ci #CONF_SECTION specifying the things to update
284  * @param[in] rule unused.
285  * @return
286  * - 0 on success.
287  * - -1 on failure.
288  */
289 static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent,
290  CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
291 {
292  int rcode;
293  CONF_SECTION *cs;
294  char const *name2;
295  map_list_t *head = (map_list_t *)out;
296 
298  map_list_init(head);
299 
300  cs = cf_item_to_section(ci);
301  name2 = cf_section_name2(cs);
302  if (!name2 || (strcmp(name2, "request") != 0)) {
303  cf_log_err(cs, "You must specify 'request' as the destination list");
304  return -1;
305  }
306 
307  /*
308  * Compile the "update" section.
309  */
310  {
311  tmpl_rules_t parse_rules = {
312  .attr = {
314  }
315  };
316 
317  rcode = map_afrom_cs(ctx, head, cs, &parse_rules, &parse_rules, unlang_fixup_update, NULL, 128);
318  if (rcode < 0) return -1; /* message already printed */
319  if (map_list_empty(head)) {
320  cf_log_err(cs, "'update' sections cannot be empty");
321  return -1;
322  }
323  }
324 
325  /*
326  * Rely on "bootstrap" to do sanity checks between 'type
327  * = Access-Request', and 'update' containing passwords.
328  */
329  return 0;
330 }
331 
332 
333 static void mod_radius_signal(module_ctx_t const *mctx, request_t *request, fr_signal_t action)
334 {
336  rlm_radius_io_t const *io = (rlm_radius_io_t const *)inst->io_submodule->module; /* Public symbol exported by the module */
337 
338  /*
339  * We received a duplicate packet, but we're not doing
340  * synchronous proxying. Ignore the dup, and rely on the
341  * IO submodule to time it's own retransmissions.
342  */
343  if ((action == FR_SIGNAL_DUP) && !inst->synchronous) return;
344 
345  if (!io->signal) return;
346 
347  io->signal(MODULE_CTX(inst->io_submodule->dl_inst,
348  module_thread(inst->io_submodule)->data, mctx->env_data,
349  mctx->rctx), request, action);
350 }
351 
352 /** Do any RADIUS-layer fixups for proxying.
353  *
354  */
355 static void radius_fixups(rlm_radius_t const *inst, request_t *request)
356 {
357  fr_pair_t *vp;
358 
359  /*
360  * Check for proxy loops.
361  */
362  if (RDEBUG_ENABLED) {
363  fr_dcursor_t cursor;
364 
365  for (vp = fr_pair_dcursor_by_da_init(&cursor, &request->request_pairs, attr_proxy_state);
366  vp;
367  vp = fr_dcursor_next(&cursor)) {
368  if (vp->vp_length != 4) continue;
369 
370  if (memcmp(&inst->proxy_state, vp->vp_octets, 4) == 0) {
371  RWARN("Possible proxy loop - please check server configuration.");
372  break;
373  }
374  }
375  }
376 
377  if (request->packet->code != FR_RADIUS_CODE_ACCESS_REQUEST) return;
378 
379  if (fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_password) &&
380  !fr_pair_find_by_da(&request->request_pairs, NULL, attr_chap_challenge)) {
382  fr_pair_value_memdup(vp, request->packet->vector, sizeof(request->packet->vector), true);
383  }
384 }
385 
386 
387 /** Send packets outbound.
388  *
389  */
390 static unlang_action_t CC_HINT(nonnull) mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
391 {
393  rlm_rcode_t rcode;
394  unlang_action_t ua;
395  fr_client_t *client;
396 
397  void *rctx = NULL;
398 
399  if (!request->packet->code) {
400  REDEBUG("You MUST specify a packet code");
402  }
403 
404  /*
405  * Reserve Status-Server for ourselves, for link-specific
406  * signaling.
407  */
408  if (request->packet->code == FR_RADIUS_CODE_STATUS_SERVER) {
409  REDEBUG("Cannot proxy Status-Server packets");
411  }
412 
413  if ((request->packet->code >= FR_RADIUS_CODE_MAX) ||
414  !fr_time_delta_ispos(inst->retry[request->packet->code].irt)) { /* can't be zero */
415  REDEBUG("Invalid packet code %d", request->packet->code);
417  }
418 
419  if (!inst->allowed[request->packet->code]) {
420  REDEBUG("Packet code %s is disallowed by the configuration",
421  fr_radius_packet_name[request->packet->code]);
423  }
424 
425  client = client_from_request(request);
426  if (client && client->dynamic && !client->active) {
427  REDEBUG("Cannot proxy packets which define dynamic clients");
429  }
430 
431  /*
432  * Do any necessary RADIUS level fixups
433  * - check Proxy-State
434  * - do CHAP-Challenge fixups
435  */
436  radius_fixups(inst, request);
437 
438  /*
439  * Push the request and it's data to the IO submodule.
440  *
441  * This may return YIELD, for "please yield", or it may
442  * return another code which indicates what happened to
443  * the request...
444  */
445  ua = inst->io->enqueue(&rcode, &rctx, inst->io_submodule->dl_inst->data,
446  module_thread(inst->io_submodule)->data, request);
447  if (ua != UNLANG_ACTION_YIELD) {
448  fr_assert(rctx == NULL);
449  RETURN_MODULE_RCODE(rcode);
450  }
451 
452  return unlang_module_yield(request, inst->io->resume, mod_radius_signal, 0, rctx);
453 }
454 
455 static int mod_bootstrap(module_inst_ctx_t const *mctx)
456 {
457  size_t i, num_types;
458  rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t);
459  CONF_SECTION *conf = mctx->inst->conf;
460 
461  inst->io = (rlm_radius_io_t const *)inst->io_submodule->module; /* Public symbol exported by the module */
462  inst->name = mctx->inst->name;
463 
464  /*
465  * These limits are specific to RADIUS, and cannot be over-ridden
466  */
467  FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, >=, 2);
468  FR_INTEGER_BOUND_CHECK("trunk.per_connection_max", inst->trunk_conf.max_req_per_conn, <=, 255);
469  FR_INTEGER_BOUND_CHECK("trunk.per_connection_target", inst->trunk_conf.target_req_per_conn, <=, inst->trunk_conf.max_req_per_conn / 2);
470 
471  FR_TIME_DELTA_BOUND_CHECK("response_window", inst->zombie_period, >=, fr_time_delta_from_sec(1));
472  FR_TIME_DELTA_BOUND_CHECK("response_window", inst->zombie_period, <=, fr_time_delta_from_sec(120));
473 
474  FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, >=, fr_time_delta_from_sec(1));
475  FR_TIME_DELTA_BOUND_CHECK("zombie_period", inst->zombie_period, <=, fr_time_delta_from_sec(120));
476 
477  if (!inst->status_check) {
478  FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, >=, fr_time_delta_from_sec(10));
479  FR_TIME_DELTA_BOUND_CHECK("revive_interval", inst->revive_interval, <=, fr_time_delta_from_sec(3600));
480  }
481 
482  num_types = talloc_array_length(inst->types);
483  fr_assert(num_types > 0);
484 
485  /*
486  * Allow for O(1) lookup later...
487  */
488  for (i = 0; i < num_types; i++) {
489  uint32_t code;
490 
491  code = inst->types[i];
492  fr_assert(code > 0);
494 
495  inst->allowed[code] = true;
496  }
497 
498  fr_assert(inst->status_check < FR_RADIUS_CODE_MAX);
499 
500  /*
501  * If we're replicating, we don't care if the other end
502  * is alive.
503  */
504  if (inst->replicate && inst->status_check) {
505  cf_log_warn(conf, "Ignoring 'status_check = %s' due to 'replicate = true'",
506  fr_radius_packet_name[inst->status_check]);
507  inst->status_check = 0;
508  }
509 
510 
511  /*
512  * If we have status checks, then do some sanity checks.
513  * Status-Server is always allowed. Otherwise, the
514  * status checks have to match one of the allowed
515  * packets.
516  */
517  if (inst->status_check) {
518  if (inst->status_check == FR_RADIUS_CODE_STATUS_SERVER) {
519  inst->allowed[inst->status_check] = true;
520 
521  } else if (!inst->allowed[inst->status_check]) {
522  cf_log_err(conf, "Using 'status_check = %s' requires also 'type = %s'",
523  fr_radius_packet_name[inst->status_check], fr_radius_packet_name[inst->status_check]);
524  return -1;
525  }
526 
527  /*
528  * @todo - check the contents of the "update"
529  * section, to be sure that (e.g.) Access-Request
530  * contains User-Name, etc.
531  */
532  }
533 
534  /*
535  * Don't sanity check the async timers if we're doing
536  * synchronous proxying.
537  */
538  if (inst->synchronous) goto setup_io_submodule;
539 
540  /*
541  * Set limits on retransmission timers
542  */
543  if (inst->allowed[FR_RADIUS_CODE_ACCESS_REQUEST]) {
544  FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, >=, fr_time_delta_from_sec(1));
545  FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
546  FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, >=, 1);
547  FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
548 
549  FR_TIME_DELTA_BOUND_CHECK("Access-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].irt, <=, fr_time_delta_from_sec(3));
550  FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
551  FR_INTEGER_BOUND_CHECK("Access-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrc, <=, 10);
552  FR_TIME_DELTA_BOUND_CHECK("Access-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCESS_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
553  }
554 
555  /*
556  * Note that RFC 5080 allows for Accounting-Request to
557  * have mrt=mrc=mrd = 0, which means "retransmit
558  * forever". We allow that, with the restriction that
559  * the server core will automatically free the request at
560  * max_request_time.
561  */
562  if (inst->allowed[FR_RADIUS_CODE_ACCOUNTING_REQUEST]) {
563  FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, >=, fr_time_delta_from_sec(1));
564 #if 0
565  FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
566  FR_INTEGER_BOUND_CHECK("Accounting-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc, >=, 0);
567  FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd, >=, fr_time_delta_from_sec(0));
568 #endif
569 
570  FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].irt, <=, fr_time_delta_from_sec(3));
571  FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
572  FR_INTEGER_BOUND_CHECK("Accounting-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrc, <=, 10);
573  FR_TIME_DELTA_BOUND_CHECK("Accounting-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_ACCOUNTING_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
574  }
575 
576  /*
577  * Status-Server
578  */
579  if (inst->allowed[FR_RADIUS_CODE_STATUS_SERVER]) {
580  FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, >=, fr_time_delta_from_sec(1));
581  FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, >=, fr_time_delta_from_sec(5));
582  FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, >=, 1);
583  FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, >=, fr_time_delta_from_sec(5));
584 
585  FR_TIME_DELTA_BOUND_CHECK("Status-Server.initial_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].irt, <=, fr_time_delta_from_sec(3));
586  FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_time", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrt, <=, fr_time_delta_from_sec(30));
587  FR_INTEGER_BOUND_CHECK("Status-Server.max_rtx_count", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrc, <=, 10);
588  FR_TIME_DELTA_BOUND_CHECK("Status-Server.max_rtx_duration", inst->retry[FR_RADIUS_CODE_STATUS_SERVER].mrd, <=, fr_time_delta_from_sec(30));
589  }
590 
591  /*
592  * CoA
593  */
594  if (inst->allowed[FR_RADIUS_CODE_COA_REQUEST]) {
595  FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, >=, fr_time_delta_from_sec(1));
596  FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
597  FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, >=, 1);
598  FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
599 
600  FR_TIME_DELTA_BOUND_CHECK("CoA-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].irt, <=, fr_time_delta_from_sec(3));
601  FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrt, <=, fr_time_delta_from_sec(60));
602  FR_INTEGER_BOUND_CHECK("CoA-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrc, <=, 10);
603  FR_TIME_DELTA_BOUND_CHECK("CoA-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_COA_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
604  }
605 
606  /*
607  * Disconnect
608  */
609  if (inst->allowed[FR_RADIUS_CODE_DISCONNECT_REQUEST]) {
610  FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, >=, fr_time_delta_from_sec(1));
611  FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, >=, fr_time_delta_from_sec(5));
612  FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, >=, 1);
613  FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, >=, fr_time_delta_from_sec(5));
614 
615  FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.initial_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].irt, <=, fr_time_delta_from_sec(3));
616  FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_time", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrt, <=, fr_time_delta_from_sec(30));
617  FR_INTEGER_BOUND_CHECK("Disconnect-Request.max_rtx_count", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrc, <=, 10);
618  FR_TIME_DELTA_BOUND_CHECK("Disconnect-Request.max_rtx_duration", inst->retry[FR_RADIUS_CODE_DISCONNECT_REQUEST].mrd, <=, fr_time_delta_from_sec(30));
619  }
620 
621 setup_io_submodule:
622  /*
623  * Get random Proxy-State identifier for this module.
624  */
625  inst->proxy_state = fr_rand();
626 
627  return 0;
628 }
629 
630 static int mod_load(void)
631 {
632  if (fr_radius_global_init() < 0) {
633  PERROR("Failed initialising protocol library");
634  return -1;
635  }
636  return 0;
637 }
638 
639 static void mod_unload(void)
640 {
642 }
643 
644 /*
645  * The module name should be the only globally exported symbol.
646  * That is, everything else should be 'static'.
647  *
648  * If the module needs to temporarily modify it's instantiation
649  * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
650  * The server will then take care of ensuring that the module
651  * is single-threaded.
652  */
653 extern module_rlm_t rlm_radius;
655  .common = {
656  .magic = MODULE_MAGIC_INIT,
657  .name = "radius",
659  .inst_size = sizeof(rlm_radius_t),
661 
662  .onload = mod_load,
663  .unload = mod_unload,
664 
665  .bootstrap = mod_bootstrap,
666  },
667  .method_names = (module_method_name_t[]){
668  { .name1 = CF_IDENT_ANY, .name2 = CF_IDENT_ANY, .method = mod_process },
670  },
671 };
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition: action.h:35
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
Definition: action.h:42
#define RCSID(id)
Definition: build.h:444
#define STRINGIFY(x)
Definition: build.h:195
#define UNUSED
Definition: build.h:313
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition: cf_parse.h:486
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:268
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition: cf_parse.h:310
#define cf_section_rule_push(_cs, _rule)
Definition: cf_parse.h:656
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:256
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition: cf_parse.h:297
#define FR_TIME_DELTA_BOUND_CHECK(_name, _var, _op, _bound)
Definition: cf_parse.h:497
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition: cf_parse.h:406
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition: cf_parse.h:420
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition: cf_parse.h:421
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition: cf_parse.h:400
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:241
Defines a CONF_PAIR to C data type mapping.
Definition: cf_parse.h:563
Common header for all CONF_* types.
Definition: cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition: cf_util.c:629
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition: cf_util.c:1126
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition: cf_util.c:1511
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition: cf_util.c:649
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition: cf_util.c:583
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition: cf_util.c:1112
#define cf_log_err(_cf, _fmt,...)
Definition: cf_util.h:265
#define cf_parent(_cf)
Definition: cf_util.h:98
#define cf_log_warn(_cf, _fmt,...)
Definition: cf_util.h:266
#define CF_IDENT_ANY
Definition: cf_util.h:78
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition: dcursor.h:287
@ FR_RADIUS_CODE_ACCESS_REQUEST
RFC2865 - Access-Request.
Definition: defs.h:33
@ FR_RADIUS_CODE_DISCONNECT_REQUEST
RFC3575/RFC5176 - Disconnect-Request.
Definition: defs.h:46
@ FR_RADIUS_CODE_MAX
Maximum possible protocol code.
Definition: defs.h:53
@ FR_RADIUS_CODE_STATUS_SERVER
RFC2865/RFC5997 - Status Server (request)
Definition: defs.h:44
@ FR_RADIUS_CODE_COA_REQUEST
RFC3575/RFC5176 - CoA-Request.
Definition: defs.h:49
@ FR_RADIUS_CODE_ACCOUNTING_REQUEST
RFC2866 - Accounting-Request.
Definition: defs.h:36
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition: dict.h:250
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition: dict.h:263
fr_value_box_t const * value
Enum value (what name maps to).
Definition: dict.h:213
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Definition: dict_util.c:2992
Specifies an attribute which must be present for the module to function.
Definition: dict.h:249
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition: dict.h:262
Value of an enumerated attribute.
Definition: dict.h:209
char const *_CONST name
Instance name.
Definition: dl_module.h:163
void *_CONST data
Module instance's parsed configuration.
Definition: dl_module.h:165
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
CONF_SECTION *_CONST conf
Module's instance configuration.
Definition: dl_module.h:166
bool active
for dynamic clients
Definition: client.h:91
bool dynamic
Whether the client was dynamically defined.
Definition: client.h:90
Describes a host allowed to send packets to the server.
Definition: client.h:77
#define PERROR(_fmt,...)
Definition: log.h:228
#define RWARN(fmt,...)
Definition: log.h:297
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:1015
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
@ FR_TYPE_VOID
User data.
Definition: merged_model.c:127
@ FR_TYPE_OCTETS
Raw octets.
Definition: merged_model.c:84
unsigned int uint32_t
Definition: merged_model.c:33
int unlang_fixup_update(map_t *map, void *ctx)
Validate and fixup a map that's part of an update section.
Definition: compile.c:553
void * env_data
Per call environment data.
Definition: module_ctx.h:44
void * rctx
Resume ctx that a module previously set.
Definition: module_ctx.h:45
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
Definition: module_ctx.h:52
dl_module_inst_t const * inst
Dynamic loader API handle for the module.
Definition: module_ctx.h:42
#define MODULE_CTX(_dl_inst, _thread, _env_data, _rctx)
Wrapper to create a module_ctx_t as a compound literal.
Definition: module_ctx.h:123
Temporary structure to hold arguments for module calls.
Definition: module_ctx.h:41
Temporary structure to hold arguments for instantiation calls.
Definition: module_ctx.h:51
Specifies a module method identifier.
Definition: module_method.c:36
int module_rlm_submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic conf_parser_t func for loading drivers.
Definition: module_rlm.c:913
module_t common
Common fields presented by all modules.
Definition: module_rlm.h:37
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition: pair.c:688
int fr_pair_value_memdup(fr_pair_t *vp, uint8_t const *src, size_t len, bool tainted)
Copy data into an "octets" data type.
Definition: pair.c:2978
static const conf_parser_t config[]
Definition: base.c:188
int fr_radius_global_init(void)
Definition: base.c:1119
void fr_radius_global_free(void)
Definition: base.c:1142
char const * fr_radius_packet_name[FR_RADIUS_CODE_MAX]
Definition: base.c:94
#define REDEBUG(fmt,...)
Definition: radclient.h:52
#define RDEBUG_ENABLED()
Definition: radclient.h:49
#define RADIUS_MAX_ATTRIBUTES
Definition: radius.h:39
static rs_t * conf
Definition: radsniff.c:53
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition: rand.c:106
#define RETURN_MODULE_RCODE(_rcode)
Definition: rcode.h:64
rlm_rcode_t
Return codes indicating the result of the module call.
Definition: rcode.h:40
static conf_parser_t coa_config[]
Definition: rlm_radius.c:81
static conf_parser_t disconnect_config[]
Definition: rlm_radius.c:89
static int status_check_type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static int mod_load(void)
Definition: rlm_radius.c:630
static fr_dict_attr_t const * attr_packet_type
Definition: rlm_radius.c:148
static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Send packets outbound.
Definition: rlm_radius.c:390
static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static fr_dict_attr_t const * attr_chap_password
Definition: rlm_radius.c:147
static fr_dict_t const * dict_radius
Definition: rlm_radius.c:138
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition: rlm_radius.c:455
static fr_dict_attr_t const * attr_chap_challenge
Definition: rlm_radius.c:146
static conf_parser_t status_config[]
Definition: rlm_radius.c:73
fr_dict_attr_autoload_t rlm_radius_dict_attr[]
Definition: rlm_radius.c:152
static void mod_unload(void)
Definition: rlm_radius.c:639
static void mod_radius_signal(module_ctx_t const *mctx, request_t *request, fr_signal_t action)
Definition: rlm_radius.c:333
static void radius_fixups(rlm_radius_t const *inst, request_t *request)
Do any RADIUS-layer fixups for proxying.
Definition: rlm_radius.c:355
static fr_dict_attr_t const * attr_proxy_state
Definition: rlm_radius.c:149
static conf_parser_t const type_interval_config[FR_RADIUS_CODE_MAX]
Definition: rlm_radius.c:129
static conf_parser_t auth_config[]
Definition: rlm_radius.c:57
module_rlm_t rlm_radius
Definition: rlm_radius.c:654
fr_dict_autoload_t rlm_radius_dict[]
Definition: rlm_radius.c:141
static int status_check_update_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static conf_parser_t const status_check_update_config[]
Definition: rlm_radius.c:45
static conf_parser_t const status_check_config[]
Definition: rlm_radius.c:38
static conf_parser_t const module_config[]
Definition: rlm_radius.c:101
static conf_parser_t acct_config[]
Definition: rlm_radius.c:65
struct rlm_radius_s rlm_radius_t
Definition: rlm_radius.h:36
unlang_module_signal_t signal
Send a signal to an IO module.
Definition: rlm_radius.h:84
Public structure describing an I/O path for an outgoing socket.
Definition: rlm_radius.h:81
@ MODULE_TYPE_RESUMABLE
does yield / resume
Definition: module.h:52
@ MODULE_TYPE_THREAD_SAFE
Module is threadsafe.
Definition: module.h:49
#define MODULE_NAME_TERMINATOR
Definition: module.h:135
void * data
Thread specific instance data.
Definition: module.h:220
#define pair_append_request(_attr, _da)
Allocate and append a fr_pair_t to the request list.
Definition: pair.h:37
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition: tmpl.h:344
Optional arguments passed to vp_tmpl functions.
Definition: tmpl.h:341
fr_signal_t
Definition: signal.h:48
fr_client_t * client_from_request(request_t *request)
Search up a list of requests trying to locate one which has a client.
Definition: client.c:1092
module_thread_instance_t * module_thread(module_instance_t *mi)
Retrieve module/thread specific instance for a module.
Definition: module.c:459
unlang_action_t unlang_module_yield(request_t *request, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition: module.c:575
RETURN_MODULE_FAIL
if(!subtype_vp) goto fail
fr_assert(0)
MEM(pair_append_request(&vp, attr_eap_aka_sim_identity) >=0)
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition: tmpl.h:285
Stores an attribute, a value and various bits of other data.
Definition: pair.h:68
#define talloc_get_type_abort_const
Definition: talloc.h:270
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition: time.h:588
#define fr_time_delta_ispos(_a)
Definition: time.h:288
conf_parser_t const fr_trunk_config[]
Config parser definitions to populate a fr_trunk_conf_t.
Definition: trunk.c:306
static fr_slen_t head
Definition: xlat.h:408
#define fr_pair_dcursor_by_da_init(_cursor, _list, _da)
Initialise a cursor that will return only attributes matching the specified fr_dict_attr_t.
Definition: pair.h:627
static fr_slen_t parent
Definition: pair.h:844
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:984