Add a -w/--no-password option that prevents all password prompts to all
authorPeter Eisentraut
Thu, 26 Feb 2009 16:02:39 +0000 (16:02 +0000)
committerPeter Eisentraut
Thu, 26 Feb 2009 16:02:39 +0000 (16:02 +0000)
programs that have a -W/--password option.

In passing, remove the ancient PSQL_ALWAYS_GET_PASSWORDS compile option.

38 files changed:
contrib/vacuumlo/vacuumlo.c
doc/src/sgml/ref/clusterdb.sgml
doc/src/sgml/ref/createdb.sgml
doc/src/sgml/ref/createlang.sgml
doc/src/sgml/ref/createuser.sgml
doc/src/sgml/ref/dropdb.sgml
doc/src/sgml/ref/droplang.sgml
doc/src/sgml/ref/dropuser.sgml
doc/src/sgml/ref/pg_dump.sgml
doc/src/sgml/ref/pg_dumpall.sgml
doc/src/sgml/ref/pg_restore.sgml
doc/src/sgml/ref/psql-ref.sgml
doc/src/sgml/ref/reindexdb.sgml
doc/src/sgml/ref/vacuumdb.sgml
doc/src/sgml/vacuumlo.sgml
src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_dump/pg_restore.c
src/bin/psql/command.c
src/bin/psql/help.c
src/bin/psql/settings.h
src/bin/psql/startup.c
src/bin/scripts/clusterdb.c
src/bin/scripts/common.c
src/bin/scripts/common.h
src/bin/scripts/createdb.c
src/bin/scripts/createlang.c
src/bin/scripts/createuser.c
src/bin/scripts/dropdb.c
src/bin/scripts/droplang.c
src/bin/scripts/dropuser.c
src/bin/scripts/reindexdb.c
src/bin/scripts/vacuumdb.c
src/include/pg_config_manual.h

index fa85890fe6d065170741a1ebed1227a82082a1b7..37a6c229ac423b552113583792d511c9b38c538a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -33,10 +33,17 @@ extern int  optind,
            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;
@@ -64,7 +71,7 @@ vacuumlo(char *database, struct _param * param)
    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);
 
    /*
@@ -91,7 +98,8 @@ vacuumlo(char *database, struct _param * param)
 
        if (PQstatus(conn) == CONNECTION_BAD &&
            PQconnectionNeedsPassword(conn) &&
-           password == NULL)
+           password == NULL &&
+           param->pg_prompt != TRI_NO)
        {
            PQfinish(conn);
            password = simple_prompt("Password: ", 100, false);
@@ -308,6 +316,7 @@ usage(void)
    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");
@@ -324,7 +333,7 @@ main(int argc, char **argv)
 
    /* 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;
@@ -332,7 +341,7 @@ main(int argc, char **argv)
 
    while (1)
    {
-       c = getopt(argc, argv, "?h:U:p:vnW");
+       c = getopt(argc, argv, "?h:U:p:vnwW");
        if (c == -1)
            break;
 
@@ -357,8 +366,11 @@ main(int argc, char **argv)
            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);
index 45bfbe2f6451a5214b22e0b5bef7e954e4298576..6dd448dca59ce788e84df08c83edcce5fb2e59a3 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -171,6 +171,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index c8c12e8b067eb09c3c82c9c5cca75f5dff6d47a8..59f108c4cddf26b8384f18c5ab847c80166def77 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -217,6 +217,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index 8383c66a8f9607d8a901dffec7a7a0e7d56a473d..afe380dc135c4b993e3a7c7e61bd93f7d2a7766e 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -139,6 +139,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index 95283e6775a655db523c877afa87ed18d9c1721a..1e8a1fc3fbd85a607a0f6f2d7b7bf262def61350 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -290,6 +290,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index daf01287fb7f21503692634bd20391abe7d7d72c..260241058c2d46cc08395e38093542992a0cb9a9 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -128,6 +128,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index ee334e13e5e5dc87c0840010c20942ebe368ed69..107a28b8aaeb20b4a3c6b4215ce9deb235e4c396 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -147,6 +147,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index af57135f120a3534e74d37562aafe5c2ce1f9620..b66a76f95630904e6ceff25f4c6752ab9e6bc919 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -130,6 +130,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index 0a9d0dc26ef9ad33c7e2aac42cc39bbc067159db..8633875006c46a18b451641b5964eab6c5574946 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -678,6 +678,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index 6e6ef46c6789cd14173cb8e899ce52e1f7fe1a63..0a8e7ef8c4114433815b47af8240207042f795f6 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -391,6 +391,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index 787db5e884b50f747e6dfa469c551c89c2579309..4971836bab8ecad27481fd77fa2d1b52d8d8e4fe 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
  
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index cab7b970ac8a7d769587c350604e0f4f6014b068..0f633e91601ae282ff048d283f498389318ce89c 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -401,6 +401,26 @@ PostgreSQL documentation
       
     
 
+    
+     
+     
+     
+      
+       Never issue a password prompt.  If the server requires password
+       authentication and a password is not available by other means
+       such as a .pgpass 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.
+      
+
+      
+       Note that this option will remain set for the entire session,
+       and so it affects uses of the meta-command
+       \connect as well as the initial connection attempt.
+      
+     
+    
+
     
       
       
index 259b170860941ded4a52ba7a0b3f4babcf647b50..936edb9c3daeec8f68f295188a44caac84da6c0f 100644 (file)
@@ -181,6 +181,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index 50d73b2465f8a3da4d2c9edd994d3dfd9fe3c1f0..75616ee46cd23ddd8549008191b8103bead452e4 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -216,6 +216,21 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+      
+       
+        Never issue a password prompt.  If the server requires
+        password authentication and a password is not available by
+        other means such as a .pgpass 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.
+       
+      
+     
+
      
       
       
index 4152d3f59a65708538d18ff52701a89247add602..5a1a69a1ea89e9ef454d3eba64f5f8f63d54ad2a 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
  vacuumlo
@@ -56,6 +56,20 @@ vacuumlo [options] database [database2 ... databaseN]
     
    
 
+   
+    
+    
+    
+     
+      Never issue a password prompt.  If the server requires password
+      authentication and a password is not available by other means
+      such as a .pgpass 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.
+     
+    
+   
+
    
     
     
index 72bc066853ee5788afe28b1eb7d343e5e496ad93..3e50b6b39a821c8bcf1e1b53c39b6daf5a11180a 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * 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,
@@ -126,7 +133,7 @@ typedef struct _restoreOptions
    char       *pghost;
    char       *username;
    int         noDataForFailedTables;
-   int         requirePassword;
+   enum trivalue promptPassword;
    int         exit_on_error;
    int         compression;
    int         suppressDumpWarnings;   /* Suppress output of WARNING entries
@@ -153,7 +160,7 @@ PGconn *ConnectDatabase(Archive *AH,
                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,
index 0b46e1097b37502691a078e52c74b8015509d03f..b768f5c2867fbdbbfea2e6b164f8d07a4934d15a 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -246,7 +246,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
 
        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
@@ -609,6 +609,7 @@ NewRestoreOptions(void)
 
    /* set any fields that shouldn't default to zeroes */
    opts->format = archUnknown;
+   opts->promptPassword = TRI_DEFAULT;
 
    return opts;
 }
@@ -1886,6 +1887,8 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
    else
        AH->format = fmt;
 
+   AH->promptPassword = TRI_DEFAULT;
+
    switch (AH->format)
    {
        case archCustom:
@@ -3206,7 +3209,7 @@ restore_toc_entries_parallel(ArchiveHandle *AH)
     */
    ConnectDatabase((Archive *) AH, ropt->dbname,
                    ropt->pghost, ropt->pgport, ropt->username,
-                   ropt->requirePassword);
+                   ropt->promptPassword);
 
    _doSetFixedOutputState(AH);
 
@@ -3476,7 +3479,7 @@ parallel_restore(RestoreArgs *args)
     */
    ConnectDatabase((Archive *) AH, ropt->dbname,
                    ropt->pghost, ropt->pgport, ropt->username,
-                   ropt->requirePassword);
+                   ropt->promptPassword);
 
    _doSetFixedOutputState(AH);
 
index 43756eba4d926753a764e22e3ee391e50c595ca8..11c6a83dcb9d685224c260d743602db271c438a2 100644 (file)
@@ -17,7 +17,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -238,7 +238,7 @@ typedef struct _archiveHandle
 
    /* 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
index f1b755b33bcc5a769343ff6b9e1b7976058c66d3..52e0d82b15d544914904167f805265f554d3f1bf 100644 (file)
@@ -5,7 +5,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -145,7 +145,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
    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)
@@ -176,7 +176,12 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
 
            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;
@@ -209,7 +214,7 @@ ConnectDatabase(Archive *AHX,
                const char *pghost,
                const char *pgport,
                const char *username,
-               int reqPwd)
+               enum trivalue prompt_password)
 {
    ArchiveHandle *AH = (ArchiveHandle *) AHX;
    char       *password = AH->savedPassword;
@@ -218,13 +223,13 @@ ConnectDatabase(Archive *AHX,
    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
@@ -241,7 +246,8 @@ ConnectDatabase(Archive *AHX,
 
        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);
index 7de9f4ec6a540a7905db71b7dd8777620eb39caf..26e1c044cb76e2df7f6ca1873c9da36082c88b69 100644 (file)
@@ -12,7 +12,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -221,7 +221,7 @@ main(int argc, char **argv)
    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;
@@ -261,6 +261,7 @@ main(int argc, char **argv)
        {"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'},
@@ -315,7 +316,7 @@ main(int argc, char **argv)
        }
    }
 
-   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)
@@ -416,8 +417,12 @@ main(int argc, char **argv)
                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 */
@@ -556,7 +561,7 @@ main(int argc, char **argv)
     * death.
     */
    g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport,
-                            username, force_password);
+                            username, prompt_password);
 
    /* Set the client encoding if requested */
    if (dumpencoding)
index 6d0add1eb60cdec84139a18583aa815d711c5073..2ddc03873e50b81c84e155e0d7d5cb51161cfb16 100644 (file)
@@ -6,7 +6,7 @@
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -52,7 +52,7 @@ static void doShellQuoting(PQExpBuffer buf, const char *str);
 
 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);
 
@@ -81,7 +81,7 @@ main(int argc, char *argv[])
    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;
@@ -114,6 +114,7 @@ main(int argc, char *argv[])
        {"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'},
@@ -177,7 +178,7 @@ main(int argc, char *argv[])
 
    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)
        {
@@ -262,8 +263,13 @@ main(int argc, char *argv[])
                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;
 
@@ -370,7 +376,7 @@ main(int argc, char *argv[])
    if (pgdb)
    {
        conn = connectDatabase(pgdb, pghost, pgport, pguser,
-                              force_password, false);
+                              prompt_password, false);
 
        if (!conn)
        {
@@ -382,10 +388,10 @@ main(int argc, char *argv[])
    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)
        {
@@ -528,6 +534,7 @@ help(void)
    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"
@@ -1329,7 +1336,7 @@ 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)
 {
    PGconn     *conn;
    bool        new_pass;
@@ -1337,7 +1344,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
    int         my_version;
    static char *password = NULL;
 
-   if (require_password && !password)
+   if (prompt_password == TRI_YES && !password)
        password = simple_prompt("Password: ", 100, false);
 
    /*
@@ -1358,7 +1365,8 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
 
        if (PQstatus(conn) == CONNECTION_BAD &&
            PQconnectionNeedsPassword(conn) &&
-           password == NULL)
+           password == NULL &&
+           prompt_password != TRI_NO)
        {
            PQfinish(conn);
            password = simple_prompt("Password: ", 100, false);
index a0ab3efecf706904ff55a8437c592448eca30b62..02b81b8e8a8900a39f7cd14b543d34b11b43ec37 100644 (file)
@@ -34,7 +34,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -99,6 +99,7 @@ main(int argc, char **argv)
        {"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'},
@@ -142,7 +143,7 @@ main(int argc, char **argv)
        }
    }
 
-   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)
@@ -240,8 +241,12 @@ main(int argc, char **argv)
                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 */
@@ -437,6 +442,7 @@ usage(const char *progname)
    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"));
index 41888666de1be88c8c27497a0a5064ce47bc5114..24c5b4d53ce14f1ed10e8875613d9600d8b9813c 100644 (file)
@@ -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);
index 25d023ff07fe194842f2200e597575f4e9edb547..36c89d516ec3068e982d4bbb381324f545d123e4 100644 (file)
@@ -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(_(
index fbf5ebe9310efab738acf72764137deeb4e03842..31b76e112daea2b81aca23e5cf9720bf20dc7e58 100644 (file)
@@ -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;
index ba4871f88e5b39072832dbbb90ab764153ed6f29..bea174c0683aa932caafcb416cfcd245eef3d12b 100644 (file)
@@ -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;
index e2755c5be64c5ab1bae25f9d538ee32730caf381..c690de36cc9a0fa20a7a1aa1fac9b8ff5da35f6e 100644 (file)
@@ -4,7 +4,7 @@
  *
  * 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);
@@ -32,6 +32,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'},
@@ -50,7 +51,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        quiet = false;
    bool        alldb = false;
@@ -62,7 +63,7 @@ main(int argc, char *argv[])
 
    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)
        {
@@ -75,8 +76,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;
@@ -133,7 +137,7 @@ main(int argc, char *argv[])
            exit(1);
        }
 
-       cluster_all_databases(verbose, host, port, username, password,
+       cluster_all_databases(verbose, host, port, username, prompt_password,
                              progname, echo, quiet);
    }
    else
@@ -149,7 +153,7 @@ main(int argc, char *argv[])
        }
 
        cluster_one_database(dbname, verbose, table,
-                            host, port, username, password,
+                            host, port, username, prompt_password,
                             progname, echo);
    }
 
