72 #define MIN_RADIUS_PDU_LEN 20 73 #define MAX_RADIUS_PDU_LEN 4095 84 for (i = 0; i < octets; ++i)
95 for (i = 0; i < octets; ++i)
127 pdu = gw_malloc(
sizeof(*pdu));
131 #define INTEGER(name, octets) \ 132 if (strcmp(#name, "code") == 0) p->name = type; \ 134 #define OCTETS(name, field_giving_octets) p->name = NULL; 135 #define PDU(name, id, fields) \ 137 struct name *p = &pdu->u.name; \ 138 pdu->type_name = #name; \ 143 error(0,
"Unknown RADIUS_PDU type, internal error.");
147 #define ATTR(attr, type, string, min, max) 148 #define UNASSIGNED(attr) 149 #define ATTRIBUTES(fields) \ 150 pdu->attr = dict_create(20, (void (*)(void *))octstr_destroy); 162 #define INTEGER(name, octets) p->name = 0; 163 #define OCTETS(name, field_giving_octets) octstr_destroy(p->name); 164 #define PDU(name, id, fields) \ 165 case id: { struct name *p = &pdu->u.name; fields } break; 168 error(0,
"Unknown RADIUS_PDU type, internal error while destroying.");
171 #define ATTR(attr, type, string, min, max) 172 #define UNASSIGNED(attr) 173 #define ATTRIBUTES(fields) dict_destroy(pdu->attr); 218 #define ATTR(atype, type, string, pmin, pmax) \ 220 Octstr *attr_strg = octstr_create(string); \ 221 Octstr *attr_val = dict_get(p->attr, attr_str); \ 222 if (attr_str != NULL) { \ 223 int attr_len = octstr_len(attr_val) + 2; \ 224 octstr_format_append(os, "%02X", atype); \ 225 octstr_append_data(os, (char*) &attr_len, 2); \ 226 radius_type_append(&os, type, pmin, pmax, attr_val); \ 228 octstr_destroy(attr_str); \ 230 #define UNASSIGNED(attr) 231 #define ATTRIBUTES(fields) 261 #define INTEGER(name, octets) \ 262 append_encoded_integer(os, p->name, octets); 263 #define OCTETS(name, field_giving_octets) \ 264 octstr_append(os, p->name); 265 #define PDU(name, id, fields) \ 266 case id: { struct name *p = &pdu->u.name; fields; oos = radius_attr_pack(pdu); \ 267 octstr_append(os, oos);octstr_destroy(oos); } break; 270 error(0,
"Unknown RADIUS_PDU type, internal error while packing.");
297 for (i = 0; i < 4; i++) {
307 panic(0,
"RADIUS: Attribute type %d does not exist.",
type);
316 #define ATTR(atype, type, string, pmin, pmax) \ 317 if (atype == attr_type) { \ 318 Octstr *tmp, *value; \ 319 if ((attr_len-2) < pmin || (attr_len-2) > pmax) { \ 320 error(0, "RADIUS: Attribute (%d) `%s' has invalid len %d, droppped.", \ 321 attr_type, string, (attr_len-2)); \ 324 attr_val = parse_get_octets(*context, attr_len - 2); \ 325 tmp = octstr_format("RADIUS: Attribute (%d) `%s', len %d", \ 326 attr_type, string, attr_len - 2); \ 327 value = radius_type_convert(type, attr_val); \ 328 octstr_destroy(attr_val); \ 329 octstr_dump_short(value, 0, octstr_get_cstr(tmp)); \ 330 octstr_destroy(tmp); \ 331 attr_str = octstr_create(string); \ 332 dict_put((*pdu)->attr, attr_str, value); \ 333 octstr_destroy(attr_str); \ 336 #define UNASSIGNED(attr) \ 337 if (attr == attr_type) { \ 338 error(0, "RADIUS: Attribute (%d) is unassigned and should not be used.", \ 342 #define ATTRIBUTES(fields) \ 343 while (parse_octets_left(*context) > 0 && !parse_error(*context)) { \ 344 int attr_type, attr_len; \ 345 Octstr *attr_val = NULL; \ 346 Octstr *attr_str = NULL; \ 347 attr_type = parse_get_char(*context); \ 348 attr_len = parse_get_char(*context); \ 351 debug("radius.unpack", 0, "RADIUS: Unknown attribute type (0x%03lx) " \ 352 "len %d in PDU `%s'.", \ 353 (long unsigned int)attr_type, attr_len, (*pdu)->type_name); \ 354 parse_skip(*context, attr_len - 2); \ 371 error(0,
"RADIUS: PDU was too short (%ld bytes).",
386 debug(
"radius", 0,
"RADIUS: Attributes len is %ld", len);
396 #define INTEGER(name, octets) \ 397 pos = octstr_len(data_without_len) - parse_octets_left(context); \ 398 p->name = decode_integer(data_without_len, pos, octets); \ 399 parse_skip(context, octets); 400 #define OCTETS(name, field_giving_octets) \ 401 p->name = parse_get_octets(context, field_giving_octets); 402 #define PDU(name, id, fields) \ 403 case id: { struct name *p = &pdu->u.name; fields; \ 404 radius_attr_unpack(&context, &pdu); } break; 407 error(0,
"Unknown RADIUS_PDU type, internal error while unpacking.");
423 stream = attributes = digest = NULL;
437 digest =
md5(stream);
439 digest) == 0 ? 1 : 0;
444 digest =
md5(stream);
461 #define UNASSIGNED(attr) 462 #define ATTR(atype, type, string, pmin, pmax) \ 464 key = octstr_create(string); \ 465 val = dict_get(pdu->attr, key); \ 467 octstr_dump_short(val, 2, #atype); \ 469 #define ATTRIBUTES(fields) \ 470 if (pdu->attr != NULL) { \ 471 Octstr *key = NULL, *val = NULL; \ 480 debug(
"radius", 0,
"RADIUS PDU %p dump:", (
void *) pdu);
481 debug(
"radius", 0,
" type_name: %s", pdu->type_name);
483 #define INTEGER(name, octets) \ 484 debug("radius", 0, " %s: %lu = 0x%08lx", #name, p->name, p->name); 485 #define OCTETS(name, field_giving_octets) \ 486 octstr_dump_short(p->name, 2, #name); 487 #define PDU(name, id, fields) \ 488 case id: { struct name *p = &pdu->u.name; fields; \ 489 radius_attr_dump(pdu); } break; 492 error(0,
"Unknown RADIUS_PDU type, internal error.");
495 debug(
"radius", 0,
"RADIUS PDU dump ends.");
502 if (pdu->
attr == NULL)
void error(int err, const char *fmt,...)
Octstr * md5(Octstr *data)
void octstr_append_data(Octstr *ostr, const char *data, long len)
int parse_get_char(ParseContext *context)
gw_assert(wtls_machine->packet_to_send !=NULL)
Octstr * radius_get_attribute(RADIUS_PDU *pdu, Octstr *attribute)
RADIUS_PDU * radius_pdu_unpack(Octstr *data_without_len)
static void radius_attr_dump(RADIUS_PDU *pdu)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
void octstr_append_char(Octstr *ostr, int ch)
void octstr_dump_short(Octstr *ostr, int level, const char *name)
static Octstr * radius_type_convert(int type, Octstr *value)
void octstr_append_cstr(Octstr *ostr, const char *cstr)
static void radius_attr_unpack(ParseContext **context, RADIUS_PDU **pdu)
#define octstr_get_cstr(ostr)
#define octstr_copy(ostr, from, len)
void radius_pdu_destroy(RADIUS_PDU *pdu)
int radius_authenticate_pdu(RADIUS_PDU *pdu, Octstr **data, Octstr *secret)
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
void * dict_get(Dict *dict, Octstr *key)
void octstr_delete(Octstr *ostr1, long pos, long len)
Octstr * parse_get_octets(ParseContext *context, long length)
#define octstr_duplicate(ostr)
static void append_encoded_integer(Octstr *os, unsigned long u, long octets)
Octstr * octstr_format(const char *fmt,...)
void octstr_destroy(Octstr *ostr)
#define octstr_create(cstr)
long octstr_len(const Octstr *ostr)
int parse_skip(ParseContext *context, long count)
void parse_context_destroy(ParseContext *context)
RADIUS_PDU * radius_pdu_create(int type, RADIUS_PDU *req)
void debug(const char *place, int err, const char *fmt,...)
static unsigned long decode_integer(Octstr *os, long pos, int octets)
void radius_pdu_dump(RADIUS_PDU *pdu)
static Octstr * radius_attr_pack(RADIUS_PDU *pdu)
Octstr * radius_pdu_pack(RADIUS_PDU *pdu)
int octstr_get_char(const Octstr *ostr, long pos)
ParseContext * parse_context_create(Octstr *str)
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)