1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-01 09:51:43 +02:00

PGPRO-1207: Add -W (--password) option

This commit is contained in:
Arthur Zakirov 2018-01-10 19:17:38 +03:00
parent 1fad089a66
commit d96e8e24f2
3 changed files with 20 additions and 6 deletions

View File

@ -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 },

View File

@ -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;

View File

@ -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);