Skip to content

Commit 5eb5661

Browse files
committed
Make vacuumlo prompt for password when needed, thus making its -W
switch optional, as is the case for every other one of our programs. I had already documented its -W as being optional, so this is bringing the code into line with the docs ...
1 parent 075e410 commit 5eb5661

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

contrib/vacuumlo/vacuumlo.c

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/contrib/vacuumlo/vacuumlo.c,v 1.33 2007/01/05 22:19:18 momjian Exp $
11+
* $PostgreSQL: pgsql/contrib/vacuumlo/vacuumlo.c,v 1.34 2007/12/11 02:08:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -61,32 +61,50 @@ vacuumlo(char *database, struct _param * param)
6161
int matched;
6262
int deleted;
6363
int i;
64-
char *password = NULL;
64+
static char *password = NULL;
65+
bool new_pass;
6566

66-
if (param->pg_prompt)
67+
if (param->pg_prompt && password == NULL)
68+
password = simple_prompt("Password: ", 100, false);
69+
70+
/*
71+
* Start the connection. Loop until we have a password if requested by
72+
* backend.
73+
*/
74+
do
6775
{
68-
password = simple_prompt("Password: ", 32, 0);
69-
if (!password)
76+
new_pass = false;
77+
78+
conn = PQsetdbLogin(param->pg_host,
79+
param->pg_port,
80+
NULL,
81+
NULL,
82+
database,
83+
param->pg_user,
84+
password);
85+
if (!conn)
7086
{
71-
fprintf(stderr, "failed to get password\n");
72-
exit(1);
87+
fprintf(stderr, "Connection to database \"%s\" failed\n",
88+
database);
89+
return -1;
7390
}
74-
}
7591

76-
conn = PQsetdbLogin(param->pg_host,
77-
param->pg_port,
78-
NULL,
79-
NULL,
80-
database,
81-
param->pg_user,
82-
password
83-
);
92+
if (PQstatus(conn) == CONNECTION_BAD &&
93+
PQconnectionNeedsPassword(conn) &&
94+
password == NULL &&
95+
!feof(stdin))
96+
{
97+
PQfinish(conn);
98+
password = simple_prompt("Password: ", 100, false);
99+
new_pass = true;
100+
}
101+
} while (new_pass);
84102

85103
/* check to see that the backend connection was successfully made */
86104
if (PQstatus(conn) == CONNECTION_BAD)
87105
{
88-
fprintf(stderr, "Connection to database '%s' failed:\n", database);
89-
fprintf(stderr, "%s", PQerrorMessage(conn));
106+
fprintf(stderr, "Connection to database \"%s\" failed:\n%s",
107+
database, PQerrorMessage(conn));
90108
PQfinish(conn);
91109
return -1;
92110
}

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