/* valuepair.c */
VALUE_PAIR *pairalloc(DICT_ATTR *da);
+VALUE_PAIR *paircreate_raw(int attr, int vendor, int type, VALUE_PAIR *);
VALUE_PAIR *paircreate(int attr, int vendor, int type);
void pairfree(VALUE_PAIR **);
void pairbasicfree(VALUE_PAIR *pair);
default:
raw:
- vp->type = PW_TYPE_OCTETS;
- vp->length = length;
- memcpy(vp->vp_octets, data, length);
-
-
/*
- * Ensure there's no encryption or tag stuff,
- * we just pass the attribute as-is.
+ * Change the name to show the user that the
+ * attribute is not of the correct format.
*/
- memset(&vp->flags, 0, sizeof(vp->flags));
+ {
+ int attr = vp->attribute;
+ int vendor = vp->vendor;
+ VALUE_PAIR *vp2;
+
+ vp2 = pairalloc(NULL);
+ if (!vp2) {
+ pairfree(&vp);
+ return NULL;
+ }
+ pairfree(&vp);
+ vp = vp2;
+
+ /*
+ * This sets "vp->flags" appropriately,
+ * and vp->type.
+ */
+ if (!paircreate_raw(attr, vendor, PW_TYPE_OCTETS, vp)) {
+ return NULL;
+ }
+
+ vp->length = length;
+ memcpy(vp->vp_octets, data, length);
+ }
+ break;
}
return vp;
return vp;
}
+/*
+ * Create a new valuepair.
+ */
+VALUE_PAIR *paircreate_raw(int attr, int vendor, int type, VALUE_PAIR *vp)
+{
+ char *p = (char *) (vp + 1);
+
+ if (!vp->flags.unknown_attr) {
+ pairfree(&vp);
+ return NULL;
+ }
+
+ vp->vendor = vendor;
+ vp->attribute = attr;
+ vp->operator = T_OP_EQ;
+ vp->name = p;
+ vp->type = type;
+ vp->length = 0;
+ memset(&vp->flags, 0, sizeof(vp->flags));
+ vp->flags.unknown_attr = 1;
+
+ if (!vp_print_name(p, FR_VP_NAME_LEN, vp->attribute, vp->vendor)) {
+ free(vp);
+ return NULL;
+ }
+
+ return vp;
+}
/*
* Create a new valuepair.
/*
* It isn't in the dictionary: update the name.
*/
- if (!da) {
- char *p = (char *) (vp + 1);
-
- vp->vendor = vendor;
- vp->attribute = attr;
- vp->name = p;
- vp->type = type; /* be forgiving */
-
- if (!vp_print_name(p, FR_VP_NAME_LEN, attr, vendor)) {
- free(vp);
- return NULL;
- }
- }
+ if (!da) return paircreate_raw(attr, vendor, type, vp);
return vp;
}
return NULL;
}
memcpy(n, vp, sizeof(*n) + name_len);
+
+ /*
+ * Reset the name field to point to the NEW attribute,
+ * rather than to the OLD one.
+ */
+ if (vp->flags.unknown_attr) n->name = (char *) (n + 1);
+
n->next = NULL;
if ((n->type == PW_TYPE_TLV) &&