@@ -40,6 +40,7 @@ const char *port = NULL;
40
40
const char * username = NULL ;
41
41
static char * password = NULL ;
42
42
bool prompt_password = true;
43
+ bool force_password = false;
43
44
44
45
/* Database connections */
45
46
static PGcancel * volatile cancel_conn = NULL ;
@@ -1336,6 +1337,12 @@ pgut_connect_extended(const char *pghost, const char *pgport,
1336
1337
if (interrupted && !in_cleanup )
1337
1338
elog (ERROR , "interrupted" );
1338
1339
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
+
1339
1346
/* Start the connection. Loop until we have a password if requested by backend. */
1340
1347
for (;;)
1341
1348
{
@@ -1348,7 +1355,7 @@ pgut_connect_extended(const char *pghost, const char *pgport,
1348
1355
if (conn && PQconnectionNeedsPassword (conn ) && prompt_password )
1349
1356
{
1350
1357
PQfinish (conn );
1351
- prompt_for_password (username );
1358
+ prompt_for_password (login );
1352
1359
1353
1360
if (interrupted )
1354
1361
elog (ERROR , "interrupted" );
@@ -1369,12 +1376,12 @@ pgut_connect_extended(const char *pghost, const char *pgport,
1369
1376
PGconn *
1370
1377
pgut_connect_replication (const char * dbname )
1371
1378
{
1372
- return pgut_connect_replication_extended (host , port , dbname , username , password );
1379
+ return pgut_connect_replication_extended (host , port , dbname , username );
1373
1380
}
1374
1381
1375
1382
PGconn *
1376
1383
pgut_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 )
1378
1385
{
1379
1386
PGconn * tmpconn ;
1380
1387
int argcount = 7 ; /* dbname, replication, fallback_app_name,
@@ -1386,6 +1393,12 @@ pgut_connect_replication_extended(const char *pghost, const char *pgport,
1386
1393
if (interrupted && !in_cleanup )
1387
1394
elog (ERROR , "interrupted" );
1388
1395
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
+
1389
1402
i = 0 ;
1390
1403
1391
1404
keywords = pg_malloc0 ((argcount + 1 ) * sizeof (* keywords ));
@@ -1448,7 +1461,7 @@ pgut_connect_replication_extended(const char *pghost, const char *pgport,
1448
1461
if (tmpconn && PQconnectionNeedsPassword (tmpconn ) && prompt_password )
1449
1462
{
1450
1463
PQfinish (tmpconn );
1451
- prompt_for_password (username );
1464
+ prompt_for_password (pguser );
1452
1465
keywords [i ] = "password" ;
1453
1466
values [i ] = password ;
1454
1467
continue ;
0 commit comments