aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql')
-rw-r--r--src/bin/psql/command.c6
-rw-r--r--src/bin/psql/help.c3
-rw-r--r--src/bin/psql/settings.h10
-rw-r--r--src/bin/psql/startup.c22
4 files changed, 24 insertions, 17 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 41888666de1..24c5b4d53ce 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.202 2009/01/20 02:13:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.203 2009/02/26 16:02:38 petere Exp $
*/
#include "postgres_fe.h"
#include "command.h"
@@ -1212,7 +1212,7 @@ do_connect(char *dbname, char *user, char *host, char *port)
* the postmaster's log. But libpq offers no API that would let us obtain
* a password and then continue with the first connection attempt.
*/
- if (pset.getPassword)
+ if (pset.getPassword == TRI_YES)
{
password = prompt_for_password(user);
}
@@ -1237,7 +1237,7 @@ do_connect(char *dbname, char *user, char *host, char *port)
* Connection attempt failed; either retry the connection attempt with
* a new password, or give up.
*/
- if (!password && PQconnectionNeedsPassword(n_conn))
+ if (!password && PQconnectionNeedsPassword(n_conn) && pset.getPassword != TRI_NO)
{
PQfinish(n_conn);
password = prompt_for_password(user);
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 25d023ff07f..36c89d516ec 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.139 2009/02/25 13:03:07 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.140 2009/02/26 16:02:38 petere Exp $
*/
#include "postgres_fe.h"
@@ -140,6 +140,7 @@ usage(void)
if (!env)
env = user;
printf(_(" -U NAME database user name (default: \"%s\")\n"), env);
+ puts(_(" -w never prompt for password"));
puts(_(" -W force password prompt (should happen automatically)"));
puts(_(
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index fbf5ebe9310..31b76e112da 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.34 2009/01/01 17:23:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.35 2009/02/26 16:02:38 petere Exp $
*/
#ifndef SETTINGS_H
#define SETTINGS_H
@@ -55,6 +55,12 @@ typedef enum
hctl_ignoreboth = hctl_ignorespace | hctl_ignoredups
} HistControl;
+enum trivalue
+{
+ TRI_DEFAULT,
+ TRI_NO,
+ TRI_YES
+};
typedef struct _psqlSettings
{
@@ -69,7 +75,7 @@ typedef struct _psqlSettings
bool notty; /* stdin or stdout is not a tty (as determined
* on startup) */
- bool getPassword; /* prompt the user for a username and password */
+ enum trivalue getPassword; /* prompt the user for a username and password */
FILE *cur_cmd_source; /* describe the status of the current main
* loop */
bool cur_cmd_interactive;
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index ba4871f88e5..bea174c0683 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.154 2009/02/25 13:24:40 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.155 2009/02/26 16:02:38 petere Exp $
*/
#include "postgres_fe.h"
@@ -140,12 +140,7 @@ main(int argc, char *argv[])
pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
- /* This is obsolete and should be removed sometime. */
-#ifdef PSQL_ALWAYS_GET_PASSWORDS
- pset.getPassword = true;
-#else
- pset.getPassword = false;
-#endif
+ pset.getPassword = TRI_DEFAULT;
EstablishVariableSpace();
@@ -175,7 +170,7 @@ main(int argc, char *argv[])
options.username);
}
- if (pset.getPassword)
+ if (pset.getPassword == TRI_YES)
password = simple_prompt(password_prompt, 100, false);
/* loop until we have a password if requested by backend */
@@ -189,7 +184,8 @@ main(int argc, char *argv[])
if (PQstatus(pset.db) == CONNECTION_BAD &&
PQconnectionNeedsPassword(pset.db) &&
- password == NULL)
+ password == NULL &&
+ pset.getPassword != TRI_NO)
{
PQfinish(pset.db);
password = simple_prompt(password_prompt, 100, false);
@@ -340,6 +336,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
{"set", required_argument, NULL, 'v'},
{"variable", required_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
+ {"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"expanded", no_argument, NULL, 'x'},
{"no-psqlrc", no_argument, NULL, 'X'},
@@ -354,7 +351,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
memset(options, 0, sizeof *options);
- while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VWxX?1",
+ while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxX?1",
long_options, &optindex)) != -1)
{
switch (c)
@@ -491,8 +488,11 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
case 'V':
showVersion();
exit(EXIT_SUCCESS);
+ case 'w':
+ pset.getPassword = TRI_NO;
+ break;
case 'W':
- pset.getPassword = true;
+ pset.getPassword = TRI_YES;
break;
case 'x':
pset.popt.topt.expanded = true;