From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by c5ff346549e7 (Postfix) with ESMTPS id D6B161E7 for ; Fri, 29 Mar 2019 03:06:05 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.60,283,1549926000"; d="scan'208,217";a="376250904" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 29 Mar 2019 04:06:04 +0100 Received: by sympa.inria.fr (Postfix, from userid 20132) id 7DFA98265D; Fri, 29 Mar 2019 04:06:04 +0100 (CET) Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 72B8C8249D for ; Fri, 29 Mar 2019 04:05:54 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=murthy.chet@gmail.com; spf=Pass smtp.mailfrom=murthy.chet@gmail.com; spf=None smtp.helo=postmaster@mail-lj1-f193.google.com IronPort-PHdr: =?us-ascii?q?9a23=3Alsj7dhVY7fCHt0rYZbgCZMulRrXV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYYxKOt8tkgFKBZ4jH8fUM07OQ7/m4Hzxdqsre+Fk5M7V0Hycfjs?= =?us-ascii?q?sXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aFRrwLxd6?= =?us-ascii?q?KfroEYDOkcu3y/qy+5rOaAlUmTaxe7x/IAiqoQnLtcQbgYRuJ6kzxxDUvnZGZu?= =?us-ascii?q?NayH9yK1mOhRj8/MCw/JBi8yRUpf0s8tNLXLv5caolU7FWFSwqPG8p6sLlsxnD?= =?us-ascii?q?VhaP6WAHUmoKiBpIAhPK4w/8U5zsryb1rOt92C2dPc3rUbA5XCmp4ql3RBP0ji?= =?us-ascii?q?oMKiU0+3/LhMNukK1boQqhpx1hzI7SfIGVL+d1cqfEcd8HWWZNQsNdWipcCY2+?= =?us-ascii?q?coQPFfIMMulWr4b/p1UAoxiwCxSyCuzz0TJHnGP60Lcg3ug9DQ3L3gotFM8Ovn?= =?us-ascii?q?TOq9X1Mb8fXP61zKbW0TXIcvRY2Srn6IjUchAgoeyHULV1ccrM00kvCwPFj1WK?= =?us-ascii?q?pYP5PzOayPgNvnOU7+plT+2vimonpxttrTiow8chk4/EjZ8WxFDc7Sh13po5KN?= =?us-ascii?q?miREN4YdOoCoVcuz2ZOodsX88vR29ltSAnwbMco5G7ZjIFyJE/yh7fdfOHd4+I?= =?us-ascii?q?7wrmVOmLIDd4gGtpeLa9hxqv6ESgxPDwW8263VpQoSpFld7Mtn8J1xPN8MSIVv?= =?us-ascii?q?x9/kK51TaO0QDc9P1ELFgqmabHL5Mt2L09m5oJvUjdAiP7m1/6gLKSe0gq4uSo?= =?us-ascii?q?7v7oYrTipp+SLY90jQT+P7wrmsyiG+Q4LggOXmiB9eug1L3s41H5Ta5Fjv0ziK?= =?us-ascii?q?bZsZTaKd4Hqa6+Bg9Zypwj5AqnDze6zNQYmmEKI05fdxKCi4jlIlXOIPHjDfej?= =?us-ascii?q?mFmsizdqx/XePrL7GJnNL37DkK3gfbln8UJcxhAznphj4MdxA60dIP/sEnXgvd?= =?us-ascii?q?qQWhowLxC0zvnPD4x534kFH2WVDfnKHrnVtAqj5u8za8yRfpMVqX6pLuU/+/7/?= =?us-ascii?q?y3Q5lEM1cqyg3J9RY3e9SKc1a36FaGbh149SWVwBuRAzGamz0AXbAGxjIk2qVq?= =?us-ascii?q?d53QkVTYevDIPNXIeo2eXT0yKyH5kQbWdDWAnVTSXYMr6cUvJJUxq8Z9d7m2Vd?= =?us-ascii?q?B7ekQo4lkxqpsV2ikuc1Hq/v4iQd8Knb+p116unUz09g8DV1C4GZ0TjIQTglxS?= =?us-ascii?q?UHQDg52K05qkt4mA+O?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BFCAAzi51cYsHQVdFlHAEBAQQBAQcEA?= =?us-ascii?q?QGBZYIRJQGBEjMnhA6BHYJeiCWHJYINiUlyj3yCBoJ1AoU0GgcBBDQSAQEDAQE?= =?us-ascii?q?JAQMBAQEGGAwKCBsMJQyCOikBgmYBAQEDASMdARsdAQMBCwYFCw0YEgICIgERA?= =?us-ascii?q?QUBDgENBhODIoFdAQMNCJ19PIsdgRIFAReCeQWEQAoZJw1fgTgCBhKBHYRdhlW?= =?us-ascii?q?CFoERgmQuPoEEAYEVgnmCO4JXA4pLh3eGI4tmYAcCk0caaYEaiU+IOp5/MIFDg?= =?us-ascii?q?XczGiNQMYI7ggoYg1aKcyIwjUyCKQEB?= X-IPAS-Result: =?us-ascii?q?A0BFCAAzi51cYsHQVdFlHAEBAQQBAQcEAQGBZYIRJQGBEjM?= =?us-ascii?q?nhA6BHYJeiCWHJYINiUlyj3yCBoJ1AoU0GgcBBDQSAQEDAQEJAQMBAQEGGAwKC?= =?us-ascii?q?BsMJQyCOikBgmYBAQEDASMdARsdAQMBCwYFCw0YEgICIgERAQUBDgENBhODIoF?= =?us-ascii?q?dAQMNCJ19PIsdgRIFAReCeQWEQAoZJw1fgTgCBhKBHYRdhlWCFoERgmQuPoEEA?= =?us-ascii?q?YEVgnmCO4JXA4pLh3eGI4tmYAcCk0caaYEaiU+IOp5/MIFDgXczGiNQMYI7ggo?= =?us-ascii?q?Yg1aKcyIwjUyCKQEB?= X-IronPort-AV: E=Sophos;i="5.60,283,1549926000"; d="scan'208,217";a="376250874" X-MGA-submission: =?us-ascii?q?MDH5wvKlxnSrXyGsiwaNpHa4sEt7HTrPCuPhLH?= =?us-ascii?q?JbPwlbvVldlGNdxznByFM2ic/W8Vvbuln1PmVLPILuwm3G+tSSBQkUkQ?= =?us-ascii?q?6TMjnBuOfmITyuR6aaQj3F/in60WMi9GtgoAvs+XuAv7ePkZoZJDUZPq?= =?us-ascii?q?JKBBWFFGKCUd5Ja9vl1r3Zlw=3D=3D?= Received: from mail-lj1-f193.google.com ([209.85.208.193]) by mail2-smtp-roc.national.inria.fr with ESMTP; 29 Mar 2019 04:05:53 +0100 Received: by mail-lj1-f193.google.com with SMTP id v22so622687lje.9 for ; Thu, 28 Mar 2019 20:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bl0CI9SMtL6qavZSJXft+qDgnvMJ7u7CGEHxbkmn9m4=; b=Rd4UQ7q1k9su5aYlN8Q0OrwYPYp1Zcin9EFr9iMo4c96hqsqnxuqfKRINz4J44KUob o221tI6F/oWzuAXyIwxBtL9j9KqYDICuD51m01yY1HZOvXmvMq5rgA0zvtyjeedTCqkz lYD1ezREBwqB6xu6eWCqyPGGsWf+5ko2gR7O3C6q9tD29pYBMfKEoxi4R5X1EpVi6s3o sN9pcCLHdHxSNDtyRN8eUOka1PaLbz7xrJKZpptanAhUylXLES/OFJaAiK7T/fvKfblQ aznlfwJ8MsOLWcBttKlIGqyMw/fI7JigC1WdjaWu9o9pWiB4a0RqJ754tDVki/HLd4HO iwow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bl0CI9SMtL6qavZSJXft+qDgnvMJ7u7CGEHxbkmn9m4=; b=YFAQOdcoCJkPxScvo/CCl8QXJv351RwOEBjcsem+gGrvCALG/kADjBmVZVWWmy61MR EZMkTS6Hs1dLA15GezWJGQN4wet1wjb1y4ghG56Mhh+VJ4jbF8+qUT6Ix107k5Nkfvd6 Cpp448Z6M3FQmjmLbowRTGj42vaENspsm1C52TJ23oNHQA4xKgRIvnuwOf5moZUQRVPc gqAu9xjuB2oDEs2Bdcd1aEWSuLjFZ2O0rnUiKWXAMw4dZOzXaPEeQbfziW2LXPOlOf2N D//KfJZIgHcPi1UryBwXfRu8H8YwvaotNaLK+GGEcDwOOgN6kvvO0NZ9xZYwxFFDRgZb ECtQ== X-Gm-Message-State: APjAAAU8gFoImRvY9ENDz1bKAq7eDlKRWuHzSU2FrQnjHdqUPhpONZ6w pECF8SywRiySSJz0COpzt6Pt9e0fqUfjk+pBJOs= X-Google-Smtp-Source: APXvYqxa4Pufj8aPHuYbOJOsQjZT9J+NVwIRJiBxb+q96RxN1qUW0YaqjI532+ExR4CcdZqCefTGoBSyB3P1THiwTT8= X-Received: by 2002:a2e:9117:: with SMTP id m23mr17073381ljg.197.1553828752754; Thu, 28 Mar 2019 20:05:52 -0700 (PDT) MIME-Version: 1.0 References: <21AC2517-8185-45A3-8520-53C92761CBBA@gmx.net> In-Reply-To: From: Chet Murthy Date: Thu, 28 Mar 2019 20:05:41 -0700 Message-ID: To: Matthew Ryan Cc: Helmut Brandl , caml users Content-Type: multipart/alternative; boundary="000000000000d98c8c058532f294" Subject: Re: [Caml-list] Turn echoing off on standard input to read e.g. passwords Reply-To: Chet Murthy X-Loop: caml-list@inria.fr X-Sequence: 17443 Errors-to: caml-list-owner@inria.fr Precedence: list Precedence: bulk Sender: caml-list-request@inria.fr X-no-archive: yes List-Id: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --000000000000d98c8c058532f294 Content-Type: text/plain; charset="UTF-8" [Argh, resending, b/c got the recipient-list wrong] Perhaps this has changed in the N years since last I worked with sgttyb/termios. But back in the day, the answer was "there is no portable way; the usual way is to manipulate terminal (actually, serial-port) attributes". This is less difficult than it seems: there should be support in ncurses for it, and there should be a portable API between glibc (on Unixes) and cygwin (on Winders). I *do* think it would be worth looking at (for instance) the code of sudo, to see what libraries it calls. OK, I'm done, lemme adjust this onion on my belt, --chet-- P.S. i re-reading the above (for resend) I'm being unclear. So I'll restate: the standard way that I've seen this done (many times over the years) is to manipulate the state of the serial-port and the "line-discipline" (that is, the equivalent of using the "stty" command). This is not connected with issuing terminal escape-sequences, because the former changes what is actually sent on the wire, whereas the latter changes only what is displayed in the virtual or real terminal. E.g. "stty -echo" disables the echoing of characters in the line-discipline -- whatever you type into a TTY, the kernel-level terminal-driver will not echo those chars back. Whereas telling the terminal emulator (or real terminal) to not display chars, doesn't change that the chars are actually sent. It's possible that this is a difference without relevance at this point in the evolution of UNIX software. But for sure, it was manipulation of line-discipline characteristics, that was the means of disabling echo, "back in the day". On Thu, Mar 28, 2019 at 1:33 PM Matthew Ryan wrote: > Hi Helmut, > > The usual way to do this (for any language) is using ANSI escape > sequences. Code 8 sets the terminal to conceal characters and code 0 resets > the attributes, making them visible again. > > For example, in a unix shell you can test this with echo and read: > > echo -e '\x1b[8m'; read varname; echo -e '\x1b[0m' > > To do the same from OCaml, you can output "\x1b[8m", read the password, > and then output "\x1b[0m" afterwards to switch printing back on. > > I believe that this will work on Windows 10, but earlier versions may not > have the necessary ANSI support. > > Hope this helps, > Matthew > > On Thu, 28 Mar 2019, 20:04 Helmut Brandl, wrote: > >> Hello list, >> >> Is there a portable way in ocaml to turn echoing off on standard input >> from the terminal to read e.g. passwords? By portable I mean that it works >> for Windows, Unix and Mac. >> >> Thanks for any hint. >> >> Regards >> Helmut > > --000000000000d98c8c058532f294 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
[Argh, resending, b/c got the recipi= ent-list wrong]

Perhaps this has changed in the N = years since last I worked with sgttyb/termios.=C2=A0 But back in the day, t= he answer was "there is no portable way; the usual way is to manipulat= e terminal (actually, serial-port) attributes".

This is less difficult than it seems: there should be support in ncurses= for it, and there should be a portable API between glibc (on Unixes) and c= ygwin (on Winders).

I *do* think it would be worth= looking at (for instance) the code of sudo, to see what libraries it calls= .

OK, I'm done, lemme adjust this onion on my = belt,
--chet--

P.S. i re-reading the abo= ve (for resend) I'm being unclear.=C2=A0 So I'll restate: the stand= ard way that I've seen this done (many times over the years) is to mani= pulate the state of the serial-port and the "line-discipline" (th= at is, the equivalent of using the "stty" command).=C2=A0 This is= not connected with issuing terminal escape-sequences, because the former c= hanges what is actually sent on the wire, whereas the latter changes only w= hat is displayed in the virtual or real terminal.=C2=A0 E.g. "stty -ec= ho" disables the echoing of characters in the line-discipline -- whate= ver you type into a TTY, the kernel-level terminal-driver will not echo tho= se chars back.=C2=A0 Whereas telling the terminal emulator (or real termina= l) to not display chars, doesn't change that the chars are actually sen= t.

It's possible that this is a difference wit= hout relevance at this point in the evolution of UNIX software.=C2=A0 But f= or sure, it was manipulation of line-discipline characteristics, that was t= he means of disabling echo, "back in the day".
<= br>
On Thu,= Mar 28, 2019 at 1:33 PM Matthew Ryan <matthew@o1labs.org> wrote:
Hi Helmut,

The usual way to do this (for any language= ) is using ANSI escape sequences. Code 8 sets the terminal to conceal chara= cters and code 0 resets the attributes, making them visible again.

For example, in a unix shell you= can test this with echo and read:

echo -e '\x1b[8m'; read varname; echo -e '\x1b[0m= 9;

To do the same from O= Caml, you can output "\x1b[8m", read the password, and then outpu= t "\x1b[0m" afterwards to switch printing back on.

I believe that this will work on Wind= ows 10, but earlier versions may not have the necessary ANSI support.
=

Hope this helps,
Matthew

On Thu, 28 Mar 2019, 20:04 Helmut Brandl, <= ;helmut.brandl@g= mx.net> wrote:
Hello list,

Is there a portable way in ocaml to turn echoing off on standard input from= the terminal to read e.g. passwords? By portable I mean that it works for = Windows, Unix and Mac.

Thanks for any hint.

Regards
Helmut
--000000000000d98c8c058532f294--