mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
feat: install trusted VPN scripts
This commit is contained in:
23 files changed
+454
-11
No files matched your search
@@ -0,0 +1,6 @@
|
||||
use gpapi::service::request::ConnectArgs;
|
||||
use openconnect::{Vpn, VpnBuilder};
|
||||
|
||||
pub(crate) fn builder(server: &str, cookie: &str, args: &ConnectArgs) -> anyhow::Result<VpnBuilder> {
|
||||
Ok(Vpn::builder(server, cookie).script_path(args.vpnc_script()))
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||
#[path = "privileged_unix.rs"]
|
||||
mod platform;
|
||||
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")))]
|
||||
#[path = "default.rs"]
|
||||
mod platform;
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", test))]
|
||||
mod selection;
|
||||
|
||||
pub(crate) use platform::builder;
|
||||
@@ -0,0 +1,15 @@
|
||||
use gpapi::service::request::ConnectArgs;
|
||||
use openconnect::{Vpn, VpnBuilder};
|
||||
|
||||
use super::selection::{ScriptSource, select};
|
||||
|
||||
pub(crate) fn builder(server: &str, cookie: &str, args: &ConnectArgs) -> anyhow::Result<VpnBuilder> {
|
||||
let installed = gpservice::vpnc_script::installed_script()?;
|
||||
match select(installed.as_deref(), args.vpnc_script()) {
|
||||
ScriptSource::Installed(path) => {
|
||||
Ok(Vpn::builder(server, cookie).script_path(Some(path.to_string_lossy().into_owned())))
|
||||
}
|
||||
ScriptSource::Legacy(script) => Ok(Vpn::builder(server, cookie).script(Some(script.to_owned()))),
|
||||
ScriptSource::Default => Ok(Vpn::builder(server, cookie).script_path(None)),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(super) enum ScriptSource<'a> {
|
||||
Installed(&'a Path),
|
||||
Legacy(&'a str),
|
||||
Default,
|
||||
}
|
||||
|
||||
pub(super) fn select<'a>(installed: Option<&'a Path>, legacy: Option<&'a str>) -> ScriptSource<'a> {
|
||||
if let Some(path) = installed {
|
||||
return ScriptSource::Installed(path);
|
||||
}
|
||||
if let Some(script) = legacy {
|
||||
return ScriptSource::Legacy(script);
|
||||
}
|
||||
ScriptSource::Default
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn installed_script_takes_precedence_over_legacy() {
|
||||
let installed = Path::new("/var/lib/gpclient/scripts/vpnc-script");
|
||||
assert_eq!(
|
||||
select(Some(installed), Some("legacy-command")),
|
||||
ScriptSource::Installed(installed)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_script_is_used_before_default() {
|
||||
assert_eq!(
|
||||
select(None, Some("legacy-command")),
|
||||
ScriptSource::Legacy("legacy-command")
|
||||
);
|
||||
assert_eq!(select(None, None), ScriptSource::Default);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user