diff --git a/rar-common/src/api.rs b/rar-common/src/api.rs index 2138111..109623c 100644 --- a/rar-common/src/api.rs +++ b/rar-common/src/api.rs @@ -6,7 +6,7 @@ use capctl::CapSet; use serde_json::Value; use strum::EnumIs; #[cfg(feature = "finder")] -use tracing::debug; +use log::debug; #[cfg(feature = "finder")] use crate::database::finder::{Cred, ExecSettings, FilterMatcher, TaskMatch, UserMin}; diff --git a/rar-common/src/database/finder.rs b/rar-common/src/database/finder.rs index 9eedef0..788e063 100644 --- a/rar-common/src/database/finder.rs +++ b/rar-common/src/database/finder.rs @@ -16,7 +16,7 @@ use nix::{ #[cfg(feature = "pcre2")] use pcre2::bytes::RegexBuilder; use strum::EnumIs; -use tracing::{debug, warn}; +use log::{debug, warn}; use crate::database::{ options::{Opt, OptStack}, @@ -488,7 +488,7 @@ fn is_root(actortype: &SActorType) -> bool { fn groups_contains_root(list: Option<&SGroups>) -> bool { if let Some(list) = list { match list { - SGroups::Single(group) => is_root(group), + SGroups::Single(group) => is_root(&group), SGroups::Multiple(groups) => groups.iter().any(is_root), } } else { @@ -703,7 +703,7 @@ impl CredMatcher for Rc> { } } SActor::Unknown(element) => { - let min = PluginManager::notify_user_matcher(&as_borrow!(self), user, element); + let min = PluginManager::notify_user_matcher(&as_borrow!(self), user, &element); if !min.is_no_match() { return Some(min); } diff --git a/rar-common/src/database/migration.rs b/rar-common/src/database/migration.rs index 85c4625..9b00fe0 100644 --- a/rar-common/src/database/migration.rs +++ b/rar-common/src/database/migration.rs @@ -1,7 +1,7 @@ use std::error::Error; use semver::Version; -use tracing::debug; +use log::debug; use crate::version::PACKAGE_VERSION; diff --git a/rar-common/src/database/mod.rs b/rar-common/src/database/mod.rs index 0fdadcb..9372553 100644 --- a/rar-common/src/database/mod.rs +++ b/rar-common/src/database/mod.rs @@ -7,7 +7,7 @@ use crate::version::PACKAGE_VERSION; use chrono::Duration; use linked_hash_set::LinkedHashSet; use serde::{de, Deserialize, Serialize}; -use tracing::debug; +use log::debug; use self::{migration::Migration, options::EnvKey, structs::SConfig, versionning::Versioning}; diff --git a/rar-common/src/database/options.rs b/rar-common/src/database/options.rs index 1b6983d..2cf0479 100644 --- a/rar-common/src/database/options.rs +++ b/rar-common/src/database/options.rs @@ -15,9 +15,9 @@ use serde::{Deserialize, Deserializer, Serialize}; use serde_json::{Map, Value}; use strum::{Display, EnumIs, EnumIter, FromRepr}; -use tracing::debug; +use log::debug; #[cfg(feature = "finder")] -use tracing::warn; +use log::warn; use crate::rc_refcell; diff --git a/rar-common/src/lib.rs b/rar-common/src/lib.rs index 6c904e4..db757d0 100644 --- a/rar-common/src/lib.rs +++ b/rar-common/src/lib.rs @@ -55,7 +55,7 @@ const ROOTASROLE: &str = "target/rootasrole.json"; use std::{cell::RefCell, error::Error, ffi::OsStr, path::PathBuf, rc::Rc}; use serde::{Deserialize, Serialize}; -use tracing::debug; +use log::debug; pub mod api; pub mod database; diff --git a/rar-common/src/plugin/hashchecker.rs b/rar-common/src/plugin/hashchecker.rs index b53a8c2..06a0219 100644 --- a/rar-common/src/plugin/hashchecker.rs +++ b/rar-common/src/plugin/hashchecker.rs @@ -8,7 +8,7 @@ use crate::{ }; use nix::unistd::{access, AccessFlags}; use serde::{Deserialize, Serialize}; -use tracing::{debug, warn}; +use log::{debug, warn}; use libc::FS_IOC_GETFLAGS; use sha2::Digest; diff --git a/rar-common/src/plugin/hierarchy.rs b/rar-common/src/plugin/hierarchy.rs index 352de2a..ca619be 100644 --- a/rar-common/src/plugin/hierarchy.rs +++ b/rar-common/src/plugin/hierarchy.rs @@ -9,7 +9,7 @@ use crate::{ }; use serde::Deserialize; -use tracing::{debug, warn}; +use log::{debug, warn}; #[derive(Deserialize)] pub struct Parents(Vec); diff --git a/rar-common/src/util.rs b/rar-common/src/util.rs index da0524f..a7075b2 100644 --- a/rar-common/src/util.rs +++ b/rar-common/src/util.rs @@ -1,7 +1,6 @@ use std::{ env, error::Error, - ffi::CString, fs::File, io, os::{fd::AsRawFd, unix::fs::MetadataExt}, @@ -13,8 +12,7 @@ use capctl::{Cap, CapSet, ParseCapError}; use libc::{FS_IOC_GETFLAGS, FS_IOC_SETFLAGS}; use serde::Serialize; use strum::EnumIs; -use tracing::{debug, warn, Level}; -use tracing_subscriber::util::SubscriberInitExt; +use log::{debug, warn}; #[cfg(feature = "finder")] use crate::api::PluginManager; @@ -257,45 +255,20 @@ pub fn final_path(path: &str) -> PathBuf { } #[cfg(debug_assertions)] -pub fn subsribe(tool: &str) { - use std::io; - let identity = CString::new(tool).unwrap(); - let options = syslog_tracing::Options::LOG_PID; - let facility = syslog_tracing::Facility::Auth; - let _syslog = syslog_tracing::Syslog::new(identity, options, facility).unwrap(); - tracing_subscriber::fmt() - .with_max_level(Level::DEBUG) - .with_file(true) - .with_line_number(true) - .with_writer(io::stdout) - .finish() +pub fn subsribe(tool: &str) -> Result<(), Box> { + env_logger::Builder::from_default_env() + .format_module_path(true) .init(); + Ok(()) } #[cfg(not(debug_assertions))] -pub fn subsribe(tool: &str) { - use std::panic::set_hook; - - let identity = CString::new(tool).unwrap(); - let options = syslog_tracing::Options::LOG_PID; - let facility = syslog_tracing::Facility::Auth; - let syslog = syslog_tracing::Syslog::new(identity, options, facility).unwrap(); - tracing_subscriber::fmt() - .compact() - .with_max_level(Level::WARN) - .with_file(false) - .with_timer(false) - .with_line_number(false) - .with_target(false) - .without_time() - .with_writer(syslog) - .finish() - .init(); - set_hook(Box::new(|info| { - if let Some(s) = info.payload().downcast_ref::() { - println!("{}", s); - } - })); +pub fn subsribe(tool: &str) -> Result<(), Box> { + use env_logger::Env; + use syslog::{BasicLogger, Facility, Formatter3164}; + use log::LevelFilter; + syslog::init(Facility::LOG_AUTH, LevelFilter::Info, Some(tool))?; + Ok(()) } pub fn drop_effective() -> Result<(), capctl::Error> { diff --git a/src/chsr/cli/mod.rs b/src/chsr/cli/mod.rs index 2c5b127..3459b3f 100644 --- a/src/chsr/cli/mod.rs +++ b/src/chsr/cli/mod.rs @@ -10,7 +10,7 @@ use data::{Cli, Inputs, Rule}; use pair::recurse_pair; use pest::Parser; use process::process_input; -use tracing::debug; +use log::debug; use usage::print_usage; use crate::util::escape_parser_string_vec; @@ -58,18 +58,11 @@ mod tests { use super::*; use capctl::Cap; use chrono::TimeDelta; - use tracing::error; - use tracing_subscriber::util::SubscriberInitExt; + use log::error; + use test_log::test; + fn setup(name: &str) { - use std::io; - let _ = tracing_subscriber::fmt() - .with_max_level(tracing::Level::DEBUG) - .with_file(true) - .with_line_number(true) - .with_writer(io::stdout) - .finish() - .try_init(); //Write json test json file let path = format!("{}.{}", ROOTASROLE, name); let mut file = std::fs::File::create(path.clone()).unwrap_or_else(|_| { diff --git a/src/chsr/cli/pair.rs b/src/chsr/cli/pair.rs index 6cfa286..46af806 100644 --- a/src/chsr/cli/pair.rs +++ b/src/chsr/cli/pair.rs @@ -4,7 +4,7 @@ use capctl::{Cap, CapSet}; use chrono::Duration; use linked_hash_set::LinkedHashSet; use pest::iterators::Pair; -use tracing::{debug, warn}; +use log::{debug, warn}; use crate::cli::data::{RoleType, TaskType}; use rar_common::database::{ diff --git a/src/chsr/cli/process.rs b/src/chsr/cli/process.rs index cf630df..96409aa 100644 --- a/src/chsr/cli/process.rs +++ b/src/chsr/cli/process.rs @@ -4,7 +4,7 @@ use std::{cell::RefCell, error::Error, rc::Rc}; use json::*; -use tracing::debug; +use log::debug; use rar_common::{ database::{ diff --git a/src/chsr/cli/process/json.rs b/src/chsr/cli/process/json.rs index bc9d230..d8763ea 100644 --- a/src/chsr/cli/process/json.rs +++ b/src/chsr/cli/process/json.rs @@ -7,7 +7,7 @@ use std::{ }; use linked_hash_set::LinkedHashSet; -use tracing::debug; +use log::debug; use crate::cli::data::{InputAction, RoleType, SetListType, TaskType, TimeoutOpt}; diff --git a/src/chsr/cli/usage.rs b/src/chsr/cli/usage.rs index 6aa9fa2..31281a4 100644 --- a/src/chsr/cli/usage.rs +++ b/src/chsr/cli/usage.rs @@ -1,7 +1,7 @@ use std::error::Error; use const_format::formatcp; -use tracing::debug; +use log::debug; use super::data::Rule; use crate::util::underline; diff --git a/src/chsr/main.rs b/src/chsr/main.rs index 8cec1c1..7f94797 100644 --- a/src/chsr/main.rs +++ b/src/chsr/main.rs @@ -6,7 +6,7 @@ use rar_common::{ util::{drop_effective, read_effective, subsribe}, Storage, }; -use tracing::{debug, error}; +use log::{debug, error}; mod cli; mod util; @@ -20,7 +20,7 @@ const ROOTASROLE: &str = "target/rootasrole.json"; fn main() -> Result<(), Box> { use rar_common::{get_settings, StorageMethod}; - subsribe("chsr"); + subsribe("chsr")?; drop_effective()?; register_plugins(); let settings = get_settings(ROOTASROLE).expect("Error on config read"); diff --git a/src/sr/main.rs b/src/sr/main.rs index 55785b9..c23ebd9 100644 --- a/src/sr/main.rs +++ b/src/sr/main.rs @@ -15,7 +15,7 @@ use rar_common::util::escape_parser_string; use pam::PAM_PROMPT; use pty_process::blocking::{Command, Pty}; use std::{cell::RefCell, error::Error, io::stdout, os::fd::AsRawFd, rc::Rc}; -use tracing::{debug, error}; +use log::{debug, error}; use rar_common::plugin::register_plugins; use rar_common::{ @@ -187,7 +187,7 @@ where fn main() -> Result<(), Box> { use crate::{pam::check_auth, ROOTASROLE}; - subsribe("sr"); + subsribe("sr")?; drop_effective()?; register_plugins(); let args = std::env::args(); diff --git a/src/sr/pam/mod.rs b/src/sr/pam/mod.rs index 75e68ec..9b11798 100644 --- a/src/sr/pam/mod.rs +++ b/src/sr/pam/mod.rs @@ -6,7 +6,7 @@ use std::{ use pam_client::{Context, ConversationHandler, ErrorCode, Flag}; use pcre2::bytes::RegexBuilder; -use tracing::{debug, error, info, warn}; +use log::{debug, error, info, warn}; use crate::timeout; use rar_common::{ diff --git a/src/sr/timeout.rs b/src/sr/timeout.rs index 6475a61..1b895fb 100644 --- a/src/sr/timeout.rs +++ b/src/sr/timeout.rs @@ -13,7 +13,7 @@ use nix::{ sys::signal::kill, }; use serde::{Deserialize, Serialize}; -use tracing::debug; +use log::debug; use rar_common::{ database::{ diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index af77b08..5b1e4a7 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -25,8 +25,8 @@ strum = { version = "0.26.3", features = ["derive"] } capctl = "0.2.4" nix = { version = "0.29.0", features = ["user","process", "signal", "fs"] } glob = "0.3.1" -tracing = "0.1.40" -tracing-subscriber = "0.3.18" +log = "0.4.22" +env_logger = "0.11.5" [features] default = ["cli", "ebpf", "deploy"] diff --git a/xtask/src/configure.rs b/xtask/src/configure.rs index a9657ff..f15242e 100644 --- a/xtask/src/configure.rs +++ b/xtask/src/configure.rs @@ -6,7 +6,7 @@ use std::path::Path; use anyhow::Context; use nix::unistd::{getresuid, getuid}; use strum::EnumIs; -use tracing::{info, warn}; +use log::{info, warn}; use crate::util::{ files_are_equal, toggle_lock_config, ImmutableLock, OsTarget, SettingsFile, ROOTASROLE, @@ -232,7 +232,7 @@ fn retrieve_real_user() -> Result, anyhow::Error> { } } -pub fn default_pam_path(os: &OsTarget) -> &'static str { +pub fn pam_config(os: &OsTarget) -> &'static str { match os { OsTarget::Debian | OsTarget::Ubuntu => { include_str!("../../resources/debian/deb_sr_pam.conf") @@ -245,7 +245,9 @@ pub fn default_pam_path(os: &OsTarget) -> &'static str { fn deploy_pam_config(os: &OsTarget) -> io::Result { if fs::metadata(PAM_CONFIG_PATH).is_err() { info!("Deploying PAM configuration file"); - return fs::copy(default_pam_path(os), PAM_CONFIG_PATH); + let mut pam_conf = File::create(PAM_CONFIG_PATH)?; + pam_conf.write_all(pam_config(os).as_bytes())?; + pam_conf.sync_all()?; } Ok(0) } diff --git a/xtask/src/deploy/debian.rs b/xtask/src/deploy/debian.rs index 094d22f..ead6dc9 100644 --- a/xtask/src/deploy/debian.rs +++ b/xtask/src/deploy/debian.rs @@ -5,7 +5,7 @@ use std::{ }; use anyhow::Context; -use tracing::debug; +use log::debug; use crate::{ installer::{self, dependencies::install_dependencies, InstallDependenciesOptions, Profile}, diff --git a/xtask/src/installer/build.rs b/xtask/src/installer/build.rs index 30f88da..d8d0d70 100644 --- a/xtask/src/installer/build.rs +++ b/xtask/src/installer/build.rs @@ -1,9 +1,9 @@ use std::{fs, os::unix, process::Command}; use anyhow::Context; -use tracing::debug; +use log::debug; -use crate::util::change_dir_to_git_root; +use crate::{installer::Toolchain, util::change_dir_to_git_root}; use super::BuildOptions; @@ -12,8 +12,13 @@ fn build_binary( options: &BuildOptions, additionnal_args: Vec<&str>, ) -> Result<(), anyhow::Error> { + let toolchain = format!("+{}", options.toolchain); - let mut args = vec![&toolchain, "build", "--bin", name]; + let mut args = if options.toolchain == Toolchain::default() { + vec!["build", "--bin", name] + } else { + vec![&toolchain, "build", "--bin", name] + }; if options.profile.is_release() { args.push("--release"); } diff --git a/xtask/src/installer/dependencies.rs b/xtask/src/installer/dependencies.rs index 94d7cde..3cfda9d 100644 --- a/xtask/src/installer/dependencies.rs +++ b/xtask/src/installer/dependencies.rs @@ -3,7 +3,7 @@ use std::process::ExitStatus; use anyhow::Context; use capctl::CapState; use nix::unistd::geteuid; -use tracing::info; +use log::info; use crate::{installer::OsTarget, util::get_os}; diff --git a/xtask/src/installer/install.rs b/xtask/src/installer/install.rs index 6411202..b765b3f 100644 --- a/xtask/src/installer/install.rs +++ b/xtask/src/installer/install.rs @@ -10,7 +10,7 @@ use nix::sys::stat::{fchmod, Mode}; use nix::unistd::{Gid, Uid}; use nix::NixPath; use strum::EnumIs; -use tracing::{debug, error, info}; +use log::{debug, error, info}; use crate::installer::Profile; use crate::util::{change_dir_to_git_root, detect_priv_bin, BOLD, RED, RST}; @@ -91,7 +91,7 @@ fn copy_docs() -> Result<(), anyhow::Error> { let lang = file.parent(); if lang.is_some_and(|p| !p.is_empty()) { let lang = lang.unwrap(); - println!("lang: {:?}", lang); + //println!("lang: {:?}", lang); let lang = lang.file_name().ok_or_else(|| { exit_directory().expect("Failed to exit directory"); anyhow!("Failed to get the language") @@ -140,7 +140,6 @@ fn setfcap() -> Result<(), anyhow::Error> { let mut file_caps = capctl::caps::FileCaps::empty(); file_caps.permitted = !CapSet::empty(); file_caps.set_for_file(SR_DEST)?; - file_caps.set_for_file(CHSR_DEST)?; Ok(()) } @@ -201,7 +200,7 @@ pub fn install( })?; change_dir_to_git_root()?; // change to the root of the project before elevating privileges env::set_var("ROOTASROLE_INSTALLER_NESTED", "1"); - tracing::warn!("Elevating privileges..."); + log::warn!("Elevating privileges..."); std::process::Command::new(priv_exe) .arg( current_exe()? diff --git a/xtask/src/installer/mod.rs b/xtask/src/installer/mod.rs index 68ed7f3..135b64f 100644 --- a/xtask/src/installer/mod.rs +++ b/xtask/src/installer/mod.rs @@ -12,7 +12,7 @@ use semver::Version; use strum::{Display, EnumIs, EnumString}; use anyhow::anyhow; -use tracing::debug; +use log::debug; use crate::{ configure, @@ -129,7 +129,7 @@ impl Display for Toolchain { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Toolchain { pub channel: Channel, pub date: Option, @@ -146,7 +146,7 @@ impl Default for Toolchain { } } -#[derive(Debug, Clone, EnumIs)] +#[derive(Debug, Clone, EnumIs, PartialEq, Eq)] pub enum Channel { Stable, Beta, diff --git a/xtask/src/installer/uninstall.rs b/xtask/src/installer/uninstall.rs index 70dee4c..1fc2460 100644 --- a/xtask/src/installer/uninstall.rs +++ b/xtask/src/installer/uninstall.rs @@ -1,6 +1,6 @@ use anyhow::Context; use std::fs; -use tracing::warn; +use log::warn; use crate::util::{files_are_equal, toggle_lock_config, ImmutableLock, ROOTASROLE}; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b3c54cf..7222e8f 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -6,8 +6,7 @@ pub mod util; use std::process::exit; use clap::Parser; -use tracing::{error, Level}; -use tracing_subscriber::util::SubscriberInitExt; +use log::error; use util::OsTarget; #[derive(Debug, Parser)] @@ -34,19 +33,9 @@ enum Command { #[cfg(feature = "deploy")] Deploy(deploy::MakeOptions), } -fn subsribe() { - use std::io; - tracing_subscriber::fmt() - .with_max_level(Level::DEBUG) - .with_file(true) - .with_line_number(true) - .with_writer(io::stdout) - .finish() - .init(); -} fn main() { - subsribe(); + env_logger::builder().default_format().format_module_path(true).init(); let opts = Options::parse(); use Command::*; let ret = match opts.command { diff --git a/xtask/src/postinst.rs b/xtask/src/postinst.rs index 2a5f308..1ea24e4 100644 --- a/xtask/src/postinst.rs +++ b/xtask/src/postinst.rs @@ -1,7 +1,7 @@ use std::{env::args, fs::File, io::BufReader}; use configure::check_filesystem; -use tracing::warn; +use log::warn; use util::{OsTarget, SettingsFile, ROOTASROLE}; mod configure; diff --git a/xtask/src/util.rs b/xtask/src/util.rs index 22a43bd..f5ac188 100644 --- a/xtask/src/util.rs +++ b/xtask/src/util.rs @@ -14,7 +14,7 @@ use nix::libc::{FS_IOC_GETFLAGS, FS_IOC_SETFLAGS}; use serde::{Deserialize, Serialize}; use serde_json::Value; use strum::{Display, EnumIs, EnumIter}; -use tracing::debug; +use log::debug; #[derive(Debug, Clone, ValueEnum, EnumIs, EnumIter, Display, PartialEq, Eq, Hash)] #[clap(rename_all = "lowercase")]