From: Timo Sirainen Date: Tue, 20 Oct 2009 18:12:55 +0000 (-0400) Subject: settings parser: Warn if a line has '#' character not preceded by whitespace. X-Git-Tag: 2.0.alpha2~59 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25e480bc781fdbcbee1d8b88ccdef163c0c63b0f;p=thirdparty%2Fdovecot%2Fcore.git settings parser: Warn if a line has '#' character not preceded by whitespace. This should help with people trying to give '#' character in e.g. a password and wondering why it's not working. --HG-- branch : HEAD --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index fc2c20d359..f30f15638f 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -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: diff --git a/src/lib-settings/settings.c b/src/lib-settings/settings.c index 08e4874985..adc828792c 100644 --- a/src/lib-settings/settings.c +++ b/src/lib-settings/settings.c @@ -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; }