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

Commitd9720e4

Browse files
committed
Fix initdb misbehavior when user mis-enters superuser password.
While testing simple_prompt() revisions, I happened to notice thatcurrent initdb behaves rather badly when --pwprompt is specified andthe user miskeys the second password. It complains about the mismatch,does "rm -rf" on the data directory, and exits. The problem is thatsince commitc4a8812, there's a standalone backend sitting waitingfor commands at that point. It gets unhappy about its datadir havinggone away, and spews a PANIC message at the user, which is not nice.(And the shell then adds to the mess with meaningless bleating about acore dump...) We don't really want that sort of thing to happen unlessthere's an internal failure in initdb, which this surely is not.The best fix seems to be to move the collection of the passwordearlier, so that it's done essentially as part of argument collection,rather than at the rather ad-hoc time it was done before.Back-patch to 9.6 where the problem was introduced.
1 parent7961c31 commitd9720e4

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static const char *default_text_search_config = "";
134134
staticchar*username="";
135135
staticboolpwprompt= false;
136136
staticchar*pwfilename=NULL;
137+
staticchar*superuser_password=NULL;
137138
staticconstchar*authmethodhost="";
138139
staticconstchar*authmethodlocal="";
139140
staticbooldebug= false;
@@ -254,7 +255,7 @@ static void test_config_settings(void);
254255
staticvoidsetup_config(void);
255256
staticvoidbootstrap_template1(void);
256257
staticvoidsetup_auth(FILE*cmdfd);
257-
staticvoidget_set_pwd(FILE*cmdfd);
258+
staticvoidget_su_pwd(void);
258259
staticvoidsetup_depend(FILE*cmdfd);
259260
staticvoidsetup_sysviews(FILE*cmdfd);
260261
staticvoidsetup_description(FILE*cmdfd);
@@ -1551,13 +1552,17 @@ setup_auth(FILE *cmdfd)
15511552

15521553
for (line=pg_authid_setup;*line!=NULL;line++)
15531554
PG_CMD_PUTS(*line);
1555+
1556+
if (superuser_password)
1557+
PG_CMD_PRINTF2("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1558+
username,escape_quotes(superuser_password));
15541559
}
15551560

15561561
/*
1557-
* get the superuser password if required, and call postgres to set it
1562+
* get the superuser password if required
15581563
*/
15591564
staticvoid
1560-
get_set_pwd(FILE*cmdfd)
1565+
get_su_pwd(void)
15611566
{
15621567
char*pwd1,
15631568
*pwd2;
@@ -1567,6 +1572,8 @@ get_set_pwd(FILE *cmdfd)
15671572
/*
15681573
* Read password from terminal
15691574
*/
1575+
printf("\n");
1576+
fflush(stdout);
15701577
pwd1=simple_prompt("Enter new superuser password: ",100, false);
15711578
pwd2=simple_prompt("Enter it again: ",100, false);
15721579
if (strcmp(pwd1,pwd2)!=0)
@@ -1616,10 +1623,7 @@ get_set_pwd(FILE *cmdfd)
16161623

16171624
}
16181625

1619-
PG_CMD_PRINTF2("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1620-
username,escape_quotes(pwd1));
1621-
1622-
free(pwd1);
1626+
superuser_password=pwd1;
16231627
}
16241628

16251629
/*
@@ -3286,8 +3290,6 @@ initialize_data_directory(void)
32863290
PG_CMD_OPEN;
32873291

32883292
setup_auth(cmdfd);
3289-
if (pwprompt||pwfilename)
3290-
get_set_pwd(cmdfd);
32913293

32923294
setup_depend(cmdfd);
32933295

@@ -3575,6 +3577,9 @@ main(int argc, char *argv[])
35753577
else
35763578
printf(_("Data page checksums are disabled.\n"));
35773579

3580+
if (pwprompt||pwfilename)
3581+
get_su_pwd();
3582+
35783583
printf("\n");
35793584

35803585
initialize_data_directory();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp