26static unsigned char rc_get_id()
28 return (
unsigned char)(random() & UCHAR_MAX);
48 unsigned short port,
char *secret,
int timeout,
int retries)
55 data->retries = retries;
69static int rc_select_aaa_server(rc_handle *rh, SERVER **aaaserver,
73 request_type != PW_ACCOUNTING_REQUEST) {
81 if (*aaaserver == NULL)
102static int rc_fill_acct_pairs(rc_handle
const *rh, SEND_DATA *data,
103 uint32_t nas_port,
int add_nas_port,
105 VALUE_PAIR **adt_vp,
double *start_time)
110 if (add_nas_port != 0
116 &nas_port, 0, 0) == NULL)
120 if (request_type == PW_ACCOUNTING_REQUEST) {
127 if (*adt_vp == NULL) {
135 *start_time = now - (*adt_vp)->lvalue;
167 VALUE_PAIR * send, VALUE_PAIR ** received,
char *msg,
173 if (rc_select_aaa_server(rh, &aaaserver, &type, request_type) != OK_RC)
177 nas_port, send, received, msg,
178 add_nas_port, request_type);
208 VALUE_PAIR * send, VALUE_PAIR ** received,
209 char *msg,
int add_nas_port,
213 VALUE_PAIR *adt_vp = NULL;
217 double start_time = 0;
224 if (rc_fill_acct_pairs(rh, &data, nas_port, add_nas_port, request_type,
225 &adt_vp, &start_time) != OK_RC)
235 rc_buildreq(rh, &data, request_type, aaaserver->name[servernum],
236 aaaserver->port[servernum],
237 aaaserver->secret[servernum], timeout, retries);
239 if (request_type == PW_ACCOUNTING_REQUEST) {
240 dtime = rc_getmtime() - start_time;
244 result = rc_send_server_ctx(rh, ctx, &data, msg, type, 0);
246 if ((result == OK_RC) || (result == CHALLENGE_RC) || (result == REJECT_RC)) {
247 if (request_type != PW_ACCOUNTING_REQUEST) {
254 "rc_send_server_ctx returned success for server %u", servernum);
261 DEBUG(LOG_INFO,
"rc_send_server_ctx returned error (%d) for server %u: (remaining: %d)",
262 result, servernum, aaaserver->max-servernum);
264 }
while (servernum < aaaserver->max && ((result == TIMEOUT_RC) || (result == NETUNREACH_RC)));
283int rc_aaa(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
284 VALUE_PAIR ** received,
char *msg,
int add_nas_port,
287 return rc_aaa_ctx(rh, NULL, nas_port, send, received, msg,
288 add_nas_port, request_type);
303int rc_auth(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
304 VALUE_PAIR ** received,
char *msg)
307 return rc_aaa(rh, nas_port, send, received, msg, 1,
328 return rc_aaa(rh, 0, send, received, msg, 0, PW_ACCESS_REQUEST);
342int rc_acct(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send)
344 return rc_aaa(rh, nas_port, send, NULL, NULL, 1,
345 PW_ACCOUNTING_REQUEST);
358 return rc_aaa(rh, 0, send, NULL, NULL, 0, PW_ACCOUNTING_REQUEST);
373static int rc_aaa_ctx_server_async(rc_handle * rh, SERVER * aaaserver,
374 rc_type type, uint32_t nas_port,
378 VALUE_PAIR *adt_vp = NULL;
379 double start_time = 0;
390 if (rc_fill_acct_pairs(rh, &data, nas_port, 1, PW_ACCOUNTING_REQUEST,
391 &adt_vp, &start_time) != OK_RC)
394 for (servernum = 0; servernum < aaaserver->max; servernum++) {
395 dtime = rc_getmtime() - start_time;
402 aaaserver->name[servernum],
403 aaaserver->port[servernum],
404 aaaserver->secret[servernum], timeout, retries);
406 result = rc_send_server_ctx(rh, NULL, &data, NULL, type, 1);
413 if (result == OK_RC) {
417 "rc_send_server_ctx returned error (%d) for server %u",
422 return sent > 0 ? OK_RC : ERROR_RC;
448 if (rc_select_aaa_server(rh, &aaaserver, &type, PW_ACCOUNTING_REQUEST) != OK_RC)
451 return rc_aaa_ctx_server_async(rh, aaaserver, type, nas_port, send);
464int rc_check(rc_handle * rh,
char *host,
char *secret,
unsigned short port,
469 uint32_t service_type;
485 service_type = PW_ADMINISTRATIVE;
489 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_conf_int(rc_handle const *rh, char const *optname)
Get the value of a config option as an integer.
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.
SERVER * rc_conf_srv(rc_handle const *rh, char const *optname)
Get the value of a config option.
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.
@ PW_NAS_PORT
Its type is integer.
@ PW_SERVICE_TYPE
Its type is integer.
@ PW_ACCT_DELAY_TIME
Its type is integer.
@ RC_SOCKET_DTLS
DTLS socket.
@ RC_SOCKET_TLS
TLS socket.
Public API of the radcli library.
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.