void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, unsigned int attr, unsigned int vendor);
VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value);
VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator);
+VALUE_PAIR *pairmake_xlat(const char *attribute, const char *value, int operator);
VALUE_PAIR *pairread(const char **ptr, FR_TOKEN *eol);
FR_TOKEN userparse(const char *buffer, VALUE_PAIR **first_pair);
VALUE_PAIR *readvp2(FILE *fp, int *pfiledone, const char *errprefix);
* extended attribute of the "evs" data type.
*/
if (*p == '.') {
- DICT_ATTR *da;
-
da = dict_attrbyvalue(attr, 0);
if (!da) {
fr_strerror_printf("Cannot parse attributes without dictionaries");
pairbasicfree(vp);
return NULL;
}
-
- strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
- vp->length = strlen(vp->vp_strvalue);
- /*
- * If anything goes wrong, this is a run-time error,
- * not a compile-time error.
- */
- return vp;
+ pairbasicfree(vp);
+ return pairmake_xlat(attribute, value, operator);
}
/*
return vp;
}
+VALUE_PAIR *pairmake_xlat(const char *attribute, const char *value, int operator)
+{
+ VALUE_PAIR *vp;
+
+ if (!value) {
+ fr_strerror_printf("Empty value passed to pairmake_xlat()");
+ return NULL;
+ }
+
+ vp = pairmake(attribute, NULL, operator);
+ if (!vp) return vp;
+
+ strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
+ vp->flags.do_xlat = 1;
+ vp->length = 0;
+
+ return vp;
+}
/*
* [a-zA-Z0-9_-:.]+
fr_strerror_printf("Value too long");
return NULL;
}
- vp = pairmake(attr, NULL, token);
+ vp = pairmake_xlat(attr, value, token);
if (!vp) {
*eol = T_OP_INVALID;
return NULL;
}
- strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
- vp->flags.do_xlat = 1;
- vp->length = 0;
} else {
/*
* Parse && escape it, as defined by the
return NULL;
}
- vp = pairmake(attr, NULL, token);
+ vp = pairmake_xlat(attr, value, token);
if (!vp) {
*eol = T_OP_INVALID;
return NULL;
}
-
- vp->flags.do_xlat = 1;
- strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
- vp->length = 0;
break;
}
*/
VALUE_PAIR *cf_pairtovp(CONF_PAIR *pair)
{
- VALUE_PAIR *vp;
-
if (!pair) {
fr_strerror_printf("Internal error");
return NULL;
}
/*
- * pairmake handles tags. pairalloc() doesn't.
- */
- vp = pairmake(pair->attr, NULL, pair->operator);
- if (!vp) {
- return NULL;
- }
-
- /*
- * Ignore the value if it's a false comparison.
+ * FALSE comparisons never match. BUT if it's a "string"
+ * or `string`, then remember to expand it later.
*/
- if (pair->operator == T_OP_CMP_FALSE) return vp;
-
- if (pair->value_type == T_BARE_WORD) {
- if ((vp->type == PW_TYPE_STRING) &&
- (pair->value[0] == '0') && (pair->value[1] == 'x')) {
- vp->type = PW_TYPE_OCTETS;
- }
- if (!pairparsevalue(vp, pair->value)) {
- pairfree(&vp);
- return NULL;
- }
- vp->flags.do_xlat = 0;
-
- } else if (pair->value_type == T_SINGLE_QUOTED_STRING) {
- if (!pairparsevalue(vp, pair->value)) {
- pairfree(&vp);
- return NULL;
- }
- vp->flags.do_xlat = 0;
- } else {
- vp->flags.do_xlat = 1;
+ if ((pair->operator != T_OP_CMP_FALSE) &&
+ ((pair->value_type == T_DOUBLE_QUOTED_STRING) ||
+ (pair->value_type == T_BACK_QUOTED_STRING))) {
+ return pairmake_xlat(pair->attr, pair->value, pair->operator);
}
- return vp;
+ return pairmake(pair->attr, pair->value, pair->operator);
}
/*
/*
* Create the pair.
*/
- newpair = pairmake(element->radius_attr,
- do_xlat ? NULL : value,
- operator);
+ if (do_xlat) {
+ newpair = pairmake_xlat(element->radius_attr,
+ value,
+ operator);
+ } else {
+ newpair = pairmake(element->radius_attr,
+ value,
+ operator);
+ }
if (newpair == NULL) {
radlog(L_ERR, " [%s] Failed to create the pair: %s", inst->xlat_name, fr_strerror());
continue;
}
- if (do_xlat) {
- newpair->flags.do_xlat = 1;
- strlcpy(newpair->vp_strvalue, buf,
- sizeof(newpair->vp_strvalue));
- newpair->length = 0;
- }
vp_prints(print_buffer, sizeof(print_buffer),
newpair);
DEBUG(" [%s] %s -> %s", inst->xlat_name,
/*
* Create the pair
*/
- pair = pairmake(row[2], value, operator);
+ if (do_xlat) {
+ pair = pairmake_xlat(row[2], value, operator);
+ } else {
+ pair = pairmake(row[2], value, operator);
+ }
if (pair == NULL) {
radlog(L_ERR, "rlm_sql: Failed to create the pair: %s", fr_strerror());
return -1;
}
- if (do_xlat) {
- pair->flags.do_xlat = 1;
- strlcpy(pair->vp_strvalue, buf, sizeof(pair->vp_strvalue));
- pair->length = 0;
- }
/*
* Add the pair into the packet