diff --git a/src/pg_probackup.c b/src/pg_probackup.c index 5e6bd99f..c9f46879 100644 --- a/src/pg_probackup.c +++ b/src/pg_probackup.c @@ -156,6 +156,7 @@ static pgut_option options[] = { 's', 'p', "pgport", &port, SOURCE_CMDLINE }, { 's', 'U', "pguser", &username, SOURCE_CMDLINE }, { 'B', 'w', "no-password", &prompt_password, SOURCE_CMDLINE }, + { 'b', 'W', "password", &force_password, SOURCE_CMDLINE }, /* other options */ { 'U', 150, "system-identifier", &system_identifier, SOURCE_FILE_STRICT }, { 's', 151, "instance", &instance_name, SOURCE_CMDLINE }, diff --git a/src/utils/pgut.c b/src/utils/pgut.c index 8fb88971..d017f364 100644 --- a/src/utils/pgut.c +++ b/src/utils/pgut.c @@ -40,6 +40,7 @@ const char *port = NULL; const char *username = NULL; static char *password = NULL; bool prompt_password = true; +bool force_password = false; /* Database connections */ static PGcancel *volatile cancel_conn = NULL; @@ -1336,6 +1337,12 @@ pgut_connect_extended(const char *pghost, const char *pgport, if (interrupted && !in_cleanup) elog(ERROR, "interrupted"); + if (force_password && !prompt_password) + elog(ERROR, "You cannot specify --password and --no-password options together"); + + if (!password && force_password) + prompt_for_password(login); + /* Start the connection. Loop until we have a password if requested by backend. */ for (;;) { @@ -1348,7 +1355,7 @@ pgut_connect_extended(const char *pghost, const char *pgport, if (conn && PQconnectionNeedsPassword(conn) && prompt_password) { PQfinish(conn); - prompt_for_password(username); + prompt_for_password(login); if (interrupted) elog(ERROR, "interrupted"); @@ -1369,12 +1376,12 @@ pgut_connect_extended(const char *pghost, const char *pgport, PGconn * pgut_connect_replication(const char *dbname) { - return pgut_connect_replication_extended(host, port, dbname, username, password); + return pgut_connect_replication_extended(host, port, dbname, username); } PGconn * pgut_connect_replication_extended(const char *pghost, const char *pgport, - const char *dbname, const char *pguser, const char *pwd) + const char *dbname, const char *pguser) { PGconn *tmpconn; int argcount = 7; /* dbname, replication, fallback_app_name, @@ -1386,6 +1393,12 @@ pgut_connect_replication_extended(const char *pghost, const char *pgport, if (interrupted && !in_cleanup) elog(ERROR, "interrupted"); + if (force_password && !prompt_password) + elog(ERROR, "You cannot specify --password and --no-password options together"); + + if (!password && force_password) + prompt_for_password(pguser); + i = 0; keywords = pg_malloc0((argcount + 1) * sizeof(*keywords)); @@ -1448,7 +1461,7 @@ pgut_connect_replication_extended(const char *pghost, const char *pgport, if (tmpconn && PQconnectionNeedsPassword(tmpconn) && prompt_password) { PQfinish(tmpconn); - prompt_for_password(username); + prompt_for_password(pguser); keywords[i] = "password"; values[i] = password; continue; diff --git a/src/utils/pgut.h b/src/utils/pgut.h index 572cc693..116bf8a5 100644 --- a/src/utils/pgut.h +++ b/src/utils/pgut.h @@ -103,6 +103,7 @@ extern const char *host; extern const char *port; extern const char *username; extern bool prompt_password; +extern bool force_password; extern bool interrupted; extern bool in_cleanup; @@ -122,8 +123,7 @@ extern PGconn *pgut_connect_extended(const char *pghost, const char *pgport, const char *dbname, const char *login); extern PGconn *pgut_connect_replication(const char *dbname); extern PGconn *pgut_connect_replication_extended(const char *pghost, const char *pgport, - const char *dbname, const char *login, - const char *pwd); + const char *dbname, const char *pguser); extern void pgut_disconnect(PGconn *conn); extern PGresult *pgut_execute(PGconn* conn, const char *query, int nParams, const char **params, bool text_result);