Skip to content

Commit

Permalink
Format Rust code using rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Apr 29, 2024
1 parent 6a0ed2c commit b063387
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 50 deletions.
4 changes: 1 addition & 3 deletions src/chsr/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,7 @@ pub fn main(storage: &Storage) -> Result<bool, Box<dyn Error>> {
}
Ok(true)
}
Err(e) => {
Err(e)
}
Err(e) => Err(e),
}
}
},
Expand Down
12 changes: 8 additions & 4 deletions src/database/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ fn final_path(path: &String) -> PathBuf {
let result;
if let Ok(cannon_path) = std::fs::canonicalize(path) {
result = cannon_path;
} else if let Some(env_path) = find_from_envpath(&path.parse().expect("The path is not valid")) {
} else if let Some(env_path) = find_from_envpath(&path.parse().expect("The path is not valid"))
{
result = env_path
} else {
result = path.parse().expect("The path is not valid");
Expand Down Expand Up @@ -548,7 +549,8 @@ impl TaskMatcher<TaskMatch> for Rc<RefCell<STask>> {
.borrow()
.cred
.capabilities
.as_ref().map(|caps| caps.to_capset());
.as_ref()
.map(|caps| caps.to_capset());
score.caps_min = get_caps_min(&capset);
score.security_min = get_security_min(&self.as_ref().borrow().options);
let setuid = &self.as_ref().borrow().cred.setuid;
Expand Down Expand Up @@ -918,9 +920,11 @@ mod tests {
fn test_get_cmd_min() {
let result = get_cmd_min(
&["/bin/ls".to_string(), "-l".to_string(), "-a".to_string()],
&["/bin/l*".into(),
&[
"/bin/l*".into(),
"/bin/ls .*".into(),
"/bin/ls -l -a".into()],
"/bin/ls -l -a".into(),
],
);
assert_eq!(result, CmdMin::Match);
}
Expand Down
1 change: 0 additions & 1 deletion src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use linked_hash_set::LinkedHashSet;
use serde::{de, Deserialize, Serialize};
use tracing::debug;


use self::{migration::Migration, options::EnvKey, structs::SConfig, version::Versioning};

use super::config::SettingsFile;
Expand Down
20 changes: 3 additions & 17 deletions src/database/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use super::{
structs::{SConfig, SRole, STask},
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Default)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Level {
None,
#[default]
Expand Down Expand Up @@ -61,8 +60,6 @@ pub enum TimestampType {
UID,
}



#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct STimeout {
#[serde(default, rename = "type")]
Expand Down Expand Up @@ -209,16 +206,6 @@ pub struct Opt {
pub level: Level,
}











impl Opt {
pub fn new(level: Level) -> Self {
let mut opt = Self::default();
Expand Down Expand Up @@ -876,9 +863,8 @@ mod tests {
as_borrow_mut!(config).roles.push(role);
let options = OptStack::from_role(config.as_ref().borrow().roles[0].clone());

let res: Option<(Level, SPathOptions)> = options.find_in_options(|opt| {
opt.path.clone().map(|value| (opt.level, value))
});
let res: Option<(Level, SPathOptions)> =
options.find_in_options(|opt| opt.path.clone().map(|value| (opt.level, value)));
assert_eq!(res, Some((Level::Role, role_path)));
}

Expand Down
6 changes: 1 addition & 5 deletions src/database/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ impl Default for SCommands {
}
}



impl Default for SCapabilities {
fn default() -> Self {
SCapabilities {
Expand Down Expand Up @@ -472,9 +470,7 @@ impl PartialEq<str> for SActorType {
fn eq(&self, other: &str) -> bool {
match self {
SActorType::Name(name) => name == other,
SActorType::Id(id) => other
.parse().map(|oid: u32| oid == *id)
.unwrap_or(false),
SActorType::Id(id) => other.parse().map(|oid: u32| oid == *id).unwrap_or(false),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub struct Parents(Vec<String>);

fn get_parents(role: &SRole) -> Option<Result<Parents, serde_json::Error>> {
role._extra_fields
.get("parents").map(|parents| serde_json::from_value::<Parents>(parents.clone()))
.get("parents")
.map(|parents| serde_json::from_value::<Parents>(parents.clone()))
}

fn find_in_parents(
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/ssd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ fn check_separation_of_duty(role: &SRole, actor: &Cred) -> PluginResult {

fn get_ssd_entry(role: &SRole) -> Option<Result<SSD, Error>> {
role._extra_fields
.get("ssd").map(|ssd| serde_json::from_value::<SSD>(ssd.clone()))
.get("ssd")
.map(|ssd| serde_json::from_value::<SSD>(ssd.clone()))
}

pub fn register() {
Expand Down
34 changes: 16 additions & 18 deletions src/sr/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ fn main() -> Result<(), Box<dyn Error>> {
register_plugins();
let args = add_dashes();
let args = Cli::parse_from(args.iter());
read_effective(true).unwrap_or_else(|_| { panic!("{}", cap_effective_error("dac_read")) });
read_effective(true).unwrap_or_else(|_| panic!("{}", cap_effective_error("dac_read")));
let settings = config::get_settings().expect("Failed to get settings");
read_effective(false).unwrap_or_else(|_| { panic!("{}", cap_effective_error("dac_read")) });
read_effective(false).unwrap_or_else(|_| panic!("{}", cap_effective_error("dac_read")));
let user = User::from_uid(getuid())
.expect("Failed to get user")
.expect("Failed to get user");
Expand Down Expand Up @@ -231,7 +231,8 @@ fn main() -> Result<(), Box<dyn Error>> {
ppid,
};

dac_override_effective(true).unwrap_or_else(|_| { panic!("{}", cap_effective_error("dac_override")) });
dac_override_effective(true)
.unwrap_or_else(|_| panic!("{}", cap_effective_error("dac_override")));
let config = match settings.clone().as_ref().borrow().storage.method {
config::StorageMethod::JSON => {
Storage::JSON(read_json_config(settings).expect("Failed to read config"))
Expand All @@ -249,7 +250,8 @@ fn main() -> Result<(), Box<dyn Error>> {

let optstack = &execcfg.opt;
check_auth(optstack, &config, &user, &args.prompt)?;
dac_override_effective(false).unwrap_or_else(|_| { panic!("{}", cap_effective_error("dac_override")) });
dac_override_effective(false)
.unwrap_or_else(|_| panic!("{}", cap_effective_error("dac_override")));

if !taskmatch.fully_matching() {
println!("You are not allowed to execute this command, this incident will be reported.");
Expand All @@ -262,10 +264,7 @@ fn main() -> Result<(), Box<dyn Error>> {

if args.info {
println!("Role: {}", execcfg.role().as_ref().borrow().name);
println!(
"Task: {}",
execcfg.task().as_ref().borrow().name
);
println!("Task: {}", execcfg.task().as_ref().borrow().name);
println!(
"With capabilities: {}",
execcfg
Expand Down Expand Up @@ -331,16 +330,15 @@ fn main() -> Result<(), Box<dyn Error>> {
}
});

setgid_effective(true).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setgid")) });
setuid_effective(true).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setuid")) });
capctl::cap_set_ids(uid, gid, groups.as_deref())
.expect("Failed to set ids");
setgid_effective(false).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setgid")) });
setuid_effective(false).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setuid")) });
setgid_effective(true).unwrap_or_else(|_| panic!("{}", cap_effective_error("setgid")));
setuid_effective(true).unwrap_or_else(|_| panic!("{}", cap_effective_error("setuid")));
capctl::cap_set_ids(uid, gid, groups.as_deref()).expect("Failed to set ids");
setgid_effective(false).unwrap_or_else(|_| panic!("{}", cap_effective_error("setgid")));
setuid_effective(false).unwrap_or_else(|_| panic!("{}", cap_effective_error("setuid")));

//set capabilities
if let Some(caps) = execcfg.caps {
setpcap_effective(true).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setpcap")) });
setpcap_effective(true).unwrap_or_else(|_| panic!("{}", cap_effective_error("setpcap")));
let mut capstate = CapState::empty();
if !optstack.get_bounding().1.is_ignore() {
for cap in (!caps).iter() {
Expand All @@ -353,15 +351,15 @@ fn main() -> Result<(), Box<dyn Error>> {
for cap in caps.iter() {
capctl::ambient::raise(cap).expect("Failed to set ambiant cap");
}
setpcap_effective(false).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setpcap")) });
setpcap_effective(false).unwrap_or_else(|_| panic!("{}", cap_effective_error("setpcap")));
} else {
setpcap_effective(true).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setpcap")) });
setpcap_effective(true).unwrap_or_else(|_| panic!("{}", cap_effective_error("setpcap")));
if !optstack.get_bounding().1.is_ignore() {
capctl::bounding::clear().expect("Failed to clear bounding cap");
}
let capstate = CapState::empty();
capstate.set_current().expect("Failed to set current cap");
setpcap_effective(false).unwrap_or_else(|_| { panic!("{}", cap_effective_error("setpcap")) });
setpcap_effective(false).unwrap_or_else(|_| panic!("{}", cap_effective_error("setpcap")));
}

//execute command
Expand Down

0 comments on commit b063387

Please sign in to comment.