]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveconf: Quote output values when necessary.
authorTimo Sirainen <tss@iki.fi>
Thu, 2 Sep 2010 16:01:00 +0000 (17:01 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 2 Sep 2010 16:01:00 +0000 (17:01 +0100)
src/config/config-parser.c
src/config/config-parser.h
src/config/doveconf.c

index 7d0602160052831c74789b4b5ef0926ae67126c1..a9e3ceb6d67ed2936d987f8963f1b9353b54f1fd 100644 (file)
@@ -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;
index 882c28671c719b85752d6aa59b351666488e8d19..c6312a587d2db70c245391cb590970c90452d4de 100644 (file)
@@ -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;
index f0a340b849f4e09ee729404373d9232ba26c6bd0..5ece82fac5dd2594ef5e1a67df373a6593d361a7 100644 (file)
@@ -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;