aboutsummaryrefslogtreecommitdiff
path: root/src/bin/scripts/createuser.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-10-19 19:03:46 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-10-19 19:03:46 -0400
commit1814f915b526d5022b3e2a6ce4ea3bcbe59abe2c (patch)
treee36e38ea2ede221fedae9218de33bdd968c67f3f /src/bin/scripts/createuser.c
parent25378db74fd97f2b10ad44d1f0b2e1f8b0a651f2 (diff)
downloadpostgresql-1814f915b526d5022b3e2a6ce4ea3bcbe59abe2c.tar.gz
postgresql-1814f915b526d5022b3e2a6ce4ea3bcbe59abe2c.zip
Fix connection string handling in src/bin/scripts/ programs.
When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org
Diffstat (limited to 'src/bin/scripts/createuser.c')
-rw-r--r--src/bin/scripts/createuser.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c
index 9ced079ac75..a15d21f2643 100644
--- a/src/bin/scripts/createuser.c
+++ b/src/bin/scripts/createuser.c
@@ -58,6 +58,7 @@ main(int argc, char *argv[])
char *username = NULL;
SimpleStringList roles = {NULL, NULL};
enum trivalue prompt_password = TRI_DEFAULT;
+ ConnParams cparams;
bool echo = false;
bool interactive = false;
int conn_limit = -2; /* less than minimum valid value */
@@ -256,8 +257,14 @@ main(int argc, char *argv[])
if (login == 0)
login = TRI_YES;
- conn = connectDatabase("postgres", host, port, username, prompt_password,
- progname, echo, false, false);
+ cparams.dbname = NULL; /* this program lacks any dbname option... */
+ cparams.pghost = host;
+ cparams.pgport = port;
+ cparams.pguser = username;
+ cparams.prompt_password = prompt_password;
+ cparams.override_dbname = NULL;
+
+ conn = connectMaintenanceDatabase(&cparams, progname, echo);
initPQExpBuffer(&sql);