aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-03-09 20:43:27 -0500
committerJesse Luehrs <doy@tozt.net>2023-03-09 20:55:01 -0500
commitbe2e4aa459222a8194163fff92ccbedcafd6cb19 (patch)
tree79ee6a74f8061ccf46b09baaf8715f56e2f2f3fb /src
parent7729e435241f16e4707fe858c6ace15bd6049c34 (diff)
downloadrbw-be2e4aa459222a8194163fff92ccbedcafd6cb19.tar.gz
rbw-be2e4aa459222a8194163fff92ccbedcafd6cb19.zip
bump deps
Diffstat (limited to 'src')
-rw-r--r--src/bin/rbw-agent/daemon.rs31
-rw-r--r--src/bin/rbw/actions.rs2
-rw-r--r--src/error.rs3
-rw-r--r--src/identity.rs6
4 files changed, 26 insertions, 16 deletions
diff --git a/src/bin/rbw-agent/daemon.rs b/src/bin/rbw-agent/daemon.rs
index 22862dd..8cb9998 100644
--- a/src/bin/rbw-agent/daemon.rs
+++ b/src/bin/rbw-agent/daemon.rs
@@ -30,32 +30,37 @@ pub fn daemonize() -> anyhow::Result<StartupAck> {
.open(rbw::dirs::agent_stderr_file())?;
let (r, w) = nix::unistd::pipe()?;
- let res = daemonize::Daemonize::new()
+ let daemonize = daemonize::Daemonize::new()
.pid_file(rbw::dirs::pid_file())
.stdout(stdout)
- .stderr(stderr)
- .exit_action(move || {
+ .stderr(stderr);
+ let res = match daemonize.execute() {
+ daemonize::Outcome::Parent(_) => {
// unwraps are necessary because not really a good way to handle
// errors here otherwise
let _ = nix::unistd::close(w);
let mut buf = [0; 1];
nix::unistd::read(r, &mut buf).unwrap();
nix::unistd::close(r).unwrap();
- })
- .start();
+ std::process::exit(0);
+ }
+ daemonize::Outcome::Child(res) => res,
+ };
+
let _ = nix::unistd::close(r);
match res {
Ok(_) => (),
Err(e) => {
- match e {
- daemonize::DaemonizeError::LockPidfile(_) => {
- // this means that there is already an agent running, so
- // return a special exit code to allow the cli to detect
- // this case and not error out
- std::process::exit(23);
- }
- _ => panic!("failed to daemonize: {e}"),
+ // XXX super gross, but daemonize removed the ability to match
+ // on specific error types for some reason?
+ if e.to_string().contains("unable to lock pid file") {
+ // this means that there is already an agent running, so
+ // return a special exit code to allow the cli to detect
+ // this case and not error out
+ std::process::exit(23);
+ } else {
+ panic!("failed to daemonize: {e}");
}
}
}
diff --git a/src/bin/rbw/actions.rs b/src/bin/rbw/actions.rs
index 7ca0ef9..29cd6fe 100644
--- a/src/bin/rbw/actions.rs
+++ b/src/bin/rbw/actions.rs
@@ -31,7 +31,7 @@ pub fn quit() -> anyhow::Result<()> {
let pidfile = rbw::dirs::pid_file();
let mut pid = String::new();
std::fs::File::open(pidfile)?.read_to_string(&mut pid)?;
- let pid = nix::unistd::Pid::from_raw(pid.parse()?);
+ let pid = nix::unistd::Pid::from_raw(pid.trim_end().parse()?);
sock.send(&rbw::protocol::Request {
tty: nix::unistd::ttyname(0).ok().and_then(|p| {
p.to_str().map(std::string::ToString::to_string)
diff --git a/src/error.rs b/src/error.rs
index d165a92..6d49e09 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -139,6 +139,9 @@ pub enum Error {
#[error("pbkdf2 requires at least 1 iteration (got 0)")]
Pbkdf2ZeroIterations,
+ #[error("failed to run pbkdf2")]
+ Pbkdf2,
+
#[error("pinentry cancelled")]
PinentryCancelled,
diff --git a/src/identity.rs b/src/identity.rs
index 90d4fad..8a5dc61 100644
--- a/src/identity.rs
+++ b/src/identity.rs
@@ -24,7 +24,8 @@ impl Identity {
email.as_bytes(),
iterations.get(),
enc_key,
- );
+ )
+ .map_err(|_| Error::Pbkdf2)?;
let mut hash = crate::locked::Vec::new();
hash.extend(std::iter::repeat(0).take(32));
@@ -33,7 +34,8 @@ impl Identity {
password.password(),
1,
hash.data_mut(),
- );
+ )
+ .map_err(|_| Error::Pbkdf2)?;
let hkdf = hkdf::Hkdf::<sha2::Sha256>::from_prk(enc_key)
.map_err(|_| Error::HkdfExpand)?;