Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c6NFu-0005Ar-9r for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Nov 2016 19:49:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c6NFt-0003vt-RI for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Nov 2016 19:49:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c6NFF-0003Cy-7o for pgsql-bugs@postgresql.org; Mon, 14 Nov 2016 19:48:45 +0000 Received: from fr1.2ndquadrant.fr ([94.23.17.124]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c6NFC-0004oZ-1N for pgsql-bugs@postgresql.org; Mon, 14 Nov 2016 19:48:44 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by fr1.2ndquadrant.fr (Postfix) with ESMTP id 82D6062AC1; Mon, 14 Nov 2016 20:48:40 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at fr1.2ndquadrant.fr Received: from fr1.2ndquadrant.fr ([127.0.0.1]) by localhost (fr1.2ndquadrant.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bZwRlLuF0Rza; Mon, 14 Nov 2016 20:48:39 +0100 (CET) Received: from [192.168.0.3] (ath91-3-88-167-161-184.fbx.proxad.net [88.167.161.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: charles) by fr1.2ndquadrant.fr (Postfix) with ESMTPSA id C81B260501; Mon, 14 Nov 2016 20:48:38 +0100 (CET) Subject: Re: DOS-style line endings in .pgpass To: Josh Berkus , pgsql-bugs References: <0de37763-5843-b2cc-855e-5d0e5df25807@agliodbs.com> From: Vik Fearing Message-ID: <17d357ef-1a01-2493-a8b0-733010bf4bf0@2ndquadrant.fr> Date: Mon, 14 Nov 2016 20:48:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <0de37763-5843-b2cc-855e-5d0e5df25807@agliodbs.com> Content-Type: multipart/mixed; boundary="------------F047CE0966E1EB7CE98D2120" X-Pg-Spam-Score: -4.7 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------F047CE0966E1EB7CE98D2120 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 --------------F047CE0966E1EB7CE98D2120 Content-Type: invalid/octet-stream; name="pgpass_crlf.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pgpass_crlf.patch" 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 || --------------F047CE0966E1EB7CE98D2120 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------F047CE0966E1EB7CE98D2120--