From: Timo Sirainen Date: Thu, 2 Sep 2010 16:01:00 +0000 (+0100) Subject: doveconf: Quote output values when necessary. X-Git-Tag: 2.0.2~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d32d7ecc76c7ed93fbdd92ec3a7157a29c5f246e;p=thirdparty%2Fdovecot%2Fcore.git doveconf: Quote output values when necessary. --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index 7d06021600..a9e3ceb6d6 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -26,8 +26,6 @@ # define GLOB_BRACE 0 #endif -#define IS_WHITE(c) ((c) == ' ' || (c) == '\t') - static const enum settings_parser_flags settings_parser_flags = SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS | SETTINGS_PARSER_FLAG_TRACK_CHANGES; diff --git a/src/config/config-parser.h b/src/config/config-parser.h index 882c28671c..c6312a587d 100644 --- a/src/config/config-parser.h +++ b/src/config/config-parser.h @@ -3,6 +3,8 @@ #define CONFIG_MODULE_DIR MODULEDIR"/settings" +#define IS_WHITE(c) ((c) == ' ' || (c) == '\t') + struct config_module_parser { const struct setting_parser_info *root; struct setting_parser_context *parser; diff --git a/src/config/doveconf.c b/src/config/doveconf.c index f0a340b849..5ece82fac5 100644 --- a/src/config/doveconf.c +++ b/src/config/doveconf.c @@ -7,6 +7,7 @@ #include "env-util.h" #include "ostream.h" #include "str.h" +#include "strescape.h" #include "settings-parser.h" #include "master-service.h" #include "all-settings.h" @@ -146,6 +147,20 @@ static void config_dump_human_deinit(struct config_dump_human_context *ctx) pool_unref(&ctx->pool); } +static bool value_need_quote(const char *value) +{ + unsigned int len = strlen(value); + + if (len == 0) + return FALSE; + + if (strchr(value, '#') != NULL) + return TRUE; + if (IS_WHITE(value[0]) || IS_WHITE(value[len-1])) + return TRUE; + return FALSE; +} + static int config_dump_human_output(struct config_dump_human_context *ctx, struct ostream *output, unsigned int indent, @@ -271,7 +286,13 @@ config_dump_human_output(struct config_dump_human_context *ctx, value = strchr(key, '='); o_stream_send(output, key, value-key); o_stream_send_str(output, " = "); - o_stream_send_str(output, value+1); + if (!value_need_quote(value+1)) + o_stream_send_str(output, value+1); + else { + o_stream_send(output, "\"", 1); + o_stream_send_str(output, str_escape(value+1)); + o_stream_send(output, "\"", 1); + } o_stream_send(output, "\n", 1); end: ; } T_END;