25 RCSID(
"$Id: 528c275eb46dbaa37217fad5ef400d2e7eeae531 $")
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
31 #define PW_CAST_BASE (1850)
33 #define GOTO_ERROR do { REDEBUG("Unexpected text at '%s'", p); goto error;} while (0)
42 UNUSED void const *mod_inst,
UNUSED void const *xlat_inst,
43 REQUEST *request,
char const *fmt)
45 char *data_name, *data_size, *data_type;
47 size_t len, input_len;
59 strlcpy(buffer, fmt,
sizeof(buffer));
62 while (isspace((
int) *p)) p++;
66 while (*p && !isspace((
int) *p)) p++;
70 REDEBUG(
"Format string should be '<data> <offset> <type>' e.g. '&Class 1 integer'");
75 while (isspace((
int) *p)) *(p++) =
'\0';
80 while (*p && !isspace((
int) *p)) p++;
83 while (isspace((
int) *p)) *(p++) =
'\0';
88 while (*p && !isspace((
int) *p)) p++;
94 if (*data_name ==
'&') {
99 REDEBUG(
"unpack requires the input attribute to be 'string' or 'octets'");
102 input = vp->vp_octets;
103 input_len = vp->vp_length;
105 }
else if ((data_name[0] ==
'0') && (data_name[1] ==
'x')) {
109 len = strlen(data_name + 2);
110 if ((len & 0x01) != 0) {
111 RDEBUG(
"Invalid hex string in '%s'", data_name);
115 input_len =
fr_hex2bin(blob,
sizeof(blob), data_name + 2, len);
121 offset = (int) strtoul(data_size, &p, 10);
123 REDEBUG(
"unpack requires a decimal number, not '%s'", data_size);
129 REDEBUG(
"Invalid data type '%s'", data_type);
138 REDEBUG(
"unpack requires fixed-size output type, not '%s'", data_type);
143 REDEBUG(
"Insufficient data to unpack '%s' from '%s'", data_type, data_name);
149 REDEBUG(
"Cannot decode type '%s'", data_type);
154 if (!cast)
goto nothing;
166 cast->vp_integer = ntohl(cast->vp_integer);
170 cast->vp_short = ((input[offset] << 8) | input[offset + 1]);
174 cast->vp_integer64 = ntohll(cast->vp_integer64);
184 REDEBUG(
"Insufficient buffer space to unpack data");
static ssize_t unpack_xlat(char **out, size_t outlen, UNUSED void const *mod_inst, UNUSED void const *xlat_inst, REQUEST *request, char const *fmt)
Unpack data.
int xlat_register(void *mod_inst, char const *name, xlat_func_t func, xlat_escape_t escape, xlat_instantiate_t instantiate, size_t inst_size, size_t buf_len)
Register an xlat function.
Metadata exported by the module.
const size_t dict_attr_sizes[PW_TYPE_MAX][2]
Map data types to min / max data sizes.
#define RLM_TYPE_THREAD_SAFE
Module is threadsafe.
void size_t fr_pair_value_snprint(char *out, size_t outlen, VALUE_PAIR const *vp, char quote)
Print the value of an attribute to a string.
#define XLAT_DEFAULT_BUF_LEN
#define is_truncated(_ret, _max)
int fr_str2int(FR_NAME_NUMBER const *table, char const *name, int def)
const FR_NAME_NUMBER dict_attr_types[]
Map data types to names representing those types.
size_t fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen)
Convert hex strings to binary data.
void void int radius_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name)
Return a VP from the specified request.
Stores an attribute, a value and various bits of other data.
Invalid (uninitialised) attribute type.
uint64_t magic
Used to validate module struct.
size_t strlcpy(char *dst, char const *src, size_t siz)
VALUE_PAIR * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute.
fr_dict_attr_t const * da
Dictionary attribute defines the attribute.
fr_dict_attr_t const * fr_dict_attr_by_num(fr_dict_t *dict, unsigned int vendor, unsigned int attr)
Lookup a fr_dict_attr_t by its vendor and attribute numbers.
String of printable characters.
static int mod_bootstrap(CONF_SECTION *conf, void *instance)
char const * cf_section_name2(CONF_SECTION const *cs)
PW_TYPE
Internal data types used within libfreeradius.