programs that have a -W/--password option.
In passing, remove the ancient PSQL_ALWAYS_GET_PASSWORDS compile option.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/contrib/vacuumlo/vacuumlo.c,v 1.39 2009/02/25 13:34:32 petere Exp $
+ * $PostgreSQL: pgsql/contrib/vacuumlo/vacuumlo.c,v 1.40 2009/02/26 16:02:37 petere Exp $
*
*-------------------------------------------------------------------------
*/
opterr,
optopt;
+enum trivalue
+{
+ TRI_DEFAULT,
+ TRI_NO,
+ TRI_YES
+};
+
struct _param
{
char *pg_user;
- int pg_prompt;
+ enum trivalue pg_prompt;
char *pg_port;
char *pg_host;
int verbose;
static char *password = NULL;
bool new_pass;
- if (param->pg_prompt && password == NULL)
+ if (param->pg_prompt == TRI_YES && password == NULL)
password = simple_prompt("Password: ", 100, false);
/*
if (PQstatus(conn) == CONNECTION_BAD &&
PQconnectionNeedsPassword(conn) &&
- password == NULL)
+ password == NULL &&
+ param->pg_prompt != TRI_NO)
{
PQfinish(conn);
password = simple_prompt("Password: ", 100, false);
printf(" -n don't remove large objects, just show what would be done\n");
printf(" -p PORT database server port\n");
printf(" -U USERNAME user name to connect as\n");
+ printf(" -w never prompt for password\n");
printf(" -W force password prompt\n");
printf(" -v write a lot of progress messages\n");
printf("\n");
/* Parameter handling */
param.pg_user = NULL;
- param.pg_prompt = 0;
+ param.pg_prompt = TRI_DEFAULT;
param.pg_host = NULL;
param.pg_port = NULL;
param.verbose = 0;
while (1)
{
- c = getopt(argc, argv, "?h:U:p:vnW");
+ c = getopt(argc, argv, "?h:U:p:vnwW");
if (c == -1)
break;
case 'U':
param.pg_user = strdup(optarg);
break;
+ case 'w':
+ param.pg_prompt = TRI_NO;
+ break;
case 'W':
- param.pg_prompt = 1;
+ param.pg_prompt = TRI_YES;
break;
case 'p':
port = strtol(optarg, NULL, 10);
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/clusterdb.sgml,v 1.24 2008/11/24 08:46:03 petere Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/clusterdb.sgml,v 1.25 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/createdb.sgml,v 1.48 2008/11/10 16:25:41 alvherre Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/createdb.sgml,v 1.49 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/createlang.sgml,v 1.42 2007/12/11 19:57:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/createlang.sgml,v 1.43 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/createuser.sgml,v 1.51 2007/12/11 19:57:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/createuser.sgml,v 1.52 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/dropdb.sgml,v 1.34 2007/12/11 19:57:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/dropdb.sgml,v 1.35 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/droplang.sgml,v 1.31 2007/12/11 19:57:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/droplang.sgml,v 1.32 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.39 2007/12/11 19:57:32 tgl Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.40 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.110 2009/02/17 15:41:50 momjian Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.111 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</option></term>
<term><option>--password</option></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.76 2009/02/17 15:41:50 momjian Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.77 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</option></term>
<term><option>--password</option></term>
-<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.79 2009/02/07 14:31:30 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.80 2009/02/26 16:02:37 petere Exp $ -->
<refentry id="APP-PGRESTORE">
<refmeta>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</option></term>
<term><option>--password</option></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.219 2009/02/09 14:09:56 momjian Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.220 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires password
+ authentication and a password is not available by other means
+ such as a <filename>.pgpass</filename> file, the connection
+ attempt will fail. This option can be useful in batch jobs and
+ scripts where no user is present to enter a password.
+ </para>
+
+ <para>
+ Note that this option will remain set for the entire session,
+ and so it affects uses of the meta-command
+ <command>\connect</command> as well as the initial connection attempt.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.43 2009/02/18 12:11:55 momjian Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.44 2009/02/26 16:02:37 petere Exp $
PostgreSQL documentation
-->
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires
+ password authentication and a password is not available by
+ other means such as a <filename>.pgpass</filename> file, the
+ connection attempt will fail. This option can be useful in
+ batch jobs and scripts where no user is present to enter a
+ password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</></term>
<term><option>--password</></term>
-<!-- $PostgreSQL: pgsql/doc/src/sgml/vacuumlo.sgml,v 1.3 2007/12/11 19:57:32 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/vacuumlo.sgml,v 1.4 2009/02/26 16:02:37 petere Exp $ -->
<sect1 id="vacuumlo">
<title>vacuumlo</title>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-w</></term>
+ <term><option>--no-password</></term>
+ <listitem>
+ <para>
+ Never issue a password prompt. If the server requires password
+ authentication and a password is not available by other means
+ such as a <filename>.pgpass</filename> file, the connection
+ attempt will fail. This option can be useful in batch jobs and
+ scripts where no user is present to enter a password.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-W</option></term>
<listitem>
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.49 2009/02/02 20:07:36 adunstan Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.50 2009/02/26 16:02:37 petere Exp $
*
*-------------------------------------------------------------------------
*/
#define oidge(x,y) ( (x) >= (y) )
#define oidzero(x) ( (x) == 0 )
+enum trivalue
+{
+ TRI_DEFAULT,
+ TRI_NO,
+ TRI_YES
+};
+
typedef enum _archiveFormat
{
archUnknown = 0,
char *pghost;
char *username;
int noDataForFailedTables;
- int requirePassword;
+ enum trivalue promptPassword;
int exit_on_error;
int compression;
int suppressDumpWarnings; /* Suppress output of WARNING entries
const char *pghost,
const char *pgport,
const char *username,
- int reqPwd);
+ enum trivalue prompt_password);
/* Called to add a TOC entry */
extern void ArchiveEntry(Archive *AHX,
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.163 2009/02/20 02:57:21 adunstan Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.164 2009/02/26 16:02:37 petere Exp $
*
*-------------------------------------------------------------------------
*/
ConnectDatabase(AHX, ropt->dbname,
ropt->pghost, ropt->pgport, ropt->username,
- ropt->requirePassword);
+ ropt->promptPassword);
/*
* If we're talking to the DB directly, don't send comments since they
/* set any fields that shouldn't default to zeroes */
opts->format = archUnknown;
+ opts->promptPassword = TRI_DEFAULT;
return opts;
}
else
AH->format = fmt;
+ AH->promptPassword = TRI_DEFAULT;
+
switch (AH->format)
{
case archCustom:
*/
ConnectDatabase((Archive *) AH, ropt->dbname,
ropt->pghost, ropt->pgport, ropt->username,
- ropt->requirePassword);
+ ropt->promptPassword);
_doSetFixedOutputState(AH);
*/
ConnectDatabase((Archive *) AH, ropt->dbname,
ropt->pghost, ropt->pgport, ropt->username,
- ropt->requirePassword);
+ ropt->promptPassword);
_doSetFixedOutputState(AH);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.77 2009/02/02 20:07:37 adunstan Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.78 2009/02/26 16:02:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
/* Stuff for direct DB connection */
char *archdbname; /* DB name *read* from archive */
- bool requirePassword;
+ enum trivalue promptPassword;
char *savedPassword; /* password for ropt->username, if known */
PGconn *connection;
int connectToDB; /* Flag to indicate if direct DB connection is
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.82 2009/02/25 13:24:40 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.83 2009/02/26 16:02:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
ahlog(AH, 1, "connecting to database \"%s\" as user \"%s\"\n",
newdb, newuser);
- if (AH->requirePassword && password == NULL)
+ if (AH->promptPassword == TRI_YES && password == NULL)
{
password = simple_prompt("Password: ", 100, false);
if (password == NULL)
if (password)
free(password);
- password = simple_prompt("Password: ", 100, false);
+
+ if (AH->promptPassword != TRI_NO)
+ password = simple_prompt("Password: ", 100, false);
+ else
+ die_horribly(AH, modulename, "connection needs password\n");
+
if (password == NULL)
die_horribly(AH, modulename, "out of memory\n");
new_pass = true;
const char *pghost,
const char *pgport,
const char *username,
- int reqPwd)
+ enum trivalue prompt_password)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
char *password = AH->savedPassword;
if (AH->connection)
die_horribly(AH, modulename, "already connected to a database\n");
- if (reqPwd && password == NULL)
+ if (prompt_password == TRI_YES && password == NULL)
{
password = simple_prompt("Password: ", 100, false);
if (password == NULL)
die_horribly(AH, modulename, "out of memory\n");
}
- AH->requirePassword = reqPwd;
+ AH->promptPassword = prompt_password;
/*
* Start the connection. Loop until we have a password if requested by
if (PQstatus(AH->connection) == CONNECTION_BAD &&
PQconnectionNeedsPassword(AH->connection) &&
- password == NULL)
+ password == NULL &&
+ prompt_password != TRI_NO)
{
PQfinish(AH->connection);
password = simple_prompt("Password: ", 100, false);
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.526 2009/02/25 13:03:06 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.527 2009/02/26 16:02:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
DumpableObject **dobjs;
int numObjs;
int i;
- bool force_password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
int compressLevel = -1;
int plainText = 0;
int outputClean = 0;
{"superuser", required_argument, NULL, 'S'},
{"table", required_argument, NULL, 't'},
{"exclude-table", required_argument, NULL, 'T'},
+ {"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"username", required_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'},
}
}
- while ((c = getopt_long(argc, argv, "abcCdDE:f:F:h:in:N:oOp:RsS:t:T:U:vWxX:Z:",
+ while ((c = getopt_long(argc, argv, "abcCdDE:f:F:h:in:N:oOp:RsS:t:T:U:vwWxX:Z:",
long_options, &optindex)) != -1)
{
switch (c)
g_verbose = true;
break;
+ case 'w':
+ prompt_password = TRI_NO;
+ break;
+
case 'W':
- force_password = true;
+ prompt_password = TRI_YES;
break;
case 'x': /* skip ACL dump */
* death.
*/
g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport,
- username, force_password);
+ username, prompt_password);
/* Set the client encoding if requested */
if (dumpencoding)
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.117 2009/02/25 13:24:40 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.118 2009/02/26 16:02:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
static int runPgDump(const char *dbname);
static PGconn *connectDatabase(const char *dbname, const char *pghost, const char *pgport,
- const char *pguser, bool require_password, bool fail_on_error);
+ const char *pguser, enum trivalue prompt_password, bool fail_on_error);
static PGresult *executeQuery(PGconn *conn, const char *query);
static void executeCommand(PGconn *conn, const char *query);
char *pguser = NULL;
char *pgdb = NULL;
char *use_role = NULL;
- bool force_password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool data_only = false;
bool globals_only = false;
bool roles_only = false;
{"tablespaces-only", no_argument, NULL, 't'},
{"username", required_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'},
+ {"no-password", no_argument, NULL, 'w'},
{"password", no_argument, NULL, 'W'},
{"no-privileges", no_argument, NULL, 'x'},
{"no-acl", no_argument, NULL, 'x'},
pgdumpopts = createPQExpBuffer();
- while ((c = getopt_long(argc, argv, "acdDf:gh:il:oOp:rsS:tU:vWxX:", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "acdDf:gh:il:oOp:rsS:tU:vwWxX:", long_options, &optindex)) != -1)
{
switch (c)
{
appendPQExpBuffer(pgdumpopts, " -v");
break;
+ case 'w':
+ prompt_password = TRI_NO;
+ appendPQExpBuffer(pgdumpopts, " -w");
+ break;
+
case 'W':
- force_password = true;
+ prompt_password = TRI_YES;
appendPQExpBuffer(pgdumpopts, " -W");
break;
if (pgdb)
{
conn = connectDatabase(pgdb, pghost, pgport, pguser,
- force_password, false);
+ prompt_password, false);
if (!conn)
{
else
{
conn = connectDatabase("postgres", pghost, pgport, pguser,
- force_password, false);
+ prompt_password, false);
if (!conn)
conn = connectDatabase("template1", pghost, pgport, pguser,
- force_password, true);
+ prompt_password, true);
if (!conn)
{
printf(_(" -l, --database=DBNAME alternative default database\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
+ printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
printf(_("\nIf -f/--file is not used, then the SQL script will be written to the standard\n"
*/
static PGconn *
connectDatabase(const char *dbname, const char *pghost, const char *pgport,
- const char *pguser, bool require_password, bool fail_on_error)
+ const char *pguser, enum trivalue prompt_password, bool fail_on_error)
{
PGconn *conn;
bool new_pass;
int my_version;
static char *password = NULL;
- if (require_password && !password)
+ if (prompt_password == TRI_YES && !password)
password = simple_prompt("Password: ", 100, false);
/*
if (PQstatus(conn) == CONNECTION_BAD &&
PQconnectionNeedsPassword(conn) &&
- password == NULL)
+ password == NULL &&
+ prompt_password != TRI_NO)
{
PQfinish(conn);
password = simple_prompt("Password: ", 100, false);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.93 2009/02/25 13:03:06 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.94 2009/02/26 16:02:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
{"no-owner", 0, NULL, 'O'},
{"no-reconnect", 0, NULL, 'R'},
{"port", 1, NULL, 'p'},
+ {"no-password", 0, NULL, 'w'},
{"password", 0, NULL, 'W'},
{"schema", 1, NULL, 'n'},
{"schema-only", 0, NULL, 's'},
}
}
- while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:m:n:Op:P:RsS:t:T:U:vWxX:1",
+ while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:m:n:Op:P:RsS:t:T:U:vwWxX:1",
cmdopts, NULL)) != -1)
{
switch (c)
opts->verbose = 1;
break;
+ case 'w':
+ opts->promptPassword = TRI_NO;
+ break;
+
case 'W':
- opts->requirePassword = true;
+ opts->promptPassword = TRI_YES;
break;
case 'x': /* skip ACL dump */
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -U, --username=NAME connect as specified database user\n"));
+ printf(_(" -w, --no-password never prompt for password\n"));
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
*
* 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"
* 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);
}
* 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);
*
* 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"
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(_(
*
* 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
hctl_ignoreboth = hctl_ignorespace | hctl_ignoredups
} HistControl;
+enum trivalue
+{
+ TRI_DEFAULT,
+ TRI_NO,
+ TRI_YES
+};
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;
*
* 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"
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();
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 */
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);
{"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'},
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)
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;
*
* Portions Copyright (c) 2002-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.24 2009/02/25 13:03:07 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.25 2009/02/26 16:02:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void cluster_one_database(const char *dbname, bool verbose, const char *table,
const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo);
static void cluster_all_databases(bool verbose, const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet);
static void help(const char *progname);
{"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'},
char *host = NULL;
char *port = NULL;
char *username = NULL;
- bool password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool quiet = false;
bool alldb = false;
handle_help_version_opts(argc, argv, "clusterdb", help);
- while ((c = getopt_long(argc, argv, "h:p:U:Weqd:at:v", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:at:v", long_options, &optindex)) != -1)
{
switch (c)
{
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;
exit(1);
}
- cluster_all_databases(verbose, host, port, username, password,
+ cluster_all_databases(verbose, host, port, username, prompt_password,
progname, echo, quiet);
}
else
}
cluster_one_database(dbname, verbose, table,
- host, port, username, password,
+ host, port, username, prompt_password,
progname, echo);
}
static void
cluster_one_database(const char *dbname, bool verbose, const char *table,
const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo)
{
PQExpBufferData sql;
appendPQExpBuffer(&sql, " %s", fmtId(table));
appendPQExpBuffer(&sql, ";\n");
- conn = connectDatabase(dbname, host, port, username, password, progname);
+ conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
if (table)
static void
cluster_all_databases(bool verbose, const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet)
{
PGconn *conn;
PGresult *result;
int i;
- conn = connectDatabase("postgres", host, port, username, password, progname);
+ conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
PQfinish(conn);
}
cluster_one_database(dbname, verbose, NULL,
- host, port, username, password,
+ host, port, username, prompt_password,
progname, echo);
}
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(_("\nRead the description of the SQL command CLUSTER for details.\n"));
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.34 2009/02/25 13:24:40 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.35 2009/02/26 16:02:38 petere Exp $
*
*-------------------------------------------------------------------------
*/
*/
PGconn *
connectDatabase(const char *dbname, const char *pghost, const char *pgport,
- const char *pguser, bool require_password,
+ const char *pguser, enum trivalue prompt_password,
const char *progname)
{
PGconn *conn;
char *password = NULL;
bool new_pass;
- if (require_password)
+ if (prompt_password == TRI_YES)
password = simple_prompt("Password: ", 100, false);
/*
if (PQstatus(conn) == CONNECTION_BAD &&
PQconnectionNeedsPassword(conn) &&
- password == NULL)
+ password == NULL &&
+ prompt_password != TRI_NO)
{
PQfinish(conn);
password = simple_prompt("Password: ", 100, false);
*
* Copyright (c) 2003-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/scripts/common.h,v 1.21 2009/01/01 17:23:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/common.h,v 1.22 2009/02/26 16:02:39 petere Exp $
*/
#ifndef COMMON_H
#define COMMON_H
extern int optreset;
#endif
+enum trivalue
+{
+ TRI_DEFAULT,
+ TRI_NO,
+ TRI_YES
+};
+
typedef void (*help_handler) (const char *progname);
extern const char *get_user_name(const char *progname);
extern PGconn *connectDatabase(const char *dbname, const char *pghost,
const char *pgport, const char *pguser,
- bool require_password, const char *progname);
+ enum trivalue prompt_password, const char *progname);
extern PGresult *executeQuery(PGconn *conn, const char *query,
const char *progname, bool echo);
* 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 $
*
*-------------------------------------------------------------------------
*/
{"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'},
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;
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)
{
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;
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);
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);
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"));
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.33 2009/02/25 13:03:07 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.34 2009/02/26 16:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
{"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'},
{"dbname", required_argument, NULL, 'd'},
{"echo", no_argument, NULL, 'e'},
char *host = NULL;
char *port = NULL;
char *username = NULL;
- bool password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
char *langname = NULL;
handle_help_version_opts(argc, argv, "createlang", help);
- while ((c = getopt_long(argc, argv, "lh:p:U:Wd:e", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "lh:p:U:wWd:e", long_options, &optindex)) != -1)
{
switch (c)
{
case 'U':
username = optarg;
break;
+ case 'w':
+ prompt_password = TRI_NO;
+ break;
case 'W':
- password = true;
+ prompt_password = TRI_YES;
break;
case 'd':
dbname = optarg;
printQueryOpt popt;
static const bool translate_columns[] = {false, true};
- conn = connectDatabase(dbname, host, port, username, password,
+ conn = connectDatabase(dbname, host, port, username, prompt_password,
progname);
printfPQExpBuffer(&sql, "SELECT lanname as \"%s\", "
if (*p >= 'A' && *p <= 'Z')
*p += ('a' - 'A');
- conn = connectDatabase(dbname, host, port, username, password, progname);
+ conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
/*
* Make sure the language isn't already installed
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"));
}
* 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 $
*
*-------------------------------------------------------------------------
*/
static void help(const char *progname);
-enum trivalue
-{
- TRI_DEFAULT,
- TRI_NO,
- TRI_YES
-};
-
int
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'},
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;
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)
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;
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);
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"));
* 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 $
*
*-------------------------------------------------------------------------
*/
{"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'},
char *host = NULL;
char *port = NULL;
char *username = NULL;
- bool password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool interactive = false;
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)
{
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;
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);
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"));
}
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.30 2009/02/25 13:03:07 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.31 2009/02/26 16:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
{"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'},
{"dbname", required_argument, NULL, 'd'},
{"echo", no_argument, NULL, 'e'},
char *host = NULL;
char *port = NULL;
char *username = NULL;
- bool password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
char *langname = NULL;
handle_help_version_opts(argc, argv, "droplang", help);
- while ((c = getopt_long(argc, argv, "lh:p:U:Wd:e", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "lh:p:U:wWd:e", long_options, &optindex)) != -1)
{
switch (c)
{
case 'U':
username = optarg;
break;
+ case 'w':
+ prompt_password = TRI_NO;
+ break;
case 'W':
- password = true;
+ prompt_password = TRI_YES;
break;
case 'd':
dbname = optarg;
printQueryOpt popt;
static const bool translate_columns[] = {false, true};
- conn = connectDatabase(dbname, host, port, username, password,
+ conn = connectDatabase(dbname, host, port, username, prompt_password,
progname);
printfPQExpBuffer(&sql, "SELECT lanname as \"%s\", "
if (*p >= 'A' && *p <= 'Z')
*p += ('a' - 'A');
- conn = connectDatabase(dbname, host, port, username, password, progname);
+ conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
/*
* Force schema search path to be just pg_catalog, so that we don't have
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"));
}
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.26 2009/02/25 13:03:07 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.27 2009/02/26 16:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
{"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'},
char *host = NULL;
char *port = NULL;
char *username = NULL;
- bool password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool interactive = false;
handle_help_version_opts(argc, argv, "dropuser", 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)
{
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;
initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "DROP ROLE %s;\n", fmtId(dropuser));
- conn = connectDatabase("postgres", host, port, username, password, progname);
+ conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
if (echo)
printf("%s", sql.data);
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 drop)\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"));
}
*
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/scripts/reindexdb.c,v 1.16 2009/02/25 13:03:07 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/reindexdb.c,v 1.17 2009/02/26 16:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void reindex_one_database(const char *name, const char *dbname,
const char *type, const char *host,
const char *port, const char *username,
- bool password, const char *progname,
+ enum trivalue prompt_password, const char *progname,
bool echo);
static void reindex_all_databases(const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo,
bool quiet);
static void reindex_system_catalogs(const char *dbname,
const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo);
static void help(const char *progname);
{"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'},
const char *host = NULL;
const char *port = NULL;
const char *username = NULL;
- bool password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool syscatalog = false;
bool alldb = false;
bool echo = false;
handle_help_version_opts(argc, argv, "reindexdb", help);
/* process command-line options */
- while ((c = getopt_long(argc, argv, "h:p:U:Weqd:ast:i:", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:ast:i:", long_options, &optindex)) != -1)
{
switch (c)
{
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;
exit(1);
}
- reindex_all_databases(host, port, username, password,
+ reindex_all_databases(host, port, username, prompt_password,
progname, echo, quiet);
}
else if (syscatalog)
dbname = get_user_name(progname);
}
- reindex_system_catalogs(dbname, host, port, username, password,
+ reindex_system_catalogs(dbname, host, port, username, prompt_password,
progname, echo);
}
else
if (index)
reindex_one_database(index, dbname, "INDEX", host, port,
- username, password, progname, echo);
+ username, prompt_password, progname, echo);
if (table)
reindex_one_database(table, dbname, "TABLE", host, port,
- username, password, progname, echo);
+ username, prompt_password, progname, echo);
/* reindex database only if index or table is not specified */
if (index == NULL && table == NULL)
reindex_one_database(dbname, dbname, "DATABASE", host, port,
- username, password, progname, echo);
+ username, prompt_password, progname, echo);
}
exit(0);
static void
reindex_one_database(const char *name, const char *dbname, const char *type,
const char *host, const char *port, const char *username,
- bool password, const char *progname, bool echo)
+ enum trivalue prompt_password, const char *progname, bool echo)
{
PQExpBufferData sql;
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
appendPQExpBuffer(&sql, ";\n");
- conn = connectDatabase(dbname, host, port, username, password, progname);
+ conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
static void
reindex_all_databases(const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet)
{
PGconn *conn;
PGresult *result;
int i;
- conn = connectDatabase("postgres", host, port, username, password, progname);
+ conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
PQfinish(conn);
}
reindex_one_database(dbname, dbname, "DATABASE", host, port, username,
- password, progname, echo);
+ prompt_password, progname, echo);
}
PQclear(result);
static void
reindex_system_catalogs(const char *dbname, const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo)
{
PQExpBufferData sql;
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", dbname);
- conn = connectDatabase(dbname, host, port, username, password, progname);
+ conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
fprintf(stderr, _("%s: reindexing of system catalogs failed: %s"),
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(_("\nRead the description of the SQL command REINDEX for details.\n"));
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.24 2009/02/25 13:03:07 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.25 2009/02/26 16:02:39 petere Exp $
*
*-------------------------------------------------------------------------
*/
static void vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
bool freeze, const char *table,
const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo);
static void vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet);
static void help(const char *progname);
{"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'},
char *host = NULL;
char *port = NULL;
char *username = NULL;
- bool password = false;
+ enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool quiet = false;
bool analyze = false;
handle_help_version_opts(argc, argv, "vacuumdb", help);
- while ((c = getopt_long(argc, argv, "h:p:U:Weqd:zaFt:fv", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zaFt:fv", long_options, &optindex)) != -1)
{
switch (c)
{
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;
}
vacuum_all_databases(full, verbose, analyze, freeze,
- host, port, username, password,
+ host, port, username, prompt_password,
progname, echo, quiet);
}
else
}
vacuum_one_database(dbname, full, verbose, analyze, freeze, table,
- host, port, username, password,
+ host, port, username, prompt_password,
progname, echo);
}
vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
bool freeze, const char *table,
const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo)
{
PQExpBufferData sql;
appendPQExpBuffer(&sql, " %s", table);
appendPQExpBuffer(&sql, ";\n");
- conn = connectDatabase(dbname, host, port, username, password, progname);
+ conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
if (table)
static void
vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
const char *host, const char *port,
- const char *username, bool password,
+ const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool quiet)
{
PGconn *conn;
PGresult *result;
int i;
- conn = connectDatabase("postgres", host, port, username, password, progname);
+ conn = connectDatabase("postgres", host, port, username, prompt_password, progname);
result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", progname, echo);
PQfinish(conn);
}
vacuum_one_database(dbname, full, verbose, analyze, freeze, NULL,
- host, port, username, password,
+ host, port, username, prompt_password,
progname, echo);
}
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(_("\nRead the description of the SQL command VACUUM for details.\n"));
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
* for developers. If you edit any of these, be sure to do a *full*
* rebuild (and an initdb if noted).
*
- * $PostgreSQL: pgsql/src/include/pg_config_manual.h,v 1.37 2009/01/12 05:10:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/pg_config_manual.h,v 1.38 2009/02/26 16:02:39 petere Exp $
*------------------------------------------------------------------------
*/
*/
#define NUM_USER_DEFINED_LWLOCKS 4
-/*
- * Define this if you want psql to _always_ ask for a username and a
- * password for password authentication.
- */
-/* #define PSQL_ALWAYS_GET_PASSWORDS */
-
/*
* Define this if you want to allow the lo_import and lo_export SQL
* functions to be executed by ordinary users. By default these