22#ifndef RADCLI_SUPPRESS_LEGACY_WARNING
23#warning "radcli.h/-lradcli is the legacy, frozen API. New code should use \
24<radcli/radcli2.h> (-lradcli2). See https://radcli.github.io/radcli/ for \
25the new API's documentation, or define RADCLI_SUPPRESS_LEGACY_WARNING to \
41#include <netinet/in.h>
44#include <sys/socket.h>
60#define AUTH_PASS_LEN (8 * 16)
63#define RC_BUFFER_LEN 8192
64#define RC_MAX_PACKET_LEN 4096
66#define RC_NAME_LENGTH 64
68#define MAX_SECRET_LENGTH (16 * 16)
70#define RADCLI_VENDOR_MASK 0xffffffff
71#define VENDOR_BIT_SIZE 32
72#define RADCLI_VENDOR_ATTR_SET(attr, vendor) ((attr)|((uint64_t)((vendor)&RADCLI_VENDOR_MASK)) << VENDOR_BIT_SIZE)
74#define VENDOR(x) (((x) >> VENDOR_BIT_SIZE) & 0xffffffff)
75#define ATTRID(x) ((x) & 0xffffffff)
77#define PW_MAX_MSG_SIZE 4096
88#define RC_SERVER_MAX 8
90#define AUTH_LOCAL_FST (1<<0)
91#define AUTH_RADIUS_FST (1<<1)
92#define AUTH_LOCAL_SND (1<<2)
93#define AUTH_RADIUS_SND (1<<3)
96typedef struct rc_conf rc_handle;
104 char *name[RC_SERVER_MAX];
105 uint16_t port[RC_SERVER_MAX];
106 char *secret[RC_SERVER_MAX];
119#define AUTH_HDR_LEN 20
120#define CHAP_VALUE_LENGTH 16
122#define PW_AUTH_UDP_PORT 1812
123#define PW_ACCT_UDP_PORT 1813
143 PW_ACCOUNTING_REQUEST=4,
144 PW_ACCOUNTING_RESPONSE=5,
145 PW_ACCOUNTING_STATUS=6,
146 PW_PASSWORD_REQUEST=7,
148 PW_PASSWORD_REJECT=9,
149 PW_ACCOUNTING_MESSAGE=10,
150 PW_ACCESS_CHALLENGE=11,
161#include <radcli/radcli-defs.h>
166enum rc_vendor_attr_microsoft {
167 PW_MS_CHAP_CHALLENGE = 11,
168 PW_MS_CHAP_RESPONSE = 1,
169 PW_MS_CHAP2_RESPONSE = 25,
170 PW_MS_CHAP2_SUCCESS = 26,
171 PW_MS_MPPE_ENCRYPTION_POLICY= 7,
172 PW_MS_MPPE_ENCRYPTION_TYPE= 8,
173 PW_MS_MPPE_ENCRYPTION_TYPES=PW_MS_MPPE_ENCRYPTION_TYPE,
174 PW_MS_CHAP_MPPE_KEYS = 12,
175 PW_MS_MPPE_SEND_KEY = 16,
176 PW_MS_MPPE_RECV_KEY = 17,
177 PW_MS_PRIMARY_DNS_SERVER= 28,
178 PW_MS_SECONDARY_DNS_SERVER= 29,
179 PW_MS_PRIMARY_NBNS_SERVER= 30,
180 PW_MS_SECONDARY_NBNS_SERVER= 31,
184enum rc_vendor_attr_roaringpenguin {
185 PW_RP_UPSTREAM_LIMIT =1,
186 PW_RP_DOWNSTREAM_LIMIT =2,
191#define PW_AUTH_ONLY 3
212 char attrname[RC_NAME_LENGTH +1];
213 char name[RC_NAME_LENGTH + 1];
223 char vendorname[RC_NAME_LENGTH +1];
229#define MGMT_POLL_SECRET "Hardlyasecret"
245# define AUTH_STRING_LEN 253
283#define AUTH_VECTOR_LEN 16
298#define RC_MIN(a, b) ((a) < (b) ? (a) : (b))
301#define RC_MAX(a, b) ((a) > (b) ? (a) : (b))
335VALUE_PAIR *
rc_avpair_add (rc_handle
const *rh, VALUE_PAIR **list, uint32_t attrid,
void const *pval,
int len, uint32_t vendorspec);
337VALUE_PAIR *
rc_avpair_new (rc_handle
const *rh, uint32_t attrid,
void const *pval,
int len, uint32_t vendorspec);
338VALUE_PAIR *
rc_avpair_gen(rc_handle
const *rh, VALUE_PAIR *pair,
unsigned char const *ptr,
339 int length, uint32_t vendorspec);
340void rc_avpair_remove (VALUE_PAIR **list, uint32_t attrid, uint32_t vendorspec);
341VALUE_PAIR *
rc_avpair_get (VALUE_PAIR *vp, uint32_t attrid, uint32_t vendorspec);
345int rc_avpair_parse (rc_handle
const *rh,
char const *buffer, VALUE_PAIR **first_pair);
346int rc_avpair_tostr (rc_handle
const *rh, VALUE_PAIR *pair,
char *name,
int ln,
char *value,
int lv);
347char *
rc_avpair_log(rc_handle
const *rh, VALUE_PAIR *pair,
char *buf,
size_t buf_len);
357void rc_buildreq(rc_handle
const *rh, SEND_DATA *data,
int code,
char *
server,
unsigned short port,
358 char *secret,
int timeout,
int retries);
359int rc_auth(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send,
360 VALUE_PAIR **received,
char *msg);
361int rc_auth_proxy(rc_handle *rh, VALUE_PAIR *send, VALUE_PAIR **received,
char *msg);
362int rc_acct(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send);
365int rc_acct_async(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send);
367int rc_check(rc_handle *rh,
char *host,
char *secret,
unsigned short port,
char *msg);
369int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **received,
372 VALUE_PAIR **received,
375 rc_type type, uint32_t client_port,
376 VALUE_PAIR *send, VALUE_PAIR **received,
381int rc_add_config(rc_handle *rh,
char const *option_name,
char const *option_val,
char const *source,
int line);
382rc_handle *rc_config_init(rc_handle *rh);
383rc_handle *rc_read_config(
char const *filename);
384char *rc_conf_str(rc_handle
const *rh,
char const *optname);
385int rc_conf_int(rc_handle
const *rh,
char const *optname);
386SERVER *rc_conf_srv(rc_handle
const *rh,
char const *optname);
387int rc_test_config(rc_handle *rh,
char const *filename);
388int rc_apply_config(rc_handle *rh);
389int rc_find_server_addr (rc_handle
const *rh,
char const *server_name,
390 struct addrinfo** info,
char *secret,
rc_type type);
391void rc_config_free(rc_handle *rh);
392rc_handle *rc_new(
void);
393void rc_destroy(rc_handle *rh);
396#define test_config rc_test_config
400int rc_read_dictionary (rc_handle *rh,
char const *filename);
401int rc_read_dictionary_from_buffer (rc_handle *rh,
char const *buf,
size_t size);
403DICT_ATTR *
rc_dict_addattr(rc_handle *rh,
char const * namestr, uint32_t value,
int type, uint32_t vendorspec);
404DICT_VALUE *
rc_dict_addval(rc_handle *rh,
char const * attrstr,
char const * namestr, uint32_t value);
405DICT_VENDOR *
rc_dict_addvend(rc_handle *rh,
char const * vendorname, uint32_t value);
411DICT_VENDOR *
rc_dict_getvend (rc_handle
const *rh, uint32_t vendorspec);
412DICT_VALUE *
rc_dict_getval(rc_handle
const *rh, uint32_t value,
char const *attrname);
413void rc_dict_free(rc_handle *rh);
417int rc_tls_fd(rc_handle * rh);
418int rc_check_tls(rc_handle * rh);
422unsigned short rc_getport(
int type);
423int rc_own_hostname(
char *hostname,
int len);
425int rc_get_srcaddr(
struct sockaddr *lia,
const struct sockaddr *ria);
429void rc_setdebug(
int debug);
430void rc_openlog(
char const *ident);
446#define _RADCLI_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
447#if !defined RADCLI_INTERNAL_BUILD
448# if _RADCLI_GCC_VERSION >= 30100
449# define _RADCLI_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__))
452char *rc_mksid(
void) _RADCLI_GCC_ATTR_DEPRECATED;
void rc_avpair_remove(VALUE_PAIR **list, uint32_t attrid, uint32_t vendorspec)
Removes an attribute-value pair from the given list.
DICT_VALUE * rc_dict_getval(rc_handle const *rh, uint32_t value, char const *attrname)
Get DICT_VALUE based on attribute name and integer value number.
int rc_avpair_get_raw(VALUE_PAIR *vp, char **res, unsigned *res_size)
Get the raw value of the given attribute value-pair.
char * rc_avpair_log(rc_handle const *rh, VALUE_PAIR *pair, char *buf, size_t buf_len)
Format a sequence of attribute value pairs into a printable string.
VALUE_PAIR * rc_avpair_next(VALUE_PAIR *t)
Iterates through the attribute-value pairs.
const void * rc_aaa_ctx_get_vector(RC_AAA_CTX *ctx)
Returns a pointer request vector used in the request. It is of AUTH_VECTOR_LEN size.
int rc_acct(rc_handle *rh, uint32_t client_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 client_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
int rc_avpair_get_uint32(VALUE_PAIR *vp, uint32_t *res)
Get the integer value of the given attribute value-pair.
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.
DICT_ATTR * rc_dict_addattr(rc_handle *rh, char const *namestr, uint32_t value, int type, uint32_t vendorspec)
Add attribute to dictionary.
int rc_avpair_get_in6(VALUE_PAIR *vp, struct in6_addr *res, unsigned *prefix)
Get the IPv6 address and prefix value of the given attribute value-pair.
void rc_avpair_get_attr(VALUE_PAIR *vp, unsigned *type, unsigned *id)
Get the attribute ID and type of the given attribute value-pair.
VALUE_PAIR * rc_avpair_gen(rc_handle const *rh, VALUE_PAIR *pair, unsigned char const *ptr, int length, uint32_t vendorspec)
Decode a raw RADIUS attribute buffer into a VALUE_PAIR list.
DICT_VENDOR * rc_dict_findvend(rc_handle const *rh, char const *vendorname)
Lookup a DICT_VENDOR by its name.
int rc_acct_proxy(rc_handle *rh, VALUE_PAIR *send)
Builds an accounting request with the value_pairs at send.
const char * rc_aaa_ctx_get_secret(RC_AAA_CTX *ctx)
Returns the secret available in this context. It is the secret value used in the request.
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 client_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.
VALUE_PAIR * rc_avpair_copy(VALUE_PAIR *p)
Return a copy of the existing list "p" ala strdup().
int rc_avpair_tostr(rc_handle const *rh, VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
Translate an av_pair into printable strings.
int rc_aaa(rc_handle *rh, uint32_t client_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.
DICT_VALUE * rc_dict_findval(rc_handle const *rh, char const *valname)
Lookup a DICT_VALUE by its name.
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 client_port, VALUE_PAIR *send)
Sends an accounting request to every configured accounting server without waiting for a reply.
int rc_avpair_parse(rc_handle const *rh, char const *buffer, VALUE_PAIR **first_pair)
Parses the buffer to extract the attribute-value pairs.
int rc_aaa_ctx_server(rc_handle *rh, RC_AAA_CTX **ctx, SERVER *aaaserver, rc_type type, uint32_t client_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.
DICT_VENDOR * rc_dict_getvend(rc_handle const *rh, uint32_t vendorspec)
Lookup a DICT_VENDOR by its IANA number.
DICT_ATTR * rc_dict_getattr(rc_handle const *rh, uint64_t attribute)
Lookup a DICT_ATTR by attribute number.
DICT_VALUE * rc_dict_addval(rc_handle *rh, char const *attrstr, char const *namestr, uint32_t value)
Add value to dictionary.
DICT_VENDOR * rc_dict_addvend(rc_handle *rh, char const *vendorname, uint32_t value)
Add vendor to dictionary.
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.
void rc_aaa_ctx_free(RC_AAA_CTX *ctx)
Deinitializes an RC_AAA_CTX structure.
void rc_avpair_insert(VALUE_PAIR **a, VALUE_PAIR *p, VALUE_PAIR *b)
Insert a VALUE_PAIR into a 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...
DICT_ATTR * rc_dict_findattr(rc_handle const *rh, char const *attrname)
Lookup a DICT_ATTR by its name.
VALUE_PAIR * rc_avpair_new(rc_handle const *rh, uint32_t attrid, void const *pval, int len, uint32_t vendorspec)
Make a new attribute-value pair with given parameters.
@ ACCT
Request for accounting server.
@ AUTH
Request for authentication server.
@ PW_TYPE_IPADDR
The attribute is an IPv4 address in host-byte order.
@ PW_TYPE_IPV6ADDR
The attribute is an 128-bit IPv6 address.
@ PW_TYPE_MAX
Maximum number of types (last+1).
@ PW_TYPE_IPV6PREFIX
The attribute is an IPv6 prefix; the lvalue will indicate its size.
@ PW_TYPE_INTEGER
The attribute is a 32-bit integer.
@ PW_TYPE_DATE
The attribute contains a 32-bit number indicating the seconds since epoch.
@ PW_TYPE_STRING
The attribute is a printable string.
@ RC_SOCKET_UDP
Plain UDP socket.
@ RC_SOCKET_TCP
Plain TCP socket.
@ RC_SOCKET_DTLS
DTLS socket.
@ RC_SOCKET_TLS
TLS socket.
rc_attr_type type
string, int, etc..
uint64_t value
attribute index and vendor number; use VENDOR() and ATTRID() to separate.
char name[RC_NAME_LENGTH+1]
attribute name.
rc_attr_type type
attribute type.
uint64_t attribute
attribute numeric value of type rc_attr_id including vendor; use VENDOR() and ATTRID() to separate.
uint32_t lvalue
attribute value if type is PW_TYPE_INTEGER, PW_TYPE_DATE or PW_TYPE_IPADDR.
char strvalue[AUTH_STRING_LEN+1]
contains attribute value in other cases.
char name[RC_NAME_LENGTH+1]
attribute name if known.
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.
double deadtime_ends[RC_SERVER_MAX]
unused