From 88fd162ef64cab7ed197f0612e0b610d57007200 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 16 Oct 2004 03:10:17 +0000 Subject: [PATCH] Allow pg_ctl to determine the server is up when getting a request for a password. Make password error message a #define and use it consistently. Sean Chittenden --- src/bin/pg_ctl/pg_ctl.c | 7 ++++--- src/bin/pg_dump/pg_backup_db.c | 6 +++--- src/bin/pg_dump/pg_dumpall.c | 4 ++-- src/bin/psql/command.c | 4 ++-- src/bin/psql/startup.c | 4 ++-- src/bin/scripts/common.c | 5 +++-- src/interfaces/libpq/fe-auth.c | 4 ++-- src/interfaces/libpq/libpq-fe.h | 5 ++++- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 9c87b39715..40674c305b 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.38 2004/10/15 04:54:33 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.39 2004/10/16 03:10:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -364,7 +364,6 @@ test_postmaster_connection(void) char portstr[32]; char *p; - *portstr = '\0'; /* post_opts */ @@ -432,7 +431,9 @@ test_postmaster_connection(void) { if ((conn = PQsetdbLogin(NULL, portstr, NULL, NULL, "template1", NULL, NULL)) != NULL && - PQstatus(conn) == CONNECTION_OK) + (PQstatus(conn) == CONNECTION_OK || + (strcmp(PQerrorMessage(conn), + PQnoPasswordSupplied) == 0))) { PQfinish(conn); success = true; diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 181414c263..989fdf8287 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -5,7 +5,7 @@ * Implements the basic DB functions used by the archiver. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.59 2004/10/01 17:25:55 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.60 2004/10/16 03:10:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -168,7 +168,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser) if (PQstatus(newConn) == CONNECTION_BAD) { noPwd = (strcmp(PQerrorMessage(newConn), - "fe_sendauth: no password supplied\n") == 0); + PQnoPasswordSupplied) == 0); badPwd = (strncmp(PQerrorMessage(newConn), "Password authentication failed for user", 39) == 0); @@ -249,7 +249,7 @@ ConnectDatabase(Archive *AHX, die_horribly(AH, modulename, "failed to connect to database\n"); if (PQstatus(AH->connection) == CONNECTION_BAD && - strcmp(PQerrorMessage(AH->connection), "fe_sendauth: no password supplied\n") == 0 && + strcmp(PQerrorMessage(AH->connection), PQnoPasswordSupplied) == 0 && !feof(stdin)) { PQfinish(AH->connection); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 1b26ebb4dc..caf439cf31 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.53 2004/10/15 04:32:28 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.54 2004/10/16 03:10:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -957,7 +957,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, } if (PQstatus(conn) == CONNECTION_BAD && - strcmp(PQerrorMessage(conn), "fe_sendauth: no password supplied\n") == 0 && + strcmp(PQerrorMessage(conn), PQnoPasswordSupplied) == 0 && !feof(stdin)) { PQfinish(conn); diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 998a002794..04c017c321 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.128 2004/10/14 20:23:46 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.129 2004/10/16 03:10:16 momjian Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -929,7 +929,7 @@ do_connect(const char *new_dbname, const char *new_user) NULL, NULL, dbparam, userparam, pwparam); if (PQstatus(pset.db) == CONNECTION_BAD && - strcmp(PQerrorMessage(pset.db), "fe_sendauth: no password supplied\n") == 0 && + strcmp(PQerrorMessage(pset.db), PQnoPasswordSupplied) == 0 && !feof(stdin)) { PQfinish(pset.db); diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 3af3bc789d..87f9200d7c 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2004, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.103 2004/10/08 11:24:19 neilc Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.104 2004/10/16 03:10:16 momjian Exp $ */ #include "postgres_fe.h" @@ -195,7 +195,7 @@ main(int argc, char *argv[]) username, password); if (PQstatus(pset.db) == CONNECTION_BAD && - strcmp(PQerrorMessage(pset.db), "fe_sendauth: no password supplied\n") == 0 && + strcmp(PQerrorMessage(pset.db), PQnoPasswordSupplied) == 0 && !feof(stdin)) { PQfinish(pset.db); diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c index 7fe8b40601..a52b30fec8 100644 --- a/src/bin/scripts/common.c +++ b/src/bin/scripts/common.c @@ -5,13 +5,14 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.11 2004/08/29 05:06:54 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.12 2004/10/16 03:10:16 momjian Exp $ * *------------------------------------------------------------------------- */ #include "postgres_fe.h" #include "common.h" +#include "libpq-fe.h" #include #include @@ -102,7 +103,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, } if (PQstatus(conn) == CONNECTION_BAD && - strcmp(PQerrorMessage(conn), "fe_sendauth: no password supplied\n") == 0 && + strcmp(PQerrorMessage(conn), PQnoPasswordSupplied) == 0 && !feof(stdin)) { PQfinish(conn); diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 17862a0c80..84477563ef 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -10,7 +10,7 @@ * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.93 2004/09/28 00:06:02 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.94 2004/10/16 03:10:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -634,7 +634,7 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, if (password == NULL || *password == '\0') { (void) snprintf(PQerrormsg, PQERRORMSG_LENGTH, - "fe_sendauth: no password supplied\n"); + PQnoPasswordSupplied); return STATUS_ERROR; } if (pg_password_sendauth(conn, password, areq) != STATUS_OK) diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index ff1a2c1ad6..9e6ebb2838 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.108 2004/08/29 05:07:00 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.109 2004/10/16 03:10:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -398,6 +398,9 @@ extern void PQfreemem(void *ptr); /* Exists for backward compatibility. bjm 2003-03-24 */ #define PQfreeNotify(ptr) PQfreemem(ptr) +/* Define the string so all uses are consistent. */ +#define PQnoPasswordSupplied "fe_sendauth: no password supplied\n" + /* * Make an empty PGresult with given status (some apps find this * useful). If conn is not NULL and status indicates an error, the -- 2.49.0