The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rlm_eap.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 (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: 1b77c125842049055d642b768df9fe0fd906cd94 $
19 * @file rlm_eap.c
20 * @brief Implements the EAP framework.
21 *
22 * @copyright 2000-2003,2006 The FreeRADIUS server project
23 * @copyright 2001 hereUare Communications, Inc. (raghud@hereuare.com)
24 * @copyright 2003 Alan DeKok (aland@freeradius.org)
25 */
26RCSID("$Id: 1b77c125842049055d642b768df9fe0fd906cd94 $")
27
28#define LOG_PREFIX mctx->mi->name
29
30#include <freeradius-devel/server/base.h>
31#include <freeradius-devel/server/module_rlm.h>
32#include <freeradius-devel/server/dl_module.h>
33#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
34#include "rlm_eap.h"
35
37
38/** Resume context for calling a submodule
39 *
40 */
41typedef struct {
42 char const *caller; //!< Original caller.
43 rlm_eap_t *inst; //!< Instance of the rlm_eap module.
44 eap_session_t *eap_session; //!< The eap_session we're continuing.
45 rlm_rcode_t rcode; //!< The result of the submodule.
47
48static int submodule_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent,
49 CONF_ITEM *ci, UNUSED conf_parser_t const *rule);
50static int eap_type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
51 CONF_ITEM *ci, UNUSED conf_parser_t const *rule);
52
54 { L("nai"), REQUIRE_REALM_NAI },
55 { L("no"), REQUIRE_REALM_NO },
56 { L("yes"), REQUIRE_REALM_YES }
57};
59
60static const conf_parser_t module_config[] = {
61 { FR_CONF_OFFSET("require_identity_realm", rlm_eap_t, require_realm),
64 .dflt = "nai" },
65
66 { FR_CONF_OFFSET_IS_SET("default_eap_type", FR_TYPE_VOID, 0, rlm_eap_t, default_method), .func = eap_type_parse },
67
69
70 { FR_CONF_OFFSET("ignore_unknown_eap_types", rlm_eap_t, ignore_unknown_types), .dflt = "no" },
71
72 { FR_CONF_DEPRECATED("timer_expire", rlm_eap_t, timer_limit), .dflt = "60" },
73 { FR_CONF_DEPRECATED("cisco_accounting_username_bug", rlm_eap_t,
74 cisco_accounting_username_bug), .dflt = "no" },
75 { FR_CONF_DEPRECATED("max_sessions", rlm_eap_t, max_sessions), .dflt = "2048" },
77};
78
80static fr_dict_t const *dict_radius;
81
84 { .out = &dict_freeradius, .proto = "freeradius" },
85 { .out = &dict_radius, .proto = "radius" },
87};
88
94
98
99
102 { .out = &attr_auth_type, .name = "Auth-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
103 { .out = &attr_eap_type, .name = "EAP-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
104 { .out = &attr_eap_identity, .name = "EAP-Identity", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
105 { .out = &attr_stripped_user_domain, .name = "Stripped-User-Domain", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
106 { .out = &attr_module_failure_message, .name = "Module-Failure-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
107
108 { .out = &attr_eap_message, .name = "EAP-Message", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
109 { .out = &attr_message_authenticator, .name = "Message-Authenticator", .type = FR_TYPE_OCTETS, .dict = &dict_radius },
110 { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_radius },
111
113};
114
115static unlang_action_t mod_authenticate(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request) CC_HINT(nonnull);
116static unlang_action_t mod_authorize(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request) CC_HINT(nonnull);
117
118/** Loads submodules based on type = foo pairs
119 *
120 * @param[in] ctx to allocate data in (instance of rlm_eap_t).
121 * @param[out] out Where to write child conf section to.
122 * @param[in] parent Base structure address.
123 * @param[in] ci #CONF_PAIR specifying the name of the type module.
124 * @param[in] rule unused.
125 * @return
126 * - 0 on success.
127 * - -1 on failure.
128 */
129static int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent,
130 CONF_ITEM *ci, conf_parser_t const *rule)
131{ char const *name = cf_pair_value(cf_item_to_pair(ci));
132 char *our_name = NULL;
133 char *p;
134 eap_type_t method;
135
136 /*
137 * Search with underscores smashed to hyphens
138 * as that's what's used in the dictionary.
139 */
140 p = our_name = talloc_strdup(NULL, name);
141 while (*p) {
142 if (*p == '_') *p = '-';
143 p++;
144 }
145
146 method = eap_name2type(our_name);
147 talloc_free(our_name);
148
149 if (method == FR_EAP_METHOD_INVALID) {
150 cf_log_err(ci, "Unknown EAP type %s", name);
151 return -1;
152 }
153
154#if !defined(HAVE_OPENSSL_SSL_H) || !defined(HAVE_LIBSSL)
155 /*
156 * This allows the default configuration to be
157 * shipped with EAP-TLS, etc. enabled. If the
158 * system doesn't have OpenSSL, they will be
159 * ignored.
160 *
161 * If the system does have OpenSSL, then this
162 * code will not be used. The administrator will
163 * then have to delete the tls,
164 * etc. configurations from eap.conf in order to
165 * have EAP without the TLS types.
166 */
167 switch (method) {
175 {
177
180 module_instance_t, "rlm_eap"))));
181 WARN("Ignoring EAP method %s because we don't have OpenSSL support", name);
182 }
183 return 0;
184
185 default:
186 break;
187 }
188#endif
189 return module_rlm_submodule_parse(ctx, out, parent, ci, rule);
190}
191
192/** Convert EAP type strings to eap_type_t values
193 *
194 * @param[in] ctx unused.
195 * @param[out] out Where to write the #eap_type_t value we found.
196 * @param[in] parent Base structure address.
197 * @param[in] ci #CONF_PAIR specifying the name of the EAP method.
198 * @param[in] rule unused.
199 * @return
200 * - 0 on success.
201 * - -1 on failure.
202 */
203static int eap_type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
204 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
205{
206 char const *default_method_name = cf_pair_value(cf_item_to_pair(ci));
207 eap_type_t method;
208
209 /*
210 * Ensure that the default EAP type is loaded.
211 */
212 method = eap_name2type(default_method_name);
213 if (method == FR_EAP_METHOD_INVALID) {
214 cf_log_err(ci, "Unknown EAP type %s", default_method_name);
215 return -1;
216 }
217
218 *(eap_type_t *)out = method;
219
220 return 0;
221}
222
223/** Process NAK data from EAP peer
224 *
225 */
227 eap_type_t last_type,
228 eap_type_data_t *nak)
229{
231 unsigned int i, s_i = 0;
232 fr_pair_t *vp = NULL;
234 eap_type_t sanitised[FR_EAP_METHOD_MAX];
235
236 /*
237 * The NAK data is the preferred EAP type(s) of
238 * the client.
239 *
240 * RFC 3748 says to list one or more proposed
241 * alternative types, one per octet, or to use
242 * 0 for no alternative.
243 */
244 if (!nak->data) {
245 REDEBUG("Peer sent empty (invalid) NAK. Can't select method to continue with");
246
248 }
249
250 /*
251 * Do a loop over the contents of the NAK, only moving entries
252 * which are valid to the sanitised array.
253 */
254 for (i = 0; (i < nak->length) && (i < FR_EAP_METHOD_MAX); i++) {
255
256 /*
257 * Type 0 is valid, and means there are no
258 * common choices.
259 */
260 if (nak->data[i] == 0) {
261 REDEBUG("Peer NAK'd indicating it is not willing to continue");
262
264 }
265
266 /*
267 * It is invalid to request identity,
268 * notification & nak in nak.
269 */
270 if (nak->data[i] < FR_EAP_METHOD_MD5) {
271 REDEBUG("Peer NAK'd asking for bad type %s (%d)", eap_type2name(nak->data[i]), nak->data[i]);
272
274 }
275
276 if ((nak->data[i] >= FR_EAP_METHOD_MAX) ||
277 !inst->methods[nak->data[i]].submodule) {
278 RDEBUG2("Peer NAK'd asking for unsupported EAP type %s (%d), skipping...",
279 eap_type2name(nak->data[i]),
280 nak->data[i]);
281
282 continue;
283 }
284
285 /*
286 * Prevent a firestorm if the client is confused.
287 *
288 * FIXME: Really we should keep a list of
289 * methods we've already sent back.
290 */
291 if (last_type == nak->data[i]) {
292 char const *type_str = eap_type2name(nak->data[i]);
293
294 RDEBUG2("Peer NAK'd our request for %s (%d) with a request for %s (%d), skipping...",
295 type_str, nak->data[i], type_str, nak->data[i]);
296
297 RWARN("!!! We requested to use EAP type %s (%i)", type_str, nak->data[i]);
298 RWARN("!!! The supplicant rejected that, and requested to use the same EAP type.");
299 RWARN("!!! i.e. the supplicant said 'I don't like %s, please use %s instead.",
300 type_str, type_str);
301 RWARN("!!! The supplicant software is broken and does not work properly.");
302 RWARN("!!! Please upgrade it to software that works.");
303
304 continue;
305 }
306
307 sanitised[s_i++] = nak->data[i];
308 }
309
310 if (s_i == 0) {
311 REDEBUG("Peer presented no valid EAP types in its NAK response");
313 }
314
315 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_eap_type);
316 if (vp) {
317 /*
318 * Loop over allowed methods and the contents
319 * of the NAK, attempting to find something
320 * we can continue with.
321 */
322 do {
323 /*
324 * Provide a way of the admin potentially
325 * disabling EAP negotiation.
326 */
327 if (vp->vp_uint32 == FR_EAP_METHOD_INVALID) continue;
328
329 for (i = 0; i < s_i; i++) {
330 /*
331 * Enforce per-user configuration of EAP
332 * types.
333 */
334 if (vp->vp_uint32 != sanitised[i]) continue;
335 RDEBUG2("Found mutually acceptable type %s (%d)", eap_type2name(sanitised[i]), sanitised[i]);
336 method = sanitised[i];
337 break;
338 }
339
340 if (method != FR_EAP_METHOD_INVALID) break; /* Found one1 */
341 } while ((vp = fr_pair_find_by_da(&request->control_pairs, vp, attr_eap_type)));
342 /*
343 * If there's no control pairs, respond with
344 * the first valid method in the NAK.
345 */
346 } else {
347 method = sanitised[0];
348 }
349
350 /*
351 * Couldn't find something to continue with,
352 * emit a very verbose message.
353 */
354 if (method == FR_EAP_METHOD_INVALID) {
355 fr_sbuff_t *proposed = NULL, *allowed = NULL;
356
357 FR_SBUFF_TALLOC_THREAD_LOCAL(&proposed, 256, 1024);
358 FR_SBUFF_TALLOC_THREAD_LOCAL(&allowed, 256, 1024);
359
360 for (i = 0; i < s_i; i++) {
361 (void) fr_sbuff_in_sprintf(proposed, "%s (%d), ", eap_type2name(sanitised[i]), sanitised[i]);
362 }
363 fr_sbuff_advance(proposed, -2);
364 fr_sbuff_terminate(proposed);
365
366 vp = NULL;
367 while ((vp = fr_pair_find_by_da(&request->control_pairs, vp, attr_eap_type))) {
368 (void) fr_sbuff_in_sprintf(allowed, "%s (%d), ", eap_type2name(vp->vp_uint32), vp->vp_uint32);
369 }
370 fr_sbuff_advance(allowed, -2); /* Negative advance past start should be disallowed */
371 fr_sbuff_terminate(allowed);
372
373 REDEBUG("No mutually acceptable EAP types found. Supplicant proposed: %s. We allow: %s",
374 fr_sbuff_start(proposed), fr_sbuff_start(allowed));
375 }
376
377 return method;
378}
379
380/** Cancel a call to a submodule
381 *
382 * @param[in] mctx module calling ctx.
383 * @param[in] request The current request.
384 * @param[in] action to perform.
385 */
386static void mod_authenticate_cancel(module_ctx_t const *mctx, request_t *request, UNUSED fr_signal_t action)
387{
388 eap_session_t *eap_session;
389
390 RDEBUG2("Request cancelled - Destroying EAP-Session");
391
392 eap_session = talloc_get_type_abort(mctx->rctx, eap_session_t);
393
394 TALLOC_FREE(eap_session->subrequest);
395
396 /*
397 * This is the only safe thing to do.
398 * We have no idea what state the submodule
399 * left its opaque data in.
400 */
401 eap_session_destroy(&eap_session);
402}
403
404/** Process the result of calling a submodule
405 *
406 * @param[out] p_result Result of calling the module, one of:
407 * - RLM_MODULE_INVALID if the request or EAP session state is invalid.
408 * - RLM_MODULE_OK if this round succeeded.
409 * - RLM_MODULE_HANDLED if we're done with this round.
410 * - RLM_MODULE_REJECT if the user should be rejected.
411 * @param[in] request The current request.
412 * @param[in] mctx module calling ctx.
413 * @param[in] eap_session the EAP session
414 * @param[in] submodule_result the input result from the submodule
415 */
417 request_t *request, eap_session_t *eap_session, unlang_result_t *submodule_result)
418{
419 rlm_rcode_t rcode;
420 fr_pair_t *next, *vp;
421
422 /*
423 * Hoist any instances of Module-Failure-Message from the subrequest
424 * so they can be used for logging failures.
425 */
426 vp = fr_pair_find_by_da(&eap_session->subrequest->request_pairs, NULL, attr_module_failure_message);
427 while (vp) {
428 next = fr_pair_find_by_da(&eap_session->subrequest->request_pairs, vp, attr_module_failure_message);
429 fr_pair_remove(&eap_session->subrequest->request_pairs, vp);
430 fr_pair_steal_append(request->request_ctx, &request->request_pairs, vp);
431 vp = next;
432 }
433
434 /*
435 * Cleanup the subrequest
436 */
437 TALLOC_FREE(eap_session->subrequest);
438
439 /*
440 * The submodule failed. Die.
441 */
442 switch (submodule_result->rcode) {
443 case RLM_MODULE_FAIL:
445 eap_fail(eap_session);
446 eap_session_destroy(&eap_session);
447
448 rcode = RLM_MODULE_INVALID;
449 goto finish;
450
451 /*
452 * Inconsistent result from submodule...
453 */
457 break;
458
459 default:
460 break;
461 }
462
463 /*
464 * We are done, wrap the EAP-request in RADIUS to send
465 * with all other required radius attributes
466 */
467 rcode = eap_compose(eap_session);
468
469 /*
470 * Add to the list only if it is EAP-Request, OR if
471 * it's LEAP, and a response.
472 */
473 if (((eap_session->this_round->request->code == FR_EAP_CODE_REQUEST) &&
474 (eap_session->this_round->request->type.num >= FR_EAP_METHOD_MD5)) ||
475
476 /*
477 * LEAP is a little different. At Stage 4,
478 * it sends an EAP-Success message, but we still
479 * need to keep the State attribute & session
480 * data structure around for the AP Challenge.
481 *
482 * At stage 6, LEAP sends an EAP-Response, which
483 * isn't put into the list.
484 */
485 ((eap_session->this_round->response->code == FR_EAP_CODE_RESPONSE) &&
486 (eap_session->this_round->response->type.num == FR_EAP_METHOD_LEAP) &&
487 (eap_session->this_round->request->code == FR_EAP_CODE_SUCCESS) &&
488 (eap_session->this_round->request->type.num == 0))) {
489 talloc_free(eap_session->prev_round);
490 eap_session->prev_round = eap_session->this_round;
491 eap_session->this_round = NULL;
492 } else {
493 RDEBUG2("Cleaning up EAP session");
494 eap_session_destroy(&eap_session);
495 }
496
497 /*
498 * Freeze the eap_session so we can continue
499 * the authentication session later.
500 */
501 eap_session_freeze(&eap_session);
502
503finish:
504 RETURN_UNLANG_RCODE(rcode);
505}
506
507/** Call mod_authenticate_result asynchronously from the unlang interpreter
508 *
509 * @param[out] p_result The result of the operation.
510 * @param[in] mctx module calling ctx.
511 * @param[in] request the current request.
512 * @return The result of this round of authentication.
513 */
515 request_t *request)
516{
517 eap_session_t *eap_session = talloc_get_type_abort(mctx->rctx, eap_session_t);
518
519 return mod_authenticate_result(p_result, mctx, request, eap_session, &eap_session->submodule_result);
520}
521
522/** Basic tests to determine if an identity is a valid NAI
523 *
524 * In this version we mostly just care about realm.
525 *
526 * @param[in] identity to check.
527 * @return
528 * - The length of the string on success.
529 * - <= 0 a negative offset specifying where the format error occurred.
530 */
531static ssize_t eap_identity_is_nai_with_realm(char const *identity)
532{
533 char const *p = identity;
534 char const *end = identity + (talloc_strlen(identity));
535 char const *realm;
536
537 /*
538 * Get the last '@'
539 */
540 p = realm = memrchr(identity, '@', end - p);
541 if (!p) {
542 fr_strerror_printf("Identity is not valid. Missing realm separator '@'");
543 return identity - end;
544 }
545
546 p = memchr(p, '.', end - p);
547 if (!p) {
548 fr_strerror_printf("Identity is not valid. Realm is missing label separator '.'");
549 return identity - end;
550 }
551
552 if ((realm + 1) == p) {
553 fr_strerror_printf("Identity is not valid. "
554 "Realm is missing label between realm separator '@' and label separator '.'");
555 return identity - realm;
556 }
557 if ((p + 1) == end) {
558 fr_strerror_printf("Identity is not valid. "
559 "Realm is missing label between label separator '.' and the end of the "
560 "identity string");
561 return identity - end;
562 }
563
564 return end - identity;
565}
566
567/** Select the correct callback based on a response
568 *
569 * Based on the EAP response from the supplicant, and setup a call on the
570 * unlang stack to the appropriate submodule.
571 *
572 * Default to the configured EAP-Type for all Unsupported EAP-Types.
573 *
574 * @param[out] p_result the result of the operation.
575 * @param[in] mctx module calling ctx.
576 * @param[in] eap_session State data that persists over multiple rounds of EAP.
577 * @return
578 * - UNLANG_ACTION_CALCULATE_RESULT + p_result->rcode = RLM_MODULE_INVALID.
579 * Invalid request.
580 * - UNLANG_ACTION_PUSHED_CHILD Yield control back to the interpreter so it can
581 * call the submodule.
582 */
584{
586 eap_type_data_t *type = &eap_session->this_round->response->type;
587 request_t *request = eap_session->request;
588
589 rlm_eap_method_t const *method;
590
591 eap_type_t next = inst->default_method;
592 fr_pair_t *vp;
593
594 /*
595 * Session must have been thawed...
596 */
597 fr_assert(eap_session->request);
598
599 /*
600 * Don't trust anyone.
601 */
602 if ((type->num == 0) || (type->num >= FR_EAP_METHOD_MAX)) {
603 REDEBUG("Peer sent EAP type number %d, which is outside known range", type->num);
604
605 is_invalid:
607 }
608
609 /*
610 * Multiple levels of TLS nesting are invalid. But if
611 * the parent has a home_server defined, then this
612 * request is being processed through a virtual
613 * server... so that's OK.
614 *
615 * i.e. we're inside an EAP tunnel, which means we have a
616 * parent. If the outer session exists, and doesn't have
617 * a home server, then it's multiple layers of tunneling.
618 */
619 if (type->num == FR_EAP_METHOD_TLS && eap_session->request->parent &&
620 eap_session->request->parent->parent) {
621 RERROR("Multiple levels of TLS nesting are invalid");
622 goto is_invalid;
623 }
624
625 RDEBUG2("Peer sent packet with EAP method %s (%d)", eap_type2name(type->num), type->num);
626
627 /*
628 * Figure out what to do.
629 */
630 switch (type->num) {
632 {
633 ssize_t slen;
634
635 /*
636 * Check if we allow this identity format
637 */
638 switch (inst->require_realm) {
640 slen = eap_identity_is_nai_with_realm(eap_session->identity);
641 if (slen <= 0) {
642 char *tmp_id;
643 bad_id:
644 /*
645 * Produce an escaped version and run that
646 * through the format check function to get
647 * the correct offset *sigh*...
648 */
649 MEM(tmp_id = fr_asprint(NULL,
650 eap_session->identity,
651 talloc_strlen(eap_session->identity),
652 '"'));
653 slen = eap_identity_is_nai_with_realm(tmp_id);
654
655 REMARKER(tmp_id, slen, "%s", fr_strerror());
656
657 talloc_free(tmp_id);
658 goto is_invalid;
659 }
660 break;
661
663 slen = eap_identity_is_nai_with_realm(eap_session->identity);
664 if (slen <= 0) {
665 fr_pair_t *stripped_user_domain;
666
667 /*
668 * If it's not an NAI with a realm, check
669 * to see if the user has set Stripped-User-domain.
670 */
671 stripped_user_domain = fr_pair_find_by_da_idx(&eap_session->request->request_pairs,
673 if (!stripped_user_domain) goto bad_id;
674 }
675 break;
676
677 case REQUIRE_REALM_NO:
678 break;
679 }
680 }
681 /*
682 * Allow per-user configuration of EAP types.
683 */
684 vp = fr_pair_find_by_da(&eap_session->request->control_pairs, NULL, attr_eap_type);
685 if (vp) {
686 RDEBUG2("Using method from control.EAP-Type");
687 next = vp->vp_uint32;
688 /*
689 * We have an array of the submodules which
690 * have a type_identity callback. Call
691 * each of these in turn to see if any of
692 * them recognise the identity.
693 */
694 } else if (inst->type_identity_submodule) {
695 size_t i;
696
697 for (i = 0; i < inst->type_identity_submodule_len; i++) {
698 rlm_eap_submodule_t const *submodule =
699 (rlm_eap_submodule_t const *)inst->type_identity_submodule[i]->exported;
700 eap_type_t ret;
701
702 ret = submodule->type_identity(inst->type_identity_submodule[i]->data,
703 eap_session->identity,
704 talloc_strlen(eap_session->identity));
705 if (ret != FR_EAP_METHOD_INVALID) {
706 next = ret;
707 break;
708 }
709 }
710 }
711 do_init:
712 /*
713 * Ensure it's valid.
714 */
715 if ((next < FR_EAP_METHOD_MD5) || (next >= FR_EAP_METHOD_MAX) || (!inst->methods[next].submodule)) {
716 REDEBUG2("Peer tried to start unsupported EAP type %s (%d)",
717 eap_type2name(next), next);
718 goto is_invalid;
719 }
720
721 eap_session->process = inst->methods[next].submodule->session_init;
722 eap_session->type = next;
723 break;
724
726 /*
727 * Delete old data, if necessary. If we called a method
728 * before, and it initialized itself, we need to free
729 * the memory it alloced.
730 */
731 TALLOC_FREE(eap_session->opaque);
732 fr_state_discard_child(eap_session->request, eap_session, 0);
733 next = eap_process_nak(mctx, eap_session->request, eap_session->type, type);
734 if (!next) RETURN_UNLANG_REJECT;
735
736 /*
737 * Initialise the state machine for the next submodule
738 */
739 goto do_init;
740
741 /*
742 * Only allow modules that are enabled to be called,
743 * treating any other requests as invalid.
744 *
745 * This may seem a bit harsh, but remember the server
746 * dictates which type of EAP method should be started,
747 * so this is the supplicant ignoring the normal EAP method
748 * negotiation mechanism, by not NAKing and just trying
749 * to start a new EAP method.
750 */
751 default:
752 if (!inst->methods[type->num].submodule) {
753 REDEBUG2("Peer asked for unsupported EAP type %s (%d)", eap_type2name(type->num), type->num);
754 goto is_invalid;
755 }
756 /*
757 * Perr started the EAP method without
758 * sending an Identity-Response.
759 *
760 * There's nothing that says it *HAS* to send an
761 * identity response before starting a method,
762 * so just jump to the initialisation function
763 * of the method and continue.
764 */
765 if (eap_session->rounds == 0) {
766 RDEBUG2("Peer started EAP type %s (%d) without sending an Identity", eap_type2name(type->num), type->num);
767 vp = fr_pair_find_by_da(&eap_session->request->control_pairs, NULL, attr_eap_type);
768 if (vp) {
769 RDEBUG2("Using method from control.EAP-Type");
770 next = vp->vp_uint32;
771 }
772 goto do_init;
773 }
774
775 /*
776 * FIXME - We should only update the type
777 * on completion of the final round.
778 */
779 eap_session->type = type->num;
780 break;
781 }
782
783 method = &inst->methods[eap_session->type];
784
785 RDEBUG2("Calling submodule %s", method->submodule->common.name);
786
787 /*
788 * Allocate a new subrequest
789 */
790 MEM(eap_session->subrequest = unlang_subrequest_alloc(request,
791 method->submodule->namespace ?
792 *(method->submodule->namespace) :
793 request->proto_dict));
794
795 if (method->submodule->clone_parent_lists) {
796 if (fr_pair_list_copy(eap_session->subrequest->control_ctx,
797 &eap_session->subrequest->control_pairs, &request->control_pairs) < 0) {
798 list_copy_fail:
799 RERROR("Failed copying parent's attribute list");
800 fail:
801 TALLOC_FREE(eap_session->subrequest);
803 }
804
805 if (fr_pair_list_copy(eap_session->subrequest->request_ctx,
806 &eap_session->subrequest->request_pairs,
807 &request->request_pairs) < 0) goto list_copy_fail;
808 }
809
810 /*
811 * Push a resumption frame for the parent
812 * This will get executed when the child is
813 * done (after the subrequest frame in the
814 * parent gets popped).
815 */
817
818 /*
819 * This sets up a subrequest frame in the parent
820 * and a resumption frame in the child.
821 *
822 * This must be done before pushing frames onto
823 * the child's stack.
824 */
825 if (unlang_subrequest_child_push(&eap_session->submodule_result, eap_session->subrequest,
826 eap_session,
827 false, UNLANG_SUB_FRAME) < 0) {
828 child_fail:
829 unlang_interpet_frame_discard(request); /* Ensure the yield frame doesn't stick around */
830 goto fail;
831 }
832
833 /*
834 * Push the EAP submodule into the child's stack
835 */
836 if (unlang_module_push(NULL, /* rcode should bubble up and be set in eap_session->submodule_rcode */
837 eap_session->subrequest, method->submodule_inst, eap_session->process,
838 UNLANG_SUB_FRAME) < 0) {
839 goto child_fail;
840 }
841
842 if (eap_session->identity) {
843 fr_pair_t *identity;
844
845 request = eap_session->subrequest; /* Set request for pair_append_request macro */
846
847 MEM(pair_append_request(&identity, attr_eap_identity) >= 0);
848 fr_pair_value_bstrdup_buffer(identity, eap_session->identity, true);
849 }
850
851 /*
852 * Add the EAP-Type we're running to the subrequest
853 * This is useful for when policies are shared between
854 * virtual server sections for multiple EAP types.
855 */
856 {
857 fr_pair_t *type_vp;
858
859 MEM(pair_append_request(&type_vp, attr_eap_type) >= 0);
860 type_vp->vp_uint32 = eap_session->type;
861 }
862
864}
865
866static void eap_failure(request_t *request)
867{
868 fr_pair_t *vp;
869 uint8_t buffer[4];
870
871 fr_pair_delete_by_da(&request->reply_pairs, attr_eap_message);
872
873 vp = fr_pair_find_by_da(&request->reply_pairs, NULL, attr_message_authenticator);
874 if (!vp) {
875 static uint8_t const auth_vector[RADIUS_AUTH_VECTOR_LENGTH] = { 0x00 };
876
878 fr_pair_value_memdup(vp, auth_vector, sizeof(auth_vector), false);
879 }
880 request->reply->code = FR_RADIUS_CODE_ACCESS_REJECT;
881
883 buffer[1] = (vp->vp_length >= 2) ? vp->vp_octets[1] : 0;
884 buffer[2] = 0;
885 buffer[3] = 4;
886
888 fr_pair_value_memdup(vp, buffer, sizeof(buffer), false);
889
890 eap_session_discard(request);
891}
892
894{
896 eap_session_t *eap_session;
897 eap_packet_raw_t *eap_packet;
899 fr_pair_t *vp;
900
901 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_eap_message);
902 if (!vp) {
903 REDEBUG("You set 'Auth-Type = EAP' for a request that does not contain an EAP-Message attribute!");
905 }
906
907 /*
908 * Reconstruct the EAP packet from the EAP-Message
909 * attribute. The relevant decoder should have already
910 * concatenated the fragments into a single buffer.
911 *
912 * If it's not a valid EAP packet, we send back a canned
913 * failure, and discard the entire EAP session.
914 */
915 eap_packet = eap_packet_from_vp(request, &request->request_pairs);
916 if (!eap_packet) {
917 RPERROR("Malformed EAP Message");
918 fail:
919 eap_failure(request);
921 }
922
923 /*
924 * Allocate a new eap_session, or if this request
925 * is part of an ongoing authentication session,
926 * retrieve the existing eap_session from the request
927 * data.
928 */
929 eap_session = eap_session_continue(inst, &eap_packet, request);
930 if (!eap_session) goto fail;
931
932 /*
933 * Call an EAP submodule to process the request,
934 * or with simple types like Identity and NAK,
935 * process it ourselves.
936 */
937 if ((ua = eap_method_select(p_result, mctx, eap_session)) != UNLANG_ACTION_CALCULATE_RESULT) return ua;
938 switch (p_result->rcode) {
939 case RLM_MODULE_OK:
941 eap_session_freeze(&eap_session);
942 break;
943
944 /*
945 * RFC 3748 Section 2
946 * The conversation continues until the authenticator cannot
947 * authenticate the peer (unacceptable Responses to one or more
948 * Requests), in which case the authenticator implementation MUST
949 * transmit an EAP Failure (Code 4).
950 */
951 default:
952 eap_fail(eap_session);
953 eap_session_destroy(&eap_session);
954 break;
955 }
956
957 return ua;
958}
959
960/*
961 * EAP authorization DEPENDS on other rlm authorizations,
962 * to check for user existence & get their configured values.
963 * It Handles EAP-START Messages, User-Name initialization.
964 */
966{
968 int status;
969
970 if (!inst->auth_type) {
971 WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup EAP authentication",
972 mctx->mi->name, mctx->mi->name);
974 }
975
976 /*
977 * For EAP_START, send Access-Challenge with EAP Identity
978 * request. even when we have to proxy this request
979 *
980 * RFC 2869, Section 2.3.1 notes that the "domain" of the
981 * user, (i.e. where to proxy it) comes from the EAP-Identity,
982 * so we CANNOT proxy the user, until we know its identity.
983 *
984 * We therefore send an EAP Identity request.
985 */
986 status = eap_start(request, inst->methods, inst->ignore_unknown_types);
987 switch (status) {
988 case RLM_MODULE_NOOP:
990 return status;
991
992 case RLM_MODULE_FAIL:
994 eap_failure(request);
995 return status;
996
997 default:
998 break;
999 }
1000
1002
1003 if (status == RLM_MODULE_OK) RETURN_UNLANG_OK;
1004
1006}
1007
1009{
1010 fr_pair_t *vp;
1011 eap_session_t *eap_session;
1012 fr_pair_t *username;
1013
1014 /*
1015 * If it's an Access-Accept, RFC 2869, Section 2.3.1
1016 * says that we MUST include a User-Name attribute in the
1017 * Access-Accept.
1018 */
1019 username = fr_pair_find_by_da(&request->request_pairs, NULL, attr_user_name);
1020 if ((request->reply->code == FR_RADIUS_CODE_ACCESS_ACCEPT) && username) {
1021 /*
1022 * Doesn't exist, add it in.
1023 */
1024 vp = fr_pair_find_by_da(&request->reply_pairs, NULL, attr_user_name);
1025 if (!vp) {
1026 MEM(vp = fr_pair_copy(request->reply_ctx, username));
1027 fr_pair_append(&request->reply_pairs, vp);
1028 }
1029 }
1030
1031 /*
1032 * Only synthesize a failure message if something
1033 * previously rejected the request.
1034 */
1035 if (request->reply->code != FR_RADIUS_CODE_ACCESS_REJECT) RETURN_UNLANG_NOOP;
1036
1037 if (!fr_pair_find_by_da(&request->request_pairs, NULL, attr_eap_message)) {
1038 RDEBUG3("Request didn't contain an EAP-Message, not inserting EAP-Failure");
1040 }
1041
1042 if (fr_pair_find_by_da(&request->reply_pairs, NULL, attr_eap_message)) {
1043 RDEBUG3("Reply already contained an EAP-Message, not inserting EAP-Failure");
1045 }
1046
1047 /*
1048 * Retrieve pre-existing eap_session from request
1049 * data. This will have been added to the request
1050 * data by the state API.
1051 */
1052 eap_session = eap_session_thaw(request);
1053 if (!eap_session) {
1054 RDEBUG3("Failed to get eap_session, probably already removed, not inserting EAP-Failure");
1056 }
1057
1058 /*
1059 * If this reject is before eap has been called in authenticate
1060 * the eap_round will not have been populated.
1061 */
1062 if (!eap_session->this_round) {
1063 eap_packet_raw_t *eap_packet = eap_packet_from_vp(request, &request->request_pairs);
1064 eap_session->this_round = eap_round_build(eap_session, &eap_packet);
1065 }
1066
1067 /*
1068 * This should never happen, but we may be here
1069 * because there was an unexpected error in the
1070 * EAP module.
1071 */
1072 if (!fr_cond_assert(eap_session->this_round) || !fr_cond_assert(eap_session->this_round->request)) {
1073 eap_session_destroy(&eap_session); /* Free the EAP session, and dissociate it from the request */
1075 }
1076
1077 /*
1078 * Already set to failure, assume something else
1079 * added EAP-Message with a failure code, do nothing.
1080 */
1082
1083 /*
1084 * Was *NOT* an EAP-Failure, so we now need to turn it into one.
1085 */
1086 REDEBUG("Request rejected after last call to module \"%s\", transforming response into EAP-Failure",
1087 mctx->mi->name);
1088 eap_fail(eap_session); /* Compose an EAP failure */
1089 eap_session_destroy(&eap_session); /* Free the EAP session, and dissociate it from the request */
1090
1091 /*
1092 * Make sure there's a message authenticator attribute in the response
1093 * RADIUS protocol code will calculate the correct value later...
1094 */
1097
1099}
1100
1101static int mod_instantiate(module_inst_ctx_t const *mctx)
1102{
1103 rlm_eap_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_eap_t);
1104 size_t i;
1105 size_t j, loaded, count = 0;
1106
1107 loaded = talloc_array_length(inst->type_submodules);
1108
1109 /*
1110 * Pre-allocate the method identity to be the number
1111 * of modules we're going to load.
1112 *
1113 * We'll shrink it later.
1114 */
1115 if (!inst->default_method_is_set) {
1116 MEM(inst->type_identity_submodule = talloc_array(inst, module_instance_t const *, loaded));
1117 }
1118
1119 for (i = 0; i < loaded; i++) {
1120 module_instance_t *submodule_inst = inst->type_submodules[i];
1121 rlm_eap_submodule_t const *submodule;
1122
1123 if (!submodule_inst) continue; /* Skipped as we don't have SSL support */
1124
1125 submodule = (rlm_eap_submodule_t const *)submodule_inst->module->exported;
1126
1127 /*
1128 * Add the methods the submodule provides
1129 */
1130 for (j = 0; j < MAX_PROVIDED_METHODS; j++) {
1131 eap_type_t method;
1132
1133 if (!submodule->provides[j]) break;
1134
1135 method = submodule->provides[j];
1136
1137 /*
1138 * If the user didn't specify a default method
1139 * take the first method provided by the first
1140 * submodule as the default.
1141 */
1142 if (!inst->default_method_is_set && (i == 0)) inst->default_method = method;
1143
1144 /*
1145 * Check for duplicates
1146 */
1147 if (inst->methods[method].submodule) {
1148 CONF_SECTION *conf = inst->methods[method].submodule_inst->conf;
1149
1150 cf_log_err(submodule_inst->conf,
1151 "Duplicate EAP-Type %s. Conflicting entry %s[%u]",
1152 eap_type2name(method),
1154
1155 return -1;
1156 }
1157
1158 inst->methods[method].submodule_inst = submodule_inst;
1159 inst->methods[method].submodule = submodule;
1160 }
1161
1162 /*
1163 * This module provides a method identity
1164 * callback. We need to call each of these
1165 * in turn if default_eap_type isn't set,
1166 * to figure out the default eap type.
1167 */
1168 if (!inst->default_method_is_set && submodule->type_identity) {
1169 inst->type_identity_submodule[inst->type_identity_submodule_len++] = submodule_inst;
1170 }
1171 count++;
1172 }
1173
1174 /*
1175 * Check if the default method specified is actually
1176 * allowed by the config.
1177 */
1178 if (inst->default_method_is_set && !inst->methods[inst->default_method].submodule) {
1179 cf_log_err_by_child(mctx->mi->conf, "default_eap_type", "EAP-Type \"%s\" is not enabled",
1180 eap_type2name(inst->default_method));
1181 return -1;
1182 }
1183
1184 if (count == 0) {
1185 cf_log_err(mctx->mi->conf, "No EAP method(s) configured, module cannot do anything");
1186 return -1;
1187 }
1188
1189 /*
1190 * Shrink the method identity array so it's the
1191 * correct length.
1192 */
1193 if (!inst->default_method_is_set) {
1194 if (inst->type_identity_submodule_len > 0) {
1195 MEM(inst->type_identity_submodule = talloc_realloc(inst, inst->type_identity_submodule,
1196 module_instance_t const *,
1197 inst->type_identity_submodule_len));
1198 } else {
1199 TALLOC_FREE(inst->type_identity_submodule);
1200 }
1201 }
1202
1203 inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->mi->name, -1);
1204 if (!inst->auth_type) {
1205 WARN("Failed to find 'authenticate %s {...}' section. EAP authentication will likely not work",
1206 mctx->mi->name);
1207 }
1208
1209 /*
1210 * Create our own random pool.
1211 */
1212 for (i = 0; i < 256; i++) inst->rand_pool.randrsl[i] = fr_rand();
1213 fr_isaac_init(&inst->rand_pool, 1);
1214 inst->rand_pool.randcnt = 0;
1215
1216 return 0;
1217}
1218
1219static int mod_load(void)
1220{
1221 if (eap_base_init() < 0) {
1222 fr_perror("Failed initialising EAP base library");
1223 return -1;
1224 }
1225 return 0;
1226}
1227
1228static void mod_unload(void)
1229{
1230 eap_base_free();
1231}
1232
1233/*
1234 * The module name should be the only globally exported symbol.
1235 * That is, everything else should be 'static'.
1236 */
1238 .common = {
1239 .magic = MODULE_MAGIC_INIT,
1240 .name = "eap",
1241 .inst_size = sizeof(rlm_eap_t),
1243 .onload = mod_load,
1244 .unload = mod_unload,
1245 .instantiate = mod_instantiate,
1246 },
1247 .method_group = {
1248 .bindings = (module_method_binding_t[]){
1249 { .section = SECTION_NAME("authenticate", CF_IDENT_ANY), .method = mod_authenticate },
1250 { .section = SECTION_NAME("recv", "Access-Request"), .method = mod_authorize },
1251 { .section = SECTION_NAME("send", CF_IDENT_ANY), .method = mod_post_auth },
1253 }
1254 }
1255};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:39
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
static int const char char buffer[256]
Definition acutest.h:576
#define RCSID(id)
Definition build.h:506
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:228
#define UNUSED
Definition build.h:336
#define NUM_ELEMENTS(_t)
Definition build.h:358
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
Definition cf_parse.c:1636
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:657
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:611
#define FR_CONF_DEPRECATED(_name, _struct, _field)
conf_parser_t entry which raises an error if a matching CONF_PAIR is found
Definition cf_parse.h:409
#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:280
#define FR_CONF_OFFSET_IS_SET(_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:294
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:446
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition cf_parse.h:447
#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:238
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:594
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
Definition cf_util.c:1743
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
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
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:285
#define cf_lineno(_cf)
Definition cf_util.h:101
#define cf_log_err_by_child(_parent, _child, _fmt,...)
Log an error message against a specified child.
Definition cf_util.h:312
#define cf_data_find(_cf, _type, _name)
Definition cf_util.h:240
#define cf_parent(_cf)
Definition cf_util.h:98
#define cf_filename(_cf)
Definition cf_util.h:104
#define CF_IDENT_ANY
Definition cf_util.h:75
eap_round_t * eap_round_build(eap_session_t *eap_session, eap_packet_raw_t **eap_packet_p)
Definition compose.c:567
rlm_rcode_t eap_fail(eap_session_t *eap_session)
Definition compose.c:513
rlm_rcode_t eap_start(request_t *request, rlm_eap_method_t const methods[], bool ignore_unknown_types)
Definition compose.c:302
rlm_rcode_t eap_compose(eap_session_t *eap_session)
Definition compose.c:157
eap_type_data_t type
Definition compose.h:38
eap_packet_t * response
Packet we received from the peer.
Definition compose.h:48
eap_code_t code
Definition compose.h:35
eap_packet_t * request
Packet we will send to the peer.
Definition compose.h:49
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:141
#define MEM(x)
Definition debug.h:46
@ FR_RADIUS_CODE_ACCESS_ACCEPT
RFC2865 - Access-Accept.
Definition defs.h:34
@ FR_RADIUS_CODE_ACCESS_REJECT
RFC2865 - Access-Reject.
Definition defs.h:35
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:292
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:305
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:311
fr_dict_enum_value_t const * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Definition dict_util.c:3701
Specifies an attribute which must be present for the module to function.
Definition dict.h:291
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:304
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
eap_type_t eap_name2type(char const *name)
Return an EAP-Type for a particular name.
Definition types.c:38
char const * eap_type2name(eap_type_t method)
Return an EAP-name for a particular type.
Definition types.c:54
@ FR_EAP_CODE_FAILURE
Definition types.h:40
@ FR_EAP_CODE_RESPONSE
Definition types.h:38
@ FR_EAP_CODE_REQUEST
Definition types.h:37
@ FR_EAP_CODE_SUCCESS
Definition types.h:39
eap_type_t num
Definition types.h:110
size_t length
Definition types.h:111
enum eap_type eap_type_t
uint8_t * data
Definition types.h:112
@ FR_EAP_METHOD_SIM
Definition types.h:63
@ FR_EAP_METHOD_LEAP
Definition types.h:62
@ FR_EAP_METHOD_NAK
Definition types.h:48
@ FR_EAP_METHOD_AKA
Definition types.h:68
@ FR_EAP_METHOD_PWD
Definition types.h:98
@ FR_EAP_METHOD_AKA_PRIME
Definition types.h:96
@ FR_EAP_METHOD_TTLS
Definition types.h:66
@ FR_EAP_METHOD_MD5
Definition types.h:49
@ FR_EAP_METHOD_IDENTITY
Definition types.h:46
@ FR_EAP_METHOD_INVALID
Definition types.h:45
@ FR_EAP_METHOD_TLS
Definition types.h:58
@ FR_EAP_METHOD_PEAP
Definition types.h:70
@ FR_EAP_METHOD_MAX
Definition types.h:102
Structure to represent packet format of eap on wire
Definition types.h:121
EAP-Type specific data.
Definition types.h:109
talloc_free(hp)
void unlang_interpet_frame_discard(request_t *request)
Discard the bottom most frame on the request's stack.
Definition interpret.c:2026
#define UNLANG_SUB_FRAME
Definition interpret.h:37
rlm_rcode_t rcode
The current rcode, from executing the instruction or merging the result from a frame.
Definition interpret.h:134
void fr_isaac_init(fr_randctx *ctx, int flag)
Definition isaac.c:85
int eap_base_init(void)
Initialise the lib eap base library.
Definition base.c:421
void eap_base_free(void)
De-init the lib eap base library.
Definition base.c:444
eap_packet_raw_t * eap_packet_from_vp(TALLOC_CTX *ctx, fr_pair_list_t *vps)
Definition base.c:279
eap_session_t * eap_session_thaw(request_t *request)
Thaw an eap_session_t so it can be continued.
Definition session.c:228
eap_session_t * eap_session_continue(void const *instance, eap_packet_raw_t **eap_packet_p, request_t *request)
Ingest an eap_packet into a thawed or newly allocated session.
Definition session.c:330
void eap_session_discard(request_t *request)
discard and 'destroy' an EAP session and disassociate it from the current request
Definition session.c:164
void eap_session_freeze(eap_session_t **eap_session)
Freeze an eap_session_t so that it can continue later.
Definition session.c:196
void eap_session_destroy(eap_session_t **eap_session)
'destroy' an EAP session and disassociate it from the current request
Definition session.c:148
char * identity
NAI (User-Name) from EAP-Identity.
Definition session.h:56
void * opaque
Opaque data used by EAP methods.
Definition session.h:63
request_t * subrequest
Current subrequest being executed.
Definition session.h:46
eap_type_t type
EAP method number.
Definition session.h:50
module_method_t process
Callback that should be used to process the next round.
Definition session.h:65
unlang_result_t submodule_result
Result of last submodule call.
Definition session.h:47
request_t * request
Current request.
Definition session.h:52
eap_round_t * this_round
The EAP response we're processing, and the EAP request we're building.
Definition session.h:60
eap_round_t * prev_round
Previous response/request pair.
Definition session.h:58
int rounds
How many roundtrips have occurred this session.
Definition session.h:67
Tracks the progress of a single session of any EAP method.
Definition session.h:41
#define RDEBUG3(fmt,...)
Definition log.h:355
#define RWARN(fmt,...)
Definition log.h:309
#define RERROR(fmt,...)
Definition log.h:310
#define RPERROR(fmt,...)
Definition log.h:314
#define REMARKER(_str, _marker_idx, _marker,...)
Output string with error marker, showing where format error occurred.
Definition log.h:510
#define REDEBUG2(fmt,...)
Definition log.h:384
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_OCTETS
Raw octets.
long int ssize_t
unsigned char uint8_t
void * memrchr(void const *s, int c, size_t n)
GNU libc extension on some platforms.
Definition missing.c:82
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
void * rctx
Resume ctx that a module previously set.
Definition module_ctx.h:45
#define MODULE_INST_CTX(_mi)
Wrapper to create a module_inst_ctx_t as a compound literal.
Definition module_ctx.h:158
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
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:50
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:947
bool module_rlm_section_type_set(request_t *request, fr_dict_attr_t const *type_da, fr_dict_enum_value_t const *enumv)
Set the next section type if it's not already set.
Definition module_rlm.c:418
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
#define RADIUS_AUTH_VECTOR_LENGTH
Definition net.h:89
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:2326
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:2962
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:707
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:1352
int fr_pair_delete_by_da(fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete matching pairs from the specified list.
Definition pair.c:1696
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
Definition pair.c:755
int fr_pair_steal_append(TALLOC_CTX *list_ctx, fr_pair_list_t *list, fr_pair_t *vp)
Change a vp's talloc ctx and insert it into a new list.
Definition pair.c:562
fr_pair_t * fr_pair_copy(TALLOC_CTX *ctx, fr_pair_t const *vp)
Copy a single valuepair.
Definition pair.c:503
int fr_pair_value_mem_alloc(fr_pair_t *vp, uint8_t **out, size_t size, bool tainted)
Pre-allocate a memory buffer for a "octets" type value pair.
Definition pair.c:2911
char * fr_asprint(TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote)
Escape string that may contain binary data, and write it to a new buffer.
Definition print.c:438
static const conf_parser_t config[]
Definition base.c:163
#define fr_assert(_expr)
Definition rad_assert.h:37
#define REDEBUG(fmt,...)
#define RDEBUG2(fmt,...)
#define WARN(fmt,...)
static rs_t * conf
Definition radsniff.c:52
uint32_t fr_rand(void)
Return a 32-bit random number.
Definition rand.c:104
#define RETURN_UNLANG_UPDATED
Definition rcode.h:70
#define RETURN_UNLANG_HANDLED
Definition rcode.h:65
#define RETURN_UNLANG_INVALID
Definition rcode.h:66
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:61
#define RETURN_UNLANG_FAIL
Definition rcode.h:63
#define RETURN_UNLANG_REJECT
Definition rcode.h:62
#define RETURN_UNLANG_OK
Definition rcode.h:64
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:44
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:51
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:52
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:47
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:55
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:54
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:50
#define RETURN_UNLANG_NOOP
Definition rcode.h:69
fr_dict_autoload_t rlm_eap_dict[]
Definition rlm_eap.c:83
static int mod_load(void)
Definition rlm_eap.c:1219
static fr_table_num_sorted_t const require_identity_realm_table[]
Definition rlm_eap.c:53
static ssize_t eap_identity_is_nai_with_realm(char const *identity)
Basic tests to determine if an identity is a valid NAI.
Definition rlm_eap.c:531
static fr_dict_attr_t const * attr_module_failure_message
Definition rlm_eap.c:93
char const * caller
Original caller.
Definition rlm_eap.c:42
static fr_dict_attr_t const * attr_eap_identity
Definition rlm_eap.c:91
static unlang_action_t mod_post_auth(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_eap.c:1008
fr_dict_attr_autoload_t rlm_eap_dict_attr[]
Definition rlm_eap.c:101
static int submodule_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
static fr_dict_attr_t const * attr_eap_message
Definition rlm_eap.c:95
static unlang_action_t mod_authenticate_result_async(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Call mod_authenticate_result asynchronously from the unlang interpreter.
Definition rlm_eap.c:514
static fr_dict_attr_t const * attr_eap_type
Definition rlm_eap.c:90
static eap_type_t eap_process_nak(module_ctx_t const *mctx, request_t *request, eap_type_t last_type, eap_type_data_t *nak)
Process NAK data from EAP peer.
Definition rlm_eap.c:226
static void mod_authenticate_cancel(module_ctx_t const *mctx, request_t *request, UNUSED fr_signal_t action)
Cancel a call to a submodule.
Definition rlm_eap.c:386
static fr_dict_t const * dict_freeradius
Definition rlm_eap.c:79
eap_session_t * eap_session
The eap_session we're continuing.
Definition rlm_eap.c:44
rlm_eap_t * inst
Instance of the rlm_eap module.
Definition rlm_eap.c:43
module_rlm_t rlm_eap
Definition rlm_eap.c:1237
static int eap_type_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Convert EAP type strings to eap_type_t values.
Definition rlm_eap.c:203
static fr_dict_t const * dict_radius
Definition rlm_eap.c:80
static fr_dict_attr_t const * attr_auth_type
Definition rlm_eap.c:89
rlm_rcode_t rcode
The result of the submodule.
Definition rlm_eap.c:45
static unlang_action_t mod_authorize(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_eap.c:965
static void mod_unload(void)
Definition rlm_eap.c:1228
static fr_dict_attr_t const * attr_stripped_user_domain
Definition rlm_eap.c:92
static unlang_action_t eap_method_select(unlang_result_t *p_result, module_ctx_t const *mctx, eap_session_t *eap_session)
Select the correct callback based on a response.
Definition rlm_eap.c:583
static unlang_action_t mod_authenticate(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_eap.c:893
static fr_dict_attr_t const * attr_user_name
Definition rlm_eap.c:97
static size_t require_identity_realm_table_len
Definition rlm_eap.c:58
static const conf_parser_t module_config[]
Definition rlm_eap.c:60
static unlang_action_t mod_authenticate_result(unlang_result_t *p_result, UNUSED module_ctx_t const *mctx, request_t *request, eap_session_t *eap_session, unlang_result_t *submodule_result)
Process the result of calling a submodule.
Definition rlm_eap.c:416
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_eap.c:1101
static fr_dict_attr_t const * attr_message_authenticator
Definition rlm_eap.c:96
Resume context for calling a submodule.
Definition rlm_eap.c:41
Implements the EAP framework.
@ REQUIRE_REALM_NAI
Require the EAP-Identity contains an NAI domain.
Definition rlm_eap.h:41
@ REQUIRE_REALM_NO
Don't require that the identity is qualified.
Definition rlm_eap.h:40
@ REQUIRE_REALM_YES
Require the EAP-Identity string contain an NAI realm or that Stripped-User-Domain is present in the r...
Definition rlm_eap.h:38
Instance data for rlm_eap.
Definition rlm_eap.h:47
static char const * name
ssize_t fr_sbuff_in_sprintf(fr_sbuff_t *sbuff, char const *fmt,...)
Print using a fmt string to an sbuff.
Definition sbuff.c:1605
#define fr_sbuff_start(_sbuff_or_marker)
#define fr_sbuff_advance(_sbuff_or_marker, _len)
#define FR_SBUFF_TALLOC_THREAD_LOCAL(_out, _init, _max)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:39
char const * name
Instance name e.g. user_database.
Definition module.h:357
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:351
size_t inst_size
Size of the module's instance data.
Definition module.h:212
void * data
Module's instance data.
Definition module.h:293
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:152
module_t * exported
Public module structure.
Definition module.h:298
Module instance data.
Definition module.h:287
Named methods exported by a module.
Definition module.h:174
#define pair_update_reply(_attr, _da)
Return or allocate a fr_pair_t in the reply list.
Definition pair.h:129
#define pair_append_request(_attr, _da)
Allocate and append a fr_pair_t to the request list.
Definition pair.h:37
#define pair_append_reply(_attr, _da)
Allocate and append a fr_pair_t to reply list.
Definition pair.h:47
void fr_state_discard_child(request_t *parent, void const *unique_ptr, int unique_int)
Remove state from a child.
Definition state.c:1008
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
return count
Definition module.c:155
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:431
int unlang_module_push(unlang_result_t *p_result, request_t *request, module_instance_t *mi, module_method_t method, bool top_frame)
Push a module or submodule onto the stack for evaluation.
Definition module.c:50
eap_aka_sim_process_conf_t * inst
fr_pair_value_bstrdup_buffer(vp, eap_session->identity, true)
fr_aka_sim_id_type_t type
fr_pair_t * vp
eap_failure
FAILURE state - State machine exit point after sending EAP-Failure.
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
module_t common
Common fields provided by all modules.
Definition submodule.h:50
module_instance_t * submodule_inst
Submodule's instance data.
Definition submodule.h:68
#define MAX_PROVIDED_METHODS
Definition submodule.h:28
rlm_eap_submodule_t const * submodule
Submodule's exported interface.
Definition submodule.h:69
bool clone_parent_lists
< Namespace children should be allocated in.
Definition submodule.h:59
eap_type_t provides[MAX_PROVIDED_METHODS]
Allow the module to register itself for more than one EAP-Method.
Definition submodule.h:52
eap_type_identity_t type_identity
Do we recognise this identity?
Definition submodule.h:55
Private structure to hold handles and interfaces for an EAP method.
Definition submodule.h:67
Interface exported by EAP submodules.
Definition submodule.h:49
request_t * unlang_subrequest_alloc(request_t *parent, fr_dict_t const *namespace)
Allocate a subrequest to run through a virtual server at some point in the future.
Definition subrequest.c:302
int unlang_subrequest_child_push(unlang_result_t *p_result, request_t *child, void const *unique_session_ptr, bool free_child, bool top_frame)
Push a pre-existing child back onto the stack as a subrequest.
Definition subrequest.c:426
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
#define talloc_get_type_abort_const
Definition talloc.h:110
#define talloc_strdup(_ctx, _str)
Definition talloc.h:142
static size_t talloc_strlen(char const *s)
Returns the length of a talloc array containing a string.
Definition talloc.h:136
fr_pair_t * fr_pair_remove(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list without freeing.
Definition pair_inline.c:93
static fr_slen_t parent
Definition pair.h:858
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
Definition strerror.c:732
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
Definition strerror.h:64
int nonnull(2, 5))
static size_t char ** out
Definition value.h:1030