26 #include <freeradius-devel/util/net.h>
27 #include <freeradius-devel/util/md5.h>
28 #include <freeradius-devel/util/struct.h>
120 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_START] =
"Authentication-Start",
121 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_PASS] =
"Authentication-Pass",
122 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_FAIL] =
"Authentication-Fail",
123 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_GETDATA] =
"Authentication-GetData",
124 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_GETUSER] =
"Authentication-GetUser",
125 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_GETPASS] =
"Authentication-GetPass",
126 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_RESTART] =
"Authentication-Restart",
127 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_ERROR] =
"Authentication-Error",
129 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_CONTINUE] =
"Authentication-Continue",
130 [FR_PACKET_TYPE_VALUE_AUTHENTICATION_CONTINUE_ABORT] =
"Authentication-Continue-Abort",
132 [FR_PACKET_TYPE_VALUE_AUTHORIZATION_REQUEST] =
"Authorization-Request",
133 [FR_PACKET_TYPE_VALUE_AUTHORIZATION_PASS_ADD] =
"Authorization-Pass-Add",
134 [FR_PACKET_TYPE_VALUE_AUTHORIZATION_PASS_REPLACE] =
"Authorization-Pass-Replace",
135 [FR_PACKET_TYPE_VALUE_AUTHORIZATION_FAIL] =
"Authorization-Fail",
136 [FR_PACKET_TYPE_VALUE_AUTHORIZATION_ERROR] =
"Authorization-Error",
138 [FR_PACKET_TYPE_VALUE_ACCOUNTING_REQUEST] =
"Accounting-Request",
139 [FR_PACKET_TYPE_VALUE_ACCOUNTING_SUCCESS] =
"Accounting-Success",
140 [FR_PACKET_TYPE_VALUE_ACCOUNTING_ERROR] =
"Accounting-Error",
190 fr_strerror_const(
"Failed to encrypt/decrept the packet, as the secret has zero length.");
203 memcpy(&buf[
sizeof(pkt->
hdr.
session_id) + secret_len], &pkt->
hdr.version,
sizeof(pkt->
hdr.version));
208 end = body + body_len;
215 if (++body == end)
goto done;
251 if (buffer_len <
sizeof(pkt->
hdr)) {
252 return sizeof(pkt->
hdr);
283 if (buffer_len < length)
return length;
299 want =
sizeof(pkt->
hdr) +
sizeof(pkt->authen_start);
302 want =
sizeof(pkt->
hdr) +
sizeof(pkt->authen_cont);
306 want =
sizeof(pkt->
hdr) +
sizeof(pkt->authen_reply);
312 want =
sizeof(pkt->
hdr) +
sizeof(pkt->author_req);
315 want =
sizeof(pkt->
hdr) +
sizeof(pkt->author_reply);
321 want =
sizeof(pkt->
hdr) +
sizeof(pkt->acct_req);
324 want =
sizeof(pkt->
hdr) +
sizeof(pkt->acct_reply);
339 if (!datalen)
return;
348 if (!datalen)
return;
356 for (p =
data; p < (
data + datalen); p++) {
357 if ((*p < 0x20) || (*p > 0x80))
goto hex;
363 #define CHECK(_length) do { \
364 size_t plen = _length; \
365 if ((size_t) (end - p) < plen) { \
366 fr_log_hex(log, L_DBG, file, line, p, end - p, "%s", " TRUNCATED "); \
375 #define ASCII(_prefix, _field) do { \
377 print_ascii(log, file, line, _prefix, data, data_len); \
381 #define HEXIT(_prefix, _field) do { \
383 print_hex(log, file, line, _prefix, data, data_len); \
386 #define PRINT(_fmt, ...) fr_log(log, L_DBG, file, line, _fmt, ## __VA_ARGS__)
395 if (argv + arg_cnt > end) {
396 PRINT(
" ARG cnt overflows packet");
401 for (i = 0; i < arg_cnt; i++) {
403 PRINT(
" ARG[%zu] is at EOF", i);
407 if ((end - p) < argv[i]) {
408 PRINT(
" ARG[%zu] overflows packet", i);
413 snprintf(prefix,
sizeof(prefix),
" arg[%zu] ", i);
416 ASCII(prefix, argv[i]);
422 size_t length, data_len;
427 end = ((
uint8_t const *) packet) + packet_len;
429 if (packet_len < 12) {
437 PRINT(
" major %u", (p[0] & 0xf0) >> 4);
438 PRINT(
" minor %u", (p[0] & 0x0f));
440 PRINT(
" type %02x", p[1]);
441 PRINT(
" seq_no %02x", p[2]);
442 PRINT(
" flags %02x", p[3]);
450 if ((p[3] & 0x01) == 0) {
451 PRINT(
" ... encrypted ...");
455 if (length > 65535) {
463 if ((p + length) != end) {
464 PRINT(
"length field does not match input packet length %08lx", packet_len - 12);
468 #define REQUIRE(_length) do { \
469 size_t plen = _length; \
470 if ((size_t) (end - hdr) < plen) { \
471 print_hex(log, file, line, " TRUNCATED ", hdr, end - hdr); \
484 PRINT(
" authentication-start");
488 PRINT(
" action %02x", hdr[0]);
489 PRINT(
" priv_lvl %02x", hdr[1]);
490 PRINT(
" authen_type %02x", hdr[2]);
491 PRINT(
" authen_service %02x", hdr[3]);
492 PRINT(
" user_len %02x", hdr[4]);
493 PRINT(
" port_len %02x", hdr[5]);
494 PRINT(
" rem_addr_len %02x", hdr[6]);
495 PRINT(
" data_len %02x", hdr[7]);
497 ASCII(
" user ", hdr[4]);
498 ASCII(
" port ", hdr[5]);
499 ASCII(
" rem_addr ", hdr[6]);
500 HEXIT(
" data ", hdr[7]);
503 PRINT(
" authentication-continue");
509 PRINT(
" flags %02x", hdr[4]);
517 PRINT(
" authentication-reply");
521 PRINT(
" status %02x", hdr[0]);
522 PRINT(
" flags %02x", hdr[1]);
533 PRINT(
" authorization-request");
536 PRINT(
" auth_method %02x", hdr[0]);
537 PRINT(
" priv_lvl %02x", hdr[1]);
538 PRINT(
" authen_type %02x", hdr[2]);
539 PRINT(
" authen_service %02x", hdr[3]);
540 PRINT(
" user_len %02x", hdr[4]);
541 PRINT(
" port_len %02x", hdr[5]);
542 PRINT(
" rem_addr_len %02x", hdr[6]);
543 PRINT(
" arg_cnt %02x", hdr[7]);
546 HEXIT(
" argc ", hdr[7]);
547 ASCII(
" user ", hdr[4]);
548 ASCII(
" port ", hdr[5]);
549 ASCII(
" rem_addr ", hdr[6]);
554 PRINT(
" authorization-reply");
560 PRINT(
" status %02x", hdr[0]);
561 PRINT(
" arg_cnt %02x", hdr[1]);
566 HEXIT(
" argc ", hdr[1]);
576 PRINT(
" accounting-request");
580 PRINT(
" flags %02x", hdr[0]);
581 PRINT(
" auth_method %02x", hdr[1]);
582 PRINT(
" priv_lvl %02x", hdr[2]);
583 PRINT(
" authen_type %02x", hdr[3]);
584 PRINT(
" authen_service %02x", hdr[4]);
585 PRINT(
" user_len %02x", hdr[5]);
586 PRINT(
" port_len %02x", hdr[6]);
587 PRINT(
" rem_addr_len %02x", hdr[7]);
588 PRINT(
" arg_cnt %02x", hdr[8]);
591 HEXIT(
" argc ", hdr[8]);
592 ASCII(
" user ", hdr[5]);
593 ASCII(
" port ", hdr[6]);
594 ASCII(
" rem_addr ", hdr[7]);
598 PRINT(
" accounting-reply");
601 PRINT(
" authentication-reply");
607 PRINT(
" status %02x", hdr[0]);
static int const char char buffer[256]
#define fr_dict_autofree(_to_free)
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
#define fr_dict_autoload(_to_load)
Specifies an attribute which must be present for the module to function.
Specifies a dictionary which must be loaded/loadable for the module to function.
void fr_log_hex(fr_log_t const *log, fr_log_type_t type, char const *file, int line, uint8_t const *data, size_t data_len, char const *line_prefix_fmt,...)
Print out hex block.
void fr_log(fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *fmt,...)
Send a server log message to its destination.
@ L_DBG
Only displayed when debugging is enabled.
#define MD5_DIGEST_LENGTH
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_OCTETS
Raw octets.
void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Perform a single digest operation on a single input buffer.
static uint16_t fr_nbo_to_uint16(uint8_t const data[static sizeof(uint16_t)])
Read an unsigned 16bit integer from wire format (big endian)
static uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
Read an unsigned 32bit integer from wire format (big endian)
fr_dict_attr_t const * attr_tacacs_authentication_flags
int fr_tacacs_body_xor(fr_tacacs_packet_t const *pkt, uint8_t *body, size_t body_len, char const *secret, size_t secret_len)
XOR the body based on the secret key.
fr_dict_attr_t const * attr_tacacs_length
void _fr_tacacs_packet_log_hex(fr_log_t const *log, fr_tacacs_packet_t const *packet, size_t packet_len, char const *file, int line)
fr_dict_attr_autoload_t libfreeradius_tacacs_dict_attr[]
ssize_t fr_tacacs_length(uint8_t const *buffer, size_t buffer_len)
fr_dict_attr_t const * attr_tacacs_authentication_continue_flags
fr_dict_attr_t const * attr_tacacs_user_message
char const * fr_tacacs_packet_names[FR_TACACS_CODE_MAX]
static uint32_t instance_count
static void print_args(fr_log_t const *log, char const *file, int line, size_t arg_cnt, uint8_t const *argv, uint8_t const *start, uint8_t const *end)
void fr_tacacs_global_free(void)
fr_dict_t const * dict_tacacs
static void print_hex(fr_log_t const *log, char const *file, int line, char const *prefix, uint8_t const *data, size_t datalen)
fr_dict_attr_t const * attr_tacacs_argument_list
fr_dict_attr_t const * attr_tacacs_chap_challenge
int fr_tacacs_global_init(void)
fr_dict_attr_t const * attr_tacacs_user_password
fr_dict_attr_t const * attr_tacacs_session_id
fr_dict_attr_t const * attr_tacacs_server_message
fr_dict_attr_t const * attr_tacacs_version_major
#define HEXIT(_prefix, _field)
fr_dict_autoload_t libfreeradius_tacacs_dict[]
fr_dict_attr_t const * attr_tacacs_privilege_level
fr_dict_attr_t const * attr_tacacs_mschap_challenge
fr_dict_attr_t const * attr_tacacs_authentication_type
fr_dict_attr_t const * attr_tacacs_mschap_response
fr_dict_attr_t const * attr_tacacs_accounting_status
static void print_ascii(fr_log_t const *log, char const *file, int line, char const *prefix, uint8_t const *data, size_t datalen)
fr_dict_attr_t const * attr_tacacs_version_minor
fr_dict_attr_t const * attr_tacacs_mschap2_response
fr_dict_attr_t const * attr_tacacs_authentication_service
fr_dict_attr_t const * attr_tacacs_authentication_status
fr_dict_attr_t const * attr_tacacs_chap_password
fr_dict_attr_t const * attr_tacacs_packet
fr_dict_attr_t const * attr_tacacs_packet_body_type
fr_dict_attr_t const * attr_tacacs_client_port
fr_dict_attr_t const * attr_tacacs_remote_address
#define ASCII(_prefix, _field)
fr_dict_attr_t const * attr_tacacs_action
fr_dict_attr_t const * attr_tacacs_sequence_number
fr_dict_attr_t const * attr_tacacs_authorization_status
fr_dict_attr_t const * attr_tacacs_authentication_method
fr_dict_attr_t const * attr_tacacs_accounting_flags
fr_dict_attr_t const * attr_tacacs_data
fr_dict_attr_t const * attr_tacacs_user_name
fr_dict_attr_t const * attr_tacacs_flags
fr_dict_attr_t const * attr_tacacs_packet_type
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
#define packet_is_authen_reply(p)
#define packet_is_authen_continue(p)
#define packet_is_acct_reply(p)
#define packet_is_author_request(p)
#define packet_is_acct_request(p)
#define packet_is_authen_start_request(p)
3.4.
fr_tacacs_packet_hdr_t hdr
#define packet_is_author_reply(p)
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)