diff --git a/src/include/libradius.h b/src/include/libradius.h index 096746ab8a04..d02425044953 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -629,7 +629,6 @@ void pairmemsteal(VALUE_PAIR *vp, uint8_t const *src); void pairstrsteal(VALUE_PAIR *vp, char const *src); void pairstrcpy(VALUE_PAIR *vp, char const * src); void pairstrncpy(VALUE_PAIR *vp, char const * src, size_t len); -int pairdatacpy(VALUE_PAIR *vp, PW_TYPE type, value_data_t const *data, size_t len); void pairsprintf(VALUE_PAIR *vp, char const * fmt, ...) CC_HINT(format (printf, 2, 3)); void pairmove(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from); void pairfilter(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from, diff --git a/src/lib/pair.c b/src/lib/pair.c index 5b6b3bfa0faf..39c95367efd0 100644 --- a/src/lib/pair.c +++ b/src/lib/pair.c @@ -2107,88 +2107,6 @@ void pairstrncpy(VALUE_PAIR *vp, char const *src, size_t len) pairtypeset(vp); } -/** Copy data from one VP to another - * - * Allocate a new pair using da, and copy over the value from the specified vp. - * - * @todo Should be able to do type conversions. - * - * @param[in,out] vp to update. - * @param[in] type of data represented by data. - * @param[in] data to copy. - * @param[in] len of data to copy. - * @return 0 on success -1 on failure. - */ -int pairdatacpy(VALUE_PAIR *vp, PW_TYPE type, value_data_t const *data, size_t len) -{ - void *old; - VERIFY_VP(vp); - - /* - * The types have to be identical, OR the "from" type has - * to be octets. - */ - if (vp->da->type != type) { - /* - * Decode the octets buffer using the RADIUS decoder. - */ - if (type == PW_TYPE_OCTETS) { - if (data2vp(vp, NULL, NULL, NULL, vp->da, data->octets, len, len, &vp) < 0) return -1; - vp->type = VT_DATA; - return 0; - } - - /* - * Else if the destination type is octets - */ - if (vp->da->type == PW_TYPE_OCTETS) { - int ret; - uint8_t *buff; - VALUE_PAIR const *pvp = vp; - - buff = talloc_array(vp, uint8_t, dict_attr_sizes[type][1] + 2); - - ret = rad_vp2rfc(NULL, NULL, NULL, &pvp, buff, dict_attr_sizes[type][1]); - if (ret < 0) return -1; - - pairmemcpy(vp, buff + 2, ret - 2); - talloc_free(buff); - - return 0; - } - - /* - * Fixme... - */ - fr_strerror_printf("Data conversion not supported"); - return -1; - } - - /* - * Clear existing value if there is one - */ - memcpy(&old, &vp->data.ptr, sizeof(old)); - talloc_free(old); - - switch (vp->da->type) { - case PW_TYPE_TLV: - case PW_TYPE_OCTETS: - pairmemcpy(vp, data->octets, len); - break; - - case PW_TYPE_STRING: - pairstrncpy(vp, data->strvalue, len); - break; - - default: - memcpy(&vp->data, data, sizeof(vp->data)); - break; - } - vp->vp_length = len; - - return 0; -} - /** Print data into an "string" data type. * * @param[in,out] vp to update diff --git a/src/lib/value.c b/src/lib/value.c index 9697d78b009d..86cb2c7b3eae 100644 --- a/src/lib/value.c +++ b/src/lib/value.c @@ -1193,10 +1193,18 @@ ssize_t value_data_cast(TALLOC_CTX *ctx, value_data_t *dst, return src_len; } -ssize_t value_data_copy(TALLOC_CTX *ctx, value_data_t *dst, PW_TYPE type, +/** Copy value data verbatim duplicating any buffers + * + * @param ctx To allocate buffers in. + * @param dst Where to copy value_data to. + * @param src_type Type of src. + * @param src Where to copy value_data from. + * @param src_len Where + */ +ssize_t value_data_copy(TALLOC_CTX *ctx, value_data_t *dst, PW_TYPE src_type, const value_data_t *src, size_t src_len) { - switch (type) { + switch (src_type) { default: memcpy(dst, src, sizeof(*src)); break; diff --git a/src/modules/rlm_cache/serialize.c b/src/modules/rlm_cache/serialize.c index 12d91355cd6f..dc162d1250f4 100644 --- a/src/modules/rlm_cache/serialize.c +++ b/src/modules/rlm_cache/serialize.c @@ -139,6 +139,7 @@ int cache_deserialize(rlm_cache_entry_t *c, char *in, ssize_t inlen) while (((size_t)(p - in)) < (size_t)inlen) { value_pair_map_t *map = NULL; VALUE_PAIR *vp = NULL; + ssize_t len; q = strchr(p, '\n'); if (!q) break; /* List should also be terminated with a \n */ @@ -172,10 +173,9 @@ int cache_deserialize(rlm_cache_entry_t *c, char *in, ssize_t inlen) if (!tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da)) goto error; vp = pairalloc(c, map->lhs->tmpl_da); - if (pairdatacpy(vp, map->rhs->tmpl_data_type, &map->rhs->tmpl_data_value, - map->rhs->tmpl_data_length) < 0) { - goto error; - } + len = value_data_copy(vp, &vp->data, map->rhs->tmpl_data_type, + &map->rhs->tmpl_data_value, map->rhs->tmpl_data_length); + if (len < 0) goto error; /* * Pull out the special attributes, and set the