Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf5df006

Browse files
committed
Add username for psql password prompt, if the username was specified.
Adrian Maier
1 parent9ad9e69 commitf5df006

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

‎src/bin/psql/command.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.150 2005/07/18 20:57:53 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.151 2005/07/25 17:17:41 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -911,6 +911,7 @@ do_connect(const char *new_dbname, const char *new_user)
911911
constchar*dbparam=NULL;
912912
constchar*userparam=NULL;
913913
constchar*pwparam=NULL;
914+
char*password_prompt=NULL;
914915
char*prompted_password=NULL;
915916
boolneed_pass;
916917
boolsuccess= false;
@@ -930,9 +931,18 @@ do_connect(const char *new_dbname, const char *new_user)
930931
else
931932
userparam=new_user;
932933

934+
if (userparam==NULL)
935+
password_prompt=strdup("Password: ");
936+
else
937+
{
938+
password_prompt=malloc(strlen("Password for user %s: ")-2+
939+
strlen(userparam)+1);
940+
sprintf(password_prompt,"Password for user %s: ",userparam);
941+
}
942+
933943
/* need to prompt for password? */
934944
if (pset.getPassword)
935-
pwparam=prompted_password=simple_prompt("Password: ",100, false);
945+
pwparam=prompted_password=simple_prompt(password_prompt,100, false);
936946

937947
/*
938948
* 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)
956966
need_pass= true;
957967
free(prompted_password);
958968
prompted_password=NULL;
959-
pwparam=prompted_password=simple_prompt("Password: ",100, false);
969+
pwparam=prompted_password=simple_prompt(password_prompt,100, false);
960970
}
961971
}while (need_pass);
962972

963973
free(prompted_password);
974+
free(password_prompt);
964975

965976
/*
966977
* If connection failed, try at least keep the old one. That's

‎src/bin/psql/startup.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.119 2005/07/14 08:42:37 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.120 2005/07/25 17:17:41 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -106,6 +106,7 @@ main(int argc, char *argv[])
106106

107107
char*username=NULL;
108108
char*password=NULL;
109+
char*password_prompt=NULL;
109110
boolneed_pass;
110111

111112
set_pglocale_pgservice(argv[0],"psql");
@@ -188,8 +189,17 @@ main(int argc, char *argv[])
188189
username=pg_strdup(options.username);
189190
}
190191

192+
if (options.username==NULL)
193+
password_prompt=strdup("Password: ");
194+
else
195+
{
196+
password_prompt=malloc(strlen("Password for user %s: ")-2+
197+
strlen(options.username)+1);
198+
sprintf(password_prompt,"Password for user %s: ",options.username);
199+
}
200+
191201
if (pset.getPassword)
192-
password=simple_prompt("Password: ",100, false);
202+
password=simple_prompt(password_prompt,100, false);
193203

194204
/* loop until we have a password if requested by backend */
195205
do
@@ -207,12 +217,13 @@ main(int argc, char *argv[])
207217
need_pass= true;
208218
free(password);
209219
password=NULL;
210-
password=simple_prompt("Password: ",100, false);
220+
password=simple_prompt(password_prompt,100, false);
211221
}
212222
}while (need_pass);
213223

214224
free(username);
215225
free(password);
226+
free(password_prompt);
216227

217228
if (PQstatus(pset.db)==CONNECTION_BAD)
218229
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp