From: | John McKown <john(dot)archie(dot)mckown(at)gmail(dot)com> |
---|---|
To: | Josh Berkus <josh(at)agliodbs(dot)com> |
Cc: | pgsql-bugs <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: DOS-style line endings in .pgpass |
Date: | 2016-11-14 20:01:29 |
Message-ID: | CAAJSdjhCPJVnt+uh+fPafDwwRVpusfxo0EjAqm8eYDdjWiGPuQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Mon, Nov 14, 2016 at 1:31 PM, Josh Berkus <josh(at)agliodbs(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2016-11-14 20:10:49 | Re: DOS-style line endings in .pgpass |
Previous Message | Vik Fearing | 2016-11-14 19:48:37 | Re: DOS-style line endings in .pgpass |