@@ -160,7 +164,7 @@ main(int argc, char *argv[])
 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;
@@ -176,7 +180,7 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
        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)
@@ -195,14 +199,14 @@ cluster_one_database(const char *dbname, bool verbose, const char *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);
 
@@ -217,7 +221,7 @@ cluster_all_databases(bool verbose, const char *host, const char *port,
        }
 
        cluster_one_database(dbname, verbose, NULL,
-                            host, port, username, password,
+                            host, port, username, prompt_password,
                             progname, echo);
    }
 
@@ -244,6 +248,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(_("\nRead the description of the SQL command CLUSTER for details.\n"));
    printf(_("\nReport bugs to .\n"));
index 2587f1a99dff4362c077d7ebb41a96b303763fa5..c34115a1ba02d84991d1588df1f19a04b05ed3dc 100644 (file)
@@ -7,7 +7,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/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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -96,14 +96,14 @@ handle_help_version_opts(int argc, char *argv[],
  */
 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);
 
    /*
@@ -124,7 +124,8 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
 
        if (PQstatus(conn) == CONNECTION_BAD &&
            PQconnectionNeedsPassword(conn) &&
-           password == NULL)
+           password == NULL &&
+           prompt_password != TRI_NO)
        {
            PQfinish(conn);
            password = simple_prompt("Password: ", 100, false);
index 5123920be4a49f663bb3811968d1a9575e965e63..5c94d46add052be5a3b0f765f271741e9ef62c82 100644 (file)
@@ -4,7 +4,7 @@
  *
  * 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);
@@ -27,7 +34,7 @@ extern void handle_help_version_opts(int argc, char *argv[],
 
 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);
index a587771f23037ce89fc9a5e26c289503f5f3b460..f7cb9cf3de441f565f88cc587f5be249eea3ebc5 100644 (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/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 .\n"));
index dcfef2b608d1f7ceb8bb635e0a5d5238eb81cd69..d00cb63a8b01fa37702536ae4fc26f94da930415 100644 (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/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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -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'},
        {"dbname", required_argument, NULL, 'd'},
        {"echo", no_argument, NULL, 'e'},
@@ -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;
    char       *langname = NULL;
 
@@ -56,7 +57,7 @@ main(int argc, char *argv[])
 
    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)
        {
@@ -72,8 +73,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 'd':
                dbname = optarg;
@@ -127,7 +131,7 @@ main(int argc, char *argv[])
        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\", "
@@ -164,7 +168,7 @@ main(int argc, char *argv[])
        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
@@ -220,6 +224,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 .\n"));
 }
index 852cafd648f046551ba57d6eb7e6d9b34c84b70c..88b9bd30d571cd4c80990b5ecf286d702c169683 100644 (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 $
  *
  *-------------------------------------------------------------------------
  */
 
 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"));
index 28747180788d55eaec23d494d9d07d7ec8b11403..086e1c151756dc9752e43862bd551426d6309e77 100644 (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 .\n"));
 }
