]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
settings parser: Warn if a line has '#' character not preceded by whitespace.
authorTimo Sirainen <tss@iki.fi>
Tue, 20 Oct 2009 18:12:55 +0000 (14:12 -0400)
committerTimo Sirainen <tss@iki.fi>
Tue, 20 Oct 2009 18:12:55 +0000 (14:12 -0400)
This should help with people trying to give '#' character in e.g. a
password and wondering why it's not working.

--HG--
branch : HEAD

src/config/config-parser.c
src/lib-settings/settings.c

index fc2c20d359084091390fe120e3b658130d8f2a3f..f30f15638f4f03812d65212164b3e2ec0fec039d 100644 (file)
@@ -414,8 +414,8 @@ enum config_line_type {
 };
 
 static enum config_line_type
-config_parse_line(char *line, string_t *full_line, const char **key_r,
-                 const char **value_r)
+config_parse_line(struct parser_context *ctx, char *line, string_t *full_line,
+                 const char **key_r, const char **value_r)
 {
        const char *key;
        unsigned int len;
@@ -445,6 +445,13 @@ config_parse_line(char *line, string_t *full_line, const char **key_r,
                        if (*p == '\0')
                                break;
                } else if (*p == '#') {
+                       if (!IS_WHITE(p[-1])) {
+                               i_warning("Configuration file %s line %u: "
+                                         "Ambiguous '#' character in line, treating it as comment. "
+                                         "Add a space before it to remove this warning.",
+                                         ctx->cur_input->path,
+                                         ctx->cur_input->linenum);
+                       }
                        *p = '\0';
                        break;
                }
@@ -609,7 +616,7 @@ int config_parse_file(const char *path, bool expand_files,
 prevfile:
        while ((line = i_stream_read_next_line(ctx.cur_input->input)) != NULL) {
                ctx.cur_input->linenum++;
-               type = config_parse_line(line, full_line,
+               type = config_parse_line(&ctx, line, full_line,
                                         &key, &value);
                switch (type) {
                case CONFIG_LINE_TYPE_SKIP:
index 08e4874985a3ba7e4b7e13a6beb1dfb0fd3f7985..adc828792cc3f259f8b487e8244b2f72685aeae5 100644 (file)
@@ -227,6 +227,12 @@ prevfile:
                                if (*p == '\0')
                                        break;
                        } else if (*p == '#') {
+                               if (!IS_WHITE(p[-1])) {
+                                       i_warning("Configuration file %s line %u: "
+                                                 "Ambiguous '#' character in line, treating it as comment. "
+                                                 "Add a space before it to remove this warning.",
+                                                 input->path, input->linenum);
+                               }
                                *p = '\0';
                                break;
                        }