mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +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:
@ -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/createdb.c,v 1.31 2009/02/25 13:03:07 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.32 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'},
|
||||
@ -47,7 +48,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 *owner = NULL;
|
||||
char *tablespace = NULL;
|
||||
@ -67,7 +68,7 @@ main(int argc, char *argv[])
|
||||
|
||||
handle_help_version_opts(argc, argv, "createdb", help);
|
||||
|
||||
while ((c = getopt_long(argc, argv, "h:p:U:WeqO:D:T:E:l:", long_options, &optindex)) != -1)
|
||||
while ((c = getopt_long(argc, argv, "h:p:U:wWeqO:D:T:E:l:", long_options, &optindex)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
@ -80,8 +81,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;
|
||||
@ -193,7 +197,7 @@ main(int argc, char *argv[])
|
||||
appendPQExpBuffer(&sql, ";\n");
|
||||
|
||||
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);
|
||||
@ -212,7 +216,7 @@ main(int argc, char *argv[])
|
||||
|
||||
if (comment)
|
||||
{
|
||||
conn = connectDatabase(dbname, host, port, username, password, progname);
|
||||
conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
|
||||
|
||||
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
|
||||
appendStringLiteralConn(&sql, comment, conn);
|
||||
@ -259,6 +263,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(_("\nBy default, a database with the same name as the current user is created.\n"));
|
||||
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
|
||||
|
Reference in New Issue
Block a user