Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dgw): dynamically load XMF native lib on startup #939

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion devolutions-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ utoipa = { version = "4.2", default-features = false, features = ["uuid", "time"
# Safe pin projection
pin-project-lite = "0.2"

# Native plugins
# Native plugins (QUESTION: now that we have Cadeau integrated, should we remove this feature?)
dlopen = "0.1"
dlopen_derive = "0.1"

# Video processing for session recording
cadeau = { version = "0.3", features = ["dlopen"] }

# Dependencies required for PCAP support (QUESTION: should we keep that built-in?)
pcap-file = "2.0"
etherparse = "0.15"
Expand Down
4 changes: 4 additions & 0 deletions devolutions-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,9 @@ pub mod dto {
/// Providing this option will cause the PCAP interceptor to be attached to each stream.
pub capture_path: Option<Utf8PathBuf>,

/// Path to the XMF shared library (Cadeau) for runtime loading.
pub lib_xmf_path: Option<Utf8PathBuf>,

/// Enable unstable API which may break at any point
#[serde(default)]
pub enable_unstable: bool,
Expand All @@ -1095,6 +1098,7 @@ pub mod dto {
override_kdc: None,
log_directives: None,
capture_path: None,
lib_xmf_path: None,
enable_unstable: false,
}
}
Expand Down
33 changes: 33 additions & 0 deletions devolutions-gateway/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Context as _;
use camino::Utf8PathBuf;
use devolutions_gateway::config::{Conf, ConfHandle};
use devolutions_gateway::listener::GatewayListener;
use devolutions_gateway::log::GatewayLog;
Expand Down Expand Up @@ -70,6 +71,38 @@ impl GatewayService {
warn!("Anomality detected with TLS configuration: {e:#}");
}

let xmf_lib_path;
let xmf_lib_path = if let Some(path) = conf.debug.lib_xmf_path.as_deref() {
Some(path)
} else if cfg!(target_os = "windows") {
if let Ok(mut exe_path) = std::env::current_exe() {
exe_path.pop();
exe_path.push("xmf.dll");
xmf_lib_path = Utf8PathBuf::from_path_buf(exe_path).ok();
xmf_lib_path.as_deref()
} else {
None
}
} else if cfg!(target_os = "linux") {
xmf_lib_path = Some(Utf8PathBuf::from("/usr/lib/libxmf.so"));
xmf_lib_path.as_deref()
} else {
None
};

if let Some(path) = xmf_lib_path {
// SAFETY: No initialisation or termination routine in the XMF library we should worry about for preconditions.
let result = unsafe { cadeau::xmf::init(path.as_str()) };

match result {
Ok(_) => info!("XMF native library loaded and installed"),
Err(error) => warn!(
%error,
"Failed to load XMF native library, video processing features are disabled"
),
}
}

Ok(GatewayService {
conf_handle,
state: GatewayState::Stopped,
Expand Down