From: Bo Peng Date: Thu, 8 May 2025 06:13:10 +0000 (+0900) Subject: Fall back to prompting for password if reading from .pcppass file fails. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=5f7d06d87256d0db53a7ec35cd13196768e31c0f;p=pgpool2.git Fall back to prompting for password if reading from .pcppass file fails. If reading password from .pcppass file fails, it should fall back to prompting the user for input, similar to how PostgreSQL handles .pgpass. This commit also changes the following messages to be displayed without requiring the -d option: WARNING: password file \"%s\" is not a plain file WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less Discussion: [pgpool-hackers: 4589] If reading password from .pcppass file fails, try to read it from prompt. https://www.pgpool.net/pipermail/pgpool-hackers/2025-May/004590.html --- diff --git a/src/libs/pcp/pcp.c b/src/libs/pcp/pcp.c index 01d822a94..03717d171 100644 --- a/src/libs/pcp/pcp.c +++ b/src/libs/pcp/pcp.c @@ -41,6 +41,7 @@ #include "pool.h" #include "pcp/pcp.h" #include "pcp/pcp_stream.h" +#include "utils/fe_ports.h" #include "utils/pool_path.h" #include "utils/palloc.h" #include "utils/pool_process_reporting.h" @@ -229,6 +230,12 @@ pcp_connect(char *hostname, int port, char *username, char *password, FILE *Pfde snprintf(port_str, sizeof(port_str), "%d", port); password_from_file = PasswordFromFile(pcpConn, hostname, port_str, username); password = password_from_file; + + /* + * If reading password from .pcppass file fails, try to read it from prompt. + */ + if (password == NULL || *password == '\0') + password = simple_prompt("Password: ", 100, false); } if (pcp_authorize(pcpConn, username, password) < 0) @@ -2087,17 +2094,15 @@ PasswordFromFile(PCPConnInfo * pcpConn, char *hostname, char *port, char *userna if (!S_ISREG(stat_buf.st_mode)) { - if (pcpConn->Pfdebug) - fprintf(pcpConn->Pfdebug, "WARNING: password file \"%s\" is not a plain file\n", pgpassfile); + fprintf(stderr, "WARNING: password file \"%s\" is not a plain file\n", pgpassfile); return NULL; } /* If password file is insecure, alert the user and ignore it. */ if (stat_buf.st_mode & (S_IRWXG | S_IRWXO)) { - if (pcpConn->Pfdebug) - fprintf(pcpConn->Pfdebug, "WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n", - pgpassfile); + fprintf(stderr, "WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n", + pgpassfile); return NULL; }