11#include <radcli/radcli.h>
39 unsigned short port,
char *secret,
int timeout,
int retries)
44 data->
seq_nbr = rc_get_random_byte();
46 data->retries = retries;
60static int rc_select_aaa_server(rc_handle *rh, SERVER **aaaserver,
64 request_type != PW_ACCOUNTING_REQUEST) {
65 *aaaserver = rc_conf_srv(rh,
"authserver");
68 *aaaserver = rc_conf_srv(rh,
"acctserver");
72 if (*aaaserver == NULL)
92static int rc_fill_acct_pairs(rc_handle
const *rh, SEND_DATA *data,
93 uint32_t nas_port,
int add_nas_port,
95 VALUE_PAIR **adt_vp,
double *start_time)
100 if (add_nas_port != 0
106 &nas_port, 0, 0) == NULL)
110 if (request_type == PW_ACCOUNTING_REQUEST) {
117 if (*adt_vp == NULL) {
119 PW_ACCT_DELAY_TIME, &dtime, 0,
125 *start_time = now - (*adt_vp)->lvalue;
157 VALUE_PAIR * send, VALUE_PAIR ** received,
char *msg,
163 if (rc_select_aaa_server(rh, &aaaserver, &type, request_type) != OK_RC)
167 nas_port, send, received, msg,
168 add_nas_port, request_type);
198 VALUE_PAIR * send, VALUE_PAIR ** received,
199 char *msg,
int add_nas_port,
203 VALUE_PAIR *adt_vp = NULL;
205 int timeout = rc_conf_int_id(rh, OPT_RADIUS_TIMEOUT);
206 int retries = rc_conf_int_id(rh, OPT_RADIUS_RETRIES);
207 double start_time = 0;
214 if (rc_fill_acct_pairs(rh, &data, nas_port, add_nas_port, request_type,
215 &adt_vp, &start_time) != OK_RC)
225 rc_buildreq(rh, &data, request_type, aaaserver->name[servernum],
226 aaaserver->port[servernum],
227 aaaserver->secret[servernum], timeout, retries);
229 if (request_type == PW_ACCOUNTING_REQUEST) {
230 dtime = rc_getmtime() - start_time;
234 result = rc_send_server_ctx(rh, ctx, &data, msg, type, 0);
236 if ((result == OK_RC) || (result == CHALLENGE_RC) || (result == REJECT_RC)) {
237 if (request_type != PW_ACCOUNTING_REQUEST) {
244 "rc_send_server_ctx returned success for server %u", servernum);
251 DEBUG(rh, LOG_INFO,
"rc_send_server_ctx returned error (%d) for server %u: (remaining: %d)",
252 result, servernum, aaaserver->max-servernum);
254 }
while (servernum < aaaserver->max && ((result == TIMEOUT_RC) || (result == NETUNREACH_RC)));
273int rc_aaa(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
274 VALUE_PAIR ** received,
char *msg,
int add_nas_port,
277 return rc_aaa_ctx(rh, NULL, nas_port, send, received, msg,
278 add_nas_port, request_type);
293int rc_auth(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
294 VALUE_PAIR ** received,
char *msg)
297 return rc_aaa(rh, nas_port, send, received, msg, 1,
318 return rc_aaa(rh, 0, send, received, msg, 0, PW_ACCESS_REQUEST);
332int rc_acct(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send)
334 return rc_aaa(rh, nas_port, send, NULL, NULL, 1,
335 PW_ACCOUNTING_REQUEST);
348 return rc_aaa(rh, 0, send, NULL, NULL, 0, PW_ACCOUNTING_REQUEST);
362static int rc_aaa_ctx_server_async(rc_handle * rh, SERVER * aaaserver,
363 rc_type type, uint32_t nas_port,
367 VALUE_PAIR *adt_vp = NULL;
368 double start_time = 0;
370 int timeout = rc_conf_int_id(rh, OPT_RADIUS_TIMEOUT);
371 int retries = rc_conf_int_id(rh, OPT_RADIUS_RETRIES);
379 if (rc_fill_acct_pairs(rh, &data, nas_port, 1, PW_ACCOUNTING_REQUEST,
380 &adt_vp, &start_time) != OK_RC)
383 for (servernum = 0; servernum < aaaserver->max; servernum++) {
384 dtime = rc_getmtime() - start_time;
391 aaaserver->name[servernum],
392 aaaserver->port[servernum],
393 aaaserver->secret[servernum], timeout, retries);
395 result = rc_send_server_ctx(rh, NULL, &data, NULL, type, 1);
402 if (result == OK_RC) {
406 "rc_send_server_ctx returned error (%d) for server %u",
411 return sent > 0 ? OK_RC : ERROR_RC;
437 if (rc_select_aaa_server(rh, &aaaserver, &type, PW_ACCOUNTING_REQUEST) != OK_RC)
440 return rc_aaa_ctx_server_async(rh, aaaserver, type, nas_port, send);
453int rc_check(rc_handle * rh,
char *host,
char *secret,
unsigned short port,
458 uint32_t service_type;
459 int timeout = rc_conf_int_id(rh, OPT_RADIUS_TIMEOUT);
460 int retries = rc_conf_int_id(rh, OPT_RADIUS_RETRIES);
474 service_type = PW_ADMINISTRATIVE;
478 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.
@ RC_SOCKET_DTLS
DTLS socket.
@ RC_SOCKET_TLS
TLS socket.
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.