Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0905edf

Browse files
committed
Merge branch 'master' into fix_ptrack_1230
2 parents 7e28977 + 97d028e commit 0905edf

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/pg_probackup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static pgut_option options[] =
156156
{ 's', 'p', "pgport", &port, SOURCE_CMDLINE },
157157
{ 's', 'U', "pguser", &username, SOURCE_CMDLINE },
158158
{ 'B', 'w', "no-password", &prompt_password, SOURCE_CMDLINE },
159+
{ 'b', 'W', "password", &force_password, SOURCE_CMDLINE },
159160
/* other options */
160161
{ 'U', 150, "system-identifier", &system_identifier, SOURCE_FILE_STRICT },
161162
{ 's', 151, "instance", &instance_name, SOURCE_CMDLINE },

src/utils/pgut.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const char *port = NULL;
4040
const char *username = NULL;
4141
static char *password = NULL;
4242
bool prompt_password = true;
43+
bool force_password = false;
4344

4445
/* Database connections */
4546
static 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,
13691376
PGconn *
13701377
pgut_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

13751382
PGconn *
13761383
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)
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;

src/utils/pgut.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ extern const char *host;
103103
extern const char *port;
104104
extern const char *username;
105105
extern bool prompt_password;
106+
extern bool force_password;
106107

107108
extern bool interrupted;
108109
extern bool in_cleanup;
@@ -122,8 +123,7 @@ extern PGconn *pgut_connect_extended(const char *pghost, const char *pgport,
122123
const char *dbname, const char *login);
123124
extern PGconn *pgut_connect_replication(const char *dbname);
124125
extern PGconn *pgut_connect_replication_extended(const char *pghost, const char *pgport,
125-
const char *dbname, const char *login,
126-
const char *pwd);
126+
const char *dbname, const char *pguser);
127127
extern void pgut_disconnect(PGconn *conn);
128128
extern PGresult *pgut_execute(PGconn* conn, const char *query, int nParams,
129129
const char **params, bool text_result);

0 commit comments

Comments
 (0)