aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-19 05:19:02 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-19 05:19:02 -0400
commita65c972116daa16efc6b4d7d355fcec9b342dd28 (patch)
tree4892293b557cd922d648ceba74df07fd90c0a12d
parent988296d6c9e053d632ee5610ba3432a02776b132 (diff)
downloadrbw-a65c972116daa16efc6b4d7d355fcec9b342dd28.tar.gz
rbw-a65c972116daa16efc6b4d7d355fcec9b342dd28.zip
implement history command to get password history
-rw-r--r--src/bin/rbw/commands.rs24
-rw-r--r--src/bin/rbw/main.rs11
2 files changed, 35 insertions, 0 deletions
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(_)) => {