|
Radcli library 2.0.0
A simple radius library -- legacy API reference
|
The following are real before/after pairs, adapted from a RADIUS authentication module mid-migration to the new API. See API mapping for the function-by-function table these draw from.
Building an Access-Request used to mean checking every rc_avpair_add() call individually:
With the new API, every add is unconditional and a single check at the end covers the whole batch:
The legacy pattern hand-rolls the "does it already have a realm" check and the concatenation:
radcli_avp_add_username() does the check and, passed NULL for realm, reaches for ctx's own default_realm config option, so an application whose realm policy is just "whatever the config file says" never reads that option out itself:
RFC 2869's Acct-Input/Output-Gigawords exists because RADIUS has no 64-bit counter attribute: a 64-bit octet count is really two 32-bit attributes, and the legacy API leaves combining them to the caller:
radcli_avp_add_gigawords64()/radcli_avp_get_gigawords64() do the splitting/reassembly, including looking up octets' Gigawords counterpart from the dictionary rather than trusting the caller to get the pairing right:
The legacy rc_attr_type enum predates RFC 8044 and has no integer64 or ifid type – attributes of those types come back as raw bytes that the caller must byte-swap by hand:
The new dictionary understands RADCLI_TYPE_INTEGER64/RADCLI_TYPE_IFID natively, so radcli_avp_get_uint64_by_num() returns the decoded value in one call, byte order already handled:
The legacy pattern is a lookup call whose result feeds a second call:
Which is manageable for one attribute, but the new API's _by_num() accessors fold "find the attribute" and "read it as this type" into a single typed call for every attribute type, including the ones (IPv6, IPv6/IPv4 prefixes, raw bytes, C strings) where the legacy struct's shared lvalue/strvalue fields otherwise need type-specific care:
For a reply attribute read repeatedly in a hot path, resolving its radcli_attr_def * once with radcli_dict_lookup_num() and reusing it across radcli_avp_get() calls (comparing by pointer identity, not attribute number) avoids repeating that lookup – see radcli2-avp-by-num.
A server is free to send more than one Reply-Message in a single Access-Accept/-Reject/-Challenge (RFC 2865 SS5.16 – one attribute cannot hold more than 253 bytes, so a longer message is split across several occurrences), and applications that surface it to the end user – as a login-failure reason, or the prompt text of an interactive multi-factor challenge – need the whole message, not just the first fragment. That means every occurrence has to be walked and joined, not just the first one rc_avpair_get() would hand back: