11#include <radcli/radcli.h>
21static double rc_getmtime(
void)
23 return rc_getmtime_ms() / 1000.0;
49 unsigned short port,
char *secret,
int timeout,
int retries)
54 data->
seq_nbr = rc_get_random_byte();
56 data->retries = retries;
70static int rc_select_aaa_server(rc_handle *rh, SERVER **aaaserver,
73 if (RC_USES_SESSION(rh) || request_type != PW_ACCOUNTING_REQUEST) {
74 *aaaserver = rc_conf_srv(rh,
"authserver");
77 *aaaserver = rc_conf_srv(rh,
"acctserver");
81 if (*aaaserver == NULL)
101static int rc_fill_acct_pairs(rc_handle
const *rh, SEND_DATA *data,
102 uint32_t nas_port,
int add_nas_port,
104 VALUE_PAIR **adt_vp,
double *start_time)
109 if (add_nas_port != 0
115 &nas_port, 0, 0) == NULL)
119 if (request_type == PW_ACCOUNTING_REQUEST) {
126 if (*adt_vp == NULL) {
128 PW_ACCT_DELAY_TIME, &dtime, 0,
134 *start_time = now - (*adt_vp)->lvalue;
166 VALUE_PAIR * send, VALUE_PAIR ** received,
char *msg,
172 if (rc_select_aaa_server(rh, &aaaserver, &type, request_type) != OK_RC)
176 nas_port, send, received, msg,
177 add_nas_port, request_type);
207 VALUE_PAIR * send, VALUE_PAIR ** received,
208 char *msg,
int add_nas_port,
212 VALUE_PAIR *adt_vp = NULL;
214 int timeout = rc_conf_int_id(rh, OPT_RADIUS_TIMEOUT);
215 int retries = rc_conf_int_id(rh, OPT_RADIUS_RETRIES);
216 double start_time = 0;
223 if (rc_fill_acct_pairs(rh, &data, nas_port, add_nas_port, request_type,
224 &adt_vp, &start_time) != OK_RC)
234 rc_buildreq(rh, &data, request_type, aaaserver->name[servernum],
235 aaaserver->port[servernum],
236 aaaserver->secret[servernum], timeout, retries);
238 if (request_type == PW_ACCOUNTING_REQUEST) {
239 dtime = rc_getmtime() - start_time;
243 result = rc_send_server_ctx(rh, ctx, &data, msg, type, 0);
245 if ((result == OK_RC) || (result == CHALLENGE_RC) || (result == REJECT_RC)) {
246 if (request_type != PW_ACCOUNTING_REQUEST) {
253 "rc_send_server_ctx returned success for server %u", servernum);
260 DEBUG(rh, LOG_INFO,
"rc_send_server_ctx returned error (%d) for server %u: (remaining: %d)",
261 result, servernum, aaaserver->max-servernum);
263 }
while (servernum < aaaserver->max && ((result == TIMEOUT_RC) || (result == NETUNREACH_RC)));
282int rc_aaa(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
283 VALUE_PAIR ** received,
char *msg,
int add_nas_port,
286 return rc_aaa_ctx(rh, NULL, nas_port, send, received, msg,
287 add_nas_port, request_type);
302int rc_auth(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
303 VALUE_PAIR ** received,
char *msg)
306 return rc_aaa(rh, nas_port, send, received, msg, 1,
327 return rc_aaa(rh, 0, send, received, msg, 0, PW_ACCESS_REQUEST);
341int rc_acct(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send)
343 return rc_aaa(rh, nas_port, send, NULL, NULL, 1,
344 PW_ACCOUNTING_REQUEST);
357 return rc_aaa(rh, 0, send, NULL, NULL, 0, PW_ACCOUNTING_REQUEST);
371static int rc_aaa_ctx_server_async(rc_handle * rh, SERVER * aaaserver,
372 rc_type type, uint32_t nas_port,
376 VALUE_PAIR *adt_vp = NULL;
377 double start_time = 0;
379 int timeout = rc_conf_int_id(rh, OPT_RADIUS_TIMEOUT);
380 int retries = rc_conf_int_id(rh, OPT_RADIUS_RETRIES);
388 if (rc_fill_acct_pairs(rh, &data, nas_port, 1, PW_ACCOUNTING_REQUEST,
389 &adt_vp, &start_time) != OK_RC)
392 for (servernum = 0; servernum < aaaserver->max; servernum++) {
393 dtime = rc_getmtime() - start_time;
400 aaaserver->name[servernum],
401 aaaserver->port[servernum],
402 aaaserver->secret[servernum], timeout, retries);
404 result = rc_send_server_ctx(rh, NULL, &data, NULL, type, 1);
411 if (result == OK_RC) {
415 "rc_send_server_ctx returned error (%d) for server %u",
420 return sent > 0 ? OK_RC : ERROR_RC;
446 if (rc_select_aaa_server(rh, &aaaserver, &type, PW_ACCOUNTING_REQUEST) != OK_RC)
449 return rc_aaa_ctx_server_async(rh, aaaserver, type, nas_port, send);
462int rc_check(rc_handle * rh,
char *host,
char *secret,
unsigned short port,
467 uint32_t service_type;
468 int timeout = rc_conf_int_id(rh, OPT_RADIUS_TIMEOUT);
469 int retries = rc_conf_int_id(rh, OPT_RADIUS_RETRIES);
474 if (RC_USES_SESSION(rh))
483 service_type = PW_ADMINISTRATIVE;
487 rc_buildreq(rh, &data, PW_STATUS_SERVER, host, port, secret, timeout,
int rc_acct(rc_handle *rh, uint32_t nas_port, VALUE_PAIR *send)
Builds an accounting request for port id nas_port with the value_pairs at send.
int rc_auth_proxy(rc_handle *rh, VALUE_PAIR *send, VALUE_PAIR **received, char *msg)
Builds an authentication request for proxying.
int rc_auth(rc_handle *rh, uint32_t nas_port, VALUE_PAIR *send, VALUE_PAIR **received, char *msg)
Builds an authentication request for port id nas_port with the value_pairs send and submits it to a s...
struct rc_aaa_ctx_st RC_AAA_CTX
void rc_buildreq(rc_handle const *rh, SEND_DATA *data, int code, char *server, unsigned short port, char *secret, int timeout, int retries)
Build a skeleton RADIUS request using information from the config file.
int rc_acct_proxy(rc_handle *rh, VALUE_PAIR *send)
Builds an accounting request with the value_pairs at send.
void rc_avpair_free(VALUE_PAIR *pair)
Frees all value_pairs in the list.
int rc_aaa_ctx(rc_handle *rh, RC_AAA_CTX **ctx, uint32_t nas_port, VALUE_PAIR *send, VALUE_PAIR **received, char *msg, int add_nas_port, rc_standard_codes request_type)
Builds an authentication/accounting request and submits it to a server, optionally returning context.
int rc_aaa(rc_handle *rh, uint32_t nas_port, VALUE_PAIR *send, VALUE_PAIR **received, char *msg, int add_nas_port, rc_standard_codes request_type)
Builds an authentication/accounting request for port id nas_port with the value_pairs send and submit...
int rc_avpair_assign(VALUE_PAIR *vp, void const *pval, int len)
Assigns the given value to an attribute-value pair.
int rc_send_server(rc_handle *rh, SEND_DATA *data, char *msg, rc_type type)
Sends a request to a RADIUS server and waits for the reply.
int rc_acct_async(rc_handle *rh, uint32_t nas_port, VALUE_PAIR *send)
Sends an accounting request to every configured accounting server without waiting for a reply.
int rc_aaa_ctx_server(rc_handle *rh, RC_AAA_CTX **ctx, SERVER *aaaserver, rc_type type, uint32_t nas_port, VALUE_PAIR *send, VALUE_PAIR **received, char *msg, int add_nas_port, rc_standard_codes request_type)
Builds an authentication/accounting request and submits it to a specific server.
int rc_check(rc_handle *rh, char *host, char *secret, unsigned short port, char *msg)
Asks the server hostname on the specified port for a status message.
VALUE_PAIR * rc_avpair_add(rc_handle const *rh, VALUE_PAIR **list, uint32_t attrid, void const *pval, int len, uint32_t vendorspec)
Adds an attribute-value pair to the given list.
VALUE_PAIR * rc_avpair_get(VALUE_PAIR *vp, uint32_t attrid, uint32_t vendorspec)
Find the first attribute value-pair (which matches the given attribute) from the specified value-pair...
@ ACCT
Request for accounting server.
@ AUTH
Request for authentication server.
int timeout
Session timeout in seconds.
char * secret
Shared secret of RADIUS server.
uint8_t seq_nbr
Packet sequence number.
int svc_port
RADIUS protocol destination port.
char * server
Name/address of RADIUS server.
VALUE_PAIR * send_pairs
More a/v pairs to send.
VALUE_PAIR * receive_pairs
Where to place received a/v pairs.
uint8_t code
RADIUS packet code.