pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthew Stickney <mtstickney@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: [PATCH] (Windows) psql echoes password when reading from pipe
Date: Wed, 23 May 2018 15:29:29 -0400
Message-ID: <c3d315f2-c1dc-18ce-29fa-7919dace540e@gmail.com> (raw)
In-Reply-To: <23826.1527027253@sss.pgh.pa.us>
References: <502a1fff-862b-da52-1031-f68df6ed5a2d@gmail.com>
	<14853.1527015354@sss.pgh.pa.us>
	<CAKH_Ld7A=3dFAvUFN1hFq-67=Ronx3Aq-muDhFKh4iHu3MMk6Q@mail.gmail.com>
	<18079.1527019746@sss.pgh.pa.us>
	<CAKH_Ld4j51U+k9_MHoA=HCx5=PP5i=6US7Lyum-2xXxAPZFG5A@mail.gmail.com>
	<23826.1527027253@sss.pgh.pa.us>

The attached is a patch that uses the _fileno/_get_osfhandle approach. 
This doesn't address the stdin fallback, or error handling if opening 
termin fails; however, it should be no worse than what's there now, and 
it fixes the immediate problem.

I'm still thinking about the fallback in terms of a mintty-type 
environment, but I wanted to get this patch out there in the meantime.

-Matt Stickney

Attachments:

0002-Disable-input-echo-on-the-console-not-stdin.patch (text/plain, 1.7K) download From 734b979e688884947e1b820f5c1a40454bb35c03 Mon Sep 17 00:00:00 2001 From: Matthew Stickney <mtstickney@gmail.com> Date: Mon, 21 May 2018 23:24:34 -0400 Subject: [PATCH] Disable input echo on the console, not stdin. When data is piped to psql, a handle to stdin will no longer be a handle to the console; SetConsoleMode will fail, and prompt input will be echoed to the screen. Instead, retrieve a handle to the console's input buffer fron termin, and set the console mode there (this requires write permissions). The code is now setting the console mode on the same handle it reads from, which should always be consistent. --- src/port/sprompt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/port/sprompt.c b/src/port/sprompt.c index 70dfa69d7b..340232a7a2 100644 --- a/src/port/sprompt.c +++ b/src/port/sprompt.c @@ -66,8 +66,12 @@ simple_prompt(const char *prompt, char *destination, size_t destlen, bool echo) * * XXX fgets() still receives text in the console's input code page. This * makes non-ASCII credentials unportable. + * + * Note that termin must also be opened with write permissions in order for + * SetConsoleMode() to succeed, even though it's only used for reading here. + * */ - termin = fopen("CONIN$", "r"); + termin = fopen("CONIN$", "w+"); termout = fopen("CONOUT$", "w+"); #else @@ -112,7 +116,7 @@ simple_prompt(const char *prompt, char *destination, size_t destlen, bool echo) if (!echo) { /* get a new handle to turn echo off */ - t = GetStdHandle(STD_INPUT_HANDLE); + t = (HANDLE)_get_osfhandle(_fileno(termin)); /* save the old configuration first */ GetConsoleMode(t, &t_orig); -- 2.16.2.windows.1

view thread (9+ messages)  latest in thread

Message-ID: <c3d315f2-c1dc-18ce-29fa-7919dace540e@gmail.com>
Permalink:  ../c3d315f2-c1dc-18ce-29fa-7919dace540e@gmail.com/
Also on:    postgresql.org/message-id/c3d315f2-c1dc-18ce-29fa-7919dace540e@gmail.com

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: mtstickney@gmail.com, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org
  Subject: Re: [PATCH] (Windows) psql echoes password when reading from pipe
  In-Reply-To: <c3d315f2-c1dc-18ce-29fa-7919dace540e@gmail.com>

* 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