From 2e3e2ce114ae48109be137dfe541cdc22f9d8760 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Fri, 28 Aug 2020 10:36:26 -0500 Subject: [PATCH] agent/rustjail/capabilities: Use anyhow for error handling Use `.to_string` to wrap up `caps::errors::Error`s since they are not thread safe, otherwise `cargo build` will fail with the following error: ``` doesn't satisfy `caps::errors::Error: std::marker::Sync` ``` Signed-off-by: Julio Montes --- src/agent/rustjail/src/capabilities.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/agent/rustjail/src/capabilities.rs b/src/agent/rustjail/src/capabilities.rs index 6a2f1201a..c250993f0 100644 --- a/src/agent/rustjail/src/capabilities.rs +++ b/src/agent/rustjail/src/capabilities.rs @@ -8,9 +8,9 @@ use lazy_static; -use crate::errors::*; use crate::log_child; use crate::sync::write_count; +use anyhow::{anyhow, Result}; use caps::{self, CapSet, Capability, CapsHashSet}; use oci::LinuxCapabilities; use std::collections::HashMap; @@ -96,7 +96,7 @@ fn to_capshashset(cfd_log: RawFd, caps: &[String]) -> CapsHashSet { } pub fn reset_effective() -> Result<()> { - caps::set(None, CapSet::Effective, caps::all())?; + caps::set(None, CapSet::Effective, caps::all()).map_err(|e| anyhow!(e.to_string()))?; Ok(()) } @@ -104,24 +104,27 @@ pub fn drop_priviledges(cfd_log: RawFd, caps: &LinuxCapabilities) -> Result<()> let all = caps::all(); for c in all.difference(&to_capshashset(cfd_log, caps.bounding.as_ref())) { - caps::drop(None, CapSet::Bounding, *c)?; + caps::drop(None, CapSet::Bounding, *c).map_err(|e| anyhow!(e.to_string()))?; } caps::set( None, CapSet::Effective, to_capshashset(cfd_log, caps.effective.as_ref()), - )?; + ) + .map_err(|e| anyhow!(e.to_string()))?; caps::set( None, CapSet::Permitted, to_capshashset(cfd_log, caps.permitted.as_ref()), - )?; + ) + .map_err(|e| anyhow!(e.to_string()))?; caps::set( None, CapSet::Inheritable, to_capshashset(cfd_log, caps.inheritable.as_ref()), - )?; + ) + .map_err(|e| anyhow!(e.to_string()))?; if let Err(_) = caps::set( None,