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

Allow arbitrary-length passwords via the CLI#2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
a13m wants to merge1 commit intopostgres:masterfromeucalyptus:master
Closed
Show file tree
Hide file tree
Changes fromall 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 deletionssrc/bin/initdb/initdb.c
View file
Open in desktop
Original file line numberDiff line numberDiff 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");
charpwdbuf[MAXPGPATH];
char*pwdbuf = calloc(1,1), buf[1024];
inti;

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 deletionssrc/bin/pg_dump/pg_backup_db.c
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 deletionssrc/bin/pg_dump/pg_dumpall.c
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionssrc/bin/psql/command.c
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionssrc/bin/psql/startup.c
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 deletionssrc/bin/scripts/common.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,7 +100,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
boolnew_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 DownExpand 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 deletionssrc/bin/scripts/createuser.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -197,8 +197,8 @@ main(int argc, char *argv[])
char *pw1,
*pw2;

pw1 = simple_prompt("Enter password for new role: ",100, false);
pw2 = simple_prompt("Enter it again: ",100, false);
pw1 = simple_prompt("Enter password for new role: ",MAX_PASSWD, false);
pw2 = simple_prompt("Enter it again: ",MAX_PASSWD, false);
if (strcmp(pw1, pw2) != 0)
{
fprintf(stderr, _("Passwords didn't match.\n"));
Expand Down
14 changes: 14 additions & 0 deletionssrc/include/pg_config_manual.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,20 @@
*/
#define NAMEDATALEN 64

/*
* Maximum password length via command line tools
*
* If 0, no maximum password length is enforced.
* If greater than 0, this defines the maximum number of characters
* which will be read as input for a password prompt. Input in
* excess of this maximum will be silently ignored.
*
* The database itself does not have a password length limit,
* regardless of this setting.
*
*/
#define MAX_PASSWD 0

/*
* Maximum number of arguments to a function.
*
Expand Down
21 changes: 15 additions & 6 deletionssrc/interfaces/libpq/fe-connect.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4905,22 +4905,31 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)

while (!feof(fp) && !ferror(fp))
{
char *t =buf,
char *t =calloc(1,sizeof(char)),
*ret,
*p1,
*p2;
intlen;

if (fgets(buf, sizeof(buf), fp) == NULL)
break;

len = strlen(buf);
do
{
if ( fgets(buf, LINELEN, fp) == NULL)
break;
t = realloc(t, strlen(t)+1+strlen(buf));
/* Out of memory? */
if( !t )
return NULL;
strcat(t, buf);
len = strlen(t);
} while (strlen(buf) > 0 && t[len-1] != '\n');

if (len == 0)
continue;

/* Remove trailing newline */
if (buf[len-1] == '\n')
buf[len - 1] = 0;
while (len> 0 && (t[len-1] == '\n' || t[len-1] == '\r'))
t[--len] = 0;

if ((t = pwdfMatchesString(t, hostname)) == NULL ||
(t = pwdfMatchesString(t, port)) == NULL ||
Expand Down
42 changes: 31 additions & 11 deletionssrc/port/sprompt.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,7 +38,10 @@ char *
simple_prompt(const char *prompt, int maxlen, bool echo)
{
intlength;
intbuflen;
intbufsize = 1024;
char *destination;
char buf[bufsize];
FILE *termin,
*termout;

Expand All@@ -52,7 +55,11 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
#endif
#endif

destination = (char *) malloc(maxlen + 1);
if (maxlen > 0) {
destination = (char *) calloc(1, sizeof(char));
} else {
destination = (char *) malloc((maxlen + 1) * sizeof(char));
}
if (!destination)
return NULL;

Expand DownExpand Up@@ -108,21 +115,34 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
fflush(termout);
}

if (fgets(destination, maxlen + 1, termin) == NULL)
destination[0] = '\0';

length = strlen(destination);
if (length > 0 && destination[length - 1] != '\n')
{
/* eat rest of the line */
charbuf[128];
intbuflen;
if (maxlen > 0) {
if (fgets(destination, maxlen + 1, termin) == NULL)
destination[0] = '\0';

length = strlen(destination);
if (length > 0 && destination[length - 1] != '\n')
{
/* eat rest of the line */
do
{
if (fgets(buf, bufsize, termin) == NULL)
break;
buflen = strlen(buf);
} while (buflen > 0 && buf[buflen - 1] != '\n');
}

} else {
do
{
if (fgets(buf,sizeof(buf), termin) == NULL)
if (fgets(buf,bufsize, termin) == NULL)
break;
buflen = strlen(buf);
destination = realloc( destination, strlen(destination)+1+buflen );
/* Out of memory ? */
if( !destination )
return NULL;
strcat( destination, buf );
length = strlen(destination);
} while (buflen > 0 && buf[buflen - 1] != '\n');
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp