From: Fabien COELHO <coelho@cri.ensmp.fr>
To: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Allow continuations in "pg_hba.conf" files
Date: Wed, 25 Mar 2020 19:09:38 +0100 (CET)
Message-ID: <alpine.DEB.2.21.2003251906140.15243@pseudo> (raw)
Hello,
After writing an unreadable and stupidly long line for ldap
authentification in a "pg_hba.conf" file, I figured out that allowing
continuations looked simple enough and should just be done.
Patch attached.
--
Fabien.
Attachments:pg-hba-cont-1.patch (text/x-diff, 3.1K) downloaddiff --git a/doc/src/sgml/client-auth.sgml b/doc/src/sgml/client-auth.sgmlindex 5f1eec78fb..cf3b432c34 100644--- a/doc/src/sgml/client-auth.sgml+++ b/doc/src/sgml/client-auth.sgml@@ -77,7 +77,7 @@
The general format of the <filename>pg_hba.conf</filename> file is
a set of records, one per line. Blank lines are ignored, as is any
text after the <literal>#</literal> comment character.
- Records cannot be continued across lines.+ Records can be backslash-continued across lines.
A record is made
up of a number of fields which are separated by spaces and/or tabs.
Fields can contain white space if the field value is double-quoted.
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.cindex da5189a4fa..95c2cfc8e4 100644--- a/src/backend/libpq/hba.c+++ b/src/backend/libpq/hba.c@@ -486,8 +486,43 @@ tokenize_file(const char *filename, FILE *file, List **tok_lines, int elevel)
char *lineptr;
List *current_line = NIL;
char *err_msg = NULL;
+ char *cur = rawline;+ int len = sizeof(rawline);+ int continuations = 0;- if (!fgets(rawline, sizeof(rawline), file))+ /* read input and handle simplistic backslash continuations */+ while ((cur = fgets(cur, len, file)) != NULL)+ {+ int curlen = strlen(cur);+ char *curend = cur + curlen - 1;++ if (curlen == len - 1)+ {+ /* Line too long! */+ ereport(elevel,+ (errcode(ERRCODE_CONFIG_FILE_ERROR),+ errmsg("authentication file line too long"),+ errcontext("line %d of configuration file \"%s\"",+ line_number + continuations, filename)));+ err_msg = "authentication file line too long";+ }++ /* Strip trailing linebreak from rawline */+ while (curend >= cur && (*curend == '\n' || *curend == '\r'))+ *curend-- = '\0';++ /* empty or not a continuation, we are done */+ if (curend < cur || *curend != '\\')+ break;++ /* else we have a continuation, just blank it and loop */+ continuations++;+ *curend++ = ' ';+ len -= (curend - cur);+ cur = curend;+ }++ if (cur == NULL)
{
int save_errno = errno;
@@ -501,21 +536,6 @@ tokenize_file(const char *filename, FILE *file, List **tok_lines, int elevel)
filename, strerror(save_errno));
rawline[0] = '\0';
}
- if (strlen(rawline) == MAX_LINE - 1)- {- /* Line too long! */- ereport(elevel,- (errcode(ERRCODE_CONFIG_FILE_ERROR),- errmsg("authentication file line too long"),- errcontext("line %d of configuration file \"%s\"",- line_number, filename)));- err_msg = "authentication file line too long";- }-- /* Strip trailing linebreak from rawline */- lineptr = rawline + strlen(rawline) - 1;- while (lineptr >= rawline && (*lineptr == '\n' || *lineptr == '\r'))- *lineptr-- = '\0';
/* Parse fields */
lineptr = rawline;
@@ -543,7 +563,7 @@ tokenize_file(const char *filename, FILE *file, List **tok_lines, int elevel)
*tok_lines = lappend(*tok_lines, tok_line);
}
- line_number++;+ line_number += continuations + 1;
}
MemoryContextSwitchTo(oldcxt);
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: coelho@cri.ensmp.fr
Subject: Re: Allow continuations in "pg_hba.conf" files
In-Reply-To: <alpine.DEB.2.21.2003251906140.15243@pseudo>
References: <alpine.DEB.2.21.2003251906140.15243@pseudo>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox