11#include <radcli/radcli.h>
25static unsigned char rc_get_id()
27 return (
unsigned char)(random() & UCHAR_MAX);
46 unsigned short port,
char *secret,
int timeout,
int retries)
53 data->retries = retries;
82 VALUE_PAIR * send, VALUE_PAIR ** received,
char *msg,
89 request_type != PW_ACCOUNTING_REQUEST) {
96 if (aaaserver == NULL)
100 nas_port, send, received, msg,
101 add_nas_port, request_type);
131 VALUE_PAIR * send, VALUE_PAIR ** received,
132 char *msg,
int add_nas_port,
136 VALUE_PAIR *adt_vp = NULL;
138 int timeout = rc_conf_int(rh,
"radius_timeout");
139 int retries = rc_conf_int(rh,
"radius_retries");
140 double start_time = 0;
148 if (add_nas_port != 0
154 &nas_port, 0, 0) == NULL)
158 if (request_type == PW_ACCOUNTING_REQUEST) {
165 if (adt_vp == NULL) {
173 start_time = now - adt_vp->
lvalue;
184 rc_buildreq(rh, &data, request_type, aaaserver->name[servernum],
185 aaaserver->port[servernum],
186 aaaserver->secret[servernum], timeout, retries);
188 if (request_type == PW_ACCOUNTING_REQUEST) {
189 dtime = rc_getmtime() - start_time;
193 result = rc_send_server_ctx(rh, ctx, &data, msg, type);
195 if ((result == OK_RC) || (result == CHALLENGE_RC) || (result == REJECT_RC)) {
196 if (request_type != PW_ACCOUNTING_REQUEST) {
203 "rc_send_server_ctx returned success for server %u", servernum);
210 DEBUG(LOG_INFO,
"rc_send_server_ctx returned error (%d) for server %u: (remaining: %d)",
211 result, servernum, aaaserver->max-servernum);
213 }
while (servernum < aaaserver->max && ((result == TIMEOUT_RC) || (result == NETUNREACH_RC)));
232int rc_aaa(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
233 VALUE_PAIR ** received,
char *msg,
int add_nas_port,
236 return rc_aaa_ctx(rh, NULL, nas_port, send, received, msg,
237 add_nas_port, request_type);
252int rc_auth(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send,
253 VALUE_PAIR ** received,
char *msg)
256 return rc_aaa(rh, nas_port, send, received, msg, 1,
277 return rc_aaa(rh, 0, send, received, msg, 0, PW_ACCESS_REQUEST);
291int rc_acct(rc_handle * rh, uint32_t nas_port, VALUE_PAIR * send)
293 return rc_aaa(rh, nas_port, send, NULL, NULL, 1,
294 PW_ACCOUNTING_REQUEST);
307 return rc_aaa(rh, 0, send, NULL, NULL, 0, PW_ACCOUNTING_REQUEST);
320int rc_check(rc_handle * rh,
char *host,
char *secret,
unsigned short port,
325 uint32_t service_type;
326 int timeout = rc_conf_int(rh,
"radius_timeout");
327 int retries = rc_conf_int(rh,
"radius_retries");
341 service_type = PW_ADMINISTRATIVE;
345 rc_buildreq(rh, &data, PW_STATUS_SERVER, host, port, secret, timeout,
int rc_acct(rc_handle *rh, uint32_t nas_port, VALUE_PAIR *send)
int rc_auth_proxy(rc_handle *rh, VALUE_PAIR *send, VALUE_PAIR **received, char *msg)
int rc_auth(rc_handle *rh, uint32_t nas_port, VALUE_PAIR *send, VALUE_PAIR **received, char *msg)
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)
int rc_acct_proxy(rc_handle *rh, VALUE_PAIR *send)
void rc_avpair_free(VALUE_PAIR *pair)
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)
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)
int rc_avpair_assign(VALUE_PAIR *vp, void const *pval, int len)
int rc_send_server(rc_handle *rh, SEND_DATA *data, char *msg, rc_type type)
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)
int rc_check(rc_handle *rh, char *host, char *secret, unsigned short port, char *msg)
SERVER * rc_conf_srv(rc_handle const *rh, char const *optname)
VALUE_PAIR * rc_avpair_add(rc_handle const *rh, VALUE_PAIR **list, uint32_t attrid, void const *pval, int len, uint32_t vendorspec)
VALUE_PAIR * rc_avpair_get(VALUE_PAIR *vp, uint32_t attrid, uint32_t vendorspec)
@ 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.
uint32_t lvalue
attribute value if type is PW_TYPE_INTEGER, PW_TYPE_DATE or PW_TYPE_IPADDR.
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.