From: Alan T. DeKok Date: Fri, 27 Jul 2018 12:19:53 +0000 (-0400) Subject: escape quoted strings X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3311a55db83d905c2feeba0e22c52e2f8138fd4a;p=thirdparty%2Ffreeradius-server.git escape quoted strings --- diff --git a/src/bin/radmin.c b/src/bin/radmin.c index b30a51826dc..11b23d0440a 100644 --- a/src/bin/radmin.c +++ b/src/bin/radmin.c @@ -643,7 +643,9 @@ static int tab_expand_config_item(TALLOC_CTX *talloc_ctx, void *ctx, fr_cmd_info static int cmd_show_config_item(FILE *fp, FILE *fp_err, UNUSED void *ctx, fr_cmd_info_t const *info) { + FR_TOKEN token; CONF_ITEM *item; + CONF_PAIR *cp; rad_assert(info->argc > 0); @@ -654,7 +656,37 @@ static int cmd_show_config_item(FILE *fp, FILE *fp_err, UNUSED void *ctx, fr_cmd return -1; } - fprintf(fp, "%s\n", cf_pair_value(cf_item_to_pair(item))); + cp = cf_item_to_pair(item); + token = cf_pair_value_quote(cp); + + if (token == T_BARE_WORD) { + bare: + fprintf(fp, "%s\n", cf_pair_value(cp)); + } else { + char quote; + char *value; + + switch (token) { + case T_DOUBLE_QUOTED_STRING: + quote = '"'; + break; + + case T_SINGLE_QUOTED_STRING: + quote = '\''; + break; + + case T_BACK_QUOTED_STRING: + quote = '`'; + break; + + default: + goto bare; + } + + value = fr_asprint(NULL, cf_pair_value(cp), -1, quote); + fprintf(fp, "%c%s%c\n", quote, value, quote); + talloc_free(value); + } return 0; }