From: Alan T. DeKok Date: Tue, 29 Nov 2011 10:56:25 +0000 (+0100) Subject: Move do_xlat=1 code to pairmake_xlat() X-Git-Tag: release_3_0_0_beta0~459 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12f19f048ed22bb8c9bc46243d058572ace51702;p=thirdparty%2Ffreeradius-server.git Move do_xlat=1 code to pairmake_xlat() This abstracts the xlat code (i.e. integer type needs string) so that it's easier to fix it later. --- diff --git a/src/include/libradius.h b/src/include/libradius.h index 2a5033d4d40..b3fa8daa2de 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -417,6 +417,7 @@ void pairmove(VALUE_PAIR **to, VALUE_PAIR **from); 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); diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c index b3eebc8d875..a2f1f0095c1 100644 --- a/src/lib/valuepair.c +++ b/src/lib/valuepair.c @@ -1435,8 +1435,6 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value, * 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"); @@ -1687,15 +1685,9 @@ VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator) 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); } /* @@ -1714,6 +1706,24 @@ VALUE_PAIR *pairmake(const char *attribute, const char *value, int 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_-:.]+ @@ -1842,15 +1852,12 @@ VALUE_PAIR *pairread(const char **ptr, FR_TOKEN *eol) 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 @@ -1900,15 +1907,11 @@ VALUE_PAIR *pairread(const char **ptr, FR_TOKEN *eol) 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; } diff --git a/src/main/conffile.c b/src/main/conffile.c index 531ea9f8c48..48960cd86c3 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -1989,8 +1989,6 @@ extern void fr_strerror_printf(const char *, ...); */ VALUE_PAIR *cf_pairtovp(CONF_PAIR *pair) { - VALUE_PAIR *vp; - if (!pair) { fr_strerror_printf("Internal error"); return NULL; @@ -2002,40 +2000,16 @@ VALUE_PAIR *cf_pairtovp(CONF_PAIR *pair) } /* - * 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); } /* diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index 3caa97c556b..6af1762b377 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -2781,20 +2781,20 @@ static VALUE_PAIR *ldap_pairget(LDAP *ld, LDAPMessage *entry, /* * 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, diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 9943deb695c..5bfa6624754 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -222,16 +222,15 @@ int sql_userparse(VALUE_PAIR ** first_pair, SQL_ROW row) /* * 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