*
*/
-VALUE_PAIR *rc_avpair_add (VALUE_PAIR **list, int attrid, void *pval, int len,
+VALUE_PAIR *rc_avpair_add (VALUE_PAIR **list, int attrid, const void *pval, int len,
int vendorcode)
{
VALUE_PAIR *vp;
*
*/
-int rc_avpair_assign (VALUE_PAIR *vp, void *pval, int len)
+int rc_avpair_assign (VALUE_PAIR *vp, const void *pval, int len)
{
int result = -1;
{
case PW_TYPE_STRING:
- if (((len == 0) && (strlen ((char *) pval)) > AUTH_STRING_LEN)
+ if (((len == 0) && (strlen ((const char *) pval)) > AUTH_STRING_LEN)
|| (len > AUTH_STRING_LEN)) {
error("rc_avpair_assign: bad attribute length");
return result;
}
if (len > 0) {
- memcpy(vp->strvalue, (char *)pval, len);
+ memcpy(vp->strvalue, (const char *)pval, len);
vp->strvalue[len] = '\0';
vp->lvalue = len;
} else {
- strncpy (vp->strvalue, (char *) pval, AUTH_STRING_LEN);
- vp->lvalue = strlen((char *) pval);
+ strncpy ((char*) vp->strvalue, (const char *) pval, AUTH_STRING_LEN);
+ vp->lvalue = strlen((const char *) pval);
}
result = 0;
*
*/
-VALUE_PAIR *rc_avpair_new (int attrid, void *pval, int len, int vendorcode)
+VALUE_PAIR *rc_avpair_new (int attrid, const void *pval, int len, int vendorcode)
{
VALUE_PAIR *vp = (VALUE_PAIR *) NULL;
DICT_ATTR *pda;
DICT_ATTR *attr;
VALUE_PAIR *vp;
VALUE_PAIR *pair;
- unsigned char hex[3]; /* For hex string conversion. */
+ char hex[3]; /* For hex string conversion. */
char buffer[512];
/*
{
attribute = *ptr++;
attrlen = *ptr++;
- attrlen -= 2;
- if (attrlen < 0)
+ if (attrlen < 2 || attrlen > length)
{
error("rc_avpair_gen: received attribute with invalid length");
break;
}
+ attrlen -= 2;
/* Handle vendor-specific specially */
if (attribute == PW_VENDOR_SPECIFIC) {
{
case PW_TYPE_STRING:
+ case PW_TYPE_IFID:
+ case PW_TYPE_IPV6ADDR:
+ case PW_TYPE_IPV6PREFIX:
memcpy (pair->strvalue, (char *) ptr, (size_t) attrlen);
pair->strvalue[attrlen] = '\0';
pair->lvalue = attrlen;
{
case PW_TYPE_STRING:
- strcpy (pair->strvalue, valstr);
+ strcpy ((char*) pair->strvalue, valstr);
pair->lvalue = strlen(valstr);
break;
int rc_avpair_tostr (VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
{
DICT_VALUE *dval;
- char buffer[32];
+ char buffer[INET6_ADDRSTRLEN + 4]; // for a prefix: addr + '/' + prefixlen
struct in_addr inad;
unsigned char *ptr;
+ char *str;
*name = *value = '\0';
}
else
{
- strncat(value, ptr, 1);
+ strncat(value, (char*) ptr, 1);
lv--;
if (lv < 0) break;
}
strncpy(value, buffer, lv-1);
break;
+ case PW_TYPE_IFID:
+ ptr = pair->strvalue;
+ snprintf(buffer, sizeof (buffer), "%x:%x:%x:%x",
+ (ptr[0] << 8) + ptr[1], (ptr[2] << 8) + ptr[3],
+ (ptr[4] << 8) + ptr[5], (ptr[6] << 8) + ptr[7]);
+ strncpy(value, buffer, lv-1);
+ break;
+
+ case PW_TYPE_IPV6ADDR:
+ inet_ntop(AF_INET6, pair->strvalue, buffer, sizeof (buffer));
+ strncpy(value, buffer, lv-1);
+ break;
+
+ case PW_TYPE_IPV6PREFIX:
+ inet_ntop(AF_INET6, pair->strvalue + 2, buffer, sizeof (buffer));
+ str = buffer + strlen(buffer);
+ snprintf(str, sizeof (buffer) - (str - buffer), "/%d", *(pair->strvalue + 1));
+ strncpy(value, buffer, lv-1);
+ break;
+
default:
error("rc_avpair_tostr: unknown attribute type %d", pair->type);
return (-1);