From: Arran Cudbard-Bell Date: Wed, 16 May 2018 06:41:46 +0000 (+0600) Subject: Move radius_(get_|copy)_vp into xlat_func.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08db7dfffd43374c433281e1deeaad4fde610e18;p=thirdparty%2Ffreeradius-server.git Move radius_(get_|copy)_vp into xlat_func.c They're only used by xlat functions and should go away once all the functions have been converted. --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 4d2d2fd9d38..9b6dfcdadd5 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -503,9 +503,6 @@ VALUE_PAIR *radius_pair_create(TALLOC_CTX *ctx, VALUE_PAIR **vps, unsigned int a void log_module_failure_msg(REQUEST *request, char const *fmt, ...) CC_HINT(format (printf, 2, 3)); void vlog_module_failure_msg(REQUEST *request, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0)); -int radius_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name); -int radius_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name); - /* * Less code == fewer bugs diff --git a/src/include/xlat.h b/src/include/xlat.h index 0c91a35ceba..197d4d1c1d4 100644 --- a/src/include/xlat.h +++ b/src/include/xlat.h @@ -231,6 +231,9 @@ typedef int (*xlat_detach_t)(void *xlat_inst, void *uctx); */ typedef int (*xlat_thread_detach_t)(void *xlat_thread_inst, void *uctx); +int xlat_fmt_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name); +int xlat_fmt_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name); + ssize_t xlat_eval(char *out, size_t outlen, REQUEST *request, char const *fmt, xlat_escape_t escape, void const *escape_ctx) CC_HINT(nonnull (1 ,3 ,4)); diff --git a/src/main/pair.c b/src/main/pair.c index f7190010bdc..5f377725a92 100644 --- a/src/main/pair.c +++ b/src/main/pair.c @@ -811,58 +811,3 @@ void rdebug_proto_pair_list(fr_log_lvl_t level, REQUEST *request, VALUE_PAIR *vp } REXDENT(); } - -/** Return a VP from the specified request. - * - * @param out where to write the pointer to the resolved VP. Will be NULL if the attribute couldn't - * be resolved. - * @param request current request. - * @param name attribute name including qualifiers. - * @return - * - -4 if either the attribute or qualifier were invalid. - * - The same error codes as #tmpl_find_vp for other error conditions. - */ -int radius_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name) -{ - int rcode; - vp_tmpl_t *vpt; - - *out = NULL; - - if (tmpl_afrom_attr_str(request, &vpt, name, - REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4; - - rcode = tmpl_find_vp(out, request, vpt); - talloc_free(vpt); - - return rcode; -} - -/** Copy VP(s) from the specified request. - * - * @param ctx to alloc new VALUE_PAIRs in. - * @param out where to write the pointer to the copied VP. Will be NULL if the attribute couldn't be - * resolved. - * @param request current request. - * @param name attribute name including qualifiers. - * @return - * - -4 if either the attribute or qualifier were invalid. - * - The same error codes as #tmpl_find_vp for other error conditions. - */ -int radius_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name) -{ - int rcode; - vp_tmpl_t *vpt; - - *out = NULL; - - if (tmpl_afrom_attr_str(request, &vpt, name, - REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4; - - rcode = tmpl_copy_vps(ctx, out, request, vpt); - talloc_free(vpt); - - return rcode; -} - - diff --git a/src/main/xlat_func.c b/src/main/xlat_func.c index caf8f5085cc..aed7a3c8f5d 100644 --- a/src/main/xlat_func.c +++ b/src/main/xlat_func.c @@ -71,6 +71,59 @@ static char const hextab[] = "0123456789abcdef"; static int xlat_foreach_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; /* up to 10 for foreach */ +/** Return a VP from the specified request. + * + * @param out where to write the pointer to the resolved VP. Will be NULL if the attribute couldn't + * be resolved. + * @param request current request. + * @param name attribute name including qualifiers. + * @return + * - -4 if either the attribute or qualifier were invalid. + * - The same error codes as #tmpl_find_vp for other error conditions. + */ +int xlat_fmt_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name) +{ + int rcode; + vp_tmpl_t *vpt; + + *out = NULL; + + if (tmpl_afrom_attr_str(request, &vpt, name, + REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4; + + rcode = tmpl_find_vp(out, request, vpt); + talloc_free(vpt); + + return rcode; +} + +/** Copy VP(s) from the specified request. + * + * @param ctx to alloc new VALUE_PAIRs in. + * @param out where to write the pointer to the copied VP. Will be NULL if the attribute couldn't be + * resolved. + * @param request current request. + * @param name attribute name including qualifiers. + * @return + * - -4 if either the attribute or qualifier were invalid. + * - The same error codes as #tmpl_find_vp for other error conditions. + */ +int xlat_fmt_copy_vp(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, char const *name) +{ + int rcode; + vp_tmpl_t *vpt; + + *out = NULL; + + if (tmpl_afrom_attr_str(request, &vpt, name, + REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false) <= 0) return -4; + + rcode = tmpl_copy_vps(ctx, out, request, vpt); + talloc_free(vpt); + + return rcode; +} + /** Print length of its RHS. * */ @@ -93,7 +146,7 @@ static ssize_t xlat_length(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; snprintf(*out, outlen, "%zu", fr_value_box_network_length(&vp->data)); return strlen(*out); @@ -113,7 +166,7 @@ static ssize_t xlat_integer(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; switch (vp->vp_type) { case FR_TYPE_OCTETS: @@ -193,7 +246,7 @@ static ssize_t xlat_hex(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) { + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) { error: return -1; } @@ -246,7 +299,7 @@ static ssize_t xlat_tag(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; if (!vp->da->flags.has_tag || !TAG_VALID(vp->tag)) return 0; @@ -452,7 +505,7 @@ static ssize_t xlat_foreach(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen, /* * See modcall, "FOREACH" for how this works. */ - pvp = (VALUE_PAIR **) request_data_reference(request, (void *)radius_get_vp, *(int const *) mod_inst); + pvp = (VALUE_PAIR **) request_data_reference(request, (void *)xlat_fmt_get_vp, *(int const *) mod_inst); if (!pvp || !*pvp) return 0; *out = fr_pair_value_asprint(ctx, *pvp, '\0'); @@ -481,7 +534,7 @@ static ssize_t xlat_string(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, return 0; } - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing; /* * These are printed specially. @@ -524,7 +577,7 @@ static ssize_t xlat_xlat(TALLOC_CTX *ctx, char **out, size_t outlen, return 0; } - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) goto nothing; RDEBUG2("EXPAND %s", fmt); RINDENT(); @@ -932,7 +985,7 @@ static int fr_value_box_from_fmt(TALLOC_CTX *ctx, fr_value_box_t *out, REQUEST * * attribute, and then store the data in network byte * order. */ - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return -1; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return -1; fr_value_box_copy(ctx, out, &vp->data); diff --git a/src/modules/proto_dhcpv4/rlm_dhcpv4.c b/src/modules/proto_dhcpv4/rlm_dhcpv4.c index 2002cdd9bbd..6ccf5f7b7d2 100644 --- a/src/modules/proto_dhcpv4/rlm_dhcpv4.c +++ b/src/modules/proto_dhcpv4/rlm_dhcpv4.c @@ -140,7 +140,7 @@ static ssize_t dhcp_xlat(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_copy_vp(request, &vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_copy_vp(request, &vp, request, fmt) < 0) || !vp) return 0; fr_cursor_init(&cursor, &vp); len = fr_dhcpv4_encode_option(binbuf, sizeof(binbuf), &cursor, NULL); diff --git a/src/modules/rlm_date/rlm_date.c b/src/modules/rlm_date/rlm_date.c index 033f5c08e54..334129302bd 100644 --- a/src/modules/rlm_date/rlm_date.c +++ b/src/modules/rlm_date/rlm_date.c @@ -104,7 +104,7 @@ static ssize_t xlat_date_convert(UNUSED TALLOC_CTX *ctx, char **out, size_t outl return date_encode_strftime(out, outlen, inst, request, now.tv_sec); } - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; switch (vp->vp_type) { /* diff --git a/src/modules/rlm_dict/rlm_dict.c b/src/modules/rlm_dict/rlm_dict.c index 05aef66cff9..1ce7ae0fb32 100644 --- a/src/modules/rlm_dict/rlm_dict.c +++ b/src/modules/rlm_dict/rlm_dict.c @@ -97,7 +97,7 @@ static ssize_t xlat_vendor(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; vendor = fr_dict_vendor_by_da(vp->da); if (!vendor) return 0; @@ -117,7 +117,7 @@ static ssize_t xlat_vendor_num(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; *out = talloc_typed_asprintf(ctx, "%i", fr_dict_vendor_num_by_da(vp->da)); return talloc_array_length(*out) - 1; @@ -134,7 +134,7 @@ static ssize_t xlat_attr(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; strlcpy(*out, vp->da->name, outlen); *out = talloc_typed_strdup(ctx, vp->da->name); @@ -152,7 +152,7 @@ static ssize_t xlat_attr_num(TALLOC_CTX *ctx, char **out, UNUSED size_t outlen, while (isspace((int) *fmt)) fmt++; - if ((radius_get_vp(&vp, request, fmt) < 0) || !vp) return 0; + if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0; *out = talloc_typed_asprintf(ctx, "%i", vp->da->attr); return talloc_array_length(*out) - 1; diff --git a/src/modules/rlm_unpack/rlm_unpack.c b/src/modules/rlm_unpack/rlm_unpack.c index c83a2399995..190ac8e0898 100644 --- a/src/modules/rlm_unpack/rlm_unpack.c +++ b/src/modules/rlm_unpack/rlm_unpack.c @@ -90,7 +90,7 @@ static ssize_t unpack_xlat(UNUSED TALLOC_CTX *ctx, char **out, size_t outlen, * Attribute reference */ if (*data_name == '&') { - if (radius_get_vp(&vp, request, data_name) < 0) goto nothing; + if (xlat_fmt_get_vp(&vp, request, data_name) < 0) goto nothing; if ((vp->vp_type != FR_TYPE_OCTETS) && (vp->vp_type != FR_TYPE_STRING)) { diff --git a/src/unlang/op.c b/src/unlang/op.c index 0f043704086..a409a892904 100644 --- a/src/unlang/op.c +++ b/src/unlang/op.c @@ -1299,7 +1299,7 @@ static unlang_action_t unlang_return(REQUEST *request, RDEBUG2("%s", unlang_ops[instruction->type].name); for (i = 8; i >= 0; i--) { - copy_p = request_data_get(request, (void *)radius_get_vp, i); + copy_p = request_data_get(request, (void *)xlat_fmt_get_vp, i); if (copy_p) { if (instruction->type == UNLANG_TYPE_BREAK) { RDEBUG2("# break Foreach-Variable-%d", i); @@ -1344,7 +1344,7 @@ static unlang_action_t unlang_foreach(REQUEST *request, * FIXME: figure this out by walking up the modcall stack instead. */ for (i = 0; i < 8; i++) { - if (!request_data_reference(request, (void *)radius_get_vp, i)) { + if (!request_data_reference(request, (void *)xlat_fmt_get_vp, i)) { foreach_depth = i; break; } @@ -1410,7 +1410,7 @@ static unlang_action_t unlang_foreach(REQUEST *request, * the xlat outside of a foreach loop and trigger a segv. */ fr_pair_list_free(&foreach->vps); - request_data_get(request, (void *)radius_get_vp, foreach->depth); + request_data_get(request, (void *)xlat_fmt_get_vp, foreach->depth); *presult = frame->result; if (*presult != RLM_MODULE_UNKNOWN) *priority = instruction->actions[*presult]; @@ -1438,7 +1438,7 @@ static unlang_action_t unlang_foreach(REQUEST *request, * xlat.c, xlat_foreach() can find it. */ foreach->variable = vp; - request_data_add(request, (void *)radius_get_vp, foreach->depth, &foreach->variable, + request_data_add(request, (void *)xlat_fmt_get_vp, foreach->depth, &foreach->variable, false, false, false); /*