use std::net::Ipv4Addr; use sparse_actions::{ adapter::{BeaconAdapter, BeaconInterface, BeaconNetworkingInfo, BeaconRoute}, error, }; #[derive(thiserror::Error, Debug)] pub enum FreeBsdAdapterError {} impl sparse_actions::error::AdapterError for FreeBsdAdapterError {} #[derive(Clone)] pub struct FreeBsdAdapter; #[async_trait::async_trait] impl BeaconAdapter for FreeBsdAdapter { type Error = FreeBsdAdapterError; const OPERATING_SYSTEM: &'static str = "Windows"; fn interface_name_from_interface(interface: &BeaconInterface) -> Vec { interface.name.clone() } fn networking_info(&self) -> Result> { Ok(BeaconNetworkingInfo { routes: vec![], interfaces: vec![], }) } async fn get_username(&self) -> Result> { let passwd = tokio::fs::read_to_string("/etc/passwd").await?; let uid = unsafe { libc::getuid() }; Ok(passwd .split("\n") .find_map(|row| -> Option { let mut entries = row.split(":"); let name = entries.next()?; entries.next()?; let euid = entries.next()?.parse::().ok()?; if euid == uid { Some(name.to_string()) } else { None } }) .unwrap_or("(unknown)".to_string())) } async fn get_hostname(&self) -> Result> { Ok(tokio::fs::read_to_string("/etc/rc.conf") .await? .split("\n") .map(|line| line.split("=").collect::>()) .find(|line| line.get(0) == Some(&"hostname")) .map(|line| line.get(1).map(|name| name.to_string())) .flatten() .unwrap_or("(unknown)".to_string())) } }