Skip to content

Commit 8a0fa9c

Browse files
committed
Add host name resolution information to pg_hba.conf error messages
This is to be able to analyze issues with host names in pg_hba.conf.
1 parent a31dc39 commit 8a0fa9c

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/backend/libpq/auth.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,32 @@ ClientAuthentication(Port *port)
439439
NULL, 0,
440440
NI_NUMERICHOST);
441441

442+
#define HOSTNAME_LOOKUP_DETAIL(port) \
443+
(port->remote_hostname \
444+
? (port->remote_hostname_resolv == +1 \
445+
? errdetail_log("Client IP address resolved to \"%s\", forward lookup matches.", port->remote_hostname) \
446+
: (port->remote_hostname_resolv == 0 \
447+
? errdetail_log("Client IP address resolved to \"%s\", forward lookup not checked.", port->remote_hostname) \
448+
: (port->remote_hostname_resolv == -1 \
449+
? errdetail_log("Client IP address resolved to \"%s\", forward lookup does not match.", port->remote_hostname) \
450+
: 0))) \
451+
: 0)
452+
442453
if (am_walsender)
443454
{
444455
#ifdef USE_SSL
445456
ereport(FATAL,
446457
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
447458
errmsg("no pg_hba.conf entry for replication connection from host \"%s\", user \"%s\", %s",
448459
hostinfo, port->user_name,
449-
port->ssl ? _("SSL on") : _("SSL off"))));
460+
port->ssl ? _("SSL on") : _("SSL off")),
461+
HOSTNAME_LOOKUP_DETAIL(port)));
450462
#else
451463
ereport(FATAL,
452464
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
453465
errmsg("no pg_hba.conf entry for replication connection from host \"%s\", user \"%s\"",
454-
hostinfo, port->user_name)));
466+
hostinfo, port->user_name),
467+
HOSTNAME_LOOKUP_DETAIL(port)));
455468
#endif
456469
}
457470
else
@@ -462,13 +475,15 @@ ClientAuthentication(Port *port)
462475
errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\", %s",
463476
hostinfo, port->user_name,
464477
port->database_name,
465-
port->ssl ? _("SSL on") : _("SSL off"))));
478+
port->ssl ? _("SSL on") : _("SSL off")),
479+
HOSTNAME_LOOKUP_DETAIL(port)));
466480
#else
467481
ereport(FATAL,
468482
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
469483
errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\"",
470484
hostinfo, port->user_name,
471-
port->database_name)));
485+
port->database_name),
486+
HOSTNAME_LOOKUP_DETAIL(port)));
472487
#endif
473488
}
474489
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy