From c1b910ed189a04c199fc1fb146262053827b524f Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sun, 31 Jul 2011 18:03:43 +0300 Subject: [PATCH] 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. --- src/backend/libpq/auth.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 76dffc1906..03fe1846d2 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -443,6 +443,17 @@ ClientAuthentication(Port *port) NULL, 0, NI_NUMERICHOST); +#define HOSTNAME_LOOKUP_DETAIL(port) \ + (port->remote_hostname \ + ? (port->remote_hostname_resolv == +1 \ + ? errdetail_log("Client IP address resolved to \"%s\", forward lookup matches.", port->remote_hostname) \ + : (port->remote_hostname_resolv == 0 \ + ? errdetail_log("Client IP address resolved to \"%s\", forward lookup not checked.", port->remote_hostname) \ + : (port->remote_hostname_resolv == -1 \ + ? errdetail_log("Client IP address resolved to \"%s\", forward lookup does not match.", port->remote_hostname) \ + : 0))) \ + : 0) + if (am_walsender) { #ifdef USE_SSL @@ -450,12 +461,14 @@ ClientAuthentication(Port *port) (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), errmsg("no pg_hba.conf entry for replication connection from host \"%s\", user \"%s\", %s", hostinfo, port->user_name, - port->ssl ? _("SSL on") : _("SSL off")))); + port->ssl ? _("SSL on") : _("SSL off")), + HOSTNAME_LOOKUP_DETAIL(port))); #else ereport(FATAL, (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), errmsg("no pg_hba.conf entry for replication connection from host \"%s\", user \"%s\"", - hostinfo, port->user_name))); + hostinfo, port->user_name), + HOSTNAME_LOOKUP_DETAIL(port))); #endif } else @@ -466,13 +479,15 @@ ClientAuthentication(Port *port) errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\", %s", hostinfo, port->user_name, port->database_name, - port->ssl ? _("SSL on") : _("SSL off")))); + port->ssl ? _("SSL on") : _("SSL off")), + HOSTNAME_LOOKUP_DETAIL(port))); #else ereport(FATAL, (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), errmsg("no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\"", hostinfo, port->user_name, - port->database_name))); + port->database_name), + HOSTNAME_LOOKUP_DETAIL(port))); #endif } break; -- 2.40.0