mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
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 ...
This commit is contained in:
parent
075e410205
commit
5eb56611e3
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/contrib/vacuumlo/vacuumlo.c,v 1.33 2007/01/05 22:19:18 momjian Exp $
|
* $PostgreSQL: pgsql/contrib/vacuumlo/vacuumlo.c,v 1.34 2007/12/11 02:08:59 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -61,32 +61,50 @@ vacuumlo(char *database, struct _param * param)
|
|||||||
int matched;
|
int matched;
|
||||||
int deleted;
|
int deleted;
|
||||||
int i;
|
int i;
|
||||||
char *password = NULL;
|
static char *password = NULL;
|
||||||
|
bool new_pass;
|
||||||
|
|
||||||
if (param->pg_prompt)
|
if (param->pg_prompt && password == NULL)
|
||||||
|
password = simple_prompt("Password: ", 100, false);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the connection. Loop until we have a password if requested by
|
||||||
|
* backend.
|
||||||
|
*/
|
||||||
|
do
|
||||||
{
|
{
|
||||||
password = simple_prompt("Password: ", 32, 0);
|
new_pass = false;
|
||||||
if (!password)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "failed to get password\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
conn = PQsetdbLogin(param->pg_host,
|
conn = PQsetdbLogin(param->pg_host,
|
||||||
param->pg_port,
|
param->pg_port,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
database,
|
database,
|
||||||
param->pg_user,
|
param->pg_user,
|
||||||
password
|
password);
|
||||||
);
|
if (!conn)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Connection to database \"%s\" failed\n",
|
||||||
|
database);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PQstatus(conn) == CONNECTION_BAD &&
|
||||||
|
PQconnectionNeedsPassword(conn) &&
|
||||||
|
password == NULL &&
|
||||||
|
!feof(stdin))
|
||||||
|
{
|
||||||
|
PQfinish(conn);
|
||||||
|
password = simple_prompt("Password: ", 100, false);
|
||||||
|
new_pass = true;
|
||||||
|
}
|
||||||
|
} while (new_pass);
|
||||||
|
|
||||||
/* check to see that the backend connection was successfully made */
|
/* check to see that the backend connection was successfully made */
|
||||||
if (PQstatus(conn) == CONNECTION_BAD)
|
if (PQstatus(conn) == CONNECTION_BAD)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Connection to database '%s' failed:\n", database);
|
fprintf(stderr, "Connection to database \"%s\" failed:\n%s",
|
||||||
fprintf(stderr, "%s", PQerrorMessage(conn));
|
database, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user