The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
decode.c File Reference

Low-Level TACACS+ decoding functions. More...

#include <freeradius-devel/io/test_point.h>
#include <freeradius-devel/protocol/tacacs/tacacs.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/net.h>
#include <freeradius-devel/util/struct.h>
#include "tacacs.h"
#include "attrs.h"
+ Include dependency graph for decode.c:

Go to the source code of this file.

Macros

#define ARG_COUNT_CHECK(_msg, _hdr)
 
#define BODY(_x)   (((uint8_t const *) pkt) + sizeof(pkt->hdr) + sizeof(pkt->_x))
 
#define DECODE_FIELD_STRING16(_da, _field)
 
#define DECODE_FIELD_STRING8(_da, _field)
 
#define DECODE_FIELD_UINT8(_da, _field)
 
#define PACKET_HEADER_CHECK(_msg, _hdr)
 

Functions

static int _encode_test_ctx (fr_tacacs_ctx_t *proto_ctx)
 
static int decode_test_ctx (void **out, TALLOC_CTX *ctx)
 
ssize_t fr_tacacs_decode (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *vendor, uint8_t const *buffer, size_t buffer_len, const uint8_t *original, char const *const secret, size_t secret_len, int *code)
 Decode a TACACS+ packet. More...
 
static ssize_t fr_tacacs_decode_proto (TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, void *proto_ctx)
 
int fr_tacacs_packet_to_code (fr_tacacs_packet_t const *pkt)
 
static int tacacs_decode_args (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t arg_cnt, uint8_t const *argv, uint8_t const *attrs, NDEBUG_UNUSED uint8_t const *end)
 Decode a TACACS+ 'arg_N' fields. More...
 
static int tacacs_decode_field (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *da, uint8_t const **field_data, uint16_t field_len, uint8_t const *end)
 Decode a TACACS+ field. More...
 

Variables

fr_test_point_proto_decode_t tacacs_tp_decode_proto
 

Detailed Description

Low-Level TACACS+ decoding functions.

Id
65119e48ca57ab616f5788f3c64847b1039f66e4

Definition in file decode.c.

Macro Definition Documentation

◆ ARG_COUNT_CHECK

#define ARG_COUNT_CHECK (   _msg,
  _hdr 
)
Value:
do { \
fr_assert(p == (uint8_t const *) &(_hdr)); \
if (data_len > (size_t) (end - p)) { \
fr_strerror_printf("Argument count %u overflows the remaining data (%zu) in the %s packet", _hdr.arg_cnt, end - p, _msg); \
goto fail; \
} \
argv = body; \
attrs = buffer + FR_HEADER_LENGTH + data_len; \
body += _hdr.arg_cnt; \
p = attrs; \
for (int i = 0; i < _hdr.arg_cnt; i++) { \
if (_hdr.arg_len[i] > (size_t) (end - p)) { \
fr_strerror_printf("Argument %u length %u overflows packet", i, _hdr.arg_len[i]); \
goto fail; \
} \
p += _hdr.arg_len[i]; \
} \
} while (0)
static int const char char buffer[256]
Definition: acutest.h:574
unsigned char uint8_t
Definition: merged_model.c:30
#define FR_HEADER_LENGTH
Definition: tacacs.h:26

Definition at line 140 of file decode.c.

◆ BODY

#define BODY (   _x)    (((uint8_t const *) pkt) + sizeof(pkt->hdr) + sizeof(pkt->_x))

Definition at line 176 of file decode.c.

◆ DECODE_FIELD_STRING16

#define DECODE_FIELD_STRING16 (   _da,
  _field 
)
Value:
do { \
if (tacacs_decode_field(ctx, out, _da, &p, \
ntohs(_field), end) < 0) goto fail; \
} while (0)
while(1)
Definition: acutest.h:856
static int tacacs_decode_field(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *da, uint8_t const **field_data, uint16_t field_len, uint8_t const *end)
Decode a TACACS+ field.
Definition: decode.c:371
static size_t char ** out
Definition: value.h:997

Definition at line 171 of file decode.c.

◆ DECODE_FIELD_STRING8

#define DECODE_FIELD_STRING8 (   _da,
  _field 
)
Value:
do { \
if (tacacs_decode_field(ctx, out, _da, &p, \
_field, end) < 0) goto fail; \
} while (0)

Definition at line 166 of file decode.c.

◆ DECODE_FIELD_UINT8

#define DECODE_FIELD_UINT8 (   _da,
  _field 
)
Value:
do { \
vp = fr_pair_afrom_da(ctx, _da); \
if (!vp) goto fail; \
vp->vp_uint8 = _field; \
fr_pair_append(out, vp); \
} while (0)
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:283
fr_pair_t * vp

