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

Commit37f6fd1

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 parent8e1e3f9 commit37f6fd1

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
@@ -135,6 +135,7 @@ static const char *default_text_search_config = "";
135135
staticchar*username="";
136136
staticboolpwprompt= false;
137137
staticchar*pwfilename=NULL;
138+
staticchar*superuser_password=NULL;
138139
staticconstchar*authmethodhost="";
139140
staticconstchar*authmethodlocal="";
140141
staticbooldebug= false;
@@ -255,7 +256,7 @@ static void test_config_settings(void);
255256
staticvoidsetup_config(void);
256257
staticvoidbootstrap_template1(void);
257258
staticvoidsetup_auth(FILE*cmdfd);
258-
staticvoidget_set_pwd(FILE*cmdfd);
259+
staticvoidget_su_pwd(void);
259260
staticvoidsetup_depend(FILE*cmdfd);
260261
staticvoidsetup_sysviews(FILE*cmdfd);
261262
staticvoidsetup_description(FILE*cmdfd);
@@ -1544,13 +1545,17 @@ setup_auth(FILE *cmdfd)
15441545

15451546
for (line=pg_authid_setup;*line!=NULL;line++)
15461547
PG_CMD_PUTS(*line);
1548+
1549+
if (superuser_password)
1550+
PG_CMD_PRINTF2("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1551+
username,escape_quotes(superuser_password));
15471552
}
15481553

15491554
/*
1550-
* get the superuser password if required, and call postgres to set it
1555+
* get the superuser password if required
15511556
*/
15521557
staticvoid
1553-
get_set_pwd(FILE*cmdfd)
1558+
get_su_pwd(void)
15541559
{
15551560
char*pwd1,
15561561
*pwd2;
@@ -1560,6 +1565,8 @@ get_set_pwd(FILE *cmdfd)
15601565
/*
15611566
* Read password from terminal
15621567
*/
1568+
printf("\n");
1569+
fflush(stdout);
15631570
pwd1=simple_prompt("Enter new superuser password: ",100, false);
15641571
pwd2=simple_prompt("Enter it again: ",100, false);
15651572
if (strcmp(pwd1,pwd2)!=0)
@@ -1609,10 +1616,7 @@ get_set_pwd(FILE *cmdfd)
16091616

16101617
}
16111618

1612-
PG_CMD_PRINTF2("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1613-
username,escape_quotes(pwd1));
1614-
1615-
free(pwd1);
1619+
superuser_password=pwd1;
16161620
}
16171621

16181622
/*
@@ -3279,8 +3283,6 @@ initialize_data_directory(void)
32793283
PG_CMD_OPEN;
32803284

32813285
setup_auth(cmdfd);
3282-
if (pwprompt||pwfilename)
3283-
get_set_pwd(cmdfd);
32843286

32853287
setup_depend(cmdfd);
32863288

@@ -3569,6 +3571,9 @@ main(int argc, char *argv[])
35693571
else
35703572
printf(_("Data page checksums are disabled.\n"));
35713573

3574+
if (pwprompt||pwfilename)
3575+
get_su_pwd();
3576+
35723577
printf("\n");
35733578

35743579
initialize_data_directory();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp