diff options
author | Bo Peng | 2025-05-08 06:13:10 +0000 |
---|---|---|
committer | Bo Peng | 2025-05-08 06:13:10 +0000 |
commit | 5f7d06d87256d0db53a7ec35cd13196768e31c0f (patch) | |
tree | 91ce31b0f62de5ee7dfb25c2f3bafb3bcd305ada /src | |
parent | 3f36fe3a39fe7c9cceec368d465506c7d1bc1c27 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/pcp/pcp.c | 15 |
1 files changed, 10 insertions, 5 deletions
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; } |