Radcli library 2.0.0
A simple radius library -- legacy API reference
Loading...
Searching...
No Matches
Main API

Main API Functions. More...

Data Structures

struct  server
struct  dict_attr
struct  dict_value
struct  dict_vendor
struct  rc_value_pair
struct  send_data

Typedefs

typedef enum rc_type rc_type
typedef struct rc_conf rc_handle
typedef struct server SERVER
typedef enum rc_socket_type rc_socket_type
typedef enum rc_attr_type rc_attr_type
typedef enum rc_standard_codes rc_standard_codes
typedef struct dict_attr DICT_ATTR
typedef struct dict_value DICT_VALUE
typedef struct dict_vendor DICT_VENDOR
typedef enum rc_send_status rc_send_status
typedef struct rc_value_pair VALUE_PAIR
typedef struct send_data SEND_DATA
typedef struct rc_aaa_ctx_st RC_AAA_CTX

Enumerations

enum  rc_type { AUTH = 0 , ACCT = 1 }
enum  rc_socket_type { RC_SOCKET_UDP = 0 , RC_SOCKET_TLS = 1 , RC_SOCKET_DTLS = 2 , RC_SOCKET_TCP = 3 }
enum  rc_attr_type {
  PW_TYPE_STRING =0 , PW_TYPE_INTEGER =1 , PW_TYPE_IPADDR =2 , PW_TYPE_DATE =3 ,
  PW_TYPE_IPV6ADDR =4 , PW_TYPE_IPV6PREFIX =5 , PW_TYPE_MAX =6
}
enum  rc_standard_codes {
  PW_ACCESS_REQUEST =1 , PW_ACCESS_ACCEPT =2 , PW_ACCESS_REJECT =3 , PW_ACCOUNTING_REQUEST =4 ,
  PW_ACCOUNTING_RESPONSE =5 , PW_ACCOUNTING_STATUS =6 , PW_PASSWORD_REQUEST =7 , PW_PASSWORD_ACK =8 ,
  PW_PASSWORD_REJECT =9 , PW_ACCOUNTING_MESSAGE =10 , PW_ACCESS_CHALLENGE =11 , PW_STATUS_SERVER =12 ,
  PW_STATUS_CLIENT =13
}
enum  rc_vendor_attr_microsoft {
  PW_MS_CHAP_CHALLENGE = 11 , PW_MS_CHAP_RESPONSE = 1 , PW_MS_CHAP2_RESPONSE = 25 , PW_MS_CHAP2_SUCCESS = 26 ,
  PW_MS_MPPE_ENCRYPTION_POLICY = 7 , PW_MS_MPPE_ENCRYPTION_TYPE = 8 , PW_MS_MPPE_ENCRYPTION_TYPES =PW_MS_MPPE_ENCRYPTION_TYPE , PW_MS_CHAP_MPPE_KEYS = 12 ,
  PW_MS_MPPE_SEND_KEY = 16 , PW_MS_MPPE_RECV_KEY = 17 , PW_MS_PRIMARY_DNS_SERVER = 28 , PW_MS_SECONDARY_DNS_SERVER = 29 ,
  PW_MS_PRIMARY_NBNS_SERVER = 30 , PW_MS_SECONDARY_NBNS_SERVER = 31
}
enum  rc_vendor_attr_roaringpenguin { PW_RP_UPSTREAM_LIMIT =1 , PW_RP_DOWNSTREAM_LIMIT =2 }
enum  rc_send_status {
  NETUNREACH_RC =-4 , BADRESPID_RC =-3 , BADRESP_RC =-2 , ERROR_RC =-1 ,
  OK_RC =0 , TIMEOUT_RC =1 , REJECT_RC =2 , CHALLENGE_RC =3
}

Functions

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.
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.
void rc_aaa_ctx_free (RC_AAA_CTX *ctx)
 Deinitializes an RC_AAA_CTX structure.
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_avpair_remove (VALUE_PAIR **list, uint32_t attrid, uint32_t vendorspec)
 Removes an attribute-value pair from the given list.
VALUE_PAIR * rc_avpair_next (VALUE_PAIR *t)
 Iterates through the attribute-value pairs.
int rc_avpair_assign (VALUE_PAIR *vp, void const *pval, int len)
 Assigns the given value to an attribute-value pair.
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.
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.
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 list.
VALUE_PAIR * rc_avpair_copy (VALUE_PAIR *p)
 Return a copy of the existing list "p" ala strdup().
void rc_avpair_insert (VALUE_PAIR **a, VALUE_PAIR *p, VALUE_PAIR *b)
 Insert a VALUE_PAIR into a list.
void rc_avpair_free (VALUE_PAIR *pair)
 Frees all value_pairs in the list.
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_avpair_tostr (rc_handle const *rh, VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
 Translate an av_pair into printable strings.
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.
int rc_avpair_get_uint32 (VALUE_PAIR *vp, uint32_t *res)
 Get the integer value of the given attribute value-pair.
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.
int rc_avpair_get_raw (VALUE_PAIR *vp, char **res, unsigned *res_size)
 Get the raw 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.
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_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_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_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 submits it to a server.
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 server.
int rc_auth_proxy (rc_handle *rh, VALUE_PAIR *send, VALUE_PAIR **received, char *msg)
 Builds an authentication request for proxying.
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_acct_proxy (rc_handle *rh, VALUE_PAIR *send)
 Builds an accounting request with the value_pairs at send.
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_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_ATTR * rc_dict_addattr (rc_handle *rh, char const *namestr, uint32_t value, int type, uint32_t vendorspec)
 Add attribute to dictionary.
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 *namestr, uint32_t vendorspec)
 Add vendor to dictionary.
DICT_ATTR * rc_dict_getattr (rc_handle const *rh, uint64_t attribute)
 Lookup a DICT_ATTR by attribute number.
DICT_ATTR * rc_dict_findattr (rc_handle const *rh, char const *attrname)
 Lookup a DICT_ATTR by its name.
DICT_VALUE * rc_dict_findval (rc_handle const *rh, char const *valname)
 Lookup a DICT_VALUE by its name.
DICT_VENDOR * rc_dict_findvend (rc_handle const *rh, char const *vendorname)
 Lookup a DICT_VENDOR by its name.
DICT_VENDOR * rc_dict_getvend (rc_handle const *rh, uint32_t vendorspec)
 Lookup a DICT_VENDOR by its IANA number.
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_pack_list (rc_handle *rh, VALUE_PAIR *vp, char *secret, AUTH_HDR *auth, int max_len)
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_send_server_ctx (rc_handle *rh, RC_AAA_CTX **ctx, SEND_DATA *data, char *msg, rc_type type, int no_wait)

Detailed Description

Main API Functions.

Typedef Documentation

◆ RC_AAA_CTX

typedef struct rc_aaa_ctx_st RC_AAA_CTX

Opaque context returned by rc_aaa_ctx() after a successful request.

Captures the shared secret and the request authenticator vector (AUTH_VECTOR_LEN bytes) that were used in the last request. These can be retrieved with rc_aaa_ctx_get_secret() and rc_aaa_ctx_get_vector().

Pass NULL for the ctx argument to rc_aaa_ctx() if this information is not needed. When a context is no longer needed, free it with rc_aaa_ctx_free().

Definition at line 295 of file radcli.h.

◆ rc_handle

typedef struct rc_conf rc_handle

Definition at line 96 of file radcli.h.

Enumeration Type Documentation

◆ rc_attr_type

Attribute types

Enumerator
PW_TYPE_STRING 

The attribute is a printable string.

PW_TYPE_INTEGER 

The attribute is a 32-bit integer.

PW_TYPE_IPADDR 

The attribute is an IPv4 address in host-byte order.

PW_TYPE_DATE 

