From 0f92b7b1d992c6174b49358f337d84ba719b9576 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 12 Nov 2021 17:10:51 +0000 Subject: [PATCH v2 2/2] Add role name to \password prompt. --- src/bin/psql/command.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 5619ed685a..eedc6243d3 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -2027,6 +2027,7 @@ exec_command_password(PsqlScanState scan_state, bool active_branch) OT_SQLID, NULL, true); char *pw1; char *pw2; + PQExpBufferData buf; if (user == NULL) { @@ -2041,7 +2042,10 @@ exec_command_password(PsqlScanState scan_state, bool active_branch) PQclear(res); } - pw1 = simple_prompt("Enter new password: ", false); + initPQExpBuffer(&buf); + printfPQExpBuffer(&buf, _("Enter new password for user \"%s\": "), user); + + pw1 = simple_prompt(buf.data, false); pw2 = simple_prompt("Enter it again: ", false); if (strcmp(pw1, pw2) != 0) @@ -2062,15 +2066,12 @@ exec_command_password(PsqlScanState scan_state, bool active_branch) } else { - PQExpBufferData buf; PGresult *res; - initPQExpBuffer(&buf); printfPQExpBuffer(&buf, "ALTER USER %s PASSWORD ", fmtId(user)); appendStringLiteralConn(&buf, encrypted_password, pset.db); res = PSQLexec(buf.data); - termPQExpBuffer(&buf); if (!res) success = false; else @@ -2083,6 +2084,7 @@ exec_command_password(PsqlScanState scan_state, bool active_branch) free(user); free(pw1); free(pw2); + termPQExpBuffer(&buf); } else ignore_slash_options(scan_state); -- 2.16.6