Add username for psql password prompt, if the username was specified.
Adrian Maier
This commit is contained in:
parent
9ad9e694ac
commit
f5df006a04
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.150 2005/07/18 20:57:53 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.151 2005/07/25 17:17:41 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
@ -911,6 +911,7 @@ do_connect(const char *new_dbname, const char *new_user)
|
|||||||
const char *dbparam = NULL;
|
const char *dbparam = NULL;
|
||||||
const char *userparam = NULL;
|
const char *userparam = NULL;
|
||||||
const char *pwparam = NULL;
|
const char *pwparam = NULL;
|
||||||
|
char *password_prompt = NULL;
|
||||||
char *prompted_password = NULL;
|
char *prompted_password = NULL;
|
||||||
bool need_pass;
|
bool need_pass;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
@ -930,9 +931,18 @@ do_connect(const char *new_dbname, const char *new_user)
|
|||||||
else
|
else
|
||||||
userparam = new_user;
|
userparam = new_user;
|
||||||
|
|
||||||
|
if (userparam == NULL)
|
||||||
|
password_prompt = strdup("Password: ");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
password_prompt = malloc(strlen("Password for user %s: ") - 2 +
|
||||||
|
strlen(userparam) + 1);
|
||||||
|
sprintf(password_prompt,"Password for user %s: ", userparam);
|
||||||
|
}
|
||||||
|
|
||||||
/* need to prompt for password? */
|
/* need to prompt for password? */
|
||||||
if (pset.getPassword)
|
if (pset.getPassword)
|
||||||
pwparam = prompted_password = simple_prompt("Password: ", 100, false);
|
pwparam = prompted_password = simple_prompt(password_prompt, 100, false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Use old password (if any) if no new one given and we are
|
* Use old password (if any) if no new one given and we are
|
||||||
@ -956,11 +966,12 @@ do_connect(const char *new_dbname, const char *new_user)
|
|||||||
need_pass = true;
|
need_pass = true;
|
||||||
free(prompted_password);
|
free(prompted_password);
|
||||||
prompted_password = NULL;
|
prompted_password = NULL;
|
||||||
pwparam = prompted_password = simple_prompt("Password: ", 100, false);
|
pwparam = prompted_password = simple_prompt(password_prompt, 100, false);
|
||||||
}
|
}
|
||||||
} while (need_pass);
|
} while (need_pass);
|
||||||
|
|
||||||
free(prompted_password);
|
free(prompted_password);
|
||||||
|
free(password_prompt);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If connection failed, try at least keep the old one. That's
|
* If connection failed, try at least keep the old one. That's
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.119 2005/07/14 08:42:37 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.120 2005/07/25 17:17:41 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -106,6 +106,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
char *password = NULL;
|
char *password = NULL;
|
||||||
|
char *password_prompt = NULL;
|
||||||
bool need_pass;
|
bool need_pass;
|
||||||
|
|
||||||
set_pglocale_pgservice(argv[0], "psql");
|
set_pglocale_pgservice(argv[0], "psql");
|
||||||
@ -188,8 +189,17 @@ main(int argc, char *argv[])
|
|||||||
username = pg_strdup(options.username);
|
username = pg_strdup(options.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.username == NULL)
|
||||||
|
password_prompt = strdup("Password: ");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
password_prompt = malloc(strlen("Password for user %s: ") - 2 +
|
||||||
|
strlen(options.username) + 1);
|
||||||
|
sprintf(password_prompt,"Password for user %s: ", options.username);
|
||||||
|
}
|
||||||
|
|
||||||
if (pset.getPassword)
|
if (pset.getPassword)
|
||||||
password = simple_prompt("Password: ", 100, false);
|
password = simple_prompt(password_prompt, 100, false);
|
||||||
|
|
||||||
/* loop until we have a password if requested by backend */
|
/* loop until we have a password if requested by backend */
|
||||||
do
|
do
|
||||||
@ -207,12 +217,13 @@ main(int argc, char *argv[])
|
|||||||
need_pass = true;
|
need_pass = true;
|
||||||
free(password);
|
free(password);
|
||||||
password = NULL;
|
password = NULL;
|
||||||
password = simple_prompt("Password: ", 100, false);
|
password = simple_prompt(password_prompt, 100, false);
|
||||||
}
|
}
|
||||||
} while (need_pass);
|
} while (need_pass);
|
||||||
|
|
||||||
free(username);
|
free(username);
|
||||||
free(password);
|
free(password);
|
||||||
|
free(password_prompt);
|
||||||
|
|
||||||
if (PQstatus(pset.db) == CONNECTION_BAD)
|
if (PQstatus(pset.db) == CONNECTION_BAD)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user