Utils: add getpass

This commit is contained in:
Vincent Bernardoff 2018-02-06 19:16:01 +01:00 committed by Benjamin Canou
parent 6096592a22
commit 28adbb5814
2 changed files with 20 additions and 0 deletions

View File

@ -136,6 +136,22 @@ let getaddrinfo ~passive ~node ~service =
addr in addr in
Lwt.return points Lwt.return points
let getpass () =
let open Unix in
(* Turn echoing off and fail if we can't. *)
let tio = tcgetattr stdin in
let old_echo = tio.c_echo in
let old_echonl = tio.c_echonl in
tio.c_echo <- false ;
tio.c_echonl <- true ;
tcsetattr stdin TCSAFLUSH tio ;
(* Read the passwd. *)
let passwd = read_line () in
(* Restore terminal. *)
tio.c_echo <- old_echo ;
tio.c_echonl <- old_echonl ;
tcsetattr stdin TCSAFLUSH tio ;
passwd
module Json = struct module Json = struct

View File

@ -34,6 +34,10 @@ val getaddrinfo:
node:string -> service:string -> node:string -> service:string ->
(Ipaddr.V6.t * int) list Lwt.t (Ipaddr.V6.t * int) list Lwt.t
(** [getpass ()] reads a password from stdio while setting-up the
terminal to not display the password being typed. *)
val getpass : unit -> string
module Json : sig module Json : sig
(** Loads a JSON file in memory *) (** Loads a JSON file in memory *)