#include "gwlib/gwlib.h"#include "gwlib/dict.h"#include "radius_attributes.def"#include "radius_pdu.def"Include dependency graph for radius_pdu.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | RADIUS_PDU |
Defines | |
| #define | ATTR(attr, type, string, min, max) |
| #define | UNASSIGNED(attr) |
| #define | ATTRIBUTES(fields) |
| #define | INTEGER(name, octets) |
| #define | OCTETS(name, field_giving_octets) |
| #define | PDU(name, id, fields) name = id, |
| #define | ATTR(attr, type, string, min, max) |
| #define | UNASSIGNED(attr) |
| #define | ATTRIBUTES(fields) |
| #define | INTEGER(name, octets) unsigned long name; |
| #define | NULTERMINATED(name, max_octets) Octstr *name; |
| #define | OCTETS(name, field_giving_octets) Octstr *name; |
| #define | PDU(name, id, fields) struct name { fields } name; |
Typedefs | |
| typedef RADIUS_PDU | RADIUS_PDU |
Enumerations | |
| enum | { t_int, t_string, t_ipaddr } |
| enum | { attr, type, string, min, attr, attr, attr, string, min, name, name, name, id, Accounting_Request, x04, Accounting_Response, x05, RADIUS_PDU_DUMMY_TYPE } |
Functions | |
| RADIUS_PDU * | radius_pdu_create (int type, RADIUS_PDU *req) |
| void | radius_pdu_destroy (RADIUS_PDU *pdu) |
| int | radius_authenticate_pdu (RADIUS_PDU *pdu, Octstr **data, Octstr *secret) |
| Octstr * | radius_pdu_pack (RADIUS_PDU *pdu) |
| RADIUS_PDU * | radius_pdu_unpack (Octstr *data_without_len) |
| void | radius_pdu_dump (RADIUS_PDU *pdu) |
| Octstr * | radius_get_attribute (RADIUS_PDU *pdu, Octstr *attribute) |
|
|
Definition at line 95 of file radius_pdu.h. |
|
|
Definition at line 95 of file radius_pdu.h. |
|
|
Definition at line 97 of file radius_pdu.h. |
|
|
Definition at line 97 of file radius_pdu.h. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 96 of file radius_pdu.h. |
|
|
Definition at line 96 of file radius_pdu.h. |
|
|
Definition at line 89 of file radius_pdu.h. |
|
|
Definition at line 72 of file radius_pdu.h. 00072 {
00073 t_int, t_string, t_ipaddr
00074 };
|
|
|
Definition at line 76 of file radius_pdu.h. 00076 {
00077 #define ATTR(attr, type, string, min, max)
00078 #define UNASSIGNED(attr)
00079 #define ATTRIBUTES(fields)
00080 #include "radius_attributes.def"
00081 #define INTEGER(name, octets)
00082 #define OCTETS(name, field_giving_octets)
00083 #define PDU(name, id, fields) name = id,
00084 #include "radius_pdu.def"
00085 RADIUS_PDU_DUMMY_TYPE
00086 };
|
|
||||||||||||||||
|
Definition at line 416 of file radius_pdu.c. References data, md5(), octstr_append(), octstr_append_data(), octstr_compare(), octstr_copy, octstr_delete(), octstr_destroy(), octstr_duplicate, octstr_insert(), octstr_len(), pdu, RADIUS_PDU::type, and RADIUS_PDU::u. Referenced by main(), proxy_thread(), and server(). 00417 {
00418 int rc = 0;
00419 Octstr *stream;
00420 Octstr *attributes;
00421 Octstr *digest;
00422
00423 stream = attributes = digest = NULL;
00424
00425 /* first extract attributes from raw data, where
00426 * the first 20 octets are code, idendifier, length
00427 * and authenticator value as described in RFC2866, sec. 3 */
00428 if (octstr_len(*data) > 20)
00429 attributes = octstr_copy(*data, 20, octstr_len(*data)-20);
00430
00431 switch (pdu->type) {
00432 case 0x04: /* Accounting-Request, see RFC2866, page 6 */
00433 stream = octstr_copy(*data, 0, 4);
00434 octstr_append_data(stream, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16);
00435 octstr_append(stream, attributes);
00436 octstr_append(stream, secret);
00437 digest = md5(stream);
00438 rc = octstr_compare(pdu->u.Accounting_Request.authenticator,
00439 digest) == 0 ? 1 : 0;
00440 break;
00441 case 0x05: /* Accounting-Response, create Response authenticator */
00442 stream = octstr_duplicate(*data);
00443 octstr_append(stream, secret);
00444 digest = md5(stream);
00445 octstr_delete(*data, 4, 16);
00446 octstr_insert(*data, digest, 4);
00447 break;
00448 default:
00449 break;
00450 }
00451
00452 octstr_destroy(attributes);
00453 octstr_destroy(stream);
00454 octstr_destroy(digest);
00455
00456 return rc;
00457 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 498 of file radius_pdu.c. References RADIUS_PDU::attr, dict_get(), gw_assert, and pdu. 00499 {
00500 gw_assert(pdu != NULL);
00501
00502 if (pdu->attr == NULL)
00503 return NULL;
00504
00505 return dict_get(pdu->attr, attribute);
00506 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 123 of file radius_pdu.c. References error(), pdu, and RADIUS_PDU::type. Referenced by main(), proxy_thread(), radius_pdu_unpack(), and server(). 00124 {
00125 RADIUS_PDU *pdu;
00126
00127 pdu = gw_malloc(sizeof(*pdu));
00128 pdu->type = type;
00129
00130 switch (type) {
00131 #define INTEGER(name, octets) \
00132 if (strcmp(#name, "code") == 0) p->name = type; \
00133 else p->name = 0;
00134 #define OCTETS(name, field_giving_octets) p->name = NULL;
00135 #define PDU(name, id, fields) \
00136 case id: { \
00137 struct name *p = &pdu->u.name; \
00138 pdu->type_name = #name; \
00139 fields \
00140 } break;
00141 #include "radius_pdu.def"
00142 default:
00143 error(0, "Unknown RADIUS_PDU type, internal error.");
00144 gw_free(pdu);
00145 return NULL;
00146 }
00147 #define ATTR(attr, type, string, min, max)
00148 #define UNASSIGNED(attr)
00149 #define ATTRIBUTES(fields) \
00150 pdu->attr = dict_create(20, (void (*)(void *))octstr_destroy);
00151 #include "radius_attributes.def"
00152
00153 return pdu;
00154 }
|
Here is the call graph for this function:

|
|
Definition at line 156 of file radius_pdu.c. References error(), pdu, and RADIUS_PDU::type. Referenced by main(), proxy_thread(), and server(). 00157 {
00158 if (pdu == NULL)
00159 return;
00160
00161 switch (pdu->type) {
00162 #define INTEGER(name, octets) p->name = 0;
00163 #define OCTETS(name, field_giving_octets) octstr_destroy(p->name);
00164 #define PDU(name, id, fields) \
00165 case id: { struct name *p = &pdu->u.name; fields } break;
00166 #include "radius_pdu.def"
00167 default:
00168 error(0, "Unknown RADIUS_PDU type, internal error while destroying.");
00169 }
00170
00171 #define ATTR(attr, type, string, min, max)
00172 #define UNASSIGNED(attr)
00173 #define ATTRIBUTES(fields) dict_destroy(pdu->attr);
00174 #include "radius_attributes.def"
00175
00176 gw_free(pdu);
00177 }
|
Here is the call graph for this function:

|
|
Definition at line 478 of file radius_pdu.c. References debug(), error(), and pdu. 00479 {
00480 debug("radius", 0, "RADIUS PDU %p dump:", (void *) pdu);
00481 debug("radius", 0, " type_name: %s", pdu->type_name);
00482 switch (pdu->type) {
00483 #define INTEGER(name, octets) \
00484 debug("radius", 0, " %s: %lu = 0x%08lx", #name, p->name, p->name);
00485 #define OCTETS(name, field_giving_octets) \
00486 octstr_dump_short(p->name, 2, #name);
00487 #define PDU(name, id, fields) \
00488 case id: { struct name *p = &pdu->u.name; fields; \
00489 radius_attr_dump(pdu); } break;
00490 #include "radius_pdu.def"
00491 default:
00492 error(0, "Unknown RADIUS_PDU type, internal error.");
00493 break;
00494 }
00495 debug("radius", 0, "RADIUS PDU dump ends.");
00496 }
|
Here is the call graph for this function:

|
|
Definition at line 237 of file radius_pdu.c. References append_encoded_integer(), error(), gw_assert, octstr_create, octstr_delete(), octstr_destroy(), octstr_insert(), octstr_len(), pdu, and RADIUS_PDU::type. Referenced by main(), proxy_thread(), and server(). 00238 {
00239 Octstr *os,*oos;
00240 Octstr *temp;
00241
00242 os = octstr_create("");
00243
00244 gw_assert(pdu != NULL);
00245
00246 /*
00247 switch (pdu->type) {
00248 #define INTEGER(name, octets) p = *(&p);
00249 #define NULTERMINATED(name, max_octets) p = *(&p);
00250 #define OCTETS(name, field_giving_octets) \
00251 p->field_giving_octets = octstr_len(p->name);
00252 #define PDU(name, id, fields) \
00253 case id: { struct name *p = &pdu->u.name; fields } break;
00254 #include "radius_pdu.def"
00255 default:
00256 error(0, "Unknown RADIUS_PDU type, internal error while packing.");
00257 }
00258 */
00259
00260 switch (pdu->type) {
00261 #define INTEGER(name, octets) \
00262 append_encoded_integer(os, p->name, octets);
00263 #define OCTETS(name, field_giving_octets) \
00264 octstr_append(os, p->name);
00265 #define PDU(name, id, fields) \
00266 case id: { struct name *p = &pdu->u.name; fields; oos = radius_attr_pack(pdu); \
00267 octstr_append(os, oos);octstr_destroy(oos); } break;
00268 #include "radius_pdu.def"
00269 default:
00270 error(0, "Unknown RADIUS_PDU type, internal error while packing.");
00271 }
00272
00273 /* now set PDU length */
00274 temp = octstr_create("");
00275 append_encoded_integer(temp, octstr_len(os), 2);
00276 octstr_delete(os, 2, 2);
00277 octstr_insert(os, temp, 2);
00278 octstr_destroy(temp);
00279
00280 return os;
00281 }
|
Here is the call graph for this function:

|
|
Definition at line 360 of file radius_pdu.c. References debug(), decode_integer(), error(), octstr_destroy(), octstr_dump_short(), octstr_len(), parse_context_create(), parse_context_destroy(), parse_get_char(), parse_get_octets(), parse_skip(), ParseContext, pdu, radius_pdu_create(), and type. Referenced by main(), proxy_thread(), and server(). 00361 {
00362 RADIUS_PDU *pdu;
00363 int type, ident;
00364 long len, pos;
00365 ParseContext *context;
00366 Octstr *authenticator;
00367
00368 len = octstr_len(data_without_len);
00369
00370 if (len < 20) {
00371 error(0, "RADIUS: PDU was too short (%ld bytes).",
00372 octstr_len(data_without_len));
00373 return NULL;
00374 }
00375
00376 context = parse_context_create(data_without_len);
00377
00378 type = parse_get_char(context);
00379 ident = parse_get_char(context);
00380 pdu = radius_pdu_create(type, NULL);
00381 if (pdu == NULL)
00382 return NULL;
00383
00384 len = decode_integer(data_without_len, 2, 2) - 19;
00385 parse_skip(context, 2);
00386 debug("radius", 0, "RADIUS: Attributes len is %ld", len);
00387
00388 authenticator = parse_get_octets(context, 16);
00389 octstr_dump_short(authenticator, 0, "RADIUS: Authenticator (md5) is:");
00390
00391 /* skipping back to context start for macro magic */
00392 parse_context_destroy(context);
00393 context = parse_context_create(data_without_len);
00394
00395 switch (type) {
00396 #define INTEGER(name, octets) \
00397 pos = octstr_len(data_without_len) - parse_octets_left(context); \
00398 p->name = decode_integer(data_without_len, pos, octets); \
00399 parse_skip(context, octets);
00400 #define OCTETS(name, field_giving_octets) \
00401 p->name = parse_get_octets(context, field_giving_octets);
00402 #define PDU(name, id, fields) \
00403 case id: { struct name *p = &pdu->u.name; fields; \
00404 radius_attr_unpack(&context, &pdu); } break;
00405 #include "radius_pdu.def"
00406 default:
00407 error(0, "Unknown RADIUS_PDU type, internal error while unpacking.");
00408 }
00409
00410 parse_context_destroy(context);
00411 octstr_destroy(authenticator);
00412
00413 return pdu;
00414 }
|
Here is the call graph for this function:
