mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
feat: expose openconnect connection options
This commit is contained in:
7 files changed
+93
-6
No files matched your search
@@ -15,6 +15,7 @@ pub(crate) struct ConnectOptions {
|
||||
pub os: *const c_char,
|
||||
pub os_version: *const c_char,
|
||||
pub client_version: *const c_char,
|
||||
pub local_hostname: *const c_char,
|
||||
|
||||
pub script: *const c_char,
|
||||
pub interface: *const c_char,
|
||||
@@ -34,6 +35,7 @@ pub(crate) struct ConnectOptions {
|
||||
pub no_dtls: u32,
|
||||
|
||||
pub dpd_interval: u32,
|
||||
pub no_xmlpost: u32,
|
||||
}
|
||||
|
||||
#[link(name = "vpn")]
|
||||
|
||||
@@ -60,6 +60,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
{
|
||||
struct openconnect_info *vpninfo;
|
||||
struct utsname utsbuf;
|
||||
const char *effective_local_hostname = NULL;
|
||||
|
||||
g_user_data = options->user_data;
|
||||
g_vpnc_script = options->script;
|
||||
@@ -79,6 +80,7 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
INFO("DISABLE_IPV6: %d", options->disable_ipv6);
|
||||
INFO("NO_DTLS: %d", options->no_dtls);
|
||||
INFO("DPD_INTERVAL: %d", options->dpd_interval);
|
||||
INFO("NO_XMLPOST: %d", options->no_xmlpost);
|
||||
|
||||
vpninfo =
|
||||
openconnect_vpninfo_new(options->user_agent, validate_peer_cert,
|
||||
@@ -109,6 +111,17 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
options->client_version);
|
||||
}
|
||||
|
||||
effective_local_hostname = options->local_hostname;
|
||||
if (!effective_local_hostname && !uname(&utsbuf)) {
|
||||
effective_local_hostname = utsbuf.nodename;
|
||||
}
|
||||
if (effective_local_hostname) {
|
||||
openconnect_set_localname(vpninfo, effective_local_hostname);
|
||||
}
|
||||
|
||||
INFO("LOCAL_HOSTNAME: %s",
|
||||
effective_local_hostname ? effective_local_hostname : "(not set)");
|
||||
|
||||
if (options->certificate) {
|
||||
INFO("Setting client certificate: %s", options->certificate);
|
||||
openconnect_set_client_cert(vpninfo, options->certificate,
|
||||
@@ -119,6 +132,10 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
openconnect_set_key_password(vpninfo, options->key_password);
|
||||
}
|
||||
|
||||
if (options->no_xmlpost) {
|
||||
openconnect_set_xmlpost(vpninfo, 0);
|
||||
}
|
||||
|
||||
if (options->csd_wrapper) {
|
||||
openconnect_setup_csd(vpninfo, options->csd_uid, 1,
|
||||
options->csd_wrapper);
|
||||
@@ -143,10 +160,6 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!uname(&utsbuf)) {
|
||||
openconnect_set_localname(vpninfo, utsbuf.nodename);
|
||||
}
|
||||
|
||||
// Essential step
|
||||
if (openconnect_make_cstp_connection(vpninfo) != 0) {
|
||||
ERROR("openconnect_make_cstp_connection failed");
|
||||
|
||||
@@ -15,6 +15,7 @@ typedef struct vpn_options {
|
||||
const char *os;
|
||||
const char *os_version;
|
||||
const char *client_version;
|
||||
const char *local_hostname;
|
||||
|
||||
const char *script;
|
||||
const char *interface;
|
||||
@@ -34,6 +35,7 @@ typedef struct vpn_options {
|
||||
const int no_dtls;
|
||||
|
||||
const int dpd_interval;
|
||||
const int no_xmlpost;
|
||||
} vpn_options;
|
||||
|
||||
int vpn_connect(const vpn_options *options, vpn_connected_callback callback);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
ffi::{c_char, CString},
|
||||
ffi::{CString, c_char},
|
||||
fmt,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
@@ -19,6 +19,7 @@ pub struct Vpn {
|
||||
os: CString,
|
||||
os_version: Option<CString>,
|
||||
client_version: Option<CString>,
|
||||
local_hostname: Option<CString>,
|
||||
|
||||
script: CString,
|
||||
interface: Option<CString>,
|
||||
@@ -38,6 +39,7 @@ pub struct Vpn {
|
||||
no_dtls: bool,
|
||||
|
||||
dpd_interval: u32,
|
||||
no_xmlpost: bool,
|
||||
|
||||
callback: OnConnectedCallback,
|
||||
}
|
||||
@@ -77,6 +79,7 @@ impl Vpn {
|
||||
os: self.os.as_ptr(),
|
||||
os_version: Self::option_to_ptr(&self.os_version),
|
||||
client_version: Self::option_to_ptr(&self.client_version),
|
||||
local_hostname: Self::option_to_ptr(&self.local_hostname),
|
||||
|
||||
script: self.script.as_ptr(),
|
||||
interface: Self::option_to_ptr(&self.interface),
|
||||
@@ -95,6 +98,7 @@ impl Vpn {
|
||||
disable_ipv6: self.disable_ipv6 as u32,
|
||||
no_dtls: self.no_dtls as u32,
|
||||
dpd_interval: self.dpd_interval,
|
||||
no_xmlpost: self.no_xmlpost as u32,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +140,7 @@ pub struct VpnBuilder {
|
||||
os: Option<String>,
|
||||
os_version: Option<String>,
|
||||
client_version: Option<String>,
|
||||
local_hostname: Option<String>,
|
||||
|
||||
certificate: Option<String>,
|
||||
sslkey: Option<String>,
|
||||
@@ -151,6 +156,7 @@ pub struct VpnBuilder {
|
||||
no_dtls: bool,
|
||||
|
||||
dpd_interval: u32,
|
||||
no_xmlpost: bool,
|
||||
}
|
||||
|
||||
impl VpnBuilder {
|
||||
@@ -166,6 +172,7 @@ impl VpnBuilder {
|
||||
os: None,
|
||||
os_version: None,
|
||||
client_version: None,
|
||||
local_hostname: None,
|
||||
|
||||
certificate: None,
|
||||
sslkey: None,
|
||||
@@ -180,6 +187,7 @@ impl VpnBuilder {
|
||||
disable_ipv6: false,
|
||||
no_dtls: false,
|
||||
dpd_interval: 0,
|
||||
no_xmlpost: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +226,11 @@ impl VpnBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn local_hostname<T: Into<Option<String>>>(mut self, local_hostname: T) -> Self {
|
||||
self.local_hostname = local_hostname.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn certificate<T: Into<Option<String>>>(mut self, certificate: T) -> Self {
|
||||
self.certificate = certificate.into();
|
||||
self
|
||||
@@ -273,6 +286,11 @@ impl VpnBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn no_xmlpost(mut self, no_xmlpost: bool) -> Self {
|
||||
self.no_xmlpost = no_xmlpost;
|
||||
self
|
||||
}
|
||||
|
||||
fn determine_script(&self) -> Result<&str, VpnError> {
|
||||
match &self.script {
|
||||
Some(script) => {
|
||||
@@ -315,6 +333,7 @@ impl VpnBuilder {
|
||||
os: Self::to_cstring(&os),
|
||||
os_version: self.os_version.as_deref().map(Self::to_cstring),
|
||||
client_version: self.client_version.as_deref().map(Self::to_cstring),
|
||||
local_hostname: self.local_hostname.as_deref().map(Self::to_cstring),
|
||||
|
||||
script: Self::to_cstring(&script),
|
||||
interface: self.interface.as_deref().map(Self::to_cstring),
|
||||
@@ -333,6 +352,7 @@ impl VpnBuilder {
|
||||
disable_ipv6: self.disable_ipv6,
|
||||
no_dtls: self.no_dtls,
|
||||
dpd_interval: self.dpd_interval,
|
||||
no_xmlpost: self.no_xmlpost,
|
||||
|
||||
callback: Default::default(),
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user