From a65c972116daa16efc6b4d7d355fcec9b342dd28 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 19 Apr 2020 05:19:02 -0400 Subject: implement history command to get password history --- src/bin/rbw/commands.rs | 24 ++++++++++++++++++++++++ src/bin/rbw/main.rs | 11 +++++++++++ 2 files changed, 35 insertions(+) (limited to 'src/bin') diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 7152a59..81ea2e2 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -299,6 +299,30 @@ pub fn remove(name: &str, username: Option<&str>) -> anyhow::Result<()> { Ok(()) } +pub fn history(name: &str, username: Option<&str>) -> anyhow::Result<()> { + unlock()?; + + let email = config_email()?; + let db = rbw::db::Db::load(&email) + .context("failed to load password database")?; + + let desc = format!( + "{}{}", + username + .map(|s| format!("{}@", s)) + .unwrap_or_else(|| "".to_string()), + name + ); + + let (_, decrypted) = find_entry(&db, name, username) + .with_context(|| format!("couldn't find entry for '{}'", desc))?; + for history in decrypted.history { + println!("{}: {}", history.last_used_date, history.password); + } + + Ok(()) +} + pub fn lock() -> anyhow::Result<()> { ensure_agent()?; crate::actions::lock()?; diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs index b09ae2b..90ef95e 100644 --- a/src/bin/rbw/main.rs +++ b/src/bin/rbw/main.rs @@ -68,6 +68,11 @@ fn main() { .arg(clap::Arg::with_name("name").required(true)) .arg(clap::Arg::with_name("user")), ) + .subcommand( + clap::SubCommand::with_name("history") + .arg(clap::Arg::with_name("name").required(true)) + .arg(clap::Arg::with_name("user")), + ) .subcommand(clap::SubCommand::with_name("lock")) .subcommand(clap::SubCommand::with_name("purge")) .subcommand(clap::SubCommand::with_name("stop-agent")) @@ -143,6 +148,12 @@ fn main() { smatches.value_of("user"), ) .context("remove"), + // this unwrap is safe because name is marked .required(true) + ("history", Some(smatches)) => commands::history( + smatches.value_of("name").unwrap(), + smatches.value_of("user"), + ) + .context("history"), ("lock", Some(_)) => commands::lock().context("lock"), ("purge", Some(_)) => commands::purge().context("purge"), ("stop-agent", Some(_)) => { -- cgit v1.2.3-54-g00ecf