8000 Allow arbitrary-length passwords via the CLI by a13m · Pull Request #2 · postgres/postgres · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/bin/initdb/initdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,8 @@ get_set_pwd(void)
/*
* Read password from terminal
*/
pwd1 = simple_prompt("Enter new superuser password: ", 100, false);
pwd2 = simple_prompt("Enter it again: ", 100, false);
pwd1 = simple_prompt("Enter new superuser password: ", MAX_PASSWD, false);
pwd2 = simple_prompt("Enter it again: ", MAX_PASSWD, false);
if (strcmp(pwd1, pwd2) != 0)
{
fprintf(stderr, _("Passwords didn't match.\n"));
Expand All @@ -1323,7 +1323,7 @@ get_set_pwd(void)
* for now.
*/
FILE *pwf = fopen(pwfilename, "r");
char pwdbuf[MAXPGPATH];
char *pwdbuf = calloc(1,1), buf[1024];
int i;

if (!pwf)
Expand All @@ -1332,18 +1332,34 @@ get_set_pwd(void)
progname, pwfilename, strerror(errno));
exit_nicely();
}
if (!fgets(pwdbuf, sizeof(pwdbuf), pwf))

do
{
if (fgets(buf, sizeof(buf), pwf) == NULL)
break;
pwdbuf = realloc( pwdbuf, strlen(pwdbuf)+1+strlen(buf) );
if (!pwdbuf)
{
// Out of memory ?
fprintf(stderr, _("%s: could not read password from file \"%s\": %s\n"),
progname, pwfilename, strerror(errno));
exit_nicely();
}
strcat( pwdbuf, buf);
i = strlen(pwdbuf);
} while (strlen(buf) > 0 && pwdbuf[i-1] != '\n');

while (i > 0 && (pwdbuf[i - 1] == '\r' || pwdbuf[i - 1] == '\n'))
pwdbuf[--i] = '\0';

if (!i)
{
fprintf(stderr, _("%s: could not read password from file \"%s\": %s\n"),
progname, pwfilename, strerror(errno));
exit_nicely();
}
fclose(pwf);

i = strlen(pwdbuf);
while (i > 0 && (pwdbuf[i - 1] == '\r' || pwdbuf[i - 1] == '\n'))
pwdbuf[--i] = '\0';

pwd1 = xstrdup(pwdbuf);

}
Expand Down
8 changes: 4 additions & 4 deletions src/bin/pg_dump/pg_backup_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)

if (AH->promptPassword == TRI_YES && password == NULL)
{
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);
if (password == NULL)
die_horribly(AH, modulename, "out of memory\n");
}
Expand Down Expand Up @@ -195,7 +195,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
free(password);

if (AH->promptPassword != TRI_NO)
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);
else
die_horribly(AH, modulename, "connection needs password\n");

Expand Down Expand Up @@ -242,7 +242,7 @@ ConnectDatabase(Archive *AHX,

if (prompt_password == TRI_YES && password == NULL)
{
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);
if (password == NULL)
die_horribly(AH, modulename, "out of memory\n");
}
Expand Down Expand Up @@ -288,7 +288,7 @@ ConnectDatabase(Archive *AHX,
prompt_password != TRI_NO)
{
PQfinish(AH->connection);
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);
if (password == NULL)
die_horribly(AH, modulename, "out of memory\n");
new_pass = true;
Expand Down
4 changes: 2 additions & 2 deletions src/bin/pg_dump/pg_dumpall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
static char *password = NULL;

if (prompt_password == TRI_YES && !password)
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);

/*
* Start the connection. Loop until we have a password if requested by
Expand Down Expand Up @@ -1733,7 +1733,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
prompt_password != TRI_NO)
{
PQfinish(conn);
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);
new_pass = true;
}
} while (new_pass);
Expand Down
8 changes: 4 additions & 4 deletions src/bin/psql/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ exec_command(const char *cmd,
char *pw1;
char *pw2;

pw1 = simple_prompt("Enter new password: ", 100, false);
pw2 = simple_prompt("Enter it again: ", 100, false);
pw1 = simple_prompt("Enter new password: ", MAX_PASSWD, false);
pw2 = simple_prompt("Enter it again: ", MAX_PASSWD, false);

if (strcmp(pw1, pw2) != 0)
{
Expand Down Expand Up @@ -1462,15 +1462,15 @@ prompt_for_password(const char *username)
char *result;

if (username == NULL)
result = simple_prompt("Password: ", 100, false);
result = simple_prompt("Password: ", MAX_PASSWD, false);
else
{
char *prompt_text;

prompt_text = malloc(strlen(username) + 100);
snprintf(prompt_text, strlen(username) + 100,
_("Password for user %s: "), username);
result = simple_prompt(prompt_text, 100, false);
result = simple_prompt(prompt_text, MAX_PASSWD, false);
free(prompt_text);
}

Expand Down
4 changes: 2 additions & 2 deletions src/bin/psql/startup.c
9E12
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ main(int argc, char *argv[])
}

if (pset.getPassword == TRI_YES)
password = simple_prompt(password_prompt, 100, false);
password = simple_prompt(password_prompt, MAX_PASSWD, false);

/* loop until we have a password if requested by backend */
do
Expand Down Expand Up @@ -213,7 +213,7 @@ main(int argc, char *argv[])
pset.getPassword != TRI_NO)
{
PQfinish(pset.db);
password = simple_prompt(password_prompt, 100, false);
password = simple_prompt(password_prompt, MAX_PASSWD, false);
new_pass = true;
}
} while (new_pass);
Expand Down
4 changes: 2 additions & 2 deletions src/bin/scripts/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
bool new_pass;

if (prompt_password == TRI_YES)
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);

/*
* Start the connection. Loop until we have a password if requested by
Expand Down Expand Up @@ -152,7 +152,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
prompt_password != TRI_NO)
{
PQfinish(conn);
password = simple_prompt("Password: ", 100, false);
password = simple_prompt("Password: ", MAX_PASSWD, false);
new_pass = true;
}
} while (new_pass);
Expand Down
4 changes: 2 additions & 2 deletions src/bin/scripts/createuser.c