pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vik Fearing <vik@2ndquadrant.fr>
To: Josh Berkus <josh@agliodbs.com>
To: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: DOS-style line endings in .pgpass
Date: Mon, 14 Nov 2016 20:48:37 +0100
Message-ID: <17d357ef-1a01-2493-a8b0-733010bf4bf0@2ndquadrant.fr> (raw)
In-Reply-To: <0de37763-5843-b2cc-855e-5d0e5df25807@agliodbs.com>
References: <0de37763-5843-b2cc-855e-5d0e5df25807@agliodbs.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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 ||

view thread (7+ messages)  latest in thread

Message-ID: <17d357ef-1a01-2493-a8b0-733010bf4bf0@2ndquadrant.fr>
Permalink:  ../17d357ef-1a01-2493-a8b0-733010bf4bf0@2ndquadrant.fr/
Also on:    postgresql.org/message-id/17d357ef-1a01-2493-a8b0-733010bf4bf0@2ndquadrant.fr

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: vik@2ndquadrant.fr, josh@agliodbs.com
  Subject: Re: DOS-style line endings in .pgpass
  In-Reply-To: <17d357ef-1a01-2493-a8b0-733010bf4bf0@2ndquadrant.fr>
  References: <0de37763-5843-b2cc-855e-5d0e5df25807@agliodbs.com> <17d357ef-1a01-2493-a8b0-733010bf4bf0@2ndquadrant.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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