pgsql: Invent open_auth_file() in hba.c to refactor authentication file - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Invent open_auth_file() in hba.c to refactor authentication file
Date
Msg-id E1ouOFh-0005Xm-77@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Invent open_auth_file() in hba.c to refactor authentication file opening

This adds a check on the recursion depth when including authentication
configuration files, something that has never been done when processing
'@' files for database and user name lists in pg_hba.conf.  On HEAD,
this was leading to a rather confusing error, as of:
FATAL:  exceeded maxAllocatedDescs (NN) while trying to open file "/path/blah.conf"

This refactors the code so as the error reported is now the following,
which is the same as for GUCs:
FATAL: could not open file "/path/blah.conf": maximum nesting depth exceeded

This reduces a bit the verbosity of the error message used for files
included in user and database lists, reporting only the file name of
what's failing to load, without mentioning the relative or absolute path
specified after '@' in a HBA file.  The absolute path is built upon what
'@' defines anyway, so there is no actual loss of information.  This
makes the future inclusion logic much simpler.  A follow-up patch will
add an error context to be able to track on which line of which file the
inclusion is failing, to close the loop, providing all the information
needed to know the full chain of events.

This logic has been extracted from a larger patch written by Julien,
rewritten by me to have a unique code path calling AllocateFile() on
authentication files, and is useful on its own.  This new interface
will be used later for authentication files included with
@include[_dir,_if_exists], in a follow-up patch.

Author: Michael Paquier, Julien Rouhaud
Discussion: https://www.postgresql.org/message-id/Y2xUBJ+S+Z0zbxRW@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/783e8c69cbcd2b7d6fce1f0c5b568b1c8b686d54

Modified Files
--------------
src/backend/libpq/hba.c          | 100 ++++++++++++++++++++++++++++-----------
src/backend/utils/adt/hbafuncs.c |  22 +++------
src/include/libpq/hba.h          |   4 +-
3 files changed, 81 insertions(+), 45 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: libpq: Remove unneeded cast and adjust format placeholder
Next
From: Michael Paquier
Date:
Subject: pgsql: Add error context callback when tokenizing authentication files