123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- #include <radius_config.h>
- #include <includes.h>
- #include <freeradius-client.h>
- #include "util.h"
- void rc_buildreq(rc_handle const *rh, SEND_DATA *data, int code, char *server, unsigned short port,
- char *secret, int timeout, int retries)
- {
- data->server = server;
- data->secret = secret;
- data->svc_port = port;
- data->seq_nbr = rc_get_id();
- data->timeout = timeout;
- data->retries = retries;
- data->code = code;
- }
- unsigned char rc_get_id()
- {
- return (unsigned char)(random() & UCHAR_MAX);
- }
- int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **received,
- char *msg, int add_nas_port, int request_type)
- {
- SEND_DATA data;
- VALUE_PAIR* myVp;
- SERVER *aaaserver;
- int timeout = rc_conf_int(rh, "radius_timeout");
- int retries = rc_conf_int(rh, "radius_retries");
- int radius_deadtime = rc_conf_int(rh, "radius_deadtime");
- unsigned type;
- int result;
- SERVER myServer;
-
- myVp = rc_avpair_get(send, PW_USER_PASSWORD, 0);
- myServer.secret[0] = myVp->name;
-
- aaaserver = &myServer;
- type = AUTH;
-
- if (aaaserver == NULL)
- return ERROR_RC;
- data.send_pairs = send;
- data.receive_pairs = NULL;
-
- if (add_nas_port != 0) {
-
- if (rc_avpair_add(rh, &(data.send_pairs), PW_NAS_PORT,
- &client_port, 0, 0) == NULL)
- return ERROR_RC;
- }
-
- if (data.receive_pairs != NULL) {
- rc_avpair_free(data.receive_pairs);
- data.receive_pairs = NULL;
- }
- rc_buildreq(rh, &data, request_type, aaaserver->name[0],
- aaaserver->port[0], aaaserver->secret[0], timeout, retries);
-
- for (uint8_t i = 0; i < 3; i++)
- {
-
- result = rc_send_server(rh, &data, msg, type);
-
- if (result != NET_ERR_RC)
- break;
- }
-
- return result;
-
- }
- int rc_auth(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **received,
- char *msg)
- {
-
- return rc_aaa(rh, client_port, send, received, msg, 0, PW_ACCESS_REQUEST);
- }
- int rc_auth_proxy(rc_handle *rh, VALUE_PAIR *send, VALUE_PAIR **received, char *msg)
- {
- return rc_aaa(rh, 0, send, received, msg, 0, PW_ACCESS_REQUEST);
- }
- int rc_acct(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send)
- {
- return rc_aaa(rh, client_port, send, NULL, NULL, 1, PW_ACCOUNTING_REQUEST);
- }
- int rc_acct_proxy(rc_handle *rh, VALUE_PAIR *send)
- {
- return rc_aaa(rh, 0, send, NULL, NULL, 0, PW_ACCOUNTING_REQUEST);
- }
|