The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
base.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: c6f78738ed1711c90b8fc826352a4f4548a6372a $
19 * @file src/process/tacacs/base.c
20 * @brief TACACS+ handler.
21 * @author Jorge Pereira <jpereira@freeradius.org>
22 *
23 * @copyright 2020 The FreeRADIUS server project.
24 * @copyright 2020 Network RADIUS SAS (legal@networkradius.com)
25 */
26#include <freeradius-devel/io/listen.h>
27#include <freeradius-devel/io/master.h>
28#include <freeradius-devel/server/main_config.h>
29#include <freeradius-devel/server/protocol.h>
30#include <freeradius-devel/server/state.h>
31#include <freeradius-devel/server/rcode.h>
32#include <freeradius-devel/tacacs/tacacs.h>
33#include <freeradius-devel/unlang/call.h>
34#include <freeradius-devel/util/debug.h>
35
36#include <freeradius-devel/protocol/tacacs/tacacs.h>
37
39static fr_dict_t const *dict_tacacs;
40
43 { .out = &dict_freeradius, .proto = "freeradius" },
44 { .out = &dict_tacacs, .proto = "tacacs" },
46};
47
53
60
64
74
78
81 { .out = &attr_auth_type, .name = "Auth-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
82 { .out = &attr_module_failure_message, .name = "Module-Failure-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
83 { .out = &attr_module_success_message, .name = "Module-Success-Message", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
84 { .out = &attr_stripped_user_name, .name = "Stripped-User-Name", .type = FR_TYPE_STRING, .dict = &dict_freeradius },
85 { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_tacacs },
86
87 { .out = &attr_tacacs_action, .name = "Action", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
88 { .out = &attr_tacacs_authentication_flags, .name = "Authentication-Flags", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
89 { .out = &attr_tacacs_authentication_type, .name = "Authentication-Type", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
90 { .out = &attr_tacacs_authentication_service, .name = "Authentication-Service", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
91
92 { .out = &attr_tacacs_authentication_status, .name = "Authentication-Status", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
93 { .out = &attr_tacacs_authorization_status, .name = "Authorization-Status", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
94
95 { .out = &attr_tacacs_accounting_status, .name = "Accounting-Status", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
96 { .out = &attr_tacacs_accounting_flags, .name = "Accounting-Flags", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
97
98 { .out = &attr_tacacs_client_port, .name = "Client-Port", .type = FR_TYPE_STRING, .dict = &dict_tacacs },
99 { .out = &attr_tacacs_data, .name = "Data", .type = FR_TYPE_OCTETS, .dict = &dict_tacacs },
100 { .out = &attr_tacacs_privilege_level, .name = "Privilege-Level", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
101 { .out = &attr_tacacs_remote_address, .name = "Remote-Address", .type = FR_TYPE_STRING, .dict = &dict_tacacs },
102 { .out = &attr_tacacs_authentication_action, .name = "Action", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
103 { .out = &attr_tacacs_session_id, .name = "Packet.Session-Id", .type = FR_TYPE_UINT32, .dict = &dict_tacacs },
104 { .out = &attr_tacacs_sequence_number, .name = "Packet.Sequence-Number", .type = FR_TYPE_UINT8, .dict = &dict_tacacs },
105 { .out = &attr_tacacs_server_message, .name = "Server-Message", .type = FR_TYPE_STRING, .dict = &dict_tacacs },
106 { .out = &attr_tacacs_state, .name = "State", .type = FR_TYPE_OCTETS, .dict = &dict_tacacs },
107 { .out = &attr_tacacs_user_message, .name = "User-Message", .type = FR_TYPE_STRING, .dict = &dict_tacacs },
108
109 { .out = &attr_user_name, .name = "User-Name", .type = FR_TYPE_STRING, .dict = &dict_tacacs },
110 { .out = &attr_user_password, .name = "User-Password", .type = FR_TYPE_STRING, .dict = &dict_tacacs },
111 { .out = &attr_chap_password, .name = "CHAP-Password", .type = FR_TYPE_OCTETS, .dict = &dict_tacacs },
112
114};
115
120
123 { .out = &enum_auth_type_accept, .name = "Accept", .attr = &attr_auth_type },
124 { .out = &enum_auth_type_reject, .name = "Reject", .attr = &attr_auth_type },
125 { .out = &enum_auth_flags_noecho, .name = "No-Echo", .attr = &attr_tacacs_authentication_flags },
126 { .out = &enum_tacacs_auth_type_ascii, .name = "ASCII", .attr = &attr_tacacs_authentication_type },
128};
129
130
162
163typedef struct {
164 fr_state_config_t session; //!< track state session information.
165 fr_state_tree_t *state_tree; //!< State tree to link multiple requests/responses.
167
168typedef struct {
169 CONF_SECTION *server_cs; //!< Our virtual server.
170
171 uint32_t session_id; //!< current session ID
172
173 process_tacacs_sections_t sections; //!< Pointers to various config sections
174 ///< we need to execute
175
176 process_tacacs_auth_t auth; //!< Authentication configuration.
177
178
180
181typedef struct {
182 uint32_t reply; //!< for multiround state machine
183 uint8_t seq_no; //!< sequence number of last request.
184 fr_pair_list_t list; //!< copied from the request
186
187
188#define PROCESS_PACKET_TYPE fr_tacacs_packet_code_t
189#define PROCESS_CODE_MAX FR_TACACS_CODE_MAX
190#define PROCESS_CODE_DO_NOT_RESPOND FR_TACACS_CODE_DO_NOT_RESPOND
191#define PROCESS_PACKET_CODE_VALID FR_TACACS_PACKET_CODE_VALID
192#define PROCESS_INST process_tacacs_t
193#define PROCESS_CODE_DYNAMIC_CLIENT FR_TACACS_CODE_AUTH_PASS
194
195#include <freeradius-devel/server/process.h>
196
197static const conf_parser_t auth_config[] = {
198 { FR_CONF_POINTER("session", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) state_session_config },
199
201};
202
203static const conf_parser_t config[] = {
204 { FR_CONF_POINTER("Authentication", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) auth_config,
205 .offset = offsetof(process_tacacs_t, auth), },
206
208};
209
210
211/*
212 * Synthesize a State attribute from connection && session information.
213 */
214static int state_create(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, bool reply)
215{
216 uint64_t hash;
217 uint32_t sequence;
218 fr_pair_t *vp;
219
220 if (!request->async->listen) return -1;
221
222 vp = fr_pair_find_by_da_nested(&request->request_pairs, NULL, attr_tacacs_session_id);
223 if (!vp) return -1;
224
225 hash = fr_hash64(&vp->vp_uint32, sizeof(vp->vp_uint32));
226
227 vp = fr_pair_find_by_da_nested(&request->request_pairs, NULL, attr_tacacs_sequence_number);
228 if (!vp) return -1;
229
230 /*
231 * Requests have odd sequence numbers, and replies have even sequence numbers.
232 * So if we want to synthesize a state in a reply which gets matched with the next
233 * request, we have to add 2 to it.
234 */
235 sequence = vp->vp_uint8 + ((int) reply << 1);
236 hash = fr_hash64_update(&sequence, sizeof(sequence), hash);
237
238 hash = fr_hash64_update(&request->async->listen, sizeof(request->async->listen), hash);
239
241 if (!vp) return -1;
242
243 (void) fr_pair_value_memdup(vp, (uint8_t const *) &hash, sizeof(hash), false);
244
246
247 return 0;
248}
249
250/** Try and determine what the response packet type should be
251 *
252 * We check three sources:
253 * - reply.``<status_attr>``
254 * - reply.Packet-Type
255 * - State machine packet type assignments for the section rcode
256 *
257 * @param[in] request The current request.
258 * @param[in] status_da Specialised status attribute.
259 * @param[in] status2code Mapping table of *packet* status types to rcodes.
260 * @param[in] state Mappings for process state machine
261 * @param[in] process_rcode Mappings for Auth-Type / Acct-Type, which don't use the process state machine
262 * @param[in] rcode The last section rcode.
263 * @return
264 * - >0 if we determined a reply code.
265 * - 0 if we couldn't - Usually indicates additional sections should be run.
266 */
267static uint32_t reply_code(request_t *request, fr_dict_attr_t const *status_da,
268 uint32_t const status2code[static UINT8_MAX + 1],
269 fr_process_state_t const *state, fr_process_rcode_t const process_rcode, rlm_rcode_t rcode)
270{
271 fr_pair_t *vp;
272 uint32_t code;
273
274 /*
275 * First check the protocol attribute for this packet type.
276 *
277 * Should be one of:
278 * - Authentication-Status
279 * - Authorization-Status
280 * - Accounting-Status
281 */
282 fr_assert(status_da->type == FR_TYPE_UINT8);
283
284 vp = fr_pair_find_by_da(&request->reply_pairs, NULL, status_da);
285 if (vp) {
286 code = status2code[vp->vp_uint8];
287 if (FR_TACACS_PACKET_CODE_VALID(code)) {
288 RDEBUG("Setting reply Packet-Type from %pP", vp);
289 return code;
290 }
291 REDEBUG("Ignoring invalid status %pP", vp);
292 }
293
294 if (state) {
295 code = state->packet_type[rcode];
296 if (FR_TACACS_PACKET_CODE_VALID(code)) return code;
297 }
298
299 if (process_rcode) {
300 code = process_rcode[rcode];
301 if (FR_TACACS_PACKET_CODE_VALID(code)) return code;
302 }
303
304 /*
305 * Otherwise use Packet-Type (if set)
306 */
307 vp = fr_pair_find_by_da(&request->reply_pairs, NULL, attr_packet_type);
308 if (vp && FR_TACACS_PACKET_CODE_VALID(vp->vp_uint32)) {
309 RDEBUG("Setting reply Packet-Type from %pV", &vp->data);
310 return vp->vp_uint32;
311 }
312
313 return 0;
314}
315
316RECV(auth_start)
317{
318 fr_process_state_t const *state;
319 fr_pair_t *vp;
320
321 /*
322 * Only "Login" is supported. The others are "change password" and "sendauth", which aren't
323 * used.
324 */
325 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_tacacs_action);
326 if (!vp) {
327 fail:
328 request->reply->code = FR_TACACS_CODE_AUTH_ERROR;
329 UPDATE_STATE(reply);
330
331 fr_assert(state->send != NULL);
332 return CALL_SEND_STATE(state);
333 }
334
335 if (vp->vp_uint8 != FR_ACTION_VALUE_LOGIN) {
336 RDEBUG("Invalid authentication action %u", vp->vp_uint8);
337 goto fail;
338 }
339
340 /*
341 * There is no state to restore, so we just run the section as normal.
342 */
343
344 return CALL_RECV(generic);
345}
346
347RESUME(auth_type);
348
358
359RESUME(auth_start)
360{
361 rlm_rcode_t rcode = RESULT_RCODE;
362 fr_pair_t *vp;
363 CONF_SECTION *cs;
364 fr_dict_enum_value_t const *dv;
365 fr_process_state_t const *state;
367
369
371
372 /*
373 * See if the return code from "recv" which says we reject, or continue.
374 */
375 UPDATE_STATE(packet);
376
377 /*
378 * Nothing set the reply, so let's see if we need to do so.
379 *
380 * If the admin didn't set authentication-status, just
381 * use the defaults from the state machine.
382 */
383 if (!request->reply->code) {
384 request->reply->code = reply_code(request,
386 authen_status_to_packet_code, state, NULL, rcode);
387 } else {
388 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->reply->code));
389 }
390
391 /*
392 * Check for multi-round authentication.
393 *
394 * We only run the automatic state machine (start -> getuser -> getpass -> pass/fail)
395 * when the admin does NOT set any reply type, or any reply authentication status.
396 *
397 * However, do DO always save and restore the attributes from the start packet, so that they are
398 * visible in a later packet.
399 */
400 if (!request->reply->code) {
402 fr_tacacs_packet_t const *packet = (fr_tacacs_packet_t const *) request->packet->data;
403
404 session = request_data_reference(request, inst, 0);
405 if (!session) {
406 /*
407 * This function is called for resuming both "start" and "continue" packets, so
408 * we have to check for "start" here.
409 *
410 * We only do multi-round authentication for the ASCII authentication type.
411 * Other authentication types are defined to be one request/reply only.
412 */
413 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_tacacs_authentication_type);
414 if (!packet_is_authen_start_request(packet) ||
415 (vp && (fr_value_box_cmp(&vp->data, enum_tacacs_auth_type_ascii) != 0))) {
416 goto auth_type;
417 }
418
419 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_user_name);
420 if (!vp) {
421 RDEBUG("No User-Name, replying with Authentication-GetUser");
422 request->reply->code = FR_TACACS_CODE_AUTH_GETUSER;
423 } else {
424 RDEBUG("User-Name = %pV, replying with Authentication-GetPass", &vp->data);
425 request->reply->code = FR_TACACS_CODE_AUTH_GETPASS;
426 goto add_auth_flags;
427 }
428
429 goto send_reply;
430 }
431
432 /*
433 * Last reply was "get username", we now get the password.
434 */
435 if (session->reply == FR_TACACS_CODE_AUTH_GETUSER) {
436 RDEBUG("No User-Password, replying with Authentication-GetPass");
437 request->reply->code = FR_TACACS_CODE_AUTH_GETPASS;
438
439 /*
440 * Pre-set the authentication flags reply to No-Echo
441 * RFC 8907 says this should be set when the data being
442 * requested is sensitive and should not be echoed to the
443 * user as it is being entered.
444 */
445 add_auth_flags:
448 RPEDEBUG("Failed creating Authentication-Flags attribute with No-Echo flag");
450 goto reject;
451 }
453 goto send_reply;
454 }
455
456 /*
457 * We either have a password, or the admin screwed up the configuration somehow. Just go
458 * run "Auth-Type foo".
459 */
460 goto auth_type;
461 }
462
463 /*
464 * Something set the reply code, skip
465 * the normal auth flow and respond immediately.
466 */
467 if (request->reply->code) {
468 switch (request->reply->code) {
470 RDEBUG("The 'recv Authentication-Start' section returned %s - rejecting the request",
471 fr_table_str_by_value(rcode_table, rcode, "<INVALID>"));
472 break;
473
474 default:
475 RDEBUG("Reply packet type was set to %s", fr_tacacs_packet_names[request->reply->code]);
476 break;
477 }
478
480 UPDATE_STATE(reply);
481
482 fr_assert(state->send != NULL);
483 return CALL_SEND_STATE(state);
484 }
485
486 /*
487 * Run authenticate foo { ... }
488 *
489 * If we can't find Auth-Type, OR if we can't find Auth-Type = foo, then it's a reject.
490 *
491 * We prefer the local Auth-Type to the Authentication-Type in the packet. But if there's no
492 * Auth-Type set by the admin, then we use what's in the packet.
493 */
494 auth_type:
495 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_auth_type);
496 if (!vp) vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_tacacs_authentication_type);
497 if (!vp) {
498 RDEBUG("No 'Auth-Type' or 'Authentication-Type' attribute found, "
499 "cannot authenticate the user - rejecting the request");
500
501 reject:
502 request->reply->code = FR_TACACS_CODE_AUTH_FAIL;
503 goto send_reply;
504 }
505
506 dv = fr_dict_enum_by_value(vp->da, &vp->data);
507 if (!dv) {
508 RDEBUG("Invalid value for '%s' attribute, cannot authenticate the user - rejecting the request",
509 vp->da->name);
510
511 goto reject;
512 }
513
514 /*
515 * The magic Auth-Type Accept value which means skip the authenticate section.
516 *
517 * And Reject means always reject. Tho the admin should just return "reject" from the section.
518 */
519 if (vp->da == attr_auth_type) {
521 request->reply->code = FR_TACACS_CODE_AUTH_PASS;
522 goto send_reply;
523
524 } else if (fr_value_box_cmp(enum_auth_type_reject, dv->value) == 0) {
525 request->reply->code = FR_TACACS_CODE_AUTH_FAIL;
526 goto send_reply;
527 }
528 }
529
530 cs = cf_section_find(inst->server_cs, "authenticate", dv->name);
531 if (!cs) {
532 RDEBUG2("No 'authenticate %s { ... }' section found - rejecting the request", dv->name);
533 goto reject;
534 }
535
536 /*
537 * Run the "authenticate foo { ... }" section.
538 *
539 * And continue with sending the generic reply.
540 */
541 RDEBUG("Running 'authenticate %s' from file %s", cf_section_name2(cs), cf_filename(cs));
542 return unlang_module_yield_to_section(RESULT_P, request,
543 cs, RLM_MODULE_NOOP, resume_auth_type,
544 NULL, 0, mctx->rctx);
545}
546
547RESUME(auth_type)
548{
549 static const fr_process_rcode_t auth_type_rcode = {
558 };
559
560 rlm_rcode_t rcode = RESULT_RCODE;
561 fr_process_state_t const *state;
562 fr_pair_t *vp;
563
565
567
568 /*
569 * If nothing set the reply code, then try to set it from various other things.
570 *
571 * The user could have set Authentication-Status
572 * or Packet-Type to something other than
573 * pass...
574 */
575 if (!request->reply->code) {
576 request->reply->code = reply_code(request,
578 authen_status_to_packet_code, NULL, auth_type_rcode, rcode);
579 } else {
580 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->reply->code));
581 }
582
583 switch (request->reply->code) {
584 case 0:
585 RDEBUG("No reply code was set. Forcing to Authentication-Fail");
586 fail:
587 request->reply->code = FR_TACACS_CODE_AUTH_FAIL;
589
590 /*
591 * Print complaints before running "send Access-Reject"
592 */
594 RDEBUG2("Failed to authenticate the user");
595 break;
596
600 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_tacacs_authentication_type);
601 if (vp && (vp->vp_uint32 != FR_AUTHENTICATION_TYPE_VALUE_ASCII)) {
602 RDEBUG2("Cannot send challenges for %pP", vp);
603 goto fail;
604 }
605 break;
606
607 default:
608 break;
609
610 }
611 UPDATE_STATE(reply);
612
613 fr_assert(state->send != NULL);
614 return state->send(p_result, mctx, request);
615}
616
617RESUME_FLAG(auth_pass, UNUSED,)
618{
620
622
623 // @todo - worry about user identity existing?
624
625 fr_state_discard(inst->auth.state_tree, request);
627}
628
629RESUME_FLAG(auth_fail, UNUSED,)
630{
632
634
635 // @todo - insert server message saying "failed"
636 // and also for FAIL
637
638 fr_state_discard(inst->auth.state_tree, request);
640}
641
642RESUME_FLAG(auth_restart, UNUSED,)
643{
645
647
648 fr_state_discard(inst->auth.state_tree, request);
650}
651
652RESUME(auth_get)
653{
656 fr_pair_t *vp, *copy;
657
659
660 /*
661 * Track multi-round authentication flows. Note that they can only start with an
662 * "Authentication-Start" packet, but they can continue with an "Authentication-Continue" packet.
663 *
664 * If there's no session being tracked, then we create one for a start packet.
665 */
666 session = request_data_reference(request, inst, 0);
667 if (!session) {
668 fr_tacacs_packet_t const *packet = (fr_tacacs_packet_t const *) request->packet->data;
669
671
672 MEM(session = talloc_zero(NULL, process_tacacs_session_t));
673 if (request_data_talloc_add(request, inst, 0, process_tacacs_session_t, session, true, true, true) < 0) {
674 talloc_free(session);
675 goto send_reply;
676 }
677
678 /*
679 * These are the only things which saved. The rest of the fields are either static (and statically
680 * known), or are irrelevant.
681 */
682 fr_pair_list_init(&session->list);
683#undef COPY
684#define COPY(_attr) do { \
685 vp = fr_pair_find_by_da(&request->request_pairs, NULL, _attr); \
686 if (!vp) break; \
687 MEM(copy = fr_pair_copy(session, vp)); \
688 fr_pair_append(&session->list, copy); \
689 RDEBUG2("%pP", copy); \
690} while (0)
691
692 RDEBUG2("Caching session attributes:");
693 RINDENT();
699 REXDENT();
700
701 } else {
702 /*
703 * It is possible that the user name or password are added on subsequent Authentication-Continue
704 * packets following replies with Authentication-GetUser or Authentication-GetPass.
705 * Check if they are already in the session cache, and if not, add them.
706 */
707#define COPY_MISSING(_attr) do { \
708 vp = fr_pair_find_by_da(&session->list, NULL, _attr); \
709 if (vp) break; \
710 COPY(_attr); \
711} while (0)
712
713 RDEBUG2("Caching additional session attributes:");
714 RINDENT();
717 REXDENT();
718 }
719 session->reply = request->reply->code;
720 session->seq_no = request->packet->data[2];
721
723 /*
724 * Cache the session state context.
725 */
726 if ((state_create(request->reply_ctx, &request->reply_pairs, request, true) < 0) ||
727 (fr_state_store(inst->auth.state_tree, request) < 0)) {
728 return CALL_SEND_TYPE(FR_TACACS_CODE_AUTH_ERROR);
729 }
730
732}
733
734RECV(auth_cont)
735{
738
739 if ((state_create(request->request_ctx, &request->request_pairs, request, false) < 0) ||
740 (fr_state_restore(inst->auth.state_tree, request) < 0)) {
741 return CALL_SEND_TYPE(FR_TACACS_CODE_AUTH_ERROR);
742 }
743
744 /*
745 * Restore key fields from the original Authentication-Start packet.
746 */
747 session = request_data_reference(request, inst, 0);
748 if (session) {
749 fr_pair_t *vp = NULL, *copy;
750
751 if (request->packet->data[2] <= session->seq_no) {
752 REDEBUG("Client sent invalid sequence number %02x, expected >%02x", request->packet->data[2], session->seq_no);
753 error:
754 return CALL_SEND_TYPE(FR_TACACS_CODE_AUTH_ERROR);
755 }
756
757 if (fr_debug_lvl >= L_DBG_LVL_2) {
758 RDEBUG2("Restoring session attributes:");
759 RINDENT();
760 while ((vp = fr_pair_list_next(&session->list, vp))) {
761 RDEBUG2("%pP", vp);
762 }
763 REXDENT();
764 }
765 if (fr_pair_list_copy(request->request_ctx, &request->request_pairs, &session->list) < 0) goto error;
766
767 /*
768 * Copy the returned user_message into the attribute we requested.
769 */
770#define EXTRACT(_attr) \
771 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_tacacs_user_message); \
772 if (!vp) break; \
773 fr_value_box_set_secret(&vp->data, _attr->flags.secret); \
774 if (pair_append_request(&copy, _attr) < 0) break; \
775 if (fr_pair_value_copy(copy, vp) < 0) { \
776 fr_pair_remove(&request->request_pairs, copy); \
777 talloc_free(copy); \
778 break; \
779 } \
780 RDEBUG2("Populated %pP from user_message", copy)
781
782 switch (session->reply) {
785 break;
786
789 break;
790
791 default:
792 break;
793 }
794 }
795
796 return CALL_RECV(generic);
797}
798
799/*
800 * The client aborted the session. The reply should be RESTART or FAIL.
801 */
802RECV(auth_cont_abort)
803{
805
806 if ((state_create(request->request_ctx, &request->request_pairs, request, false) < 0) ||
807 (fr_state_restore(inst->auth.state_tree, request) < 0)) {
808 return CALL_SEND_TYPE(FR_TACACS_CODE_AUTH_ERROR);
809 }
810
811 return CALL_RECV(generic);
812}
813
814RESUME(auth_cont_abort)
815{
816 fr_process_state_t const *state;
817
818 if (!request->reply->code) request->reply->code = FR_TACACS_CODE_AUTH_RESTART;
819
820 UPDATE_STATE(reply);
821
822 fr_assert(state->send != NULL);
823 return CALL_SEND_STATE(state);
824}
825
826
833
834
835RESUME(autz_request)
836{
837 rlm_rcode_t rcode = RESULT_RCODE;
838 fr_process_state_t const *state;
839
841
843
844 /*
845 * See if the return code from "recv" which says we reject, or continue.
846 */
847 UPDATE_STATE(packet);
848
849 /*
850 * Nothing set the reply, so let's see if we need to do so.
851 *
852 * If the admin didn't set authorization-status, just
853 * use the defaults from the state machine.
854 */
855 if (!request->reply->code) {
856 request->reply->code = reply_code(request, attr_tacacs_authorization_status,
857 author_status_to_packet_code, state, NULL, rcode);
858 if (!request->reply->code) request->reply->code = FR_TACACS_CODE_AUTZ_ERROR;
859
860 } else {
861 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->reply->code));
862 }
863
864 RDEBUG("Reply packet type set to %s", fr_tacacs_packet_names[request->reply->code]);
865
866 UPDATE_STATE(reply);
867
868 fr_assert(state->send != NULL);
869 return CALL_SEND_STATE(state);
870}
871
876
877RESUME(acct_type)
878{
879 static const fr_process_rcode_t acct_type_rcode = {
888 };
889
890 rlm_rcode_t rcode = RESULT_RCODE;
891 fr_process_state_t const *state;
892
894
895 /*
896 * One more chance to override
897 */
898 if (!request->reply->code) {
900 NULL, acct_type_rcode, rcode);
901 if (!request->reply->code) request->reply->code = FR_TACACS_CODE_ACCT_ERROR;
902 } else {
903 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->reply->code));
904 }
905
906 UPDATE_STATE(reply);
907
908 fr_assert(state->send != NULL);
909 return state->send(p_result, mctx, request);
910}
911
912static const bool acct_flag_valid[8] = {
913 false, true, true, false, /* invalid, start, stop, invalid */
914 true, true, false, false, /* watchdog - no update, watchdog - update, invalid, invalid */
915};
916
917RECV(accounting_request)
918{
919 fr_pair_t *vp;
920
921 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_tacacs_accounting_flags);
922
923 /*
924 * RFC 8907 Section 7.2
925 */
926 if (vp && !acct_flag_valid[(vp->vp_uint8 & 0x0e) >> 1]) {
927 RWDEBUG("Invalid accounting request flag field %02x", vp->vp_uint8);
928 return CALL_SEND_TYPE(FR_TACACS_CODE_ACCT_ERROR);
929 }
930
931 return CALL_RECV(generic);
932}
933
934RESUME(accounting_request)
935{
936 rlm_rcode_t rcode = RESULT_RCODE;
937 fr_pair_t *vp;
938 CONF_SECTION *cs;
939 fr_dict_enum_value_t const *dv;
940 fr_process_state_t const *state;
942
944
946
947 UPDATE_STATE(packet);
948
949 /*
950 * Nothing set the reply, so let's see if we need to do so.
951 *
952 * If the admin didn't set accounting-status, just
953 * use the defaults from the state machine.
954 */
955 if (!request->reply->code) {
956 request->reply->code = reply_code(request, attr_tacacs_accounting_status,
957 acct_status_to_packet_code, state, NULL, rcode);
958 } else {
959 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->reply->code));
960 }
961
962 /*
963 * Something set the reply code, so we reply and don't run "accounting foo { ... }"
964 */
965 if (request->reply->code) {
966 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->packet->code));
967
968 RDEBUG("Reply packet type was set to %s", fr_tacacs_packet_names[request->reply->code]);
969
970 UPDATE_STATE(reply);
971
972 fr_assert(state->send != NULL);
973 return CALL_SEND_STATE(state);
974 }
975
976 /*
977 * Run accounting foo { ... }
978 */
979 vp = fr_pair_find_by_da(&request->request_pairs, NULL, attr_tacacs_accounting_flags);
980 if (!vp) {
981 fail:
982 request->reply->code = FR_TACACS_CODE_ACCT_ERROR;
983 UPDATE_STATE(reply);
984 fr_assert(state->send != NULL);
985 return CALL_SEND_STATE(state);
986 }
987
988 dv = fr_dict_enum_by_value(vp->da, &vp->data);
989 if (!dv) goto fail;
990
991 cs = cf_section_find(inst->server_cs, "accounting", dv->name);
992 if (!cs) {
993 RDEBUG2("No 'accounting %s { ... }' section found - skipping...", dv->name);
994 goto fail;
995 }
996
997 /*
998 * Run the "accounting foo { ... }" section.
999 *
1000 * And continue with sending the generic reply.
1001 */
1002 return unlang_module_yield_to_section(RESULT_P, request,
1003 cs, RLM_MODULE_NOOP, resume_acct_type,
1004 NULL, 0, mctx->rctx);
1005}
1006
1007static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1008{
1009 fr_process_state_t const *state;
1010
1012
1014 fr_assert(FR_TACACS_PACKET_CODE_VALID(request->packet->code));
1015
1016 request->component = "tacacs";
1017 request->module = NULL;
1018 fr_assert(request->proto_dict == dict_tacacs);
1019
1020 UPDATE_STATE(packet);
1021
1022 if (!state->recv) {
1023 REDEBUG("Invalid packet type (%u)", request->packet->code);
1025 }
1026
1027 // @todo - debug stuff!
1028// tacacs_packet_debug(request, request->packet, &request->request_pairs, true);
1029
1030 if (unlikely(request_is_dynamic_client(request))) {
1031 return new_client(p_result, mctx, request);
1032 }
1033
1034 return state->recv(p_result, mctx, request);
1035}
1036
1037static int mod_instantiate(module_inst_ctx_t const *mctx)
1038{
1039 process_tacacs_t *inst = talloc_get_type_abort(mctx->mi->data, process_tacacs_t);
1040
1041 inst->server_cs = cf_item_to_section(cf_parent(mctx->mi->conf));
1042
1043 FR_INTEGER_BOUND_CHECK("session.max_rounds", inst->auth.session.max_rounds, >=, 1);
1044 FR_INTEGER_BOUND_CHECK("session.max_rounds", inst->auth.session.max_rounds, <=, 8);
1045
1046 FR_INTEGER_BOUND_CHECK("session.max", inst->auth.session.max_sessions, >=, 64);
1047 FR_INTEGER_BOUND_CHECK("session.max", inst->auth.session.max_sessions, <=, (1 << 18));
1048
1049 inst->auth.session.thread_safe = main_config->spawn_workers;
1050 inst->auth.session.context_id = fr_hash_string(cf_section_name2(inst->server_cs));
1051
1052 inst->auth.state_tree = fr_state_tree_init(inst, attr_tacacs_state, &inst->auth.session);
1053 return 0;
1054}
1055
1056static int mod_bootstrap(module_inst_ctx_t const *mctx)
1057{
1058 CONF_SECTION *server_cs = cf_item_to_section(cf_parent(mctx->mi->conf));
1059
1060 if (virtual_server_section_attribute_define(server_cs, "authenticate", attr_auth_type) < 0) return -1;
1061
1062 return 0;
1063}
1064
1065/*
1066 * rcodes not listed under a packet_type
1067 * mean that the packet code will not be
1068 * changed.
1069 */
1070static fr_process_state_t const process_state[] = {
1071 /*
1072 * Authentication
1073 */
1075 .packet_type = {
1082 },
1083 .default_rcode = RLM_MODULE_NOOP,
1084 .recv = recv_auth_start,
1085 .resume = resume_auth_start,
1086 .section_offset = offsetof(process_tacacs_sections_t, auth_start),
1087 },
1089 .packet_type = {
1095 },
1096 .default_rcode = RLM_MODULE_NOOP,
1097 .result_rcode = RLM_MODULE_OK,
1098 .send = send_generic,
1099 .resume = resume_auth_pass,
1100 .section_offset = offsetof(process_tacacs_sections_t, auth_pass),
1101 },
1103 .packet_type = {
1109 },
1110 .default_rcode = RLM_MODULE_NOOP,
1111 .result_rcode = RLM_MODULE_REJECT,
1112 .send = send_generic,
1113 .resume = resume_auth_fail,
1114 .section_offset = offsetof(process_tacacs_sections_t, auth_fail),
1115 },
1117 .packet_type = {
1123 },
1124 .default_rcode = RLM_MODULE_NOOP,
1125 .result_rcode = RLM_MODULE_OK,
1126 .send = send_generic,
1127 .resume = resume_auth_get,
1128 .section_offset = offsetof(process_tacacs_sections_t, auth_getdata),
1129 },
1131 .packet_type = {
1137 },
1138 .default_rcode = RLM_MODULE_NOOP,
1139 .result_rcode = RLM_MODULE_OK,
1140 .send = send_generic,
1141 .resume = resume_auth_get,
1142 .section_offset = offsetof(process_tacacs_sections_t, auth_getpass),
1143 },
1145 .packet_type = {
1151 },
1152 .default_rcode = RLM_MODULE_NOOP,
1153 .result_rcode = RLM_MODULE_OK,
1154 .send = send_generic,
1155 .resume = resume_auth_get,
1156 .section_offset = offsetof(process_tacacs_sections_t, auth_getuser),
1157 },
1159 .packet_type = {
1160 },
1161 .default_rcode = RLM_MODULE_NOOP,
1162 .result_rcode = RLM_MODULE_OK,
1163 .send = send_generic,
1164 .resume = resume_auth_restart,
1165 .section_offset = offsetof(process_tacacs_sections_t, auth_restart),
1166 },
1168 .packet_type = {
1169 },
1170 .default_rcode = RLM_MODULE_NOOP,
1171 .result_rcode = RLM_MODULE_REJECT,
1172 .send = send_generic,
1173 .resume = resume_auth_restart,
1174 .section_offset = offsetof(process_tacacs_sections_t, auth_error),
1175 },
1176
1178 .packet_type = {
1185 },
1186 .default_rcode = RLM_MODULE_NOOP,
1187 .result_rcode = RLM_MODULE_OK,
1188 .recv = recv_auth_cont,
1189 .resume = resume_auth_start, /* we go back to running 'authenticate', etc. */
1190 .section_offset = offsetof(process_tacacs_sections_t, auth_cont),
1191 },
1193 .packet_type = {
1200 },
1201 .default_rcode = RLM_MODULE_NOOP,
1202 .result_rcode = RLM_MODULE_REJECT,
1203 .recv = recv_auth_cont_abort,
1204 .resume = resume_auth_cont_abort,
1205 .section_offset = offsetof(process_tacacs_sections_t, auth_cont_abort),
1206 },
1207
1208 /*
1209 * Authorization
1210 */
1212 .packet_type = {
1217
1224 },
1225 .default_rcode = RLM_MODULE_NOOP,
1226 .recv = recv_generic,
1227 .resume = resume_autz_request,
1228 .section_offset = offsetof(process_tacacs_sections_t, autz_request),
1229 },
1231 .packet_type = {
1238 },
1239 .default_rcode = RLM_MODULE_NOOP,
1240 .result_rcode = RLM_MODULE_OK,
1241 .send = send_generic,
1242 .resume = resume_send_generic,
1243 .section_offset = offsetof(process_tacacs_sections_t, autz_pass_add),
1244 },
1246 .packet_type = {
1253 },
1254 .default_rcode = RLM_MODULE_NOOP,
1255 .result_rcode = RLM_MODULE_OK,
1256 .send = send_generic,
1257 .resume = resume_send_generic,
1258 .section_offset = offsetof(process_tacacs_sections_t, autz_pass_replace),
1259 },
1261 .packet_type = {
1262 },
1263 .default_rcode = RLM_MODULE_NOOP,
1264 .result_rcode = RLM_MODULE_REJECT,
1265 .send = send_generic,
1266 .resume = resume_send_generic,
1267 .section_offset = offsetof(process_tacacs_sections_t, autz_fail),
1268 },
1270 .packet_type = {
1271 },
1272 .default_rcode = RLM_MODULE_NOOP,
1273 .result_rcode = RLM_MODULE_REJECT,
1274 .send = send_generic,
1275 .resume = resume_send_generic,
1276 .section_offset = offsetof(process_tacacs_sections_t, autz_error),
1277 },
1278
1279 /*
1280 * Accounting
1281 */
1283 .packet_type = {
1290 },
1291 .default_rcode = RLM_MODULE_NOOP,
1292 .recv = recv_accounting_request,
1293 .resume = resume_accounting_request,
1294 .section_offset = offsetof(process_tacacs_sections_t, acct_request),
1295 },
1297 .packet_type = {
1304 },
1305 .default_rcode = RLM_MODULE_NOOP,
1306 .result_rcode = RLM_MODULE_OK,
1307 .send = send_generic,
1308 .resume = resume_send_generic,
1309 .section_offset = offsetof(process_tacacs_sections_t, acct_success),
1310 },
1312 .packet_type = {
1313 },
1314 .default_rcode = RLM_MODULE_NOOP,
1315 .result_rcode = RLM_MODULE_FAIL,
1316 .send = send_generic,
1317 .resume = resume_send_generic,
1318 .section_offset = offsetof(process_tacacs_sections_t, acct_error),
1319 },
1321 .packet_type = {
1326
1333 },
1334 .default_rcode = RLM_MODULE_NOOP,
1335 .result_rcode = RLM_MODULE_HANDLED,
1336 .send = send_generic,
1337 .resume = resume_send_generic,
1338 .section_offset = offsetof(process_tacacs_sections_t, do_not_respond),
1339 }
1340};
1341
1342
1344 /**
1345 * Basically, the TACACS+ protocol use same type "authenticate" to handle
1346 * Start and Continue requests. (yep, you're right. it's horrible)
1347 * Therefore, we split the same "auth" type into two different sections just
1348 * to allow the user to have different logic for that.
1349 *
1350 * If you want to cry, just take a look at
1351 *
1352 * https://tools.ietf.org/html/rfc8907 Section 4.
1353 *
1354 * This should be an abject lesson in how NOT to design a
1355 * protocol. Pretty much everything they did was wrong.
1356 */
1357 {
1358 .section = SECTION_NAME("recv", "Authentication-Start"),
1359 .actions = &mod_actions_authenticate,
1360 .offset = PROCESS_CONF_OFFSET(auth_start),
1361 },
1362 {
1363 .section = SECTION_NAME("send", "Authentication-Pass"),
1365 .offset = PROCESS_CONF_OFFSET(auth_pass),
1366 },
1367 {
1368 .section = SECTION_NAME("send", "Authentication-Fail"),
1370 .offset = PROCESS_CONF_OFFSET(auth_fail),
1371 },
1372 {
1373 .section = SECTION_NAME("send", "Authentication-GetData"),
1375 .offset = PROCESS_CONF_OFFSET(auth_getdata),
1376 },
1377 {
1378 .section = SECTION_NAME("send", "Authentication-GetUser"),
1380 .offset = PROCESS_CONF_OFFSET(auth_getuser),
1381 },
1382 {
1383 .section = SECTION_NAME("send", "Authentication-GetPass"),
1385 .offset = PROCESS_CONF_OFFSET(auth_getpass),
1386 },
1387 {
1388 .section = SECTION_NAME("send", "Authentication-Restart"),
1390 .offset = PROCESS_CONF_OFFSET(auth_restart),
1391 },
1392 {
1393 .section = SECTION_NAME("send", "Authentication-Error"),
1395 .offset = PROCESS_CONF_OFFSET(auth_error),
1396 },
1397 {
1398 .section = SECTION_NAME("recv", "Authentication-Continue"),
1400 .offset = PROCESS_CONF_OFFSET(auth_cont),
1401 },
1402 {
1403 .section = SECTION_NAME("recv", "Authentication-Continue-Abort"),
1405 .offset = PROCESS_CONF_OFFSET(auth_cont_abort),
1406 },
1407
1408 {
1409 .section = SECTION_NAME("authenticate", CF_IDENT_ANY),
1411 },
1412
1413 /* authorization */
1414
1415 {
1416 .section = SECTION_NAME("recv", "Authorization-Request"),
1418 .offset = PROCESS_CONF_OFFSET(autz_request),
1419 },
1420 {
1421 .section = SECTION_NAME("send", "Authorization-Pass-Add"),
1423 .offset = PROCESS_CONF_OFFSET(autz_pass_add),
1424 },
1425 {
1426 .section = SECTION_NAME("send", "Authorization-Pass-Replace"),
1428 .offset = PROCESS_CONF_OFFSET(autz_pass_replace),
1429 },
1430 {
1431 .section = SECTION_NAME("send", "Authorization-Fail"),
1433 .offset = PROCESS_CONF_OFFSET(autz_fail),
1434 },
1435 {
1436 .section = SECTION_NAME("send", "Authorization-Error"),
1438 .offset = PROCESS_CONF_OFFSET(autz_error),
1439 },
1440
1441 /* accounting */
1442
1443 {
1444 .section = SECTION_NAME("recv", "Accounting-Request"),
1446 .offset = PROCESS_CONF_OFFSET(acct_request),
1447 },
1448 {
1449 .section = SECTION_NAME("send", "Accounting-Success"),
1451 .offset = PROCESS_CONF_OFFSET(acct_success),
1452 },
1453 {
1454 .section = SECTION_NAME("send", "Accounting-Error"),
1456 .offset = PROCESS_CONF_OFFSET(acct_error),
1457 },
1458
1459 {
1460 .section = SECTION_NAME("accounting", CF_IDENT_ANY),
1462 },
1463
1464 {
1465 .section = SECTION_NAME("send", "Do-Not-Respond"),
1467 .offset = PROCESS_CONF_OFFSET(do_not_respond),
1468 },
1469
1470 DYNAMIC_CLIENT_SECTIONS,
1471
1473};
1474
1475
1478 .common = {
1479 .magic = MODULE_MAGIC_INIT,
1480 .name = "tacacs",
1481 .config = config,
1483 MODULE_RCTX(process_rctx_t),
1484 .bootstrap = mod_bootstrap,
1485 .instantiate = mod_instantiate
1486 },
1487 .process = mod_process,
1488 .compile_list = compile_list,
1489 .dict = &dict_tacacs,
1490 .packet_type = &attr_packet_type
1491};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:324
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:660
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:520
#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:337
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:426
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:597
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1184
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1027
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
#define cf_parent(_cf)
Definition cf_util.h:101
#define cf_filename(_cf)
Definition cf_util.h:107
#define CF_IDENT_ANY
Definition cf_util.h:78
#define MEM(x)
Definition debug.h:36
fr_value_box_t const ** out
Enumeration value.
Definition dict.h:283
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:294
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:307
fr_value_box_t const * value
Enum value (what name maps to).
Definition dict.h:259
fr_dict_enum_value_t const * fr_dict_enum_by_value(fr_dict_attr_t const *da, fr_value_box_t const *value)
Lookup the structure representing an enum value in a fr_dict_attr_t.
Definition dict_util.c:3662
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:313
char const * name
Enum name.
Definition dict.h:256
Specifies an attribute which must be present for the module to function.
Definition dict.h:293
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:306
Specifies a value which must be present for the module to function.
Definition dict.h:282
Value of an enumerated attribute.
Definition dict.h:255
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
uint64_t fr_hash64(void const *data, size_t size)
Definition hash.c:909
uint32_t fr_hash_string(char const *p)
Definition hash.c:869
uint64_t fr_hash64_update(void const *data, size_t size, uint64_t hash)
Definition hash.c:937
talloc_free(hp)
static fr_dict_t const * dict_freeradius
Definition base.c:37
fr_dict_attr_t const * attr_packet_type
Definition base.c:93
fr_dict_attr_t const * attr_user_name
Definition base.c:104
static fr_dict_attr_t const * attr_module_failure_message
Definition log.c:206
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:443
#define RWDEBUG(fmt,...)
Definition log.h:361
#define RPEDEBUG(fmt,...)
Definition log.h:376
#define RINDENT()
Indent R* messages by one level.
Definition log.h:430
int fr_debug_lvl
Definition log.c:40
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
Definition log.h:71
main_config_t const * main_config
Main server configuration.
Definition main_config.c:58
bool spawn_workers
Should the server spawn threads.
Definition main_config.h:58
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_OCTETS
Raw octets.
unsigned int uint32_t
unsigned char uint8_t
#define UINT8_MAX
unlang_mod_actions_t const mod_actions_authenticate
Definition mod_action.c:30
unlang_mod_actions_t const mod_actions_accounting
Definition mod_action.c:78
unlang_mod_actions_t const mod_actions_authorize
Definition mod_action.c:46
unlang_mod_actions_t const mod_actions_postauth
Definition mod_action.c:93
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:69
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
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 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:2944
fr_pair_t * fr_pair_find_by_da_nested(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find a pair with a matching fr_dict_attr_t, by walking the nested fr_dict_attr_t tree.
Definition pair.c:780
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:703
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:1348
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:289
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
static unlang_action_t mod_process(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition base.c:188
static const virtual_server_compile_t compile_list[]
Definition base.c:214
static fr_process_state_t const process_state[]
Definition base.c:69
RESUME_FLAG(recv_bfd, UNUSED,)
Definition base.c:119
static fr_dict_attr_t const * attr_module_success_message
Definition base.c:37
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition base.c:753
RECV(for_any_server)
Validate a solicit/rebind/confirm message.
Definition base.c:402
static fr_dict_attr_t const * attr_user_password
Definition base.c:66
static fr_dict_attr_t const * attr_stripped_user_name
Definition base.c:59
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition base.c:880
static fr_dict_attr_t const * attr_auth_type
Definition base.c:56
static fr_value_box_t const * enum_auth_type_reject
Definition base.c:94
static const conf_parser_t auth_config[]
Definition base.c:166
static fr_value_box_t const * enum_auth_type_accept
Definition base.c:93
static const conf_parser_t config[]
Definition base.c:172
fr_process_module_t process_tacacs
Definition base.c:1477
static fr_dict_attr_t const * attr_tacacs_authentication_flags
Definition base.c:56
CONF_SECTION * autz_pass_add
Definition base.c:147
fr_pair_list_t list
copied from the request
Definition base.c:184
CONF_SECTION * new_client
Definition base.c:158
static fr_value_box_t const * enum_tacacs_auth_type_ascii
Definition base.c:119
CONF_SECTION * add_client
Definition base.c:159
CONF_SECTION * auth_pass
Definition base.c:135
CONF_SECTION * auth_start
Definition base.c:134
CONF_SECTION * acct_success
Definition base.c:153
CONF_SECTION * auth_error
Definition base.c:141
CONF_SECTION * acct_request
Definition base.c:152
CONF_SECTION * auth_cont_abort
Definition base.c:144
fr_dict_attr_autoload_t process_tacacs_dict_attr[]
Definition base.c:80
static fr_dict_attr_t const * attr_tacacs_user_message
Definition base.c:73
CONF_SECTION * server_cs
Our virtual server.
Definition base.c:169
static fr_dict_attr_t const * attr_chap_password
Definition base.c:77
CONF_SECTION * auth_cont
Definition base.c:143
static const uint32_t acct_status_to_packet_code[UINT8_MAX+1]
Definition base.c:872
CONF_SECTION * auth_restart
Definition base.c:140
static const uint32_t authen_status_to_packet_code[UINT8_MAX+1]
Definition base.c:349
process_tacacs_sections_t sections
Pointers to various config sections we need to execute.
Definition base.c:173
static uint32_t reply_code(request_t *request, fr_dict_attr_t const *status_da, uint32_t const status2code[static UINT8_MAX+1], fr_process_state_t const *state, fr_process_rcode_t const process_rcode, rlm_rcode_t rcode)
Try and determine what the response packet type should be.
Definition base.c:267
static fr_dict_t const * dict_tacacs
Definition base.c:39
fr_dict_enum_autoload_t process_tacacs_dict_enum[]
Definition base.c:122
#define COPY_MISSING(_attr)
static fr_dict_attr_t const * attr_tacacs_session_id
Definition base.c:70
static fr_dict_attr_t const * attr_tacacs_server_message
Definition base.c:69
CONF_SECTION * autz_error
Definition base.c:150
CONF_SECTION * do_not_respond
Definition base.c:156
static const uint32_t author_status_to_packet_code[UINT8_MAX+1]
Definition base.c:827
static fr_value_box_t const * enum_auth_flags_noecho
Definition base.c:118
CONF_SECTION * autz_pass_replace
Definition base.c:148
uint32_t reply
for multiround state machine
Definition base.c:182
#define EXTRACT(_attr)
CONF_SECTION * auth_getuser
Definition base.c:138
static fr_dict_attr_t const * attr_tacacs_privilege_level
Definition base.c:67
CONF_SECTION * auth_getdata
Definition base.c:137
static fr_dict_attr_t const * attr_tacacs_authentication_type
Definition base.c:57
CONF_SECTION * acct_error
Definition base.c:154
static fr_dict_attr_t const * attr_tacacs_accounting_status
Definition base.c:62
CONF_SECTION * autz_request
Definition base.c:146
fr_state_config_t session
track state session information.
Definition base.c:164
static const bool acct_flag_valid[8]
Definition base.c:912
static fr_dict_attr_t const * attr_tacacs_authentication_service
Definition base.c:58
static fr_dict_attr_t const * attr_tacacs_authentication_status
Definition base.c:59
CONF_SECTION * deny_client
Definition base.c:160
CONF_SECTION * auth_fail
Definition base.c:136
static fr_dict_attr_t const * attr_tacacs_authentication_action
Definition base.c:55
static fr_dict_attr_t const * attr_tacacs_client_port
Definition base.c:65
process_tacacs_auth_t auth
Authentication configuration.
Definition base.c:176
static fr_dict_attr_t const * attr_tacacs_remote_address
Definition base.c:68
uint8_t seq_no
sequence number of last request.
Definition base.c:183
fr_state_tree_t * state_tree
State tree to link multiple requests/responses.
Definition base.c:165
#define COPY(_attr)
static fr_dict_attr_t const * attr_tacacs_action
Definition base.c:54
static fr_dict_attr_t const * attr_tacacs_sequence_number
Definition base.c:71
static fr_dict_attr_t const * attr_tacacs_authorization_status
Definition base.c:61
CONF_SECTION * autz_fail
Definition base.c:149
static fr_dict_attr_t const * attr_tacacs_accounting_flags
Definition base.c:63
static fr_dict_attr_t const * attr_tacacs_data
Definition base.c:66
static fr_dict_attr_t const * attr_tacacs_state
Definition base.c:72
uint32_t session_id
current session ID
Definition base.c:171
CONF_SECTION * auth_getpass
Definition base.c:139
fr_dict_autoload_t process_tacacs_dict[]
Definition base.c:42
static int state_create(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, bool reply)
Definition base.c:214
#define PROCESS_TRACE
Trace each state function as it's entered.
Definition process.h:55
#define PROCESS_CONF_OFFSET(_x)
Definition process.h:79
module_t common
Common fields for all loadable modules.
Common public symbol definition for all process modules.
char const * fr_tacacs_packet_names[FR_TACACS_CODE_MAX]
Definition base.c:120
#define fr_assert(_expr)
Definition rad_assert.h:38
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG2(fmt,...)
Definition radclient.h:54
#define RDEBUG(fmt,...)
Definition radclient.h:53
static void send_reply(int sockfd, fr_channel_data_t *reply)
fr_table_num_sorted_t const rcode_table[]
Definition rcode.c:35
#define RETURN_UNLANG_FAIL
Definition rcode.h:59
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition rcode.h:47
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:45
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:44
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition rcode.h:48
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:43
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
Definition rcode.h:52
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:49
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:51
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:50
@ RLM_MODULE_NUMCODES
How many valid return codes there are.
Definition rcode.h:53
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition rcode.h:46
#define request_is_dynamic_client(_x)
Definition request.h:188
void * request_data_reference(request_t *request, void const *unique_ptr, int unique_int)
Get opaque data from a request without removing it.
#define request_data_talloc_add(_request, _unique_ptr, _unique_int, _type, _opaque, _free_on_replace, _free_on_parent, _persist)
Add opaque data to a request_t.
static unlang_action_t process_rcode(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
static unsigned int hash(char const *username, unsigned int tablesize)
Definition rlm_passwd.c:132
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:349
void * data
Module's instance data.
Definition module.h:291
#define MODULE_RCTX(_ctype)
Definition module.h:257
#define MODULE_INST(_ctype)
Definition module.h:255
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:206
#define pair_delete_reply(_pair_or_da)
Delete a fr_pair_t in the reply list.
Definition pair.h:181
#define pair_append_reply(_attr, _da)
Allocate and append a fr_pair_t to reply list.
Definition pair.h:47
int fr_state_restore(fr_state_tree_t *state, request_t *request)
Copy a pointer to the head of the list of state fr_pair_ts (and their ctx) into the request.
Definition state.c:738
void fr_state_discard(fr_state_tree_t *state, request_t *request)
Called when sending an Access-Accept/Access-Reject to discard state information.
Definition state.c:684
int fr_state_store(fr_state_tree_t *state, request_t *request)
Transfer ownership of the state fr_pair_ts and ctx, back to a state entry.
Definition state.c:814
const conf_parser_t state_session_config[]
Definition state.c:59
fr_state_tree_t * fr_state_tree_init(TALLOC_CTX *ctx, fr_dict_attr_t const *da, fr_state_config_t const *config)
Initialise a new state tree.
Definition state.c:232
unlang_action_t unlang_module_yield_to_section(unlang_result_t *p_result, request_t *request, CONF_SECTION *subcs, rlm_rcode_t default_rcode, module_method_t resume, unlang_module_signal_t signal, fr_signal_t sigmask, void *rctx)
Definition module.c:236
eap_aka_sim_process_conf_t * inst
#define RESUME(_x)
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
@ FR_TAC_PLUS_AUTHOR_STATUS_PASS_ADD
Definition tacacs.h:211
@ FR_TAC_PLUS_AUTHOR_STATUS_ERROR
Definition tacacs.h:214
@ FR_TAC_PLUS_AUTHOR_STATUS_FAIL
Definition tacacs.h:213
@ FR_TAC_PLUS_AUTHOR_STATUS_PASS_REPL
Definition tacacs.h:212
#define FR_TACACS_PACKET_CODE_VALID(_code)
Definition tacacs.h:322
#define packet_is_authen_start_request(p)
3.4.
Definition tacacs.h:49
@ FR_TACACS_CODE_ACCT_ERROR
Definition tacacs.h:315
@ FR_TACACS_CODE_DO_NOT_RESPOND
Definition tacacs.h:318
@ FR_TACACS_CODE_ACCT_REQUEST
Definition tacacs.h:313
@ FR_TACACS_CODE_AUTZ_REQUEST
Definition tacacs.h:307
@ FR_TACACS_CODE_AUTH_GETDATA
Definition tacacs.h:298
@ FR_TACACS_CODE_AUTH_RESTART
Definition tacacs.h:301
@ FR_TACACS_CODE_AUTZ_PASS_REPLACE
Definition tacacs.h:309
@ FR_TACACS_CODE_AUTH_GETUSER
Definition tacacs.h:299
@ FR_TACACS_CODE_AUTH_GETPASS
Definition tacacs.h:300
@ FR_TACACS_CODE_AUTZ_FAIL
Definition tacacs.h:310
@ FR_TACACS_CODE_AUTH_CONT_ABORT
Definition tacacs.h:305
@ FR_TACACS_CODE_AUTH_PASS
Definition tacacs.h:296
@ FR_TACACS_CODE_AUTH_CONT
Definition tacacs.h:304
@ FR_TACACS_CODE_AUTZ_PASS_ADD
Definition tacacs.h:308
@ FR_TACACS_CODE_AUTH_START
Definition tacacs.h:295
@ FR_TACACS_CODE_AUTH_FAIL
Definition tacacs.h:297
@ FR_TACACS_CODE_AUTH_ERROR
Definition tacacs.h:302
@ FR_TACACS_CODE_AUTZ_ERROR
Definition tacacs.h:311
@ FR_TACACS_CODE_ACCT_SUCCESS
Definition tacacs.h:314
@ FR_TAC_PLUS_ACCT_STATUS_SUCCESS
Definition tacacs.h:255
@ FR_TAC_PLUS_ACCT_STATUS_ERROR
Definition tacacs.h:256
@ FR_TAC_PLUS_AUTHEN_STATUS_PASS
Definition tacacs.h:151
@ FR_TAC_PLUS_AUTHEN_STATUS_GETDATA
Definition tacacs.h:153
@ FR_TAC_PLUS_AUTHEN_STATUS_ERROR
Definition tacacs.h:157
@ FR_TAC_PLUS_AUTHEN_STATUS_GETUSER
Definition tacacs.h:154
@ FR_TAC_PLUS_AUTHEN_STATUS_FAIL
Definition tacacs.h:152
@ FR_TAC_PLUS_AUTHEN_STATUS_RESTART
Definition tacacs.h:156
@ FR_TAC_PLUS_AUTHEN_STATUS_GETPASS
Definition tacacs.h:155
#define talloc_get_type_abort_const
Definition talloc.h:245
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
Definition pair_inline.c:69
int8_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
Compare two values.
Definition value.c:749
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
Copy value data verbatim duplicating any buffers.
Definition value.c:4411
static size_t char ** out
Definition value.h:1024
int virtual_server_section_attribute_define(CONF_SECTION *server_cs, char const *subcs_name, fr_dict_attr_t const *da)
Define a values for Auth-Type attributes by the sections present in a virtual-server.
section_name_t const * section
Identifier for the section.
#define COMPILE_TERMINATOR
Processing sections which are allowed in this virtual server.