diff options
author | Teddy Wing | 2022-08-20 17:02:38 +0200 |
---|---|---|
committer | Teddy Wing | 2022-08-20 17:02:38 +0200 |
commit | c1f72865741868d094a53fa73ee9b8562202ab0a (patch) | |
tree | 98745b8e7f2c1892aeefb54c9d9ef88be9f33f65 /src | |
parent | 0eae53c6fe2c5dc9c382d45fabbb515f65a3d32f (diff) | |
download | Passextract-c1f72865741868d094a53fa73ee9b8562202ab0a.tar.bz2 |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 25 insertions, 6 deletions
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<String> { 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()); } } |