]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
escape quoted strings
authorAlan T. DeKok <aland@freeradius.org>
Fri, 27 Jul 2018 12:19:53 +0000 (08:19 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 27 Jul 2018 12:19:53 +0000 (08:19 -0400)
src/bin/radmin.c

index b30a51826dc28c29bca9e1cd8fc5d706602e8eb0..11b23d0440a0046646b571c3c3b298d93f0a2591 100644 (file)
@@ -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;
 }