index 13f8e325bb58a055ca9052d9af04fc052ac4f7a0..7038e08b8af57bc79abe324cad52f1762b473b03 100644 (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/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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -28,6 +28,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'},
        {"dbname", required_argument, NULL, 'd'},
        {"echo", no_argument, NULL, 'e'},
@@ -43,7 +44,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       *langname = NULL;
 
@@ -67,7 +68,7 @@ main(int argc, char *argv[])
 
    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)
        {
@@ -83,8 +84,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 'd':
                dbname = optarg;
@@ -138,7 +142,7 @@ main(int argc, char *argv[])
        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\", "
@@ -177,7 +181,7 @@ main(int argc, char *argv[])
        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
@@ -337,6 +341,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 .\n"));
 }
index a5087afcf05b6987193e0b5afd7df966e6e22ff7..be2e2ceda6a1192649cba7ed648e637211a5b676 100644 (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/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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -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, "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)
        {
@@ -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;
@@ -112,7 +116,7 @@ main(int argc, char *argv[])
    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);
@@ -147,6 +151,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 drop)\n"));
+   printf(_("  -w, --no-password         never prompt for password\n"));
    printf(_("  -W, --password            force password prompt\n"));
    printf(_("\nReport bugs to .\n"));
 }
index ebccd04f5e14ccc4dde5b31be3a4db61de44004b..3bfa55249a7debe722be16b19bedc31ecb12564d 100644 (file)
@@ -4,7 +4,7 @@
  *
  * 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);
 
@@ -36,6 +36,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'},
@@ -55,7 +56,7 @@ main(int argc, char *argv[])
    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;
@@ -69,7 +70,7 @@ main(int argc, char *argv[])
    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)
        {
@@ -82,8 +83,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;
@@ -150,7 +154,7 @@ main(int argc, char *argv[])
            exit(1);
        }
 
-       reindex_all_databases(host, port, username, password,
+       reindex_all_databases(host, port, username, prompt_password,
                              progname, echo, quiet);
    }
    else if (syscatalog)
@@ -176,7 +180,7 @@ main(int argc, char *argv[])
                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
@@ -193,14 +197,14 @@ main(int argc, char *argv[])
 
        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);
@@ -209,7 +213,7 @@ main(int argc, char *argv[])
 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;
 
@@ -226,7 +230,7 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
        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))
    {
@@ -249,14 +253,14 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
 
 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);
 
@@ -271,7 +275,7 @@ reindex_all_databases(const char *host, const char *port,
        }
 
        reindex_one_database(dbname, dbname, "DATABASE", host, port, username,
-                            password, progname, echo);
+                            prompt_password, progname, echo);
    }
 
    PQclear(result);
@@ -279,7 +283,7 @@ reindex_all_databases(const char *host, const char *port,
 
 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;
@@ -290,7 +294,7 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
 
    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"),
@@ -322,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\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 .\n"));
index 204ec7b7f2be19a74e92a760adedb5441e7bf8fa..ada55735bebbdc645879299f1619523706740a2a 100644 (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/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);
@@ -34,6 +34,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'},
@@ -55,7 +56,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        quiet = false;
    bool        analyze = false;
@@ -70,7 +71,7 @@ main(int argc, char *argv[])
 
    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)
        {
@@ -83,8 +84,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;
@@ -151,7 +155,7 @@ main(int argc, char *argv[])
        }
 
        vacuum_all_databases(full, verbose, analyze, freeze,
-                            host, port, username, password,
+                            host, port, username, prompt_password,
                             progname, echo, quiet);
    }
    else
@@ -167,7 +171,7 @@ main(int argc, char *argv[])
        }
 
        vacuum_one_database(dbname, full, verbose, analyze, freeze, table,
-                           host, port, username, password,
+                           host, port, username, prompt_password,
                            progname, echo);
    }
 
@@ -179,7 +183,7 @@ 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)
 {
    PQExpBufferData sql;
@@ -201,7 +205,7 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
        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)
@@ -221,14 +225,14 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
 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);
 
@@ -243,7 +247,7 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
        }
 
        vacuum_one_database(dbname, full, verbose, analyze, freeze, NULL,
-                           host, port, username, password,
+                           host, port, username, prompt_password,
                            progname, echo);
    }
 
@@ -273,6 +277,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(_("\nRead the description of the SQL command VACUUM for details.\n"));
    printf(_("\nReport bugs to .\n"));
index bc66df2eb340060620c1ff7ff74af01ee1560e56..57bcec768f81e0f31de7e137620eae6014a82ce7 100644 (file)
@@ -6,7 +6,7 @@
  * 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