The attribute contains a 32-bit number indicating the seconds since epoch.

PW_TYPE_IPV6ADDR 

The attribute is an 128-bit IPv6 address.

PW_TYPE_IPV6PREFIX 

The attribute is an IPv6 prefix; the lvalue will indicate its size.

PW_TYPE_MAX 

Maximum number of types (last+1).

Definition at line 127 of file radcli.h.

◆ rc_send_status

Return codes for rc_send_server()

Definition at line 233 of file radcli.h.

◆ rc_socket_type

Indicate the type of the socket

Enumerator
RC_SOCKET_UDP 

Plain UDP socket.

RC_SOCKET_TLS 

TLS socket.

RC_SOCKET_DTLS 

DTLS socket.

RC_SOCKET_TCP 

Plain TCP socket.

Definition at line 112 of file radcli.h.

◆ rc_standard_codes

Standard RADIUS request codes

Definition at line 139 of file radcli.h.

◆ rc_type

enum rc_type

Codes to indicate the type of server

Enumerator
AUTH 

Request for authentication server.

ACCT 

Request for accounting server.

Definition at line 81 of file radcli.h.

◆ rc_vendor_attr_microsoft

enum rc_vendor_attr_microsoft

Definition at line 166 of file radcli.h.

◆ rc_vendor_attr_roaringpenguin

enum rc_vendor_attr_roaringpenguin

Definition at line 184 of file radcli.h.

Function Documentation

◆ rc_aaa()

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 submits it to a server.

Parameters
rha handle to parsed configuration.
nas_portthe physical NAS port number to use (may be zero).
senda VALUE_PAIR array of values (e.g., PW_USER_NAME).
receivedan allocated array of received values.
msgmust be an array of PW_MAX_MSG_SIZE or NULL; will contain the concatenation of any PW_REPLY_MESSAGE received.
add_nas_portthis should be zero; if non-zero it will include PW_NAS_PORT in sent pairs.
request_typeone of standard RADIUS codes (e.g., PW_ACCESS_REQUEST).
Returns
received value_pairs in received, messages from the server in msg and OK_RC (0) on success, CHALLENGE_RC (3) on Access-Challenge received, negative on failure as return value.

Definition at line 273 of file buildreq.c.

◆ rc_aaa_ctx()

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.

Selects the server list from configuration (authserver or acctserver depending on request_type and transport), sends the request with automatic retry and server failover, and returns the server's response.

Note
Use rc_auth() or rc_acct() when no context is needed (they call this with ctx set to NULL). Pass a non-NULL ctx only when you need to inspect the secret and vector used in the request afterwards.
Parameters
rha handle to parsed configuration.
ctxif non-NULL, receives an allocated RC_AAA_CTX on success; the caller must free it with rc_aaa_ctx_free(). Pass NULL if not needed.
nas_portthe physical NAS port number to include (may be zero).
sendVALUE_PAIR list of attributes to send (e.g., PW_USER_NAME).
receivedon success, receives the server's reply VALUE_PAIR list; the caller must free it with rc_avpair_free().
msgif non-NULL, must point to a buffer of PW_MAX_MSG_SIZE bytes; will contain the concatenation of any PW_REPLY_MESSAGE attributes received.
add_nas_portif non-zero, PW_NAS_PORT is added to the sent pairs.
request_typeone of the standard RADIUS codes (e.g., PW_ACCESS_REQUEST).
Returns
OK_RC (0) on success, CHALLENGE_RC (3) on Access-Challenge, REJECT_RC (2) on Access-Reject, or a negative error code on failure.

Definition at line 156 of file buildreq.c.

◆ rc_aaa_ctx_free()

void rc_aaa_ctx_free ( RC_AAA_CTX * ctx)

Deinitializes an RC_AAA_CTX structure.

Parameters
ctxa pointer to a RC_AAA_CTX structure.

Definition at line 62 of file aaa_ctx.c.

