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 From 19f554358d19f2cf5f71478aebd1400aff907a79 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 20 Aug 2022 18:10:34 +0200 Subject: parse_options: Clean up `Command.spawn` code * Remove old in-progress code * Remove `child.stdout.take()` call, which is suggested in https://doc.rust-lang.org/std/process/struct.Child.html#structfield.stdout but ended up not being necessary in this instance. --- src/main.rs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 7701dd3..ac289cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,25 +72,11 @@ fn parse_options(filename: &str) -> Vec { child.wait().expect("Error waiting for `pass`"); - let stdout = child.stdout.take().unwrap(); - - // let file = stdout; - // let stdout = child.stdout.unwrap(); + let stdout = child.stdout.expect("No standard output"); 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()); + push_option(&mut options, line.expect("Error reading line")); } } -- cgit v1.2.3