]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add username for psql password prompt, if the username was specified.
authorBruce Momjian <bruce@momjian.us>
Mon, 25 Jul 2005 17:17:41 +0000 (17:17 +0000)
committerBruce Momjian <bruce@momjian.us>
Mon, 25 Jul 2005 17:17:41 +0000 (17:17 +0000)
Adrian Maier

src/bin/psql/command.c
src/bin/psql/startup.c

index 6e5730e4436b4b9021836b13d5e6d72092231efc..824f23210353d67c692047e88dd4bdaacc0da6ec 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.150 2005/07/18 20:57:53 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.151 2005/07/25 17:17:41 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -911,6 +911,7 @@ do_connect(const char *new_dbname, const char *new_user)
        const char *dbparam = NULL;
        const char *userparam = NULL;
        const char *pwparam = NULL;
+       char       *password_prompt = NULL;
        char       *prompted_password = NULL;
        bool            need_pass;
        bool            success = false;
@@ -930,9 +931,18 @@ do_connect(const char *new_dbname, const char *new_user)
        else
                userparam = new_user;
 
+       if (userparam == NULL) 
+               password_prompt = strdup("Password: ");
+       else
+       {
+               password_prompt = malloc(strlen("Password for user %s: ") - 2 +
+                                                                strlen(userparam) + 1);
+               sprintf(password_prompt,"Password for user %s: ", userparam);
+       }
+
        /* need to prompt for password? */
        if (pset.getPassword)
-               pwparam = prompted_password = simple_prompt("Password: ", 100, false);
+               pwparam = prompted_password = simple_prompt(password_prompt, 100, false);
 
        /*
         * Use old password (if any) if no new one given and we are
@@ -956,11 +966,12 @@ do_connect(const char *new_dbname, const char *new_user)
                        need_pass = true;
                        free(prompted_password);
                        prompted_password = NULL;
-                       pwparam = prompted_password = simple_prompt("Password: ", 100, false);
+                       pwparam = prompted_password = simple_prompt(password_prompt, 100, false);
                }
        } while (need_pass);
 
        free(prompted_password);
+       free(password_prompt);
 
        /*
         * If connection failed, try at least keep the old one. That's
index 3f603757c4adf072e0b321797d3ff74e5995360f..0c3606ed25bf5f9a9df528a80adbdfc19de98fbe 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.119 2005/07/14 08:42:37 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.120 2005/07/25 17:17:41 momjian Exp $
  */
 #include "postgres_fe.h"
 
@@ -106,6 +106,7 @@ main(int argc, char *argv[])
 
        char       *username = NULL;
        char       *password = NULL;
+       char       *password_prompt = NULL;
        bool            need_pass;
 
        set_pglocale_pgservice(argv[0], "psql");
@@ -188,8 +189,17 @@ main(int argc, char *argv[])
                        username = pg_strdup(options.username);
        }
 
+       if (options.username == NULL)
+               password_prompt = strdup("Password: ");
+       else
+       {
+               password_prompt = malloc(strlen("Password for user %s: ") - 2 +
+                                                                strlen(options.username) + 1);
+               sprintf(password_prompt,"Password for user %s: ", options.username);
+       }
+       
        if (pset.getPassword)
-               password = simple_prompt("Password: ", 100, false);
+               password = simple_prompt(password_prompt, 100, false);
 
        /* loop until we have a password if requested by backend */
        do
@@ -207,12 +217,13 @@ main(int argc, char *argv[])
                        need_pass = true;
                        free(password);
                        password = NULL;
-                       password = simple_prompt("Password: ", 100, false);
+                       password = simple_prompt(password_prompt, 100, false);
                }
        } while (need_pass);
 
        free(username);
        free(password);
+       free(password_prompt);
 
        if (PQstatus(pset.db) == CONNECTION_BAD)
        {