Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e27f52f

Browse files
committed
Reject empty pg_hba.conf files.
An empty HBA file is surely an error, since it means there is no way to connect to the server. We've not heard identifiable reports of people actually doing that, but this will also close off the case Thom Brown just complained of, namely pointing hba_file at a directory. (On at least some platforms with some directories, it will read as an empty file.) Perhaps this should be back-patched, but given the lack of previous complaints, I won't add extra work for the translators.
1 parent 7c19e04 commit e27f52f

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/backend/libpq/hba.c

+22-10
Original file line numberDiff line numberDiff line change
@@ -1685,9 +1685,13 @@ check_hba(hbaPort *port)
16851685
/*
16861686
* Read the config file and create a List of HbaLine records for the contents.
16871687
*
1688-
* The configuration is read into a temporary list, and if any parse error occurs
1689-
* the old list is kept in place and false is returned. Only if the whole file
1690-
* parses Ok is the list replaced, and the function returns true.
1688+
* The configuration is read into a temporary list, and if any parse error
1689+
* occurs the old list is kept in place and false is returned. Only if the
1690+
* whole file parses OK is the list replaced, and the function returns true.
1691+
*
1692+
* On a false result, caller will take care of reporting a FATAL error in case
1693+
* this is the initial startup. If it happens on reload, we just keep running
1694+
* with the old data.
16911695
*/
16921696
bool
16931697
load_hba(void)
@@ -1710,12 +1714,6 @@ load_hba(void)
17101714
(errcode_for_file_access(),
17111715
errmsg("could not open configuration file \"%s\": %m",
17121716
HbaFileName)));
1713-
1714-
/*
1715-
* Caller will take care of making this a FATAL error in case this is
1716-
* the initial startup. If it happens on reload, we just keep the old
1717-
* version around.
1718-
*/
17191717
return false;
17201718
}
17211719

@@ -1755,13 +1753,27 @@ load_hba(void)
17551753
new_parsed_lines = lappend(new_parsed_lines, newline);
17561754
}
17571755

1756+
/*
1757+
* A valid HBA file must have at least one entry; else there's no way
1758+
* to connect to the postmaster. But only complain about this if we
1759+
* didn't already have parsing errors.
1760+
*/
1761+
if (ok && new_parsed_lines == NIL)
1762+
{
1763+
ereport(LOG,
1764+
(errcode(ERRCODE_CONFIG_FILE_ERROR),
1765+
errmsg("configuration file \"%s\" contains no entries",
1766+
HbaFileName)));
1767+
ok = false;
1768+
}
1769+
17581770
/* Free tokenizer memory */
17591771
MemoryContextDelete(linecxt);
17601772
MemoryContextSwitchTo(oldcxt);
17611773

17621774
if (!ok)
17631775
{
1764-
/* Parsing failed at one or more rows, so bail out */
1776+
/* File contained one or more errors, so bail out */
17651777
MemoryContextDelete(hbacxt);
17661778
return false;
17671779
}

0 commit comments

Comments
 (0)