◆ rc_aaa_ctx_get_secret()

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.

Parameters
ctxa pointer to a RC_AAA_CTX structure.
Returns
a null-terminated string.

Definition at line 41 of file aaa_ctx.c.

◆ rc_aaa_ctx_get_vector()

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.

Parameters
ctxa pointer to a RC_AAA_CTX structure.
Returns
a pointer to the vector.

Definition at line 52 of file aaa_ctx.c.

◆ rc_aaa_ctx_server()

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.

Like rc_aaa_ctx() but sends to aaaserver instead of the server list from the configuration. Use this when the caller has already selected the server (e.g., in proxy scenarios).

Parameters
rha handle to parsed configuration.
ctxif non-NULL, receives an allocated RC_AAA_CTX on success; the caller must free it with rc_aaa_ctx_free(). Pass NULL if not needed.
aaaservera non-NULL SERVER describing the target server(s).
typeAUTH to use the authentication port, ACCT for the accounting port. Under TLS/DTLS only AUTH is valid (both auth and acct share the same TLS connection to the authserver).
nas_portthe physical NAS port number to include (may be zero).
sendVALUE_PAIR list of attributes to send (e.g., PW_USER_NAME).
receivedon success, receives the server's reply VALUE_PAIR list; the caller must free it with rc_avpair_free().
msgif non-NULL, must point to a buffer of PW_MAX_MSG_SIZE bytes; will contain the concatenation of any PW_REPLY_MESSAGE attributes received.
add_nas_portif non-zero, PW_NAS_PORT is added to the sent pairs.
request_typeone of the standard RADIUS codes (e.g., PW_ACCESS_REQUEST).
Returns
OK_RC (0) on success, CHALLENGE_RC (3) on Access-Challenge, REJECT_RC (2) on Access-Reject, or a negative error code on failure.

Definition at line 195 of file buildreq.c.

◆ rc_acct()

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.

Note
NAS-IP-Address, NAS-Port and Acct-Delay-Time get filled in by this function, the rest has to be supplied.
Parameters
rha handle to parsed configuration.
nas_portthe physical NAS port number to use (may be zero).
senda VALUE_PAIR array of values (e.g., PW_USER_NAME).
Returns
received value_pairs in received, and OK_RC (0) on success, CHALLENGE_RC (3) on Access-Challenge received, negative on failure as return value.

Definition at line 332 of file buildreq.c.

◆ rc_acct_async()

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.

Selects the server list the same way rc_acct() does (acctserver, or authserver under TLS/DTLS). Unlike rc_acct()/rc_aaa(), which stop at the first server that replies and fail over to the next only after a timeout, this sends to every configured server unconditionally, since there is no reply to judge success or failure by. Intended for best-effort notifications such as an Accounting-Stop sent while an application is shutting down and cannot afford to block.

Parameters
rha handle to parsed configuration.
nas_portthe physical NAS port number to include (may be zero).
sendVALUE_PAIR list of attributes to send; NAS-Port and Acct-Delay-Time are filled in as with rc_acct().
Returns
OK_RC (0) if the packet was handed to the socket layer for at least one server, ERROR_RC if no accounting servers are configured or the send failed for all of them.

Definition at line 432 of file buildreq.c.

◆ rc_acct_proxy()

int rc_acct_proxy ( rc_handle * rh,
VALUE_PAIR * send )

Builds an accounting request with the value_pairs at send.

Parameters
rha handle to parsed configuration.
senda VALUE_PAIR array of values (e.g., PW_USER_NAME).
Returns
OK_RC (0) on success, CHALLENGE_RC (3) on Access-Challenge received, negative on failure as return value.

Definition at line 345 of file buildreq.c.

◆ rc_auth()

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 server.

Parameters
rha handle to parsed configuration.
nas_portthe physical NAS port number to use (may be zero).
senda VALUE_PAIR array of values (e.g., PW_USER_NAME).
receivedan allocated array of received values.
msgmust be an array of PW_MAX_MSG_SIZE or NULL; will contain the concatenation of any PW_REPLY_MESSAGE received.
Returns
received value_pairs in received, messages from the server in msg (if non-NULL), and OK_RC (0) on success,CHALLENGE_RC (3) on Access-Challenge received, negative on failure as return value.

Definition at line 293 of file buildreq.c.

◆ rc_auth_proxy()

int rc_auth_proxy ( rc_handle * rh,
VALUE_PAIR * send,
VALUE_PAIR ** received,
char * msg )

Builds an authentication request for proxying.

Builds an authentication request with the value_pairs send and submits it to a server. Works for a proxy; does not add IP address, and does does not rely on config file.

Parameters
rha handle to parsed configuration.
senda VALUE_PAIR array of values (e.g., PW_USER_NAME).
receivedan allocated array of received values.
msgmust be an array of PW_MAX_MSG_SIZE or NULL; will contain the concatenation of any PW_REPLY_MESSAGE received.
Returns
received value_pairs in received, messages from the server in msg (if non-NULL) and OK_RC (0) on success, CHALLENGE_RC (3) on Access-Challenge received, negative on failure as return value.

Definition at line 315 of file buildreq.c.

◆ rc_avpair_add()

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.

See rc_avpair_assign() for the format of the data.

Note
It always appends the new pair to the end of the list.
Parameters
rha handle to parsed configuration.
lista VALUE_PAIR array of values; initially must be NULL.
attridThe attribute of the pair to add (e.g., PW_USER_NAME).
pvalthe value (e.g., the actual username).
lenthe length of pval, or -1 if to calculate (in case of strings).
vendorspecThe vendor ID in case of a vendor specific value - 0 otherwise.
Returns
pointer to added a/v pair upon success, NULL pointer upon failure.

Definition at line 47 of file avpair.c.

◆ rc_avpair_assign()

int rc_avpair_assign ( VALUE_PAIR * vp,
void const * pval,
int len )

Assigns the given value to an attribute-value pair.

If the value is of type PW_TYPE_STRING it must either be a null terminated string with len set to -1, or raw data with length properly set. For PW_TYPE_DATE, PW_TYPE_INTEGER, and PW_TYPE_IPADDR an uint32_t number should be set at pval. For IPv4 addresses it should be in host byte order.

For PW_TYPE_IPV6ADDR type a 16-byte long address is expected, and for PW_TYPE_IPV6PREFIX the rfc3162 prefix format is expected. Simply that is a zero byte, a byte with the value of prefix (e.g., 112), and the remaining bytes are the IPv6 address.

Parameters
vpa pointer to a VALUE_PAIR structure.
pvalthe value (e.g., the actual username).
lenthe length of pval, or -1 if to calculate (in case of strings).
Returns
0 on success or -1 on failure.

Definition at line 136 of file avpair.c.

◆ rc_avpair_copy()

VALUE_PAIR * rc_avpair_copy ( VALUE_PAIR * p)

Return a copy of the existing list "p" ala strdup().

Parameters
pa pointer to a VALUE_PAIR structure.
Returns
the copy of "p".

Definition at line 482 of file avpair.c.

◆ rc_avpair_free()

void rc_avpair_free ( VALUE_PAIR * pair)

Frees all value_pairs in the list.

Parameters
paira pointer to a VALUE_PAIR structure.

Definition at line 569 of file avpair.c.

◆ rc_avpair_gen()

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.

Note
This is a low-level function retained for ABI compatibility with freeradius-client and radiusclient-ng. Application code should not call it directly; build requests with rc_avpair_add() and send them with rc_auth() or rc_acct(), which handle wire encoding and decoding internally.

Decodes the attribute/value region of a received RADIUS packet (the bytes that follow the 20-byte fixed header) into a linked list of VALUE_PAIR structures. Unknown attributes are logged and skipped; they are not a hard error.

Parameters
rha handle to parsed configuration (used for dictionary lookups).
pairoptional existing VALUE_PAIR list to append decoded attributes to; pass NULL to start a fresh list.
ptrpointer to the start of the attribute data region.
lengthnumber of bytes in the attribute region.
vendorspecvendor PEN when decoding a vendor-specific sub-attribute block; pass 0 for top-level packet attributes.
Returns
head of the (possibly extended) VALUE_PAIR list, or NULL on a hard decode error (malformed length field, allocation failure).

Definition at line 444 of file avpair.c.

◆ rc_avpair_get()

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 list.

Parameters
vpa pointer to a VALUE_PAIR structure.
attridThe attribute of the pair to find (e.g., PW_USER_NAME).
vendorspecThe vendor ID in case of a vendor specific value - 0 otherwise.
Returns
the value pair found.

Definition at line 465 of file avpair.c.

◆ rc_avpair_get_attr()

void rc_avpair_get_attr ( VALUE_PAIR * vp,
unsigned * type,
unsigned * id )

Get the attribute ID and type of the given attribute value-pair.

Parameters
vpa pointer to a VALUE_PAIR structure.
typeThe attribute type, of type rc_attr_type
idThe attribute identifier, of type rc_attr_id

Definition at line 1059 of file avpair.c.

◆ rc_avpair_get_in6()

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.

This function is valid for PW_TYPE_IPV6ADDR, PW_TYPE_IPV6PREFIX.

Parameters
vpa pointer to a VALUE_PAIR structure.
resAn in6_addr structure for result to be copied in.
prefixIf of type PW_TYPE_IPV6PREFIX the prefix will be copied (may be NULL).
Returns
zero on success or -1 on failure.

Definition at line 1007 of file avpair.c.

◆ rc_avpair_get_raw()

int rc_avpair_get_raw ( VALUE_PAIR * vp,
char ** res,
unsigned * res_size )

Get the raw value of the given attribute value-pair.

This function is valid for PW_TYPE_STRING, PW_TYPE_IPV6ADDR, PW_TYPE_IPV6PREFIX.

Parameters
vpa pointer to a VALUE_PAIR structure.
resWill contain pointer to the data value.
res_sizeWill contain the data size.
Returns
zero on success or -1 on failure.

Definition at line 1039 of file avpair.c.

◆ rc_avpair_get_uint32()

int rc_avpair_get_uint32 ( VALUE_PAIR * vp,
uint32_t * res )

Get the integer value of the given attribute value-pair.

This function is valid for PW_TYPE_INTEGER, PW_TYPE_IPADDR. PW_TYPE_DATE. In PW_TYPE_IPADDR this value will contain the IPv4 address in host by order.

Parameters
vpa pointer to a VALUE_PAIR structure.
resThe integer value returned.
Returns
zero on success or -1 on failure.

Definition at line 986 of file avpair.c.

◆ rc_avpair_insert()

void rc_avpair_insert ( VALUE_PAIR ** a,
VALUE_PAIR * p,
VALUE_PAIR * b )

Insert a VALUE_PAIR into a list.

Given the address of an existing list "a" and a pointer to an entry "p" in that list, add the value pair "b" to the "a" list after the "p" entry. If "p" is NULL, add the value pair "b" to the end of "a".

Parameters
aa VALUE_PAIR array of values.
pa pointer to a VALUE_PAIR in a.
bThe VALUE_PAIR pointer to add in a.

Definition at line 517 of file avpair.c.

◆ rc_avpair_log()

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.

The caller should provide a storage buffer and the buffer length.

Parameters
rha handle to parsed configuration.
paira pointer to a VALUE_PAIR structure.
bufwill hold the string output of the pair.
buf_lenthe size of buf.
Returns
a pointer to provided storage buffer.

Definition at line 954 of file avpair.c.

◆ rc_avpair_new()

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.

See rc_avpair_assign() for the format of the data.