Definition at line 159 of file decode.c.

◆ PACKET_HEADER_CHECK

#define PACKET_HEADER_CHECK (   _msg,
  _hdr 
)
Value:
do { \
if (sizeof(_hdr) > (size_t) (end - p)) { \
fr_strerror_printf("Header for %s is too small (%zu < %zu)", _msg, end - (uint8_t const *) pkt, p - (uint8_t const *) pkt); \
goto fail; \
} \
body = p + sizeof(_hdr); \
data_len = sizeof(_hdr); \
} while (0)

Definition at line 127 of file decode.c.

Function Documentation

◆ _encode_test_ctx()

static int _encode_test_ctx ( fr_tacacs_ctx_t proto_ctx)
static

Definition at line 1082 of file decode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode_test_ctx()

static int decode_test_ctx ( void **  out,
TALLOC_CTX *  ctx 
)
static

Definition at line 1091 of file decode.c.

+ Here is the call graph for this function:

◆ fr_tacacs_decode()

ssize_t fr_tacacs_decode ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  vendor,
uint8_t const *  buffer,
size_t  buffer_len,
const uint8_t original,
char const *const  secret,
size_t  secret_len,
int *  code 
)

Decode a TACACS+ packet.

4.1. The Authentication START Packet Body

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 +-------------—+-------------—+-------------—+-------------—+ | action | priv_lvl | authen_type | authen_service | +-------------—+-------------—+-------------—+-------------—+ | user_len | port_len | rem_addr_len | data_len | +-------------—+-------------—+-------------—+-------------—+ | user ... +-------------—+-------------—+-------------—+-------------—+ | port ... +-------------—+-------------—+-------------—+-------------—+ | rem_addr ... +-------------—+-------------—+-------------—+-------------—+ | data... +-------------—+-------------—+-------------—+-------------—+

6.1. The Account REQUEST Packet Body

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 +-------------—+-------------—+-------------—+-------------—+ | flags | authen_method | priv_lvl | authen_type | +-------------—+-------------—+-------------—+-------------—+ | authen_service | user_len | port_len | rem_addr_len | +-------------—+-------------—+-------------—+-------------—+ | arg_cnt | arg_1_len | arg_2_len | ... | +-------------—+-------------—+-------------—+-------------—+ | arg_N_len | user ... +-------------—+-------------—+-------------—+-------------—+ | port ... +-------------—+-------------—+-------------—+-------------—+ | rem_addr ... +-------------—+-------------—+-------------—+-------------—+ | arg_1 ... +-------------—+-------------—+-------------—+-------------—+ | arg_2 ... +-------------—+-------------—+-------------—+-------------—+ | ... +-------------—+-------------—+-------------—+-------------—+ | arg_N ... +-------------—+-------------—+-------------—+-------------—+

6.2. The Accounting REPLY Packet Body

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 +-------------—+-------------—+-------------—+-------------—+ | server_msg len | data_len | +-------------—+-------------—+-------------—+-------------—+ | status | server_msg ... +-------------—+-------------—+-------------—+-------------—+ | data ... +-------------—+

Definition at line 409 of file decode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_tacacs_decode_proto()

static ssize_t fr_tacacs_decode_proto ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
uint8_t const *  data,
size_t  data_len,
void *  proto_ctx 
)
static

Definition at line 1070 of file decode.c.

+ Here is the call graph for this function:

◆ fr_tacacs_packet_to_code()

int fr_tacacs_packet_to_code ( fr_tacacs_packet_t const *  pkt)

Definition at line 36 of file decode.c.

+ Here is the caller graph for this function:

◆ tacacs_decode_args()

static int tacacs_decode_args ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t  arg_cnt,
uint8_t const *  argv,
uint8_t const *  attrs,
NDEBUG_UNUSED uint8_t const *  end 
)
static

Decode a TACACS+ 'arg_N' fields.

Definition at line 181 of file decode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tacacs_decode_field()

static int tacacs_decode_field ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  da,
uint8_t const **  field_data,
uint16_t  field_len,
uint8_t const *  end 
)
static

Decode a TACACS+ field.

Definition at line 371 of file decode.c.

+ Here is the call graph for this function:

Variable Documentation

◆ tacacs_tp_decode_proto

fr_test_point_proto_decode_t tacacs_tp_decode_proto
Initial value:
= {
.test_ctx = decode_test_ctx,
}
static ssize_t fr_tacacs_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, void *proto_ctx)
Definition: decode.c:1070
static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
Definition: decode.c:1091

Definition at line 1110 of file decode.c.