pgsql: Add error context callback when tokenizing authentication files

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add error context callback when tokenizing authentication files
Date: 2022-11-14 02:59:41
Message-ID: E1ouPhE-00065i-9K@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add error context callback when tokenizing authentication files

The parsing of the authentication files for HBA and ident entries
happens in two phases:
- Tokenization of the files, creating a list of TokenizedAuthLines.
- Validation of the HBA and ident entries, building a set of HbaLines or
IdentLines.

The second phase doing the validation provides already some error
context about the configuration file and the line where a problem
happens, but there is no such information in the first phase when
tokenizing the files. This commit adds an ErrorContextCallback in
tokenize_auth_file(), with a context made of the line number and the
configuration file name involved in a problem. This is useful for files
included in an HBA file for user and database lists, and it will become
much more handy to track problems for files included via a potential
@include[_dir,_if_exists].

The error context is registered so as the full chain of events is
reported when using cascaded inclusions when for example
tokenize_auth_file() recurses over itself on new files, displaying one
context line for each file gone through when tokenizing things.

Author: Michael Paquier
Reviewed-by: Julien Rouhaud
Discussion: https://postgr.es/m/Y2xUBJ+S+Z0zbxRW@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ad6c52846f13e4e86daa247c1369ed85558830e7

Modified Files
--------------
src/backend/libpq/hba.c | 31 +++++++++++++++++++++++++++++++
src/tools/pgindent/typedefs.list | 1 +
2 files changed, 32 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2022-11-14 05:23:57 pgsql: Fix cleanup lock acquisition in SPLIT_ALLOCATE_PAGE replay.
Previous Message Michael Paquier 2022-11-14 01:27:09 pgsql: Invent open_auth_file() in hba.c to refactor authentication file