Parameters
rha handle to parsed configuration.
attridThe attribute of the pair to add (e.g., PW_USER_NAME).
pvalthe value (e.g., the actual username).
lenthe length of pval, or -1 if to calculate (in case of strings).
vendorspecThe vendor ID in case of a vendor specific value - 0 otherwise.
Returns
pointer to generated a/v pair when successful, NULL when failure.

Definition at line 197 of file avpair.c.

◆ rc_avpair_next()

VALUE_PAIR * rc_avpair_next ( VALUE_PAIR * t)

Iterates through the attribute-value pairs.

The attribute-value are organized in a linked-list, and this function provides a way to iterate them given the first element initially.

Parameters
tthe current pair.
Returns
pointer to the next pair, or NULL when finished.

Definition at line 113 of file avpair.c.

◆ rc_avpair_parse()

int rc_avpair_parse ( rc_handle const * rh,
char const * buffer,
VALUE_PAIR ** first_pair )

Parses the buffer to extract the attribute-value pairs.

Parameters
rha handle to parsed configuration.
bufferthe buffer to be parsed.
first_pairan allocated array of values.
Returns
0 on successful parse of attribute-value pair, or -1 on syntax (or other) error detected.

Definition at line 631 of file avpair.c.

◆ rc_avpair_remove()

void rc_avpair_remove ( VALUE_PAIR ** list,
uint32_t attrid,
uint32_t vendorspec )

Removes an attribute-value pair from the given list.

See rc_avpair_assign() for the format of the data.

Parameters
lista VALUE_PAIR array of values
attridThe attribute of the pair to remove (e.g., PW_USER_NAME).
vendorspecThe vendor ID in case of a vendor specific value - 0 otherwise.

Definition at line 70 of file avpair.c.

◆ rc_avpair_tostr()

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.

Parameters
rha handle to parsed configuration.
paira pointer to a VALUE_PAIR structure.
namethe name of the pair.
lnthe size of name.
valuethe value of the pair.
lvthe size of value.
Returns
0 on success, -1 on failure.

Definition at line 838 of file avpair.c.

◆ rc_buildreq()

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.

Note
This is a low-level helper used internally by rc_aaa_ctx_server(). Normal applications should call rc_auth() or rc_acct() instead of constructing SEND_DATA directly.
Parameters
rha handle to parsed configuration.
dataa pointer to a SEND_DATA structure.
codeone of standard RADIUS codes (e.g., PW_ACCESS_REQUEST).
serverthe name of the server.
portthe server's port number.
secretthe secret used by the server.
timeoutthe timeout in seconds of a message.
retriesthe number of retries.

Definition at line 38 of file buildreq.c.

◆ rc_check()

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.

Parameters
rha handle to parsed configuration.
hostthe name of the server.
secretthe secret used by the server.
portthe server's port number.
msgmust be an array of PW_MAX_MSG_SIZE or NULL; will contain the concatenation of any PW_REPLY_MESSAGE received.
Returns
OK_RC (0) on success, negative on failure as return value.

Definition at line 453 of file buildreq.c.

◆ rc_dict_addattr()

DICT_ATTR * rc_dict_addattr ( rc_handle * rh,
char const * namestr,
uint32_t value,
int type,
uint32_t vendorspec )

Add attribute to dictionary.

A re-add identical to an already-loaded attribute of the same name returns that existing attribute rather than adding a duplicate; a re-add of the same name with a conflicting definition (different id/vendor/type) fails, after a warning naming both definitions.

Parameters
rha handle to configuration.
namestrattribute name
typeattribute type
valueattribute value
vendorspecvendorspec
Returns
added (or already-existing, identical) attr on success, NULL on failure or conflict

Definition at line 59 of file dict.c.

◆ rc_dict_addval()

DICT_VALUE * rc_dict_addval ( rc_handle * rh,
char const * attrstr,
char const * namestr,
uint32_t value )

Add value to dictionary.

