1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +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/dropdb.c,v 1.25 2009/02/25 13:03:07 petere Exp $
* $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.26 2009/02/26 16:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -25,6 +25,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'},
@ -40,7 +41,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;
bool interactive = false;
@ -54,7 +55,7 @@ main(int argc, char *argv[])
handle_help_version_opts(argc, argv, "dropdb", help);
while ((c = getopt_long(argc, argv, "h:p:U:Weqi", long_options, &optindex)) != -1)
while ((c = getopt_long(argc, argv, "h:p:U:wWeqi", long_options, &optindex)) != -1)
{
switch (c)
{
@ -67,8 +68,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;
@ -114,7 +118,7 @@ main(int argc, char *argv[])
fmtId(dbname));
conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres",
host, port, username, password, progname);
host, port, username, prompt_password, progname);
if (echo)
printf("%s", sql.data);
@ -148,6 +152,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\n"));
printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt\n"));
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
}