From 8131acc75a2bddb03b4dc839464e886c76fab7e3 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 3 Aug 2022 17:09:09 +0200 Subject: [PATCH] pass login: Only use first line from result It's possible to create multi-line entries in `pass(1)` where additional lines have further metadata, e.g. $ pass show kit-access user: uXXXX which can be helpful to persist e.g. the corresponding username. However it's a convention that the password is only in the first line, e.g. `pass show -c` (which is used by `passmenu` to copy a secret into the clipboard) only the first line is used by default. I switched to such an approach recently and realized that this is now a problem because `KIT-ILIAS-Downloader` passes the entire string to the SAML login, so I decided to just strip everything after the first line in the output of `pass show`. We may want to implement support for extracting usernames from such a format in the future, but... that's an exercise left for the reader ;-) --- src/cli.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 1918519..196a079 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -201,8 +201,8 @@ pub fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { ))? } else { pass = String::from_utf8(pw_out.stdout).map(|x| { - x.trim_end().to_string() - }).expect("utf-8 decode of `pass(1)`-output failed"); + x.lines().next().map(|x| x.to_owned()).ok_or_else(|| anyhow!("empty pass(1) entry!")) + })?.expect("utf-8 decode of `pass(1)`-output failed"); should_store = false; } } else {