A re-add identical to an already-loaded value of the same attribute+number returns that existing value rather than adding a duplicate; a re-add of the same attribute+number with a conflicting name fails, after a warning naming both definitions.

Parameters
rha handle to configuration.
attrstrattribute name
namestrname
valueattribute value
Returns
added (or already-existing, identical) value on success, NULL on failure or conflict

Definition at line 78 of file dict.c.

◆ rc_dict_addvend()

DICT_VENDOR * rc_dict_addvend ( rc_handle * rh,
char const * namestr,
uint32_t vendorspec )

Add vendor to dictionary.

A re-add identical to an already-loaded vendor of the same name returns that existing vendor rather than adding a duplicate; a re-add of the same name with a conflicting Vendor-Id fails, after a warning naming both definitions.

Parameters
rha handle to configuration.
namestrvendor name
vendorspecvendorspec
Returns
added (or already-existing, identical) vendor on success, NULL on failure or conflict

Definition at line 96 of file dict.c.

◆ rc_dict_findattr()

DICT_ATTR * rc_dict_findattr ( rc_handle const * rh,
char const * attrname )

Lookup a DICT_ATTR by its name.

Parameters
rha handle to parsed configuration.
attrnamethe attribute name.
Returns
the full attribute structure based on the attribute name.

Definition at line 119 of file dict.c.

◆ rc_dict_findval()

DICT_VALUE * rc_dict_findval ( rc_handle const * rh,
char const * valname )

Lookup a DICT_VALUE by its name.

Parameters
rha handle to parsed configuration.
valnamethe value name.
Returns
the full value structure based on the value name.

Definition at line 130 of file dict.c.

◆ rc_dict_findvend()

DICT_VENDOR * rc_dict_findvend ( rc_handle const * rh,
char const * vendorname )

Lookup a DICT_VENDOR by its name.

Parameters
rha handle to parsed configuration.
vendornamethe vendor name.
Returns
the full vendor structure based on the vendor name.

Definition at line 141 of file dict.c.

◆ rc_dict_getattr()

DICT_ATTR * rc_dict_getattr ( rc_handle const * rh,
uint64_t attribute )

Lookup a DICT_ATTR by attribute number.

Parameters
rha handle to parsed configuration.
attributethe attribute ID.
Returns
the full attribute structure based on the attribute id number.

Definition at line 107 of file dict.c.

◆ rc_dict_getval()

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.

Parameters
rha handle to parsed configuration.
valuethe attribute value.
attrnamethe attribute name.
Returns
the full value structure based on the actual value and the associated attribute name.

Definition at line 164 of file dict.c.

◆ rc_dict_getvend()

DICT_VENDOR * rc_dict_getvend ( rc_handle const * rh,
uint32_t vendorspec )

Lookup a DICT_VENDOR by its IANA number.

Parameters
rha handle to parsed configuration.
vendorspecthe vendor ID.
Returns
the full vendor structure based on the vendor id number.

Definition at line 152 of file dict.c.

◆ rc_pack_list()

int rc_pack_list ( rc_handle * rh,
VALUE_PAIR * vp,
char * secret,
AUTH_HDR * auth,
int max_len )

Definition at line 73 of file send.c.

◆ rc_send_server()

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.

Parameters
rha handle to parsed configuration
dataa pointer to a SEND_DATA structure
msgmust be an array of PW_MAX_MSG_SIZE or NULL; will contain the concatenation of any PW_REPLY_MESSAGE received.
typemust be AUTH or ACCT
Returns
OK_RC (0) on success, TIMEOUT_RC on timeout REJECT_RC on access reject, or negative on failure as return value.

Definition at line 238 of file send.c.

◆ rc_send_server_ctx()

int rc_send_server_ctx ( rc_handle * rh,
RC_AAA_CTX ** ctx,
SEND_DATA * data,
char * msg,
rc_type type,
int no_wait )

Definition at line 267 of file send.c.