|
Lines 42-53
Link Here
|
| 42 |
#include <string.h> |
42 |
#include <string.h> |
| 43 |
#include <unistd.h> |
43 |
#include <unistd.h> |
| 44 |
|
44 |
|
|
|
45 |
/* For FreeBSD 2.2.8-STABLE */ |
| 46 |
#ifndef __printflike |
| 47 |
#define __printflike(x,y) |
| 48 |
#endif |
| 49 |
|
| 45 |
#include "radlib_private.h" |
50 |
#include "radlib_private.h" |
| 46 |
|
51 |
|
| 47 |
static void clear_password(struct rad_handle *); |
52 |
static void clear_password(struct rad_handle *); |
| 48 |
static void generr(struct rad_handle *, const char *, ...) |
53 |
static void generr(struct rad_handle *, const char *, ...) |
| 49 |
__printflike(2, 3); |
54 |
__printflike(2, 3); |
| 50 |
static void insert_scrambled_password(struct rad_handle *, int); |
55 |
static void insert_scrambled_password(struct rad_handle *, int); |
|
|
56 |
static void insert_request_authenticator(struct rad_handle *, int); |
| 51 |
static int is_valid_response(struct rad_handle *, int, |
57 |
static int is_valid_response(struct rad_handle *, int, |
| 52 |
const struct sockaddr_in *); |
58 |
const struct sockaddr_in *); |
| 53 |
static int put_password_attr(struct rad_handle *, int, |
59 |
static int put_password_attr(struct rad_handle *, int, |
|
Lines 110-115
Link Here
|
| 110 |
} |
116 |
} |
| 111 |
} |
117 |
} |
| 112 |
|
118 |
|
|
|
119 |
static void |
| 120 |
insert_request_authenticator(struct rad_handle *h, int srv) |
| 121 |
{ |
| 122 |
MD5_CTX ctx; |
| 123 |
const struct rad_server *srvp; |
| 124 |
|
| 125 |
srvp = &h->servers[srv]; |
| 126 |
|
| 127 |
/* Create the request authenticator */ |
| 128 |
MD5Init(&ctx); |
| 129 |
MD5Update(&ctx, &h->request[POS_CODE], POS_AUTH - POS_CODE); |
| 130 |
MD5Update(&ctx, memset(&h->request[POS_AUTH], 0, LEN_AUTH), LEN_AUTH); |
| 131 |
MD5Update(&ctx, &h->request[POS_ATTRS], h->req_len - POS_ATTRS); |
| 132 |
MD5Update(&ctx, srvp->secret, strlen(srvp->secret)); |
| 133 |
MD5Final(&h->request[POS_AUTH], &ctx); |
| 134 |
} |
| 135 |
|
| 113 |
/* |
136 |
/* |
| 114 |
* Return true if the current response is valid for a request to the |
137 |
* Return true if the current response is valid for a request to the |
| 115 |
* specified server. |
138 |
* specified server. |
|
Lines 229-237
Link Here
|
| 229 |
else { |
252 |
else { |
| 230 |
struct servent *sent; |
253 |
struct servent *sent; |
| 231 |
|
254 |
|
| 232 |
srvp->addr.sin_port = |
255 |
if (h->type == RADIUS_AUTH) |
| 233 |
(sent = getservbyname("radius", "udp")) != NULL ? |
256 |
srvp->addr.sin_port = |
| 234 |
sent->s_port : htons(RADIUS_PORT); |
257 |
(sent = getservbyname("radius", "udp")) != NULL ? |
|
|
258 |
sent->s_port : htons(RADIUS_PORT); |
| 259 |
else |
| 260 |
srvp->addr.sin_port = |
| 261 |
(sent = getservbyname("radacct", "udp")) != NULL ? |
| 262 |
sent->s_port : htons(RADACCT_PORT); |
| 235 |
} |
263 |
} |
| 236 |
if ((srvp->secret = strdup(secret)) == NULL) { |
264 |
if ((srvp->secret = strdup(secret)) == NULL) { |
| 237 |
generr(h, "Out of memory"); |
265 |
generr(h, "Out of memory"); |
|
Lines 269-275
Link Here
|
| 269 |
int retval; |
297 |
int retval; |
| 270 |
|
298 |
|
| 271 |
if (path == NULL) |
299 |
if (path == NULL) |
| 272 |
path = PATH_RADIUS_CONF; |
300 |
path = (h->type == RADIUS_AUTH) |
|
|
301 |
? PATH_RADIUS_CONF : PATH_RADACCT_CONF; |
| 273 |
if ((fp = fopen(path, "r")) == NULL) { |
302 |
if ((fp = fopen(path, "r")) == NULL) { |
| 274 |
generr(h, "Cannot open \"%s\": %s", path, strerror(errno)); |
303 |
generr(h, "Cannot open \"%s\": %s", path, strerror(errno)); |
| 275 |
return -1; |
304 |
return -1; |
|
Lines 421-429
Link Here
|
| 421 |
if (++h->srv >= h->num_servers) |
450 |
if (++h->srv >= h->num_servers) |
| 422 |
h->srv = 0; |
451 |
h->srv = 0; |
| 423 |
|
452 |
|
| 424 |
/* Insert the scrambled password into the request */ |
453 |
if (h->request[POS_CODE] == RAD_ACCOUNTING_REQUEST) |
| 425 |
if (h->pass_pos != 0) |
454 |
/* Insert the request authenticator into the request */ |
| 426 |
insert_scrambled_password(h, h->srv); |
455 |
insert_request_authenticator(h, h->srv); |
|
|
456 |
else |
| 457 |
/* Insert the scrambled password into the request */ |
| 458 |
if (h->pass_pos != 0) |
| 459 |
insert_scrambled_password(h, h->srv); |
| 427 |
|
460 |
|
| 428 |
/* Send the request */ |
461 |
/* Send the request */ |
| 429 |
n = sendto(h->fd, h->request, h->req_len, 0, |
462 |
n = sendto(h->fd, h->request, h->req_len, 0, |
|
Lines 552-565
Link Here
|
| 552 |
} |
585 |
} |
| 553 |
} |
586 |
} |
| 554 |
|
587 |
|
| 555 |
/* Make sure the user gave us a password */ |
588 |
if (h->request[POS_CODE] == RAD_ACCOUNTING_REQUEST) { |
| 556 |
if (h->pass_pos == 0 && !h->chap_pass) { |
589 |
/* Make sure no password given */ |
| 557 |
generr(h, "No User or Chap Password attributes given"); |
590 |
if (h->pass_pos || h->chap_pass) { |
| 558 |
return -1; |
591 |
generr(h, "User or Chap Password in accounting request"); |
| 559 |
} |
592 |
return -1; |
| 560 |
if (h->pass_pos != 0 && h->chap_pass) { |
593 |
} |
| 561 |
generr(h, "Both User and Chap Password attributes given"); |
594 |
} else { |
| 562 |
return -1; |
595 |
/* Make sure the user gave us a password */ |
|
|
596 |
if (h->pass_pos == 0 && !h->chap_pass) { |
| 597 |
generr(h, "No User or Chap Password attributes given"); |
| 598 |
return -1; |
| 599 |
} |
| 600 |
if (h->pass_pos != 0 && h->chap_pass) { |
| 601 |
generr(h, "Both User and Chap Password attributes given"); |
| 602 |
return -1; |
| 603 |
} |
| 563 |
} |
604 |
} |
| 564 |
|
605 |
|
| 565 |
/* Fill in the length field in the message */ |
606 |
/* Fill in the length field in the message */ |
|
Lines 591-597
Link Here
|
| 591 |
* In that case, it returns NULL. |
632 |
* In that case, it returns NULL. |
| 592 |
*/ |
633 |
*/ |
| 593 |
struct rad_handle * |
634 |
struct rad_handle * |
| 594 |
rad_open(void) |
635 |
rad_auth_open(void) |
| 595 |
{ |
636 |
{ |
| 596 |
struct rad_handle *h; |
637 |
struct rad_handle *h; |
| 597 |
|
638 |
|
|
Lines 606-613
Link Here
|
| 606 |
h->pass_len = 0; |
647 |
h->pass_len = 0; |
| 607 |
h->pass_pos = 0; |
648 |
h->pass_pos = 0; |
| 608 |
h->chap_pass = 0; |
649 |
h->chap_pass = 0; |
|
|
650 |
h->type = RADIUS_AUTH; |
| 609 |
} |
651 |
} |
| 610 |
return h; |
652 |
return h; |
|
|
653 |
} |
| 654 |
|
| 655 |
struct rad_handle * |
| 656 |
rad_acct_open(void) |
| 657 |
{ |
| 658 |
struct rad_handle *h; |
| 659 |
|
| 660 |
h = rad_open(); |
| 661 |
if (h != NULL) |
| 662 |
h->type = RADIUS_ACCT; |
| 663 |
return h; |
| 664 |
} |
| 665 |
|
| 666 |
struct rad_handle * |
| 667 |
rad_open(void) |
| 668 |
{ |
| 669 |
return rad_auth_open(); |
| 611 |
} |
670 |
} |
| 612 |
|
671 |
|
| 613 |
int |
672 |
int |