@@ -40,6 +40,7 @@ const char *port = NULL;
4040const char * username = NULL ;
4141static char * password = NULL ;
4242bool prompt_password = true;
43+ bool force_password = false;
4344
4445/* Database connections */
4546static PGcancel * volatile cancel_conn = NULL ;
@@ -1336,6 +1337,12 @@ pgut_connect_extended(const char *pghost, const char *pgport,
13361337 if (interrupted && !in_cleanup )
13371338 elog (ERROR , "interrupted" );
13381339
1340+ if (force_password && !prompt_password )
1341+ elog (ERROR , "You cannot specify --password and --no-password options together" );
1342+
1343+ if (!password && force_password )
1344+ prompt_for_password (login );
1345+
13391346 /* Start the connection. Loop until we have a password if requested by backend. */
13401347 for (;;)
13411348 {
@@ -1348,7 +1355,7 @@ pgut_connect_extended(const char *pghost, const char *pgport,
13481355 if (conn && PQconnectionNeedsPassword (conn ) && prompt_password )
13491356 {
13501357 PQfinish (conn );
1351- prompt_for_password (username );
1358+ prompt_for_password (login );
13521359
13531360 if (interrupted )
13541361 elog (ERROR , "interrupted" );
@@ -1369,12 +1376,12 @@ pgut_connect_extended(const char *pghost, const char *pgport,
13691376PGconn *
13701377pgut_connect_replication (const char * dbname )
13711378{
1372- return pgut_connect_replication_extended (host , port , dbname , username , password );
1379+ return pgut_connect_replication_extended (host , port , dbname , username );
13731380}
13741381
13751382PGconn *
13761383pgut_connect_replication_extended (const char * pghost , const char * pgport ,
1377- const char * dbname , const char * pguser , const char * pwd )
1384+ const char * dbname , const char * pguser )
13781385{
13791386 PGconn * tmpconn ;
13801387 int argcount = 7 ; /* dbname, replication, fallback_app_name,
@@ -1386,6 +1393,12 @@ pgut_connect_replication_extended(const char *pghost, const char *pgport,
13861393 if (interrupted && !in_cleanup )
13871394 elog (ERROR , "interrupted" );
13881395
1396+ if (force_password && !prompt_password )
1397+ elog (ERROR , "You cannot specify --password and --no-password options together" );
1398+
1399+ if (!password && force_password )
1400+ prompt_for_password (pguser );
1401+
13891402 i = 0 ;
13901403
13911404 keywords = pg_malloc0 ((argcount + 1 ) * sizeof (* keywords ));
@@ -1448,7 +1461,7 @@ pgut_connect_replication_extended(const char *pghost, const char *pgport,
14481461 if (tmpconn && PQconnectionNeedsPassword (tmpconn ) && prompt_password )
14491462 {
14501463 PQfinish (tmpconn );
1451- prompt_for_password (username );
1464+ prompt_for_password (pguser );
14521465 keywords [i ] = "password" ;
14531466 values [i ] = password ;
14541467 continue ;
0 commit comments