From: Alan T. DeKok Date: Fri, 10 Dec 2021 21:25:07 +0000 (-0500) Subject: remove "op" from fr_pair_make() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d2ad0b8828bbc6a7bd2a0f4617221e6d1a5cf1c;p=thirdparty%2Ffreeradius-server.git remove "op" from fr_pair_make() which was only called from rlm_passwd and rlm_perl. And those only used it to append attributes to a list. Also removed the call to fr_pair_mark_xlat() from fr_pair_make() Neither module used that functionality --- diff --git a/src/lib/util/pair_legacy.c b/src/lib/util/pair_legacy.c index 9a46eaf5a1..846994fd63 100644 --- a/src/lib/util/pair_legacy.c +++ b/src/lib/util/pair_legacy.c @@ -100,12 +100,10 @@ int fr_pair_mark_xlat(fr_pair_t *vp, char const *value) * @param dict to user for partial resolution. * @param attribute name to parse. * @param value to parse (must be a hex string). - * @param op to assign to new valuepair. * @return new #fr_pair_t or NULL on error. */ static fr_pair_t *fr_pair_make_unknown(TALLOC_CTX *ctx, fr_dict_t const *dict, - char const *attribute, char const *value, - fr_token_t op) + char const *attribute, char const *value) { fr_pair_t *vp; fr_dict_attr_t *n; @@ -139,7 +137,7 @@ static fr_pair_t *fr_pair_make_unknown(TALLOC_CTX *ctx, fr_dict_t const *dict, if (fr_pair_value_from_str(vp, value, strlen(value), &fr_value_unescape_double, false) < 0) goto error; - vp->op = (op == 0) ? T_OP_EQ : op; + vp->op = T_OP_EQ; return vp; } @@ -155,11 +153,10 @@ static fr_pair_t *fr_pair_make_unknown(TALLOC_CTX *ctx, fr_dict_t const *dict, * @param[in] vps list where the attribute will be added (optional) * @param[in] attribute name. * @param[in] value attribute value (may be NULL if value will be set later). - * @param[in] op to assign to new #fr_pair_t. * @return a new #fr_pair_t. */ fr_pair_t *fr_pair_make(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t *vps, - char const *attribute, char const *value, fr_token_t op) + char const *attribute, char const *value) { fr_dict_attr_t const *da; fr_pair_t *vp; @@ -171,7 +168,7 @@ fr_pair_t *fr_pair_make(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t * */ da = fr_dict_attr_search_by_qualified_oid(NULL, dict, attrname, true, true); if (!da) { - vp = fr_pair_make_unknown(ctx, dict, attrname, value, op); + vp = fr_pair_make_unknown(ctx, dict, attrname, value); if (!vp) return NULL; if (vps) fr_pair_append(vps, vp); @@ -185,60 +182,7 @@ fr_pair_t *fr_pair_make(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_pair_list_t * vp = fr_pair_afrom_da(ctx, da); if (!vp) return NULL; - vp->op = (op == 0) ? T_OP_EQ : op; - - switch (vp->op) { - case T_OP_CMP_TRUE: - case T_OP_CMP_FALSE: - fr_pair_value_clear(vp); - value = NULL; /* ignore it! */ - break; - - /* - * Regular expression comparison of integer attributes - * does a STRING comparison of the names of their - * integer attributes. - */ - case T_OP_REG_EQ: /* =~ */ - case T_OP_REG_NE: /* !~ */ - { -#ifndef HAVE_REGEX - fr_strerror_const("Regular expressions are not supported"); - return NULL; -#else - ssize_t slen; - regex_t *preg; - - /* - * Someone else will fill in the value. - */ - if (!value) break; - - talloc_free(vp); - - slen = regex_compile(ctx, &preg, value, strlen(value), NULL, false, true); - if (slen <= 0) { - fr_strerror_printf_push("Error at offset %zu compiling regex for %s", -slen, attribute); - return NULL; - } - talloc_free(preg); - - vp = fr_pair_afrom_da(ctx, da); - if (!vp) return NULL; - vp->op = op; - - if (fr_pair_mark_xlat(vp, value) < 0) { - talloc_free(vp); - return NULL; - } - - value = NULL; /* ignore it */ - break; -#endif - } - default: - break; - } + vp->op = T_OP_EQ; /* * We probably want to fix fr_pair_value_from_str to accept diff --git a/src/lib/util/pair_legacy.h b/src/lib/util/pair_legacy.h index 468a348b3e..0afb5bcda9 100644 --- a/src/lib/util/pair_legacy.h +++ b/src/lib/util/pair_legacy.h @@ -35,7 +35,7 @@ extern "C" { #endif fr_pair_t *fr_pair_make(TALLOC_CTX *ctx, fr_dict_t const *dict, - fr_pair_list_t *vps, char const *attribute, char const *value, fr_token_t op); + fr_pair_list_t *vps, char const *attribute, char const *value); int fr_pair_mark_xlat(fr_pair_t *vp, char const *value); diff --git a/src/lib/util/pair_legacy_tests.c b/src/lib/util/pair_legacy_tests.c index 966f04d52a..1b75e641a3 100644 --- a/src/lib/util/pair_legacy_tests.c +++ b/src/lib/util/pair_legacy_tests.c @@ -92,7 +92,7 @@ static void test_fr_pair_make(void) fr_pair_list_init(&list); TEST_CASE("Creating 'vp' using fr_pair_make()"); - TEST_CHECK((vp = fr_pair_make(ctx, test_dict, &list, "Test-String-0", test_string, T_DOUBLE_QUOTED_STRING)) != NULL); + TEST_CHECK((vp = fr_pair_make(ctx, test_dict, &list, "Test-String-0", test_string)) != NULL); TEST_CASE("Validating PAIR_VERIFY()"); PAIR_VERIFY(vp); diff --git a/src/modules/rlm_passwd/rlm_passwd.c b/src/modules/rlm_passwd/rlm_passwd.c index 5625a54f4c..65a83e9a2e 100644 --- a/src/modules/rlm_passwd/rlm_passwd.c +++ b/src/modules/rlm_passwd/rlm_passwd.c @@ -524,7 +524,7 @@ static void result_add(TALLOC_CTX *ctx, rlm_passwd_t const *inst, request_t *req (i != inst->key_field) && inst->pwd_fmt->listflag[i] == when) { if (!inst->ignore_empty || pw->field[i][0] != 0 ) { /* if value in key/value pair is not empty */ vp = fr_pair_make(ctx, request->dict, - vps, inst->pwd_fmt->field[i], pw->field[i], T_OP_EQ); + vps, inst->pwd_fmt->field[i], pw->field[i]); if (vp) { RDEBUG2("Added %s: '%s' to %s ", inst->pwd_fmt->field[i], pw->field[i], listname); } diff --git a/src/modules/rlm_perl/rlm_perl.c b/src/modules/rlm_perl/rlm_perl.c index df67088f7e..5b65d226fd 100644 --- a/src/modules/rlm_perl/rlm_perl.c +++ b/src/modules/rlm_perl/rlm_perl.c @@ -738,7 +738,7 @@ static void perl_store_vps(UNUSED TALLOC_CTX *ctx, request_t *request, fr_pair_l * Value Pair Format * */ -static int pairadd_sv(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vps, char *key, SV *sv, fr_token_t op, +static int pairadd_sv(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vps, char *key, SV *sv, const char *hash_name, const char *list_name) { char *val; @@ -748,11 +748,10 @@ static int pairadd_sv(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vps, if (!SvOK(sv)) return -1; val = SvPV(sv, len); - vp = fr_pair_make(ctx, request->dict, vps, key, NULL, op); + vp = fr_pair_make(ctx, request->dict, vps, key, NULL); if (!vp) { fail: - REDEBUG("Failed to create pair %s.%s %s %s", list_name, key, - fr_table_str_by_value(fr_tokens_table, op, ""), val); + REDEBUG("Failed to create pair %s.%s = %s", list_name, key, val); return -1; } @@ -771,8 +770,7 @@ static int pairadd_sv(TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vps, PAIR_VERIFY(vp); - RDEBUG2("&%s.%s %s $%s{'%s'} -> '%s'", list_name, key, fr_table_str_by_value(fr_tokens_table, op, ""), - hash_name, key, val); + RDEBUG2("&%s.%s = $%s{'%s'} -> '%s'", list_name, key, hash_name, key, val); return 0; } @@ -795,9 +793,9 @@ static int get_hv_content(TALLOC_CTX *ctx, request_t *request, HV *my_hv, fr_pai len = av_len(av); for (j = 0; j <= len; j++) { av_sv = av_fetch(av, j, 0); - ret = pairadd_sv(ctx, request, vps, key, *av_sv, T_OP_ADD_EQ, hash_name, list_name) + ret; + ret = pairadd_sv(ctx, request, vps, key, *av_sv, hash_name, list_name) + ret; } - } else ret = pairadd_sv(ctx, request, vps, key, res_sv, T_OP_EQ, hash_name, list_name) + ret; + } else ret = pairadd_sv(ctx, request, vps, key, res_sv, hash_name, list_name) + ret; } if (!fr_pair_list_empty(vps)) PAIR_LIST_VERIFY(vps);