From c1f72865741868d094a53fa73ee9b8562202ab0a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 20 Aug 2022 17:02:38 +0200 Subject: Spawn `pass` in order to support GnuPG 2 and Pinentry Previously, Passextract didn't work with GnuPG 2 because I was immediately collecting the output of `pass`. With GnuPG 1.4, the password prompt was like a conventional `read`-style password prompt. However, in GnuPG 2, the prompt is replaced with Pinentry. Pinentry interferes with capturing the output from Pass, such that Passextract exits immediately, without even prompting for a password. Instead of using `Command.output`, use `Command.spawn`. This allows GnuPG to work correctly and display a Pinentry prompt. We can then capture the standard output from the child process and parse it for the Passextract interface. --- src/main.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 47095b8..7701dd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,15 +63,34 @@ fn parse_options(filename: &str) -> Vec { push_option(&mut options, line.to_owned()); } } else { - let file = Command::new("pass") + let mut child = Command::new("pass") .arg("show") .arg(filename) - .output() - .expect("Error executing `pass`") - .stdout; + .stdout(std::process::Stdio::piped()) + .spawn() + .expect("Error executing `pass`"); - for line in String::from_utf8_lossy(&file).lines() { - push_option(&mut options, line.to_owned()); + child.wait().expect("Error waiting for `pass`"); + + let stdout = child.stdout.take().unwrap(); + + // let file = stdout; + // let stdout = child.stdout.unwrap(); + let file = io::BufReader::new(stdout); + + // let mut line = String::new(); + + // loop { + // let n_bytes = file.read_line(&mut line).unwrap(); + // if n_bytes == 0 { + // break; + // } + // + // push_option(&mut options, line.to_owned()); + // } + + for line in file.lines() { + push_option(&mut options, line.unwrap()); } } -- cgit v1.2.3