Mercurial > dovecot > core-2.2
changeset 12067:31387c9d5b88
doveconf: Quote output values when necessary.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 02 Sep 2010 17:01:00 +0100 |
parents | 4d8b54fc4ef5 |
children | a3f016b7b914 |
files | src/config/config-parser.c src/config/config-parser.h src/config/doveconf.c |
diffstat | 3 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/config/config-parser.c Thu Sep 02 15:53:08 2010 +0100 +++ b/src/config/config-parser.c Thu Sep 02 17:01:00 2010 +0100 @@ -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;
--- a/src/config/config-parser.h Thu Sep 02 15:53:08 2010 +0100 +++ b/src/config/config-parser.h Thu Sep 02 17:01:00 2010 +0100 @@ -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;
--- a/src/config/doveconf.c Thu Sep 02 15:53:08 2010 +0100 +++ b/src/config/doveconf.c Thu Sep 02 17:01:00 2010 +0100 @@ -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 @@ 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 @@ 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;