pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedDOS-style line endings in .pgpass
7+ messages / 4 participants
[nested] [flat]
* DOS-style line endings in .pgpass
@ 2016-11-14 19:31 Josh Berkus <josh@agliodbs.com>
0 siblings, 2 replies; 7+ messages in thread
From: Josh Berkus @ 2016-11-14 19:31 UTC (permalink / raw)
To: pgsql-bugs
Version Tested: 9.6.1
Platform: Fedora 24 Docker Base Image
Summary: DOS-style line endings (CRLF) cause .pgpass to fail.
Steps to Reproduce:
1. Install PostgreSQL
2. Set up user with md5 passwords
3. Create pgpass file using program which makes CRLF line endings, such
as Python's CSV module, or windows Notepad.
4. Try to log in
5. Get:
psql: FATAL: password authentication failed for user "postgres"
password retrieved from file "/var/lib/pgsql/.pgpass"
What appears to be happening here is that one of the characters of the
CRLF is being appended to the password, making it invalid.
Is this a known issue on Windows? Or is this peculiar to Fedora?
If it's a general issue, it would be friendly to Windows devs to fix it.
--
--
Josh Berkus
Red Hat OSAS
(any opinions are my own)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: DOS-style line endings in .pgpass
@ 2016-11-14 19:48 Vik Fearing <vik@2ndquadrant.fr>
parent: Josh Berkus <josh@agliodbs.com>
1 sibling, 1 reply; 7+ messages in thread
From: Vik Fearing @ 2016-11-14 19:48 UTC (permalink / raw)
To: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On 11/14/2016 08:31 PM, Josh Berkus wrote:
> Version Tested: 9.6.1
> Platform: Fedora 24 Docker Base Image
> Summary: DOS-style line endings (CRLF) cause .pgpass to fail.
>
> Steps to Reproduce:
>
> 1. Install PostgreSQL
> 2. Set up user with md5 passwords
> 3. Create pgpass file using program which makes CRLF line endings, such
> as Python's CSV module, or windows Notepad.
> 4. Try to log in
> 5. Get:
>
> psql: FATAL: password authentication failed for user "postgres"
> password retrieved from file "/var/lib/pgsql/.pgpass"
>
> What appears to be happening here is that one of the characters of the
> CRLF is being appended to the password, making it invalid.
>
> Is this a known issue on Windows? Or is this peculiar to Fedora?
>
> If it's a general issue, it would be friendly to Windows devs to fix it.
Maybe something like the attached patch?
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
pgpass_crlf.patch (invalid/octet-stream, 674B) download
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index b4f9ad7..4bd30f1 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -6029,9 +6029,14 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
if (len == 0)
continue;
- /* Remove trailing newline */
+ /* Remove trailing newline, including msdos-style */
if (buf[len - 1] == '\n')
- buf[len - 1] = 0;
+ {
+ if (len > 1 && buf[len - 2] == '\r')
+ buf[len - 2] = 0;
+ else
+ buf[len - 1] = 0;
+ }
if ((t = pwdfMatchesString(t, hostname)) == NULL ||
(t = pwdfMatchesString(t, port)) == NULL ||
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: DOS-style line endings in .pgpass
@ 2016-11-14 20:01 John McKown <john.archie.mckown@gmail.com>
parent: Josh Berkus <josh@agliodbs.com>
1 sibling, 0 replies; 7+ messages in thread
From: John McKown @ 2016-11-14 20:01 UTC (permalink / raw)
To: Josh Berkus <josh@agliodbs.com>; +Cc: pgsql-bugs
On Mon, Nov 14, 2016 at 1:31 PM, Josh Berkus <josh@agliodbs.com> wrote:
> Version Tested: 9.6.1
> Platform: Fedora 24 Docker Base Image
> Summary: DOS-style line endings (CRLF) cause .pgpass to fail.
>
> Steps to Reproduce:
>
> 1. Install PostgreSQL
> 2. Set up user with md5 passwords
> 3. Create pgpass file using program which makes CRLF line endings, such
> as Python's CSV module, or windows Notepad.
> 4. Try to log in
> 5. Get:
>
> psql: FATAL: password authentication failed for user "postgres"
> password retrieved from file "/var/lib/pgsql/.pgpass"
>
> What appears to be happening here is that one of the characters of the
> CRLF is being appended to the password, making it invalid.
>
> Is this a known issue on Windows? Or is this peculiar to Fedora?
>
> If it's a general issue, it would be friendly to Windows devs to fix it.
>
The problem is the Windows line endings. Such a file ends with a CRLF
which is 0x0D0A. When a Linux/UNIX system reads this, the 0x0D is processed
as a data character. So a line like:
*:*:*:user:password
which has DOS line endings will end up with the last field looking like
"password^M" where ^M is 0x0D. The only "solution" that I can think of is
for the PostgreSQL people to put in special code which removes any trailing
0x0D character from the end a a line. Something along the lines of:
fgets(pgpass_line,sizeof pgpass_line,pgpass_fd);
int line_length=length(pgpass_line);
if (pgpass_line[line_length]=0x0D) {
pg_pass_line[line_length]=0x00; /* remove 0x0D from end of line */
line_length--;
}
Likewise, in many cases, if you read a file with UNIX line endings, a
Windows program will no recognize the 0x0A (which a preceeding 0x0D) as an
end-of-line but will use it as a data character and continue reading.
Possibly until the end of the file.
--
Heisenberg may have been here.
Unicode: http://xkcd.com/1726/
Maranatha! <><
John McKown
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: DOS-style line endings in .pgpass
@ 2016-11-14 20:10 Tom Lane <tgl@sss.pgh.pa.us>
parent: Vik Fearing <vik@2ndquadrant.fr>
0 siblings, 2 replies; 7+ messages in thread
From: Tom Lane @ 2016-11-14 20:10 UTC (permalink / raw)
To: Vik Fearing <vik@2ndquadrant.fr>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
Vik Fearing <vik@2ndquadrant.fr> writes:
> On 11/14/2016 08:31 PM, Josh Berkus wrote:
>> What appears to be happening here is that one of the characters of the
>> CRLF is being appended to the password, making it invalid.
> Maybe something like the attached patch?
Our usual approach to \r characters is that they're whitespace. I wonder
whether the most friendly solution here is to chomp all trailing
whitespace. Anybody ever heard of using a trailing space or tab in a
password?
while (len > 0 && strchr(" \t\r\n", buf[len - 1]) != NULL)
buf[--len] = '\0';
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: DOS-style line endings in .pgpass
@ 2016-11-14 20:19 John McKown <john.archie.mckown@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 7+ messages in thread
From: John McKown @ 2016-11-14 20:19 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Vik Fearing <vik@2ndquadrant.fr>; Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On Mon, Nov 14, 2016 at 2:10 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Vik Fearing <vik@2ndquadrant.fr> writes:
> > On 11/14/2016 08:31 PM, Josh Berkus wrote:
> >> What appears to be happening here is that one of the characters of the
> >> CRLF is being appended to the password, making it invalid.
>
> > Maybe something like the attached patch?
>
> Our usual approach to \r characters is that they're whitespace. I wonder
> whether the most friendly solution here is to chomp all trailing
> whitespace. Anybody ever heard of using a trailing space or tab in a
> password?
>
> while (len > 0 && strchr(" \t\r\n", buf[len - 1]) != NULL)
> buf[--len] = '\0';
>
> regards, tom lane
FWIW, I think that's a really good idea. I, personally, don't like
non-printable characters in passwords. They are harder than <elided> to
enter on the keyboard.
>
>
--
Heisenberg may have been here.
Unicode: http://xkcd.com/1726/
Maranatha! <><
John McKown
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: DOS-style line endings in .pgpass
@ 2016-11-15 01:07 Vik Fearing <vik@2ndquadrant.fr>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 7+ messages in thread
From: Vik Fearing @ 2016-11-15 01:07 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
On 11/14/2016 09:10 PM, Tom Lane wrote:
> Vik Fearing <vik@2ndquadrant.fr> writes:
>> On 11/14/2016 08:31 PM, Josh Berkus wrote:
>>> What appears to be happening here is that one of the characters of the
>>> CRLF is being appended to the password, making it invalid.
>
>> Maybe something like the attached patch?
>
> Our usual approach to \r characters is that they're whitespace. I wonder
> whether the most friendly solution here is to chomp all trailing
> whitespace. Anybody ever heard of using a trailing space or tab in a
> password?
Trailing, no; but I have a password with a space in the middle.
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: DOS-style line endings in .pgpass
@ 2016-11-15 16:02 Tom Lane <tgl@sss.pgh.pa.us>
parent: Vik Fearing <vik@2ndquadrant.fr>
0 siblings, 0 replies; 7+ messages in thread
From: Tom Lane @ 2016-11-15 16:02 UTC (permalink / raw)
To: Vik Fearing <vik@2ndquadrant.fr>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-bugs
Vik Fearing <vik@2ndquadrant.fr> writes:
> On 11/14/2016 09:10 PM, Tom Lane wrote:
>> Our usual approach to \r characters is that they're whitespace. I wonder
>> whether the most friendly solution here is to chomp all trailing
>> whitespace. Anybody ever heard of using a trailing space or tab in a
>> password?
> Trailing, no; but I have a password with a space in the middle.
Hm, well, given that we found somebody with an embedded space so
easily, maybe trailing spaces are out there too. Also it strikes me
that we don't strip whitespace from the other fields in .pgpass,
so maybe doing it just for the password isn't so smart.
Let's just chomp \n and then \r, and be done.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2016-11-15 16:02 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-11-14 19:31 DOS-style line endings in .pgpass Josh Berkus <josh@agliodbs.com>
2016-11-14 19:48 ` Vik Fearing <vik@2ndquadrant.fr>
2016-11-14 20:10 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-11-14 20:19 ` John McKown <john.archie.mckown@gmail.com>
2016-11-15 01:07 ` Vik Fearing <vik@2ndquadrant.fr>
2016-11-15 16:02 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-11-14 20:01 ` John McKown <john.archie.mckown@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox