1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Add a -w/--no-password option that prevents all password prompts to all

programs that have a -W/--password option.

In passing, remove the ancient PSQL_ALWAYS_GET_PASSWORDS compile option.
This commit is contained in:
Peter Eisentraut
2009-02-26 16:02:39 +00:00
parent eea49769d4
commit 9de59fd191
38 changed files with 478 additions and 170 deletions

View File

@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.41 2009/02/25 13:03:07 petere Exp $
* $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.42 2009/02/26 16:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -17,13 +17,6 @@
static void help(const char *progname);
enum trivalue
{
TRI_DEFAULT,
TRI_NO,
TRI_YES
};
int
main(int argc, char *argv[])
{
@ -31,6 +24,7 @@ main(int argc, char *argv[])
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
{"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"echo", no_argument, NULL, 'e'},
{"quiet", no_argument, NULL, 'q'},
@ -61,7 +55,7 @@ main(int argc, char *argv[])
char *host = NULL;
char *port = NULL;
char *username = NULL;
bool password = false;
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
char *conn_limit = NULL;
bool pwprompt = false;
@ -85,7 +79,7 @@ main(int argc, char *argv[])
handle_help_version_opts(argc, argv, "createuser", help);
while ((c = getopt_long(argc, argv, "h:p:U:WeqdDsSaArRiIlLc:PEN",
while ((c = getopt_long(argc, argv, "h:p:U:wWeqdDsSaArRiIlLc:PEN",
long_options, &optindex)) != -1)
{
switch (c)
@ -99,8 +93,11 @@ main(int argc, char *argv[])
case 'U':
username = optarg;
break;
case 'w':
prompt_password = TRI_NO;
break;
case 'W':
password = true;
prompt_password = TRI_YES;
break;
case 'e':
echo = true;
@ -228,7 +225,7 @@ main(int argc, char *argv[])
if (login == 0)
login = TRI_YES;
conn = connectDatabase("postgres", host, port, username, password, progname);
conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
initPQExpBuffer(&sql);
@ -329,6 +326,7 @@ help(const char *progname)
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port\n"));
printf(_(" -U, --username=USERNAME user name to connect as (not the one to create)\n"));
printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt\n"));
printf(_("\nIf one of -d, -D, -r, -R, -s, -S, and ROLENAME is not specified, you will\n"
"be prompted interactively.\n"));