39#include <radcli/radcli.h>
40#include <radcli/radcli2.h>
80int radcli_avp_list_to_value_pairs(rc_handle
const *rh,
const radcli_avp_list *l, VALUE_PAIR **out)
84 VALUE_PAIR *head = NULL, **tail = &head;
86 if (rh == NULL || out == NULL)
97 it = radcli_avp_list_iter(l);
98 while ((a = radcli_avp_iter_next(&it)) != NULL) {
99 const struct radcli_dict_attr *def = (
const struct radcli_dict_attr *)radcli_avp_def(a);
105 rc_attr_type type = radcli_dict_type_to_legacy(def->type);
106 unsigned max_vlen = (VENDOR(def->value) != 0) ? (AUTH_STRING_LEN - VSA_HDR_LEN) : AUTH_STRING_LEN;
111 radcli_avp_get_bytes(a, &data, &len);
116 if (len > max_vlen) {
117 rc_log(LOG_WARNING,
"radcli_avp_list_to_value_pairs: %s: "
118 "%zu bytes exceeds VALUE_PAIR's %u-byte limit, omitting",
119 def->name, len, max_vlen);
125 rc_log(LOG_WARNING,
"radcli_avp_list_to_value_pairs: %s: "
126 "%zu bytes, expected 16, omitting", def->name, len);
133 if (len !=
sizeof(uint32_t)) {
134 rc_log(LOG_WARNING,
"radcli_avp_list_to_value_pairs: %s: "
135 "%zu bytes, expected 4, omitting", def->name, len);
143 vp = calloc(1,
sizeof(*vp));
145 rc_log(LOG_CRIT,
"radcli_avp_list_to_value_pairs: out of memory");
149 strlcpy(vp->
name, def->name,
sizeof(vp->
name));
157 vp->
lvalue = (uint32_t)len;
166 memcpy(&vp->
lvalue, data,
sizeof(uint32_t));
187int radcli_value_pairs_to_avp_list(rc_handle
const *rh, VALUE_PAIR *vp, radcli_avp_list **out)
189 radcli_avp_list *list;
191 if (rh == NULL || out == NULL)
194 list = radcli_avp_list_new();
198 for (; vp != NULL; vp = vp->next) {
199 const radcli_attr_def *def = radcli_dict_lookup_num(rh, (uint32_t)ATTRID(vp->
attribute),
212 if (radcli_avp_add_bytes(list, def, vp->
strvalue, vp->
lvalue) != 0) {
213 radcli_avp_list_free(list);
220 if (radcli_avp_add_bytes(list, def, &vp->
lvalue,
sizeof(vp->
lvalue)) != 0) {
221 radcli_avp_list_free(list);
void rc_avpair_free(VALUE_PAIR *pair)
Frees all value_pairs in the list.
@ 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_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_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.