From 7ebd67e63a37468d1f1dacb92c262f10275f973c Mon Sep 17 00:00:00 2001 From: Lauri Tirkkonen Date: Tue, 9 Jul 2024 11:15:20 +0900 Subject: mount: replace rpassword with rustix::termios because rpassword unconditionally open()s /dev/tty, it fails with ENXIO on the console without workarounds like busybox's cttyhack. in contrast, bcachefs unlock works fine on console, so change the passphrase prompt logic in mount to be closer to what it is in unlock. Signed-off-by: Lauri Tirkkonen Signed-off-by: Kent Overstreet --- src/key.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/key.rs b/src/key.rs index 0a2d08da..efca0a9a 100644 --- a/src/key.rs +++ b/src/key.rs @@ -16,6 +16,7 @@ use bch_bindgen::{ }; use byteorder::{LittleEndian, ReadBytesExt}; use log::info; +use rustix::termios; use uuid::Uuid; use zeroize::{ZeroizeOnDrop, Zeroizing}; @@ -151,9 +152,20 @@ impl Passphrase { // blocks indefinitely if no input is available on stdin pub fn new_from_prompt() -> Result { - let passphrase = Zeroizing::new(rpassword::prompt_password("Enter passphrase: ")?); + let old = termios::tcgetattr(stdin())?; + let mut new = old.clone(); + new.local_modes.remove(termios::LocalModes::ECHO); + termios::tcsetattr(stdin(), termios::OptionalActions::Flush, &new)?; - Ok(Self(CString::new(passphrase.trim_end_matches('\n'))?)) + eprint!("Enter passphrase: "); + + let mut line = Zeroizing::new(String::new()); + let res = stdin().read_line(&mut line); + termios::tcsetattr(stdin(), termios::OptionalActions::Flush, &old)?; + eprintln!(""); + res?; + + Ok(Self(CString::new(line.trim_end_matches('\n'))?)) } // blocks indefinitely if no input is available on stdin -- cgit v1.2.3