mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
25 lines
856 B
Rust
25 lines
856 B
Rust
use gpapi::service::request::ConnectArgs;
|
|
use openconnect::{Vpn, VpnBuilder};
|
|
use std::sync::Mutex;
|
|
const RECOVERY_KEY: &str = r"SOFTWARE\GP Connect\NetworkRecovery";
|
|
|
|
pub(crate) fn recover_network() -> std::io::Result<()> {
|
|
gpvpnc::windows::recover(RECOVERY_KEY)
|
|
}
|
|
|
|
pub(crate) fn builder(server: &str, cookie: &str, args: &ConnectArgs) -> anyhow::Result<VpnBuilder> {
|
|
anyhow::ensure!(
|
|
args.vpnc_script().is_none(),
|
|
"Windows does not support custom VPN scripts"
|
|
);
|
|
let network = Mutex::new(gpvpnc::windows::NetworkConfigurator::new(RECOVERY_KEY)?);
|
|
Ok(
|
|
Vpn::builder(server, cookie).network_configuration_handler(move |configuration| {
|
|
network
|
|
.lock()
|
|
.map_err(|_| std::io::Error::other("Windows network state is unavailable"))?
|
|
.configure(&configuration.reason, &configuration.environment)
|
|
}),
|
|
)
|
|
}
|