26 RCSID(
"$Id: 106a0161b95d8eda0f0ec116748046c932ff947e $")
28 #include <freeradius-devel/util/udp.h>
30 #include <freeradius-devel/io/test_point.h>
80 if (data_len == 0)
return -1;
89 end = (
data + data_len);
96 vp->vp_uint16 = opcode;
101 case FR_OPCODE_VALUE_READ_REQUEST:
102 case FR_OPCODE_VALUE_WRITE_REQUEST:
112 if (*(end - 1) !=
'\0')
goto error_malformed;
115 if (!isalnum(p[0])) {
121 q = memchr(p,
'\0', (end - p));
122 if (!(q && q[0] ==
'\0')) {
136 q = memchr(p,
'\0', (end - p));
137 if (!(q && q[0] ==
'\0'))
goto error_malformed;
143 if ((q - p) == 5 && !memcmp(p,
"octet", 5)) {
145 vp->vp_uint8 = FR_MODE_VALUE_OCTET;
146 }
else if ((q - p) == 5 && !memcmp(p,
"ascii", 5)) {
148 vp->vp_uint8 = FR_MODE_VALUE_ASCII;
149 }
else if ((q - p) == 8 && !memcmp(p,
"netascii", 8)) {
151 vp->vp_uint8 = FR_MODE_VALUE_ASCII;
160 if (p >= end)
goto done;
166 if ((end - p) < 10)
goto error_malformed;
168 if (!memcmp(p,
"blksize\0", 8)) {
174 if (p >= end || (end - p) < 1 || (end - p) > 6)
goto error_malformed;
179 blksize = strtol((
const char *)p, &p_end, 10);
192 case FR_OPCODE_VALUE_ACKNOWLEDGEMENT:
193 case FR_OPCODE_VALUE_DATA:
218 if (opcode != FR_OPCODE_VALUE_DATA)
goto done;
220 if ((p + 2) >= end)
goto error_malformed;
232 case FR_OPCODE_VALUE_ERROR:
242 if ((p + 2) >= end)
goto error_malformed;
252 q = memchr(p,
'\0', (end - p));
253 if (!q || q[0] !=
'\0')
goto error_malformed;
302 if (!test_ctx)
return -1;
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)
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.
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.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
int fr_pair_value_bstrndup(fr_pair_t *vp, char const *src, size_t len, bool tainted)
Copy data into a "string" type value pair.
HIDDEN fr_dict_attr_t const * attr_tftp_error_code
HIDDEN fr_dict_attr_t const * attr_tftp_filename
HIDDEN fr_dict_attr_t const * attr_tftp_block_size
HIDDEN fr_dict_attr_t const * attr_tftp_opcode
HIDDEN fr_dict_attr_t const * attr_tftp_mode
HIDDEN fr_dict_attr_t const * attr_tftp_data
HIDDEN fr_dict_attr_t const * attr_tftp_block
HIDDEN fr_dict_attr_t const * attr_tftp_error_message
int fr_tftp_global_init(void)
void fr_tftp_global_free(void)
fr_test_point_proto_decode_t tftp_tp_decode_proto
static ssize_t fr_tftp_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, UNUSED void *proto_ctx)
static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
int fr_tftp_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len)
static int _decode_test_ctx(UNUSED fr_tftp_ctx_t *proto_ctx)
Stores an attribute, a value and various bits of other data.
fr_test_point_ctx_alloc_t test_ctx
Allocate a test ctx for the encoder.
Entry point for protocol decoders.
Functions to encode/decode TFTP packets.
#define FR_TFTP_BLOCK_MAX_SIZE
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
static size_t char ** out