17#include <radcli/radcli.h>
20#define PARSE_MODE_NAME 0
21#define PARSE_MODE_EQUAL 1
22#define PARSE_MODE_VALUE 2
23#define PARSE_MODE_INVALID 3
74 if(vendorspec != VENDOR_NONE)
75 vattrid = RADCLI_VENDOR_ATTR_SET(attrid, vendorspec);
90 prev->next = vp->next;
142 len = (uint32_t)strlen((
char const *)pval);
143 if (len > AUTH_STRING_LEN) {
144 rc_log(LOG_ERR,
"rc_avpair_assign: bad attribute length");
147 memcpy(vp->
strvalue, (
char const *)pval, len);
155 vp->
lvalue = * (uint32_t *) pval;
159 rc_log(LOG_ERR,
"rc_avpair_assign: bad IPv6 length");
162 memcpy(vp->
strvalue, (
char const *)pval, len);
167 if (len < 2 || len > 18) {
168 rc_log(LOG_ERR,
"rc_avpair_assign: bad IPv6 prefix length");
171 memcpy(vp->
strvalue, (
char const *)pval, len);
176 rc_log(LOG_ERR,
"rc_avpair_assign: no attribute %d in dictionary", vp->
type);
199 if(vendorspec != VENDOR_NONE) {
200 vattrid = RADCLI_VENDOR_ATTR_SET(attrid, vendorspec);
207 rc_log(LOG_ERR,
"rc_avpair_new: no attribute %d/%u in dictionary", vendorspec, attrid);
212 rc_log(LOG_ERR,
"rc_avpair_new: no Vendor-Id %d in dictionary", vendorspec);
215 if ((vp = malloc (
sizeof (
VALUE_PAIR))) != NULL)
236 if (vp->
lvalue > AUTH_STRING_LEN - 2)
237 vp->
lvalue = AUTH_STRING_LEN - 2;
254 rc_log(LOG_CRIT,
"rc_avpair_new: out of memory");
272 int length, uint32_t vendorspec)
276 unsigned char const *x_ptr;
280 char buffer[(AUTH_STRING_LEN * 2) + 1];
285 rc_log(LOG_ERR,
"rc_avpair_gen: received attribute with "
290 if (length < attrlen || attrlen < 2) {
291 rc_log(LOG_ERR,
"rc_avpair_gen: received attribute with "
297 if (length != attrlen) {
298 pair =
rc_avpair_gen(rh, pair, ptr + attrlen, length - attrlen,
303 attribute = RADCLI_VENDOR_ATTR_SET(ptr[0], vendorspec);
310 rc_log(LOG_ERR,
"rc_avpair_gen: received VSA "
311 "attribute with invalid length");
314 memcpy(&lvalue, ptr, 4);
315 vendorspec = ntohl(lvalue);
318 rc_log(LOG_WARNING,
"rc_avpair_gen: received VSA "
319 "attribute with unknown Vendor-Id %d", vendorspec);
332 for (x_len = attrlen; x_len > 0; x_len--, x_ptr++) {
333 snprintf(hex,
sizeof(hex),
"%2.2X", x_ptr[0]);
336 if (vendorspec == 0) {
337 rc_log(LOG_WARNING,
"rc_avpair_gen: received "
338 "unknown attribute %d of length %d: 0x%s",
339 (
unsigned)attribute, attrlen + 2, buffer);
341 rc_log(LOG_WARNING,
"rc_avpair_gen: received "
342 "unknown VSA attribute %u, vendor %u of "
343 "length %d: 0x%s", (
unsigned)ATTRID(attribute),
344 (
unsigned)VENDOR(attribute), attrlen + 2, buffer);
348 rpair = calloc(1,
sizeof(*rpair));
350 rc_log(LOG_CRIT,
"rc_avpair_gen: out of memory");
361 switch (attr->
type) {
363 memcpy(pair->
strvalue, (
char *)ptr, (
size_t)attrlen);
370 rc_log(LOG_ERR,
"rc_avpair_gen: received INT "
371 "attribute with invalid length");
376 rc_log(LOG_ERR,
"rc_avpair_gen: received IPADDR"
377 " attribute with invalid length");
380 memcpy((
char *)&lvalue, (
char *)ptr, 4);
381 pair->
lvalue = ntohl(lvalue);
385 rc_log(LOG_ERR,
"rc_avpair_gen: received IPV6ADDR"
386 " attribute with invalid length");
389 memcpy(pair->
strvalue, (
char *)ptr, 16);
393 if (attrlen > 18 || attrlen < 2) {
394 rc_log(LOG_ERR,
"rc_avpair_gen: received IPV6PREFIX"
395 " attribute with invalid length: %d", attrlen);
398 memcpy(pair->
strvalue, (
char *)ptr, attrlen);
403 rc_log(LOG_ERR,
"rc_avpair_gen: received DATE "
404 "attribute with invalid length");
409 rc_log(LOG_WARNING,
"rc_avpair_gen: %s has unknown type",
418 while (pair != NULL) {
435 uint64_t attr = RADCLI_VENDOR_ATTR_SET(attrid, vendorspec);
437 for (; vp != NULL && !(attr == vp->
attribute); vp = vp->next)
492 rc_log(LOG_CRIT,
"rc_avpair_insert: value pair (0x%p) next ptr. (0x%p) not NULL", b, b->next);
515 while (this_node != NULL)
521 this_node = this_node->next;
526 b->next = this_node->next;
559static void rc_fieldcpy(
char *
string,
char const **uptr,
char const *stopat,
size_t len)
561 char const *ptr, *estring;
564 estring =
string + len - 1;
568 while (*ptr !=
'"' && *ptr !=
'\0' && *ptr !=
'\n')
570 if (
string < estring)
583 while (*ptr !=
'\0' && strchr(stopat, *ptr) == NULL)
585 if (
string < estring)
604 char attrstr[AUTH_ID_LEN];
605 char valstr[AUTH_STRING_LEN + 1], *p;
613 mode = PARSE_MODE_NAME;
614 while (*buffer !=
'\n' && *buffer !=
'\0')
616 if (*buffer ==
' ' || *buffer ==
'\t')
624 case PARSE_MODE_NAME:
625 rc_fieldcpy (attrstr, &buffer,
" \t\n=,",
sizeof(attrstr));
629 rc_log(LOG_ERR,
"rc_avpair_parse: unknown attribute");
636 mode = PARSE_MODE_EQUAL;
639 case PARSE_MODE_EQUAL:
642 mode = PARSE_MODE_VALUE;
647 rc_log(LOG_ERR,
"rc_avpair_parse: missing or misplaced equal sign");
656 case PARSE_MODE_VALUE:
657 rc_fieldcpy (valstr, &buffer,
" \t\n,",
sizeof(valstr));
659 if ((pair = malloc (
sizeof (
VALUE_PAIR))) == NULL)
661 rc_log(LOG_CRIT,
"rc_avpair_parse: out of memory");
677 pair->
lvalue = (uint32_t)strlen(valstr);
681 if (isdigit (*valstr))
683 pair->
lvalue = atoi (valstr);
690 rc_log(LOG_ERR,
"rc_avpair_parse: unknown attribute value: %s", valstr);
700 pair->
lvalue = dval->value;
706 if (inet_pton(AF_INET, valstr, &pair->
lvalue) == 0) {
707 rc_log(LOG_ERR,
"rc_avpair_parse: invalid IPv4 address %s", valstr);
716 if (inet_pton(AF_INET6, valstr, pair->
strvalue) == 0) {
717 rc_log(LOG_ERR,
"rc_avpair_parse: invalid IPv6 address %s", valstr);
725 p = strchr(valstr,
'/');
727 rc_log(LOG_ERR,
"rc_avpair_parse: invalid IPv6 prefix %s", valstr);
736 if (inet_pton(AF_INET6, valstr, pair->
strvalue+2) == 0) {
737 rc_log(LOG_ERR,
"rc_avpair_parse: invalid IPv6 prefix %s", valstr);
746 tm = localtime_r (&timeval, &_tm);
750 rc_str2tm (valstr, tm);
752 pair->
lvalue = (uint32_t) timelocal (tm);
754 pair->
lvalue = (uint32_t) mktime (tm);
759 rc_log(LOG_ERR,
"rc_avpair_parse: unknown attribute type %d", pair->
type);
781 if (pair->
lvalue > AUTH_STRING_LEN - 2)
782 pair->
lvalue = AUTH_STRING_LEN - 2;
796 if (*first_pair == NULL)
803 while (link->next != NULL)
810 mode = PARSE_MODE_NAME;
814 mode = PARSE_MODE_NAME;
839 *name = *value =
'\0';
841 if (!pair || pair->
name[0] ==
'\0') {
842 rc_log(LOG_ERR,
"rc_avpair_tostr: pair is NULL or empty");
846 strlcpy(name, pair->
name, (
size_t) ln);
853 ptr = (
unsigned char *) pair->
strvalue;
862 if (!(isprint (*ptr)))
865 snprintf (&value[pos], lv,
"\\%03o", *ptr);
890 strlcpy(value, dval->name, (
size_t) lv);
894 snprintf(value, lv,
"%ld", (
long int)pair->
lvalue);
899 inad.s_addr = htonl(pair->
lvalue);
900 strlcpy (value, inet_ntoa (inad), (
size_t) lv);
904 if (inet_ntop(AF_INET6, pair->
strvalue, value, lv) == NULL)
914 memset(ip, 0,
sizeof(ip));
917 if (inet_ntop(AF_INET6, ip, (
void*)txt,
sizeof(txt)) == NULL)
919 snprintf(value, lv,
"%s/%u", txt, (
unsigned)pair->
strvalue[1]);
925 struct tm *ptm = gmtime_r((time_t *) & pair->
lvalue, &_tm);
929 strftime (value, lv,
"%m/%d/%y %H:%M:%S", ptm);
934 rc_log(LOG_ERR,
"rc_avpair_tostr: unknown attribute type %d", pair->
type);
956 char name[33], value[256];
959 for (vp = pair; vp != NULL; vp = vp->next) {
961 sizeof(value)) == -1)
963 nlen = len + 32 + 3 + strlen(value) + 2 + 2;
965 sprintf(buf + len,
"%-32s = '%s'\n", name, value);
1018 *prefix = (
unsigned char)vp->
strvalue[1];
void rc_avpair_remove(VALUE_PAIR **list, uint32_t attrid, uint32_t vendorspec)
DICT_VALUE * rc_dict_getval(rc_handle const *rh, uint32_t value, char const *attrname)
int rc_avpair_get_raw(VALUE_PAIR *vp, char **res, unsigned *res_size)
char * rc_avpair_log(rc_handle const *rh, VALUE_PAIR *pair, char *buf, size_t buf_len)
VALUE_PAIR * rc_avpair_next(VALUE_PAIR *t)
int rc_avpair_get_uint32(VALUE_PAIR *vp, uint32_t *res)
int rc_avpair_get_in6(VALUE_PAIR *vp, struct in6_addr *res, unsigned *prefix)
void rc_avpair_get_attr(VALUE_PAIR *vp, unsigned *type, unsigned *id)
VALUE_PAIR * rc_avpair_gen(rc_handle const *rh, VALUE_PAIR *pair, unsigned char const *ptr, int length, uint32_t vendorspec)
void rc_avpair_free(VALUE_PAIR *pair)
VALUE_PAIR * rc_avpair_copy(VALUE_PAIR *p)
int rc_avpair_tostr(rc_handle const *rh, VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
int rc_avpair_assign(VALUE_PAIR *vp, void const *pval, int len)
DICT_VALUE * rc_dict_findval(rc_handle const *rh, char const *valname)
int rc_avpair_parse(rc_handle const *rh, char const *buffer, VALUE_PAIR **first_pair)
DICT_VENDOR * rc_dict_getvend(rc_handle const *rh, uint32_t vendorspec)
DICT_ATTR * rc_dict_getattr(rc_handle const *rh, uint64_t attribute)
VALUE_PAIR * rc_avpair_add(rc_handle const *rh, VALUE_PAIR **list, uint32_t attrid, void const *pval, int len, uint32_t vendorspec)
void rc_avpair_insert(VALUE_PAIR **a, VALUE_PAIR *p, VALUE_PAIR *b)
VALUE_PAIR * rc_avpair_get(VALUE_PAIR *vp, uint32_t attrid, uint32_t vendorspec)
DICT_ATTR * rc_dict_findattr(rc_handle const *rh, char const *attrname)
VALUE_PAIR * rc_avpair_new(rc_handle const *rh, uint32_t attrid, void const *pval, int len, uint32_t vendorspec)
@ PW_DIGEST_NONCE
Its type is string.
@ PW_DIGEST_REALM
Its type is string.
@ PW_DIGEST_USER_NAME
Its type is string.
@ PW_DIGEST_URI
Its type is string.
@ PW_DIGEST_QOP
Its type is string.
@ PW_DIGEST_BODY_DIGEST
Its type is string.
@ PW_DIGEST_ATTRIBUTES
Its type is string.
@ PW_DIGEST_NONCE_COUNT
Its type is string.
@ PW_DIGEST_ALGORITHM
Its type is string.
@ PW_DIGEST_CNONCE
Its type is string.
@ PW_DIGEST_METHOD
Its type is string.
@ PW_VENDOR_SPECIFIC
Its type is string.
@